implement CellBuffer.cell, which gives a cell for x,y. this is used several times
1 files changed, 10 insertions(+), 6 deletions(-)

M cellbuffer.go
M cellbuffer.go +10 -6
@@ 52,8 52,6 @@ func (cb *CellBuffer) SetContent(x int, 
 		// todo: error?
 		return
 	}
-	c := &cb.cells[y*cb.w+x]
-
 	for i := 0; i < len(combc); i++ {
 		r := combc[i]
 		if runewidth.RuneWidth(r) != 0 {

          
@@ 63,6 61,7 @@ func (cb *CellBuffer) SetContent(x int, 
 		}
 	}
 
+	c := cb.cell(x, y)
 	if c.currMain != mainc {
 		c.width = runewidth.RuneWidth(mainc)
 	}

          
@@ 80,7 79,7 @@ func (cb *CellBuffer) GetContent(x, y in
 		// todo: error?
 		return mainc, combc, style, width
 	}
-	c := &cb.cells[(y*cb.w)+x]
+	c := cb.cell(x, y)
 	mainc, combc, style = c.currMain, c.currComb, c.currStyle
 	if width = c.width; width == 0 || mainc < ' ' {
 		width = 1

          
@@ 101,6 100,11 @@ func (cb *CellBuffer) Invalidate() {
 	}
 }
 
+// always guard a call ti cell with cb.isOutside
+func (cb *CellBuffer) cell(x, y int) *cell {
+	return &cb.cells[y*cb.w+x]
+}
+
 // Dirty checks if a character at the given location needs an
 // to be refreshed on the physical display.  This returns true
 // if the cell content is different since the last time it was

          
@@ 110,7 114,7 @@ func (cb *CellBuffer) Dirty(x, y int) bo
 		// todo: error?
 		return false
 	}
-	c := &cb.cells[(y*cb.w)+x]
+	c := cb.cell(x, y)
 	if c.lastMain == rune(0) {
 		return true
 	}

          
@@ 139,7 143,7 @@ func (cb *CellBuffer) SetDirty(x, y int,
 		// todo: error?
 		return
 	}
-	c := &cb.cells[(y*cb.w)+x]
+	c := cb.cell(x, y)
 	c.lastMain = rune(0)
 	if !dirty {
 		if c.currMain == rune(0) {

          
@@ 162,7 166,7 @@ func (cb *CellBuffer) Resize(w, h int) {
 	newc := make([]cell, w*h)
 	for y := 0; y < h && y < cb.h; y++ {
 		for x := 0; x < w && x < cb.w; x++ {
-			oc := &cb.cells[(y*cb.w)+x]
+			oc := cb.cell(x, y)
 			nc := &newc[(y*w)+x]
 			nc.currMain = oc.currMain
 			nc.currComb = oc.currComb