Skip to content

Commit 15a7ab6

Browse files
authored
Merge pull request cli#1187 from gabgodBB/Disabling_color_for_output_file
Issue cli#930 - Removing color for output files
2 parents ab903bd + ac7d5ec commit 15a7ab6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

utils/color.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
)
1111

1212
var (
13-
_isColorEnabled bool = true
14-
_isStdoutTerminal, checkedTerminal, checkedNoColor bool
13+
_isStdoutTerminal, checkedTerminal bool
1514

1615
// Outputs ANSI color if stdout is a tty
1716
Magenta = makeColorFunc("magenta")
@@ -45,17 +44,17 @@ func NewColorable(f *os.File) io.Writer {
4544
func makeColorFunc(color string) func(string) string {
4645
cf := ansi.ColorFunc(color)
4746
return func(arg string) string {
48-
if isColorEnabled() && isStdoutTerminal() {
47+
if isColorEnabled() {
4948
return cf(arg)
5049
}
5150
return arg
5251
}
5352
}
5453

5554
func isColorEnabled() bool {
56-
if !checkedNoColor {
57-
_isColorEnabled = os.Getenv("NO_COLOR") == ""
58-
checkedNoColor = true
55+
if os.Getenv("NO_COLOR") != "" {
56+
return false
5957
}
60-
return _isColorEnabled
58+
59+
return isStdoutTerminal()
6160
}

0 commit comments

Comments
 (0)