Skip to content

Commit 176443e

Browse files
committed
refactor(awl): merge function colorPrint into rotateColorPrint 🛠️
1 parent 5b25e67 commit 176443e

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

bin/a2l

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ readonly PROG_VERSION='2.6.0-dev'
1919
# util functions
2020
################################################################################
2121

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-
3522
usage() {
3623
cat <<EOF
3724
Usage: $PROG [OPTION]... ARG...
@@ -95,13 +82,15 @@ readonly -a ROTATE_COLORS=(33 35 36 31 32 37 34)
9582
COUNT=0
9683
rotateColorPrint() {
9784
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
10190
printf '%s\n' "$content"
10291
else
10392
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]}]}
104-
colorPrint "$color" "$content"
93+
printf '\e[1;%sm%s\e[0m\n' "$color" "$content"
10594
fi
10695
}
10796

bin/coat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COUNT=0
2222
rotateColorPrint() {
2323
local content=$*
2424
# skip color for white space
25-
if [[ "$content" =~ ^[[:space:]]*$ ]]; then
25+
if [[ $content =~ ^[[:space:]]*$ ]]; then
2626
printf %s "$content"
2727
else
2828
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]}]}

bin/taoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COUNT=0
2222
rotateColorPrint() {
2323
local content=$*
2424
# skip color for white space
25-
if [[ "$content" =~ ^[[:space:]]*$ ]]; then
25+
if [[ $content =~ ^[[:space:]]*$ ]]; then
2626
printf %s "$content"
2727
else
2828
local color=${ROTATE_COLORS[COUNT++ % ${#ROTATE_COLORS[@]}]}

0 commit comments

Comments
 (0)