Skip to content

Commit cc0d87e

Browse files
committed
+ coat/a2l: skip color for white space lines
1 parent 1b72352 commit cc0d87e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

bin/a2l

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ done
9393

9494
readonly -a ECHO_COLORS=(33 35 36 31 32 37 34)
9595
COUNT=0
96+
rotateColorEcho() {
97+
local message="$*"
98+
99+
# skip color for white space
100+
if [[ "$message" =~ ^[[:space:]]*$ ]]; then
101+
echo "$message"
102+
else
103+
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
104+
colorEcho "$color" "$*"
105+
fi
106+
}
96107

97108
for a in ${args[@]:+"${args[@]}"}; do
98-
colorEcho "${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}" "$a"
109+
rotateColorEcho "$a"
99110
done

bin/coat

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ readonly eend=$'\033[0m' # escape end
2121

2222
readonly -a ECHO_COLORS=(33 35 36 31 32 37 34)
2323
COUNT=0
24-
colorEcho() {
25-
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
26-
echo "${ec}[1;${color}m$*$eend"
24+
rotateColorEcho() {
25+
local message="$*"
26+
27+
# skip color for white space
28+
if [[ "$message" =~ ^[[:space:]]*$ ]]; then
29+
echo "$message"
30+
else
31+
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
32+
echo "${ec}[1;${color}m$message$eend"
33+
fi
2734
}
2835

2936
# Bash read line does not read leading spaces
3037
# https://stackoverflow.com/questions/29689172
3138
cat "$@" | while IFS= read -r line; do
32-
colorEcho "$line"
39+
rotateColorEcho "$line"
3340
done

0 commit comments

Comments
 (0)