From 7cd324fe2638a99c4fc1853782bcdc838eacf8a2 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jun 2024 21:45:40 +0200 Subject: [PATCH] ui/table: avoid duplicate table cell width calculation --- internal/ui/table/table.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/ui/table/table.go b/internal/ui/table/table.go index 0423ddb48..1c535cadb 100644 --- a/internal/ui/table/table.go +++ b/internal/ui/table/table.go @@ -141,16 +141,18 @@ func (t *Table) Write(w io.Writer) error { columnWidths := make([]int, columns) for i, desc := range t.columns { for _, line := range strings.Split(desc, "\n") { - if columnWidths[i] < ui.TerminalDisplayWidth(line) { - columnWidths[i] = ui.TerminalDisplayWidth(line) + width := ui.TerminalDisplayWidth(line) + if columnWidths[i] < width { + columnWidths[i] = width } } } for _, line := range lines { for i, content := range line { for _, l := range strings.Split(content, "\n") { - if columnWidths[i] < ui.TerminalDisplayWidth(l) { - columnWidths[i] = ui.TerminalDisplayWidth(l) + width := ui.TerminalDisplayWidth(l) + if columnWidths[i] < width { + columnWidths[i] = width } } }