From 417de6257a2a5b0a1cb10907b36a517c8f306696 Mon Sep 17 00:00:00 2001 From: gedenata Date: Wed, 10 Jun 2020 13:57:31 +0800 Subject: [PATCH 1/3] variable global color --- utils/color.go | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/utils/color.go b/utils/color.go index b2b2add21..84525dc80 100644 --- a/utils/color.go +++ b/utils/color.go @@ -9,10 +9,20 @@ import ( "github.com/mgutz/ansi" ) -var _isColorEnabled = true -var _isStdoutTerminal = false -var checkedTerminal = false -var checkedNoColor = false +var ( + _isColorEnabled bool = true + _isStdoutTerminal, checkedTerminal, checkedNoColor bool + + // Outputs ANSI color if stdout is a tty + Magenta = makeColorFunc("magenta") + Cyan = makeColorFunc("cyan") + Red = makeColorFunc("red") + Yellow = makeColorFunc("yellow") + Blue = makeColorFunc("blue") + Green = makeColorFunc("green") + Gray = makeColorFunc("black+h") + Bold = makeColorFunc("default+b") +) func isStdoutTerminal() bool { if !checkedTerminal { @@ -42,34 +52,10 @@ func makeColorFunc(color string) func(string) string { } } -func isColorEnabled() bool { +func isColorEnabled() bool { if !checkedNoColor { _isColorEnabled = os.Getenv("NO_COLOR") == "" checkedNoColor = true } return _isColorEnabled } - -// Magenta outputs ANSI color if stdout is a tty -var Magenta = makeColorFunc("magenta") - -// Cyan outputs ANSI color if stdout is a tty -var Cyan = makeColorFunc("cyan") - -// Red outputs ANSI color if stdout is a tty -var Red = makeColorFunc("red") - -// Yellow outputs ANSI color if stdout is a tty -var Yellow = makeColorFunc("yellow") - -// Blue outputs ANSI color if stdout is a tty -var Blue = makeColorFunc("blue") - -// Green outputs ANSI color if stdout is a tty -var Green = makeColorFunc("green") - -// Gray outputs ANSI color if stdout is a tty -var Gray = makeColorFunc("black+h") - -// Bold outputs ANSI color if stdout is a tty -var Bold = makeColorFunc("default+b") From 81799caeb6c51861d49aef0804c76246a7200079 Mon Sep 17 00:00:00 2001 From: gedenata Date: Wed, 10 Jun 2020 13:59:28 +0800 Subject: [PATCH 2/3] variable global color --- utils/color.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/color.go b/utils/color.go index 84525dc80..6d8c367b3 100644 --- a/utils/color.go +++ b/utils/color.go @@ -52,7 +52,7 @@ func makeColorFunc(color string) func(string) string { } } -func isColorEnabled() bool { +func isColorEnabled() bool { if !checkedNoColor { _isColorEnabled = os.Getenv("NO_COLOR") == "" checkedNoColor = true From 4c94d126dac58140fdde19e230c4dc0d7e44c57f Mon Sep 17 00:00:00 2001 From: gedenata Date: Wed, 10 Jun 2020 14:02:42 +0800 Subject: [PATCH 3/3] variable global color --- utils/color.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/color.go b/utils/color.go index 6d8c367b3..4940fe26b 100644 --- a/utils/color.go +++ b/utils/color.go @@ -10,7 +10,7 @@ import ( ) var ( - _isColorEnabled bool = true + _isColorEnabled bool = true _isStdoutTerminal, checkedTerminal, checkedNoColor bool // Outputs ANSI color if stdout is a tty