aboutsummaryrefslogtreecommitdiff
path: root/internal/game/table.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-16 23:37:50 -0400
committerhistoria <[not public]>2026-06-16 23:37:50 -0400
commit389e307f205f9b7edf604fb9f86e1038ead736ef (patch)
tree595095b5877cc2b0513d31fb126303d8796cc311 /internal/game/table.go
parent085e728d22a3369bd110b77409914cfbe9ebe611 (diff)
downloadthehouseoficarus-389e307f205f9b7edf604fb9f86e1038ead736ef.tar.gz
feat: major xterm256 color overhaul, see worldbuilding docs.
Diffstat (limited to 'internal/game/table.go')
-rw-r--r--internal/game/table.go18
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
}