Handle leading zeros in SGR escape sequences (#1912)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-02-10 17:13:34 +11:00
1 parent 7797ad695f
commit 74b2954e6a
2 files changed
+5 -2

No files matched your search

+2 -2
View File
@@ -103,8 +103,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
// Probably because this is used for previewers too
tokslen := len(toks)
for i := 0; i < tokslen; i++ {
switch toks[i] {
case "", "0":
switch strings.TrimLeft(toks[i], "0") {
case "":
st = tcell.StyleDefault
case "1":
st = st.Bold(true)
+3
View File
@@ -53,6 +53,9 @@ func TestApplyAnsiCodes(t *testing.T) {
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"01;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"01;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
{"38;5;8", none, none.Foreground(tcell.ColorGray)},