Skip to content

Commit

Permalink
+ coat/a2l: skip color for white space lines
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Aug 17, 2021
1 parent 1b72352 commit cc0d87e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 12 additions & 1 deletion bin/a2l
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ done

readonly -a ECHO_COLORS=(33 35 36 31 32 37 34)
COUNT=0
rotateColorEcho() {
local message="$*"

# skip color for white space
if [[ "$message" =~ ^[[:space:]]*$ ]]; then
echo "$message"
else
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
colorEcho "$color" "$*"
fi
}

for a in ${args[@]:+"${args[@]}"}; do
colorEcho "${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}" "$a"
rotateColorEcho "$a"
done
15 changes: 11 additions & 4 deletions bin/coat
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ readonly eend=$'\033[0m' # escape end

readonly -a ECHO_COLORS=(33 35 36 31 32 37 34)
COUNT=0
colorEcho() {
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
echo "${ec}[1;${color}m$*$eend"
rotateColorEcho() {
local message="$*"

# skip color for white space
if [[ "$message" =~ ^[[:space:]]*$ ]]; then
echo "$message"
else
local color="${ECHO_COLORS[COUNT++ % ${#ECHO_COLORS[@]}]}"
echo "${ec}[1;${color}m$message$eend"
fi
}

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

0 comments on commit cc0d87e

Please sign in to comment.