Skip to content

Commit

Permalink
Merge pull request cli#1187 from gabgodBB/Disabling_color_for_output_…
Browse files Browse the repository at this point in the history
…file

Issue cli#930 - Removing color for output files
  • Loading branch information
mislav authored Jun 24, 2020
2 parents ab903bd + ac7d5ec commit 15a7ab6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions utils/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -45,17 +44,17 @@ 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
}
}

func isColorEnabled() bool {
if !checkedNoColor {
_isColorEnabled = os.Getenv("NO_COLOR") == ""
checkedNoColor = true
if os.Getenv("NO_COLOR") != "" {
return false
}
return _isColorEnabled

return isStdoutTerminal()
}

0 comments on commit 15a7ab6

Please sign in to comment.