aboutsummaryrefslogtreecommitdiff
path: root/internal/ui/table.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-29 01:41:49 -0400
committerhistoria <[not public]>2026-06-29 01:41:49 -0400
commit12ed73f9ff9de1a145683de8a73c170613371979 (patch)
tree8b35d3dfda8231edcbc33e2fc2eb68000128e48c /internal/ui/table.go
parente9d87838590a02c7ca028fad8cd16e42a582dd32 (diff)
downloadthehouseoficarus-12ed73f9ff9de1a145683de8a73c170613371979.tar.gz
wrap_width and table improvements, targeting 80 character default width
Diffstat (limited to 'internal/ui/table.go')
-rw-r--r--internal/ui/table.go30
1 files changed, 29 insertions, 1 deletions
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)