Ejemplo n.º 1
0
func FindStart(b *util.Buffer, w int, startl, starty int, tabw int) (line, char int) {
	line, char = startl, 0
	y := starty
	for line > 0 && y > 0 {
		line--
		l := b.Line(line)
		t := NewTabber(l, tabw)
		dy := t.VisLen/w + 1
		y -= dy
		char = 0
		if y < 0 && t.VisLen > w {
			char = t.XToCh[w*-1*y]
		}
	}
	return line, char
}
Ejemplo n.º 2
0
func printSurf(t *testing.T, surf Surface, tst viewtest, b *util.Buffer) {
	t.Log("")
	tabrep := strings.Repeat("\\t", tst.tabw)
	tabstr := "\\t" + strings.Repeat("--", tst.tabw-1)
	for y := 0; y < tst.h; y++ {
		got := ""
		expect := ""
		pretxt := "        "
		midtxt := "   "
		if y == 0 {
			pretxt = "expected"
			midtxt = "got"
		}
		for x := 0; x < tst.w; x++ {
			if r := surf.Rune(x, y); r == '\t' {
				got += "\\t"
			} else if r == '\n' {
				got += "\\n"
			} else {
				got += string(r) + " "
			}

			l, ch := tst.expectl[y][x], tst.expectch[y][x]
			if l == -1 || ch == -1 {
				expect += "  "
			} else if r := b.Rune(l, ch); r == '\t' {
				expect += "\\t"
			} else if r == '\n' {
				expect += "\\n"
			} else {
				expect += string(r) + " "
			}
		}
		expect = strings.Replace(expect, tabrep, tabstr, -1)
		got = strings.Replace(got, tabrep, tabstr, -1)
		t.Logf("\t%v   |%v|   %v   |%v|", pretxt, expect, midtxt, got)
	}
	t.Log("")
}
Ejemplo n.º 3
0
func (c *WrapSurf) init(w, h int, b *util.Buffer, startl, starty int, tabw int) {
	c.w, c.h = w, h
	c.b = b
	c.lines = PosMap{}
	c.chars = PosMap{}
	c.xs = PosMap{}
	c.ys = PosMap{}

	// figure out line+char for top left corner of canvas
	l, nextch := FindStart(b, w, startl, starty, tabw)

	// draw from start line and char down
	for y := 0; y < h; y++ {
		if c.xs[l] == nil {
			c.xs[l], c.ys[l] = map[int]int{}, map[int]int{}
		}
		if c.chars[y] == nil {
			c.chars[y], c.lines[y] = map[int]int{}, map[int]int{}
		}

		var line []rune
		if l < b.Nlines() {
			line = b.Line(l)
		}

		var chs []int
		chs, nextch = RenderLine(line, nextch, w, tabw)
		for x := 0; x < w; x++ {
			ch := chs[x]
			c.chars[y][x] = ch
			c.lines[y][x] = l
			if l >= b.Nlines() {
				c.lines[y][x] = -1
			}

			if _, ok := c.xs[l][ch]; !ok {
				c.xs[l][ch] = x
				c.ys[l][ch] = y
			}
		}

		if nextch >= len(line) { // if we drew entire line
			nextch = 0
			l++ // go to next line
		}
	}
}