feat: extend SGR support (#2749)

* feat: support `SGR` color resets and double underline

* test: add cases to TestApplySGR
This commit is contained in:
CatsDeservePets authored and GitHub committed 2026-11-19 23:51:06 +01:00
1 parent d4b5b4647b
commit 8b8780299a
2 files changed
+11 -1

No files matched your search

+7 -1
View File
@@ -162,7 +162,7 @@ loop:
st = st.Underline(false)
case "4", "4:1":
st = st.Underline(true)
case "4:2":
case "4:2", "21":
st = st.Underline(tcell.UnderlineStyleDouble)
case "4:3":
st = st.Underline(tcell.UnderlineStyleCurly)
@@ -205,6 +205,8 @@ loop:
}
st = st.Foreground(color)
i += offset
case "39":
st = st.Foreground(tcell.ColorDefault)
case "40", "41", "42", "43", "44", "45", "46", "47":
n, _ := strconv.Atoi(toks[i])
st = st.Background(tcell.PaletteColor(n - 40))
@@ -219,6 +221,8 @@ loop:
}
st = st.Background(color)
i += offset
case "49":
st = st.Background(tcell.ColorDefault)
case "58":
color, offset, err := parseColor(toks[i+1:])
if err != nil {
@@ -227,6 +231,8 @@ loop:
}
st = st.Underline(color)
i += offset
case "59":
st = st.Underline(tcell.ColorDefault)
default:
log.Printf("unknown ANSI code: %s", toks[i])
}
+4
View File
@@ -230,6 +230,7 @@ func TestApplySGR(t *testing.T) {
{"4:0", none.Underline(true), none},
{"4:1", none, none.Underline(true)},
{"4:2", none, none.Underline(tcell.UnderlineStyleDouble)},
{"21", none, none.Underline(tcell.UnderlineStyleDouble)},
{"4:3", none, none.Underline(tcell.UnderlineStyleCurly)},
{"4:4", none, none.Underline(tcell.UnderlineStyleDotted)},
{"4:5", none, none.Underline(tcell.UnderlineStyleDashed)},
@@ -244,9 +245,11 @@ func TestApplySGR(t *testing.T) {
{"31", none, none.Foreground(color.Maroon)},
{"31", none.Foreground(color.Green), none.Foreground(color.Maroon)},
{"31", none.Foreground(color.Green).Bold(true), none.Foreground(color.Maroon).Bold(true)},
{"39", none.Foreground(color.Maroon).Bold(true), none.Bold(true)},
{"41", none, none.Background(color.Maroon)},
{"41", none.Background(color.Green), none.Background(color.Maroon)},
{"49", none.Background(color.Maroon).Bold(true), none.Bold(true)},
{"1;31", none, none.Foreground(color.Maroon).Bold(true)},
{"1;31", none.Foreground(color.Green), none.Foreground(color.Maroon).Bold(true)},
@@ -276,6 +279,7 @@ func TestApplySGR(t *testing.T) {
{"38;2;5;102;8", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
{"59", none.Underline(true, color.Maroon), none.Underline(true)},
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
{"38;5;34;1", none, none.Foreground(color.XTerm34).Bold(true)},