mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix(table): use ansi.Truncate instead of runewidth.Truncate (#884)
`runewidth.Truncate` does not consider terminal escape characters - this means that if a table cell contains funky characters, then it will be incorrectly truncated. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@@ -288,6 +288,21 @@ func TestModel_RenderRow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModel_RenderRow_AnsiWidth(t *testing.T) {
|
||||
value := "\x1b[31mABCDEFGH\x1b[0m"
|
||||
table := &Model{
|
||||
rows: []Row{{value}},
|
||||
cols: []Column{{Title: "col1", Width: 8}},
|
||||
styles: Styles{Cell: lipgloss.NewStyle()},
|
||||
}
|
||||
|
||||
got := ansi.Strip(table.renderRow(0))
|
||||
want := "ABCDEFGH"
|
||||
if got != want {
|
||||
t.Fatalf("\n\nWant: \n%s\n\nGot: \n%s\n", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTableAlignment(t *testing.T) {
|
||||
t.Run("No border", func(t *testing.T) {
|
||||
biscuits := New(
|
||||
|
||||
Reference in New Issue
Block a user