From 74b2954e6a11b1b9396777c5371a653ababe9a77 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Mon, 10 Feb 2025 17:13:34 +1100 Subject: [PATCH] Handle leading zeros in SGR escape sequences (#1912) --- colors.go | 4 ++-- colors_test.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/colors.go b/colors.go index 69c5bb14..54e5b21b 100644 --- a/colors.go +++ b/colors.go @@ -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) diff --git a/colors_test.go b/colors_test.go index e7e62e17..8085ce13 100644 --- a/colors_test.go +++ b/colors_test.go @@ -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)},