Repository: JanDeDobbeleer/oh-my-posh
Pull request #3322 (2023-01-06 09:56:41)

fix writer
### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md]
- [x] The commit message follows the [conventional commits][cc] guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [x] Docs have been added/updated (for bug fixes/features)

### Description

- chore: remove local debug setting
- fix(ansi): do not print clear colors

<!---

Tips:

If you're not comfortable with working with Git, we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[CONTRIBUTING.md]: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/CONTRIBUTING.md
[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 0303647b..215face5 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -13,8 +13,6 @@
         "primary",
         "--shell=pwsh",
         "--terminal-width=200",
-        "--execution-time=600",
-        "--config=/Users/jan/.posh.omp.json"
       ]
     },
     {
diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go
index 6eb921f7..d1a3207f 100644
--- a/src/ansi/ansi_writer.go
+++ b/src/ansi/ansi_writer.go
@@ -403,15 +403,23 @@ func (w *Writer) writeColorOverrides(match map[string]string, background string,
 		if position == len(w.runes)-1 {
 			return
 		}
-		if w.currentBackground != w.background || w.transparent {
-			if w.transparent {
-				w.writeEscapedAnsiString(transparentEnd)
-			}
+
+		if w.transparent {
+			w.writeEscapedAnsiString(transparentEnd)
+		}
+
+		if w.background.IsClear() {
+			w.writeEscapedAnsiString(colorStyle.End)
+		}
+
+		if w.currentBackground != w.background && !w.background.IsClear() {
 			w.writeEscapedAnsiString(fmt.Sprintf(colorise, w.background))
 		}
-		if w.currentForeground != w.foreground || w.transparent {
+
+		if (w.currentForeground != w.foreground || w.transparent) && !w.foreground.IsClear() {
 			w.writeEscapedAnsiString(fmt.Sprintf(colorise, w.foreground))
 		}
+
 		w.transparent = false
 		return
 	}
diff --git a/src/ansi/colors.go b/src/ansi/colors.go
index 56e11b46..120b4bd7 100644
--- a/src/ansi/colors.go
+++ b/src/ansi/colors.go
@@ -36,6 +36,10 @@ func (c Color) IsTransparent() bool {
 	return c == transparentColor
 }
 
+func (c Color) IsClear() bool {
+	return c == transparentColor || c == emptyColor
+}
+
 func (c Color) ToForeground() Color {
 	colorString := string(c)
 	if strings.HasPrefix(colorString, "38;") {


Test patch:
diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go
index afc2a241..ce171cd8 100644
--- a/src/ansi/ansi_writer_test.go
+++ b/src/ansi/ansi_writer_test.go
@@ -26,7 +26,7 @@ func TestWriteANSIColors(t *testing.T) {
 		{
 			Case:     "Bold with color override",
 			Input:    "<b><#ffffff>test</></b>",
-			Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[30m\x1b[22m\x1b[0m",
+			Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[0m\x1b[30m\x1b[22m\x1b[0m",
 			Colors:   &cachedColor{Foreground: "black", Background: ParentBackground},
 		},
 		{