Example #1
0
// XXX: Currently only usable on main screen. Unbuffered needs some love later.
func ScrollWriteUpwards(panel *panel.Buffered, s string) {
	lines := strings.Split(s, "\n")
	buf := panel.Buffer()
	r := panel.Bounds()

	var (
		length     = r.Dx() * len(lines)
		START      = 0
		STARTLINES = START + length
		END        = len(buf)
		ENDLINES   = END - length
	)

	src := buf[STARTLINES:]
	target := buf[:ENDLINES]

	width := r.Dx()
	for i := 0; i < len(target); i += width {
		copy(target[i:i+width], src[i:i+width])
	}

	for i := 0; i < len(lines); i++ {
		clearRow(panel, r.Dy()-1-i)
	}

	targetr := panel.Area(image.Rect(0, r.Dy()-len(lines), width, r.Dy()))
	targetr.Write([]byte(s))
}