diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/ui | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/ui')
| -rw-r--r-- | internal/ui/table.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/internal/ui/table.go b/internal/ui/table.go index 437c445..a1800ba 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -45,6 +45,17 @@ func FitWidths(colWidths []int, budget int) { rebalanceWidths(colWidths, budget) } +// TableBudget returns the total cell width available to nCols columns in a +// table rendered at maxWidth. Callers that pre-wrap cells must use this so +// their shrink target matches Render's padding/separator arithmetic. +func TableBudget(nCols, maxWidth int) int { + budget := maxWidth - (3*nCols + 1) + if budget < nCols { + budget = nCols + } + return budget +} + // rebalanceWidths shrinks column widths in place so their sum fits budget. // Rather than crushing only the last column, every column wider than the // fair share (budget/nCols) is capped first, then columns are trimmed one @@ -52,6 +63,9 @@ func FitWidths(colWidths []int, budget int) { // handed back round-robin to columns that lost width so wide layouts still // use the full line. func rebalanceWidths(colWidths []int, budget int) { + if len(colWidths) == 0 { + return + } original := make([]int, len(colWidths)) copy(original, colWidths) @@ -138,13 +152,7 @@ func (t *Table) Render(unicode bool, maxWidth int) []string { bodyRows := t.Rows if maxWidth > 0 { - // Cell padding: one space on each side of every cell, plus one - // separator between columns. - overhead := 3*nCols + 1 - budget := maxWidth - overhead - if budget < nCols { - budget = nCols - } + budget := TableBudget(nCols, maxWidth) total := 0 for _, w := range colWidths { |
