fix(cli): render glyph shortcodes in tables

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 11:29:19 +00:00
parent 07bea81d4a
commit c0cb67cada
2 changed files with 19 additions and 6 deletions

View file

@ -291,14 +291,14 @@ func (t *Table) columnWidths() []int {
widths := make([]int, cols) widths := make([]int, cols)
for i, h := range t.Headers { for i, h := range t.Headers {
if w := displayWidth(h); w > widths[i] { if w := displayWidth(compileGlyphs(h)); w > widths[i] {
widths[i] = w widths[i] = w
} }
} }
for _, row := range t.Rows { for _, row := range t.Rows {
for i, cell := range row { for i, cell := range row {
if i < cols { if i < cols {
if w := displayWidth(cell); w > widths[i] { if w := displayWidth(compileGlyphs(cell)); w > widths[i] {
widths[i] = w widths[i] = w
} }
} }
@ -367,7 +367,7 @@ func (t *Table) renderPlain() string {
if i > 0 { if i > 0 {
sb.WriteString(sep) 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 { if t.Style.HeaderStyle != nil {
cell = t.Style.HeaderStyle.Render(cell) cell = t.Style.HeaderStyle.Render(cell)
} }
@ -385,7 +385,7 @@ func (t *Table) renderPlain() string {
if i < len(row) { if i < len(row) {
val = row[i] 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 { if style := t.resolveStyle(i, val); style != nil {
cell = style.Render(cell) cell = style.Render(cell)
} }
@ -423,7 +423,7 @@ func (t *Table) renderBordered() string {
if i < len(t.Headers) { if i < len(t.Headers) {
h = t.Headers[i] 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 { if t.Style.HeaderStyle != nil {
cell = t.Style.HeaderStyle.Render(cell) cell = t.Style.HeaderStyle.Render(cell)
} }
@ -454,7 +454,7 @@ func (t *Table) renderBordered() string {
if i < len(row) { if i < len(row) {
val = row[i] 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 { if style := t.resolveStyle(i, val); style != nil {
cell = style.Render(cell) cell = style.Render(cell)
} }

View file

@ -146,6 +146,19 @@ func TestTable_Good(t *testing.T) {
assert.Contains(t, out, "ok") 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) { t.Run("max width truncates", func(t *testing.T) {
SetColorEnabled(false) SetColorEnabled(false)
defer SetColorEnabled(true) defer SetColorEnabled(true)