Merge pull request #1187 from gabgodBB/Disabling_color_for_output_file

Issue #930 - Removing color for output files
This commit is contained in:
Mislav Marohnić 2020-06-24 17:18:22 +02:00 committed by GitHub
commit 15a7ab6b92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()
}