feat(cli): add ASCII table borders
All checks were successful
Security Scan / security (push) Successful in 23s

This commit is contained in:
Virgil 2026-04-02 05:26:20 +00:00
parent 8b30e80688
commit 323f408601
2 changed files with 36 additions and 1 deletions

View file

@ -174,6 +174,13 @@ var borderSets = map[BorderStyle]borderSet{
BorderDouble: {"╔", "╗", "╚", "╝", "═", "║", "╦", "╩", "╠", "╣", "╬"},
}
var borderSetsASCII = map[BorderStyle]borderSet{
BorderNormal: {"+", "+", "+", "+", "-", "|", "+", "+", "+", "+", "+"},
BorderRounded: {"+", "+", "+", "+", "-", "|", "+", "+", "+", "+", "+"},
BorderHeavy: {"+", "+", "+", "+", "=", "|", "+", "+", "+", "+", "+"},
BorderDouble: {"+", "+", "+", "+", "=", "|", "+", "+", "+", "+", "+"},
}
// CellStyleFn returns a style based on the cell's raw value.
// Return nil to use the table's default CellStyle.
type CellStyleFn func(value string) *AnsiStyle
@ -391,7 +398,7 @@ func (t *Table) renderPlain() string {
}
func (t *Table) renderBordered() string {
b := borderSets[t.borders]
b := tableBorderSet(t.borders)
widths := t.columnWidths()
cols := t.colCount()
@ -472,3 +479,15 @@ func (t *Table) renderBordered() string {
return sb.String()
}
func tableBorderSet(style BorderStyle) borderSet {
if currentTheme == ThemeASCII {
if b, ok := borderSetsASCII[style]; ok {
return b
}
}
if b, ok := borderSets[style]; ok {
return b
}
return borderSet{}
}

View file

@ -81,6 +81,22 @@ func TestTable_Good(t *testing.T) {
assert.Contains(t, out, "║")
})
t.Run("ASCII theme uses ASCII borders", func(t *testing.T) {
restoreThemeAndColors(t)
UseASCII()
tbl := NewTable("REPO", "STATUS").WithBorders(BorderRounded)
tbl.AddRow("core", "clean")
out := tbl.String()
assert.Contains(t, out, "+")
assert.Contains(t, out, "-")
assert.Contains(t, out, "|")
assert.NotContains(t, out, "╭")
assert.NotContains(t, out, "╮")
assert.NotContains(t, out, "│")
})
t.Run("bordered structure", func(t *testing.T) {
SetColorEnabled(false)
defer SetColorEnabled(true)