Skip to content

Commit 55be0d2

Browse files
committed
Tweak isColorEnabled
1 parent e6e8f70 commit 55be0d2

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

utils/color.go

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

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

1616
// Outputs ANSI color if stdout is a tty
1717
Magenta = makeColorFunc("magenta")
@@ -45,21 +45,17 @@ func NewColorable(f *os.File) io.Writer {
4545
func makeColorFunc(color string) func(string) string {
4646
cf := ansi.ColorFunc(color)
4747
return func(arg string) string {
48-
if isColorEnabled() && isStdoutTerminal() {
48+
if isColorEnabled() {
4949
return cf(arg)
5050
}
5151
return arg
5252
}
5353
}
5454

5555
func isColorEnabled() bool {
56-
if !isStdoutTerminal() {
56+
if os.Getenv("NO_COLOR") != "" {
5757
return false
5858
}
5959

60-
if !checkedNoColor {
61-
_isColorEnabled = os.Getenv("NO_COLOR") == ""
62-
checkedNoColor = true
63-
}
64-
return _isColorEnabled
60+
return isStdoutTerminal()
6561
}

0 commit comments

Comments
 (0)