diff --git a/utils/color.go b/utils/color.go index 4940fe26b..dd9a7d11c 100644 --- a/utils/color.go +++ b/utils/color.go @@ -10,8 +10,7 @@ import ( ) var ( - _isColorEnabled bool = true - _isStdoutTerminal, checkedTerminal, checkedNoColor bool + _isStdoutTerminal, checkedTerminal bool // Outputs ANSI color if stdout is a tty Magenta = makeColorFunc("magenta") @@ -45,7 +44,7 @@ func NewColorable(f *os.File) io.Writer { func makeColorFunc(color string) func(string) string { cf := ansi.ColorFunc(color) return func(arg string) string { - if isColorEnabled() && isStdoutTerminal() { + if isColorEnabled() { return cf(arg) } return arg @@ -53,9 +52,9 @@ func makeColorFunc(color string) func(string) string { } func isColorEnabled() bool { - if !checkedNoColor { - _isColorEnabled = os.Getenv("NO_COLOR") == "" - checkedNoColor = true + if os.Getenv("NO_COLOR") != "" { + return false } - return _isColorEnabled + + return isStdoutTerminal() }