mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-30 13:48:54 +08:00
Correctly handle setting cells to zero values.
This commit is contained in:
parent
c2f5326954
commit
88d4632adf
@ -115,6 +115,11 @@ func (b Buffer) SetCell(p image.Point, r rune, opts ...cell.Option) (int, error)
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
rw := runewidth.RuneWidth(r)
|
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 {
|
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)
|
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)
|
||||||
}
|
}
|
||||||
|
@ -411,6 +411,18 @@ func TestSetCell(t *testing.T) {
|
|||||||
return b
|
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",
|
desc: "sets cell options",
|
||||||
buffer: mustNew(image.Point{3, 3}),
|
buffer: mustNew(image.Point{3, 3}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user