Merge pull request #1187 from gabgodBB/Disabling_color_for_output_file
Issue #930 - Removing color for output files
This commit is contained in:
commit
15a7ab6b92
1 changed files with 6 additions and 7 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue