Repository: JanDeDobbeleer/oh-my-posh
Pull request #3289 (2023-01-02 18:17:07)

refactor(ansi): do not allow plain GOOS override
### 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

<!--TemplateBody-->

<!---

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/src/cli/config_export_image.go b/src/cli/config_export_image.go
index 18de8ff0..71c966a9 100644
--- a/src/cli/config_export_image.go
+++ b/src/cli/config_export_image.go
@@ -59,7 +59,7 @@ Exports the config to an image file using customized output options.`,
 		defer env.Close()
 		cfg := engine.LoadConfig(env)
 		ansi := &color.Ansi{}
-		ansi.InitPlain("")
+		ansi.InitPlain()
 		writerColors := cfg.MakeColors()
 		writer := &color.AnsiWriter{
 			Ansi:               ansi,
diff --git a/src/cli/debug.go b/src/cli/debug.go
index d898eaec..4493e1c0 100644
--- a/src/cli/debug.go
+++ b/src/cli/debug.go
@@ -34,7 +34,7 @@ var debugCmd = &cobra.Command{
 		defer env.Close()
 		cfg := engine.LoadConfig(env)
 		ansi := &color.Ansi{}
-		ansi.InitPlain(env.GOOS())
+		ansi.InitPlain()
 		writerColors := cfg.MakeColors()
 		writer := &color.AnsiWriter{
 			Ansi:               ansi,
diff --git a/src/color/ansi.go b/src/color/ansi.go
index 9e28f2e7..d091c13c 100644
--- a/src/color/ansi.go
+++ b/src/color/ansi.go
@@ -148,8 +148,8 @@ func (a *Ansi) Init(shellName, goos string) {
 	}
 }
 
-func (a *Ansi) InitPlain(goos string) {
-	a.Init(shell.PLAIN, goos)
+func (a *Ansi) InitPlain() {
+	a.Init(shell.PLAIN, "")
 }
 
 func (a *Ansi) GenerateHyperlink(text string) string {
diff --git a/src/engine/block.go b/src/engine/block.go
index f2c51562..2d73a180 100644
--- a/src/engine/block.go
+++ b/src/engine/block.go
@@ -67,7 +67,7 @@ func (b *Block) Init(env platform.Environment, writer color.Writer, ansi *color.
 
 func (b *Block) InitPlain(env platform.Environment, config *Config) {
 	b.ansi = &color.Ansi{}
-	b.ansi.InitPlain(b.env.GOOS())
+	b.ansi.InitPlain()
 	b.writer = &color.AnsiWriter{
 		Ansi:               b.ansi,
 		TerminalBackground: shell.ConsoleBackgroundColor(env, config.TerminalBackground),
diff --git a/src/engine/engine.go b/src/engine/engine.go
index 6fb640e1..e188f71f 100644
--- a/src/engine/engine.go
+++ b/src/engine/engine.go
@@ -211,7 +211,7 @@ func (e *Engine) renderBlock(block *Block) {
 		ansi := e.Ansi
 		if e.Env.Shell() == shell.BASH {
 			ansi = &color.Ansi{}
-			ansi.InitPlain(e.Env.GOOS())
+			ansi.InitPlain()
 		}
 		prompt := ansi.CarriageForward()
 		prompt += ansi.GetCursorForRightWrite(length, block.HorizontalOffset)
@@ -307,7 +307,7 @@ func (e *Engine) print() string {
 		// in bash, the entire rprompt needs to be escaped for the prompt to be interpreted correctly
 		// see https://github.com/jandedobbeleer/oh-my-posh/pull/2398
 		ansi := &color.Ansi{}
-		ansi.InitPlain(e.Env.GOOS())
+		ansi.InitPlain()
 		prompt := ansi.SaveCursorPosition()
 		prompt += ansi.CarriageForward()
 		prompt += ansi.GetCursorForRightWrite(e.rpromptLength, 0)
diff --git a/src/engine/new.go b/src/engine/new.go
index ccb5b7f8..0caf7163 100644
--- a/src/engine/new.go
+++ b/src/engine/new.go
@@ -18,15 +18,15 @@ func New(flags *platform.Flags) *Engine {
 	env.Init()
 	cfg := LoadConfig(env)
 	ansi := &color.Ansi{}
-	ansi.Init(env.Shell(), env.GOOS())
 
 	var writer color.Writer
 	if flags.Plain {
-		ansi.InitPlain(env.GOOS())
+		ansi.InitPlain()
 		writer = &color.PlainWriter{
 			Ansi: ansi,
 		}
 	} else {
+		ansi.Init(env.Shell(), env.GOOS())
 		writerColors := cfg.MakeColors()
 		writer = &color.AnsiWriter{
 			Ansi:               ansi,


Test patch:
diff --git a/src/color/ansi_test.go b/src/color/ansi_test.go
index 0c80f316..ccc5da76 100644
--- a/src/color/ansi_test.go
+++ b/src/color/ansi_test.go
@@ -96,7 +96,7 @@ func TestFormatText(t *testing.T) {
 	}
 	for _, tc := range cases {
 		a := Ansi{}
-		a.InitPlain("")
+		a.InitPlain()
 		formattedText := a.formatText(tc.Text)
 		assert.Equal(t, tc.Expected, formattedText, tc.Case)
 	}
diff --git a/src/console/title_test.go b/src/console/title_test.go
index 7742d950..4f8c4954 100644
--- a/src/console/title_test.go
+++ b/src/console/title_test.go
@@ -62,7 +62,7 @@ func TestGetTitle(t *testing.T) {
 			Folder:   "vagrant",
 		})
 		ansi := &color.Ansi{}
-		ansi.InitPlain("")
+		ansi.InitPlain()
 		ct := &Title{
 			Env:      env,
 			Ansi:     ansi,
@@ -117,7 +117,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
 			HostName: "",
 		})
 		ansi := &color.Ansi{}
-		ansi.InitPlain("")
+		ansi.InitPlain()
 		ct := &Title{
 			Env:      env,
 			Ansi:     ansi,
diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go
index 0a7456e5..474765f6 100644
--- a/src/engine/engine_test.go
+++ b/src/engine/engine_test.go
@@ -72,7 +72,7 @@ func TestPrintPWD(t *testing.T) {
 			Shell: "shell",
 		})
 		ansi := &color.Ansi{}
-		ansi.InitPlain("")
+		ansi.InitPlain()
 		engine := &Engine{
 			Env: env,
 			Config: &Config{
@@ -102,7 +102,7 @@ func engineRender() {
 	defer testClearDefaultConfig()
 
 	ansi := &color.Ansi{}
-	ansi.InitPlain("")
+	ansi.InitPlain()
 	writerColors := cfg.MakeColors()
 	writer := &color.AnsiWriter{
 		Ansi:               ansi,
diff --git a/src/engine/image_test.go b/src/engine/image_test.go
index b740537f..3e7dcf73 100644
--- a/src/engine/image_test.go
+++ b/src/engine/image_test.go
@@ -33,7 +33,7 @@ func runImageTest(config, content string) (string, error) {
 	}
 	defer os.Remove(file.Name())
 	ansi := &color.Ansi{}
-	ansi.InitPlain("")
+	ansi.InitPlain()
 	image := &ImageRenderer{
 		AnsiString: content,
 		Ansi:       ansi,