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() {
394
394
# use tput because simple environment variable checking heuristics suffice. Deprecated because this code
395
395
# has been moved to bash-std
396
396
core.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 $?
405
399
fi
406
-
407
- return 1
408
400
}
409
401
410
402
# @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() {
79
79
# @internal
80
80
core.private.should_print_color () {
81
81
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
82
92
83
- if [[ ${NO_COLOR+x} || " $TERM " = ' dumb' ] ]; then
93
+ if [ " $TERM " = ' dumb' ]; then
84
94
return 1
85
95
fi
86
96
Original file line number Diff line number Diff line change @@ -15,11 +15,27 @@ load './util/init.sh'
15
15
}
16
16
17
17
@test " core.should_output_color works" {
18
- unset NO_COLOR COLORTERM TERM
18
+ unset -v NO_COLOR FORCE_COLOR TERM
19
19
20
20
NO_COLOR= run core.should_output_color
21
21
assert_failure
22
22
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
+
23
39
TERM=' dumb' run core.should_output_color
24
40
assert_failure
25
41
}
You can’t perform that action at this time.
0 commit comments