File tree Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -394,17 +394,9 @@ core.print_debug() {
394394# use tput because simple environment variable checking heuristics suffice. Deprecated because this code
395395# has been moved to bash-std
396396core.should_output_color () {
397- local fd=" $1 "
398-
399- if [[ ${NO_COLOR+x} || " $TERM " = ' dumb' ]]; then
400- return 1
401- fi
402-
403- if [ -t " $fd " ]; then
404- return 0
397+ if core.private.should_print_color " $@ " ; then : ; else
398+ return $?
405399 fi
406-
407- return 1
408400}
409401
410402# @description (DEPRECATED) Gets information from a particular package. If the key does not exist, then the value
Original file line number Diff line number Diff line change @@ -79,8 +79,18 @@ core.private.util.err_print() {
7979# @internal
8080core.private.should_print_color () {
8181 local fd=" $1 "
82+
83+ if [ ${NO_COLOR+x} ]; then
84+ return 1
85+ fi
86+
87+ if [[ $FORCE_COLOR == @ (1| 2| 3) ]]; then
88+ return 0
89+ elif [[ $FORCE_COLOR == ' 0' ]]; then
90+ return 1
91+ fi
8292
83- if [[ ${NO_COLOR+x} || " $TERM " = ' dumb' ] ]; then
93+ if [ " $TERM " = ' dumb' ]; then
8494 return 1
8595 fi
8696
Original file line number Diff line number Diff line change @@ -15,11 +15,27 @@ load './util/init.sh'
1515}
1616
1717@test " core.should_output_color works" {
18- unset NO_COLOR COLORTERM TERM
18+ unset -v NO_COLOR FORCE_COLOR TERM
1919
2020 NO_COLOR= run core.should_output_color
2121 assert_failure
2222
23+ FORCE_COLOR=0 run core.should_output_color
24+ assert_failure
25+
26+ FORCE_COLOR=1 run core.should_output_color
27+ assert_success
28+
29+ FORCE_COLOR=2 run core.should_output_color
30+ assert_success
31+
32+ FORCE_COLOR=3 run core.should_output_color
33+ assert_success
34+
35+ # NO_COLOR has precedent over FORCE_COLOR
36+ NO_COLOR= FORCE_COLOR=1 run core.should_output_color
37+ assert_failure
38+
2339 TERM=' dumb' run core.should_output_color
2440 assert_failure
2541}
You can’t perform that action at this time.
0 commit comments