fix(ansi): reset background when transparent

This commit is contained in:
Jan De Dobbeleer 2024-05-29 14:04:23 +02:00 committed by Jan De Dobbeleer
parent 517b7a6d57
commit 099f6cb6c3
2 changed files with 12 additions and 1 deletions

View file

@ -558,7 +558,12 @@ func (w *Writer) endColorOverride(position int) int {
}
if previousBg != bg {
w.writeEscapedAnsiString(fmt.Sprintf(colorise, previousBg))
background := fmt.Sprintf(colorise, previousBg)
if previousBg.IsClear() {
background = backgroundStyle.End
}
w.writeEscapedAnsiString(background)
}
if previousFg != fg {

View file

@ -212,6 +212,12 @@ func TestWriteANSIColors(t *testing.T) {
Expected: "\x1b[47m\x1b[31m<\x1b[30m>\x1b[33m<\x1b[0m",
Colors: &Colors{Foreground: "black", Background: "white"},
},
{
Case: "Transparent override with parent",
Input: "hello <#011627,#82AAFF>new</> world",
Expected: "\x1b[33mhello \x1b[48;2;130;170;255m\x1b[38;2;1;22;39mnew\x1b[49m\x1b[33m world\x1b[0m",
Colors: &Colors{Foreground: "yellow", Background: "transparent"},
},
}
for _, tc := range cases {