This repository was archived by the owner on Apr 19, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package core
22
33import (
44 "bytes"
5+ "os"
56 "sync"
67 "text/template"
78
@@ -23,6 +24,17 @@ var TemplateFuncsNoColor = map[string]interface{}{
2324 },
2425}
2526
27+ // envColorDisabled returns if output colors are forbid by environment variables
28+ func envColorDisabled () bool {
29+ return os .Getenv ("NO_COLOR" ) != "" || os .Getenv ("CLICOLOR" ) == "0"
30+ }
31+
32+ // envColorForced returns if output colors are forced from environment variables
33+ func envColorForced () bool {
34+ val , ok := os .LookupEnv ("CLICOLOR_FORCE" )
35+ return ok && val != "0"
36+ }
37+
2638// RunTemplate returns two formatted strings given a template and
2739// the data it requires. The first string returned is generated for
2840// user-facing output and may or may not contain ANSI escape codes
@@ -74,7 +86,8 @@ func GetTemplatePair(tmpl string) ([2]*template.Template, error) {
7486
7587 templatePair [1 ] = templateNoColor
7688
77- if DisableColor {
89+ envColorHide := envColorDisabled () && ! envColorForced ()
90+ if DisableColor || envColorHide {
7891 templatePair [0 ] = templatePair [1 ]
7992 } else {
8093 templateWithColor , err := template .New ("prompt" ).Funcs (TemplateFuncsWithColor ).Parse (tmpl )
You can’t perform that action at this time.
0 commit comments