File tree 3 files changed +8
-19
lines changed
3 files changed +8
-19
lines changed Original file line number Diff line number Diff line change @@ -19,19 +19,6 @@ readonly PROG_VERSION='2.6.0-dev'
19
19
# util functions
20
20
# ###############################################################################
21
21
22
- colorPrint () {
23
- local color=$1
24
- shift
25
- # if stdout is a terminal, turn on color output.
26
- # '-t' check: is a terminal?
27
- # check isatty in bash https://stackoverflow.com/questions/10022323
28
- if [ -t 1 ]; then
29
- printf ' \e[1;%sm%s\e[0m\n' " $color " " $* "
30
- else
31
- printf ' %s\n' " $* "
32
- fi
33
- }
34
-
35
22
usage () {
36
23
cat << EOF
37
24
Usage: $PROG [OPTION]... ARG...
@@ -95,13 +82,15 @@ readonly -a ROTATE_COLORS=(33 35 36 31 32 37 34)
95
82
COUNT=0
96
83
rotateColorPrint () {
97
84
local content=$*
98
-
99
- # skip color for white space
100
- if [[ " $content " =~ ^[[:space:]]* $ ]]; then
85
+ # - if stdout is a terminal, turn on color output.
86
+ # '-t' check: is a terminal?
87
+ # check isatty in bash https://stackoverflow.com/questions/10022323
88
+ # - skip color for white space
89
+ if [[ ! -t 1 || $content =~ ^[[:space:]]* $ ]]; then
101
90
printf ' %s\n' " $content "
102
91
else
103
92
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]} ]}
104
- colorPrint " $color " " $content "
93
+ printf ' \e[1;%sm%s\e[0m\n ' " $color " " $content "
105
94
fi
106
95
}
107
96
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ COUNT=0
22
22
rotateColorPrint () {
23
23
local content=$*
24
24
# skip color for white space
25
- if [[ " $content " =~ ^[[:space:]]* $ ]]; then
25
+ if [[ $content =~ ^[[:space:]]* $ ]]; then
26
26
printf %s " $content "
27
27
else
28
28
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]} ]}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ COUNT=0
22
22
rotateColorPrint () {
23
23
local content=$*
24
24
# skip color for white space
25
- if [[ " $content " =~ ^[[:space:]]* $ ]]; then
25
+ if [[ $content =~ ^[[:space:]]* $ ]]; then
26
26
printf %s " $content "
27
27
else
28
28
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]} ]}
You can’t perform that action at this time.
0 commit comments