Commit bab4ad2d authored by Robert Schmidt's avatar Robert Schmidt

Auto-detect if terminal supports colors

This enables build_oai to detect if the output terminal supports colors.
If it does, it will use colors in its output. If it does not, it will
just print the text, without color codes, improving legibility.
parent 09af6d1c
...@@ -54,12 +54,17 @@ fi ...@@ -54,12 +54,17 @@ fi
############################### ###############################
## echo and family ## echo and family
############################### ###############################
red='\E[31m' # only emit color if connected to a terminal, and if it supports colors
green='\E[32m' if [ -t 1 ]; then
yellow='\E[33m' num_colors=$(tput colors)
blue='\E[1;34m' if [ -n "$num_colors" ] && [ "$num_colors" -ge 8 ]; then
reset_color='\E[00m' red='\E[31m'
COLORIZE=1 green='\E[32m'
yellow='\E[33m'
blue='\E[1;34m'
reset_color='\E[00m'
fi
fi
cecho() { cecho() {
# Color-echo # Color-echo
...@@ -68,8 +73,7 @@ cecho() { ...@@ -68,8 +73,7 @@ cecho() {
local default_msg="No Message." local default_msg="No Message."
message=${1:-$default_msg} message=${1:-$default_msg}
color=${2:-$green} color=${2:-$green}
[ "$COLORIZE" = "1" ] && message="$color$message$reset_color" echo -e "$color$message$reset_color"
echo -e "$message"
return return
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment