diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go index 13522a38..18eeeed0 100644 --- a/src/ansi/ansi_writer.go +++ b/src/ansi/ansi_writer.go @@ -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 { diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go index 7e1881b9..9e91f6bc 100644 --- a/src/ansi/ansi_writer_test.go +++ b/src/ansi/ansi_writer_test.go @@ -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 {