From edd3e214c2337ae69758c46506a1e94c81b67d68 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jun 2024 21:44:49 +0200 Subject: [PATCH] ui/table: fix width calculation of multi-line column headers --- internal/ui/table/table.go | 2 +- internal/ui/table/table_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/ui/table/table.go b/internal/ui/table/table.go index ae09063be..0423ddb48 100644 --- a/internal/ui/table/table.go +++ b/internal/ui/table/table.go @@ -142,7 +142,7 @@ func (t *Table) Write(w io.Writer) error { for i, desc := range t.columns { for _, line := range strings.Split(desc, "\n") { if columnWidths[i] < ui.TerminalDisplayWidth(line) { - columnWidths[i] = ui.TerminalDisplayWidth(desc) + columnWidths[i] = ui.TerminalDisplayWidth(line) } } } diff --git a/internal/ui/table/table_test.go b/internal/ui/table/table_test.go index 7a94b7f9b..2902860b9 100644 --- a/internal/ui/table/table_test.go +++ b/internal/ui/table/table_test.go @@ -29,6 +29,21 @@ first column ---------------------- data: first data field ---------------------- +`, + }, + { + func(t testing.TB) *Table { + table := New() + table.AddColumn("first\ncolumn", "{{.First}}") + table.AddRow(struct{ First string }{"data"}) + return table + }, + ` +first +column +------ +data +------ `, }, {