extract_utils: Introduce colored echo helper function

Change-Id: I25db42087232c646525f281cc0a1404fe60d1c8c
This commit is contained in:
Bruno Martins
2021-04-10 14:57:32 +01:00
parent b49ac3f9a9
commit ac8ec32080

View File

@@ -1783,3 +1783,24 @@ function generate_prop_list_from_image() {
# Clean-up
rm -f "$output_list_tmp"
}
function colored_echo() {
IFS=" "
local color=$1;
shift
if ! [[ $color =~ '^[0-9]$' ]] ; then
case $(echo $color | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;; # white or invalid color
esac
fi
tput setaf $color
printf '%s\n' "$*"
tput sgr0
}