From c0cb67cada0977b41c8e1315afeaf04e4331c2d7 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 11:29:19 +0000 Subject: [PATCH] fix(cli): render glyph shortcodes in tables Co-Authored-By: Virgil --- pkg/cli/styles.go | 12 ++++++------ pkg/cli/styles_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/cli/styles.go b/pkg/cli/styles.go index 1e281d8..921018a 100644 --- a/pkg/cli/styles.go +++ b/pkg/cli/styles.go @@ -291,14 +291,14 @@ func (t *Table) columnWidths() []int { widths := make([]int, cols) for i, h := range t.Headers { - if w := displayWidth(h); w > widths[i] { + if w := displayWidth(compileGlyphs(h)); w > widths[i] { widths[i] = w } } for _, row := range t.Rows { for i, cell := range row { if i < cols { - if w := displayWidth(cell); w > widths[i] { + if w := displayWidth(compileGlyphs(cell)); w > widths[i] { widths[i] = w } } @@ -367,7 +367,7 @@ func (t *Table) renderPlain() string { if i > 0 { sb.WriteString(sep) } - cell := Pad(Truncate(h, widths[i]), widths[i]) + cell := Pad(Truncate(compileGlyphs(h), widths[i]), widths[i]) if t.Style.HeaderStyle != nil { cell = t.Style.HeaderStyle.Render(cell) } @@ -385,7 +385,7 @@ func (t *Table) renderPlain() string { if i < len(row) { val = row[i] } - cell := Pad(Truncate(val, widths[i]), widths[i]) + cell := Pad(Truncate(compileGlyphs(val), widths[i]), widths[i]) if style := t.resolveStyle(i, val); style != nil { cell = style.Render(cell) } @@ -423,7 +423,7 @@ func (t *Table) renderBordered() string { if i < len(t.Headers) { h = t.Headers[i] } - cell := Pad(Truncate(h, widths[i]), widths[i]) + cell := Pad(Truncate(compileGlyphs(h), widths[i]), widths[i]) if t.Style.HeaderStyle != nil { cell = t.Style.HeaderStyle.Render(cell) } @@ -454,7 +454,7 @@ func (t *Table) renderBordered() string { if i < len(row) { val = row[i] } - cell := Pad(Truncate(val, widths[i]), widths[i]) + cell := Pad(Truncate(compileGlyphs(val), widths[i]), widths[i]) if style := t.resolveStyle(i, val); style != nil { cell = style.Render(cell) } diff --git a/pkg/cli/styles_test.go b/pkg/cli/styles_test.go index b127a59..3b3fe17 100644 --- a/pkg/cli/styles_test.go +++ b/pkg/cli/styles_test.go @@ -146,6 +146,19 @@ func TestTable_Good(t *testing.T) { assert.Contains(t, out, "ok") }) + t.Run("glyph shortcodes render in headers and cells", func(t *testing.T) { + restoreThemeAndColors(t) + UseASCII() + + tbl := NewTable(":check: NAME", "STATUS"). + WithBorders(BorderRounded) + tbl.AddRow("core", ":warn:") + + out := tbl.String() + assert.Contains(t, out, "[OK] NAME") + assert.Contains(t, out, "[WARN]") + }) + t.Run("max width truncates", func(t *testing.T) { SetColorEnabled(false) defer SetColorEnabled(true) -- 2.45.3