config/functions: fix colors - escape sequences are not supported

This commit is contained in:
MilhouseVH 2018-11-21 11:43:03 +00:00 committed by Ian Leonard
parent 4ec394b3e3
commit d97b2b3793
2 changed files with 45 additions and 49 deletions

View File

@ -37,6 +37,8 @@ listremoveitem() {
print_color() { print_color() {
local clr_name="$1" clr_text="$2" clr_actual local clr_name="$1" clr_text="$2" clr_actual
local black red green yellow blue magenta cyan white endcolor
local boldblack boldred boldgreen boldyellow boldblue boldmagenta boldcyan boldwhite
[ -z "${clr_name}" ] && return 0 [ -z "${clr_name}" ] && return 0
@ -45,45 +47,60 @@ print_color() {
return 0 return 0
fi fi
black="\e[0;30m"
boldblack="\e[1;30m"
red="\e[0;31m"
boldred="\e[1;31m"
green="\e[0;32m"
boldgreen="\e[1;32m"
yellow="\e[0;33m"
boldyellow="\e[1;33m"
blue="\e[0;34m"
boldblue="\e[1;34m"
magenta="\e[0;35m"
boldmagenta="\e[1;35m"
cyan="\e[0;36m"
boldcyan="\e[1;36m"
white="\e[0;37m"
boldwhite="\e[1;37m"
endcolor="\e[0m"
# $clr_name can be a color variable (boldgreen etc.) or a
# "standard" color determined by an indirect name (CLR_ERROR etc.)
#
# If ${!clr_name} doesn't exist then assume it's a standard color.
#
clr_actual="${!clr_name}" clr_actual="${!clr_name}"
# If $clr_name isn't another colour variable (boldgreen etc.), then if [ -z "${clr_actual}" ]; then
# assume it's an actual colour escape sequence.
#
# Otherwise if $clr_name isn't defined, or doesn't exist, then use
# standard colours.
#
if [[ -n "${clr_actual}" ]] && [[ -z "${!clr_actual}" ]]; then
clr_actual="${clr_name}"
elif [[ -z "${clr_actual}" ]] || [[ -z "${!clr_actual}" ]]; then
case "${clr_name}" in case "${clr_name}" in
CLR_ERROR) clr_actual="boldred";; CLR_ERROR) clr_actual="${boldred}";;
CLR_WARNING) clr_actual="boldred";; CLR_WARNING) clr_actual="${boldred}";;
CLR_WARNING_DIM) clr_actual="red";; CLR_WARNING_DIM) clr_actual="${red}";;
CLR_APPLY_PATCH) clr_actual="boldgreen";; CLR_APPLY_PATCH) clr_actual="${boldgreen}";;
CLR_AUTORECONF) clr_actual="boldmagenta";; CLR_AUTORECONF) clr_actual="${boldmagenta}";;
CLR_BUILD) clr_actual="boldyellow";; CLR_BUILD) clr_actual="${boldyellow}";;
CLR_TOOLCHAIN) clr_actual="boldmagenta";; CLR_TOOLCHAIN) clr_actual="${boldmagenta}";;
CLR_CLEAN) clr_actual="boldred";; CLR_CLEAN) clr_actual="${boldred}";;
CLR_FIXCONFIG) clr_actual="boldyellow";; CLR_FIXCONFIG) clr_actual="${boldyellow}";;
CLR_GET) clr_actual="boldcyan";; CLR_GET) clr_actual="${boldcyan}";;
CLR_INFO) clr_actual="boldgreen";; CLR_INFO) clr_actual="${boldgreen}";;
CLR_INSTALL) clr_actual="boldgreen";; CLR_INSTALL) clr_actual="${boldgreen}";;
CLR_PATCH_DESC) clr_actual="boldwhite";; CLR_PATCH_DESC) clr_actual="${boldwhite}";;
CLR_TARGET) clr_actual="boldwhite";; CLR_TARGET) clr_actual="${boldwhite}";;
CLR_UNPACK) clr_actual="boldcyan";; CLR_UNPACK) clr_actual="${boldcyan}";;
CLR_ENDCOLOR) clr_actual="endcolor";; CLR_ENDCOLOR) clr_actual="${endcolor}";;
*) clr_actual="endcolor";; *) clr_actual="${endcolor}";;
esac esac
fi fi
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
echo -en "${!clr_actual}${clr_text}${endcolor}" echo -en "${clr_actual}${clr_text}${endcolor}"
else else
echo -en "${!clr_actual}" echo -en "${clr_actual}"
fi fi
} }

View File

@ -162,27 +162,6 @@ else
fi fi
BUILD_INDENT_SIZE=4 BUILD_INDENT_SIZE=4
# define colors
if [ "$DISABLE_COLORS" != "yes" ]; then
black="\e[0;30m"
boldblack="\e[1;30m"
red="\e[0;31m"
boldred="\e[1;31m"
green="\e[0;32m"
boldgreen="\e[1;32m"
yellow="\e[0;33m"
boldyellow="\e[1;33m"
blue="\e[0;34m"
boldblue="\e[1;34m"
magenta="\e[0;35m"
boldmagenta="\e[1;35m"
cyan="\e[0;36m"
boldcyan="\e[1;36m"
white="\e[0;37m"
boldwhite="\e[1;37m"
endcolor="\e[0m"
fi
# If sourcing a package, configure any package variables dependent on variables we have set # If sourcing a package, configure any package variables dependent on variables we have set
if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then if [ -n "$PKG_DIR" -a -r $PKG_DIR/package.mk ]; then
if [ "$(type -t configure_package)" = "function" ]; then if [ "$(type -t configure_package)" = "function" ]; then