diff options
Diffstat (limited to 'internal/game/table.go')
| -rw-r--r-- | internal/game/table.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/internal/game/table.go b/internal/game/table.go index 56c0079..b96dca1 100644 --- a/internal/game/table.go +++ b/internal/game/table.go @@ -1,8 +1,9 @@ package game import ( - "fmt" "strings" + + "thehouseoficarus/internal/color" ) type tableGlyphs struct { @@ -50,15 +51,16 @@ func (t *Table) Render(unicode bool) []string { colWidths := make([]int, nCols) for i, h := range t.Columns { - colWidths[i] = len(h) + colWidths[i] = color.VisibleLen(h) } for _, row := range t.Rows { for i, cell := range row { if i >= nCols { break } - if len(cell) > colWidths[i] { - colWidths[i] = len(cell) + vl := color.VisibleLen(cell) + if vl > colWidths[i] { + colWidths[i] = vl } } } @@ -87,7 +89,11 @@ func (t *Table) Render(unicode bool) []string { if i < len(cells) { cell = cells[i] } - b.WriteString(fmt.Sprintf(" %-*s ", colWidths[i], cell)) + pad := colWidths[i] - color.VisibleLen(cell) + if pad < 0 { + pad = 0 + } + b.WriteString(" " + cell + strings.Repeat(" ", pad) + " ") } b.WriteRune(g.side) return b.String() @@ -115,7 +121,7 @@ func (t *Table) Render(unicode bool) []string { tr.WriteRune(g.side) tr.WriteString(" ") tr.WriteString(t.Title) - padding := innerWidth - 2 - len(t.Title) + padding := innerWidth - 2 - color.VisibleLen(t.Title) if padding < 0 { padding = 0 } |
