From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/ui/table.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'internal/ui/table.go') 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 { -- cgit v1.2.3