1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-25 13:48:50 +08:00

Correctly handle setting cells to zero values.

This commit is contained in:
Jakub Sobon 2019-04-24 22:58:00 -04:00
parent c2f5326954
commit 88d4632adf
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
2 changed files with 17 additions and 0 deletions

View File

@ -115,6 +115,11 @@ func (b Buffer) SetCell(p image.Point, r rune, opts ...cell.Option) (int, error)
return -1, err
}
rw := runewidth.RuneWidth(r)
if rw == 0 {
// Even if the rune is invisible, like the zero-value rune, it still
// occupies at least the target cell.
rw = 1
}
if rw > remW {
return -1, fmt.Errorf("cannot set rune %q of width %d at point %v, only have %d remaining cells at this line", r, rw, p, remW)
}

View File

@ -411,6 +411,18 @@ func TestSetCell(t *testing.T) {
return b
}(),
},
{
desc: "sets zero-value rune in a cell",
buffer: mustNew(image.Point{3, 3}),
point: image.Point{1, 2},
r: 0,
wantCells: 1,
want: func() Buffer {
b := mustNew(size)
b[1][2].Rune = 0
return b
}(),
},
{
desc: "sets cell options",
buffer: mustNew(image.Point{3, 3}),