From 12ed73f9ff9de1a145683de8a73c170613371979 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 29 Jun 2026 01:41:49 -0400 Subject: wrap_width and table improvements, targeting 80 character default width --- internal/ui/table.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index 0ac41ad..5061417 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -38,7 +38,7 @@ type Table struct { Rows [][]string } -func (t *Table) Render(unicode bool) []string { +func (t *Table) Render(unicode bool, maxWidth int) []string { g := tableGlyphSet(unicode) nCols := len(t.Columns) @@ -65,6 +65,34 @@ func (t *Table) Render(unicode bool) []string { } } + if maxWidth > 0 { + overhead := 3*nCols + 1 + total := overhead + for _, w := range colWidths { + total += w + } + if total > maxWidth { + last := nCols - 1 + budget := maxWidth - overhead + for i := 0; i < last; i++ { + budget -= colWidths[i] + } + if budget < 5 { + budget = 5 + } + colWidths[last] = budget + + if len(t.Columns) > last { + t.Columns[last] = color.TruncateVisible(t.Columns[last], budget) + } + for i := range t.Rows { + if len(t.Rows[i]) > last { + t.Rows[i][last] = color.TruncateVisible(t.Rows[i][last], budget) + } + } + } + } + makeSep := func(left, cross, right rune, fill rune) string { var b strings.Builder b.WriteRune(left) -- cgit v1.2.3