diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go index c62b07e1..e56603a6 100644 --- a/src/ansi/ansi_writer.go +++ b/src/ansi/ansi_writer.go @@ -409,6 +409,12 @@ func (w *Writer) writeColorOverrides(match map[string]string, background string, if match[ANCHOR] == colorStyle.AnchorEnd { // make sure to reset the colors if needed position += len([]rune(colorStyle.AnchorEnd)) - 1 + + // do not reset when colors are identical + if w.currentBackground == w.background && w.currentForeground == w.foreground { + return + } + // do not restore colors at the end of the string, we print it anyways if position == len(w.runes)-1 { return diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go index 1eb1ba81..886374b0 100644 --- a/src/ansi/ansi_writer_test.go +++ b/src/ansi/ansi_writer_test.go @@ -17,6 +17,12 @@ func TestWriteANSIColors(t *testing.T) { Parent *Colors TerminalBackground string }{ + { + Case: "Inline override identical", + Input: "\ue0a0saturnay ↑1", + Expected: "\x1b[31m\ue0a0saturnay ↑1\x1b[0m", + Colors: &Colors{Foreground: "red", Background: Transparent}, + }, { Case: "Bold", Input: "test",