diff --git a/buffer.go b/buffer.go index 6425b0d..6b83501 100644 --- a/buffer.go +++ b/buffer.go @@ -30,9 +30,17 @@ func NewBuffer(width, height int) *Buffer { } } +func (b *Buffer) x(x int) int { + return limit(x, 0, b.width-1) +} + +func (b *Buffer) y(y int) int { + return limit(y, 0, b.height-1) +} + // Set sets the rune at position (x,y) to c func (b *Buffer) Set(x, y int, c rune) { - b.data[y][x] = c + b.data[b.y(y)][b.x(x)] = c } // Get returns the rune at position (x,y)