# HG changeset patch # User telesto # Date 1513892287 -3600 # Thu Dec 21 22:38:07 2017 +0100 # Node ID 7f3e7e4c8e2e5d509081498c6e21b8f25e0cb6ca # Parent dede6902c4af6efbd39c35525fbb6f09b408b42d implement CellBuffer.cell, which gives a cell for x,y. this is used several times diff --git a/cellbuffer.go b/cellbuffer.go --- a/cellbuffer.go +++ b/cellbuffer.go @@ -52,8 +52,6 @@ // 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 @@ } } + c := cb.cell(x, y) if c.currMain != mainc { c.width = runewidth.RuneWidth(mainc) } @@ -80,7 +79,7 @@ // 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 @@ } } +// 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 @@ // 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 @@ // 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 @@ 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