From e9026580bf4499404ce258b90d8ea3833919b46e Mon Sep 17 00:00:00 2001 From: ceriath Date: Fri, 16 Nov 2018 15:17:01 +0100 Subject: [PATCH 1/3] Disable colored output on windows entirely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the textformatter on windows outputs ``←[31mERRO←[0m[0000] test windows`` when coloring is not disabled explicitly. However, windows up to windows 8.1 does not support colored output on cmd entirely. Windows 10 added support for it, which is off by default and has to be enabled via registry or environment variable. Therefore i suggest removing colored output on windows entirely to make the output usable again. --- text_formatter.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/text_formatter.go b/text_formatter.go index 49ec92f..ed578d2 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os" + "runtime" "sort" "strings" "sync" @@ -102,7 +103,7 @@ func (f *TextFormatter) isColored() bool { } } - return isColored && !f.DisableColors + return isColored && !f.DisableColors && (runtime.GOOS != "windows") } // Format renders a single log entry From f1b98e4006fd58afa9cc5b28cd665b96519ef166 Mon Sep 17 00:00:00 2001 From: ceriath Date: Fri, 16 Nov 2018 15:19:37 +0100 Subject: [PATCH 2/3] ignore expected color on windows --- text_formatter_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/text_formatter_test.go b/text_formatter_test.go index b0d3a91..8dfec5a 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "runtime" "sort" "strings" "testing" @@ -443,7 +444,11 @@ func TestTextFormatterIsColored(t *testing.T) { os.Setenv("CLICOLOR_FORCE", val.clicolorForceVal) } res := tf.isColored() - assert.Equal(subT, val.expectedResult, res) + if runtime.GOOS == "windows" { + assert.Equal(subT, false, res) + } else { + assert.Equal(subT, val.expectedResult, res) + } }) } } From d96201375623f7f4dffa8f39457c6f00afaf922e Mon Sep 17 00:00:00 2001 From: Ceriath Date: Sun, 9 Dec 2018 21:47:44 +0100 Subject: [PATCH 3/3] respect ForceColor and environment variables over OS check --- text_formatter.go | 4 ++-- text_formatter_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index ed578d2..acb0dc0 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -91,7 +91,7 @@ func (f *TextFormatter) init(entry *Entry) { } func (f *TextFormatter) isColored() bool { - isColored := f.ForceColors || f.isTerminal + isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows")) if f.EnvironmentOverrideColors { if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" { @@ -103,7 +103,7 @@ func (f *TextFormatter) isColored() bool { } } - return isColored && !f.DisableColors && (runtime.GOOS != "windows") + return isColored && !f.DisableColors } // Format renders a single log entry diff --git a/text_formatter_test.go b/text_formatter_test.go index 8dfec5a..5b13237 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -444,7 +444,7 @@ func TestTextFormatterIsColored(t *testing.T) { os.Setenv("CLICOLOR_FORCE", val.clicolorForceVal) } res := tf.isColored() - if runtime.GOOS == "windows" { + if runtime.GOOS == "windows" && !tf.ForceColors && !val.clicolorForceIsSet { assert.Equal(subT, false, res) } else { assert.Equal(subT, val.expectedResult, res)