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 } } }