From ac8ec32080a97f22b947f71d63fe3dfa953db732 Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Sat, 10 Apr 2021 14:57:32 +0100 Subject: [PATCH] extract_utils: Introduce colored echo helper function Change-Id: I25db42087232c646525f281cc0a1404fe60d1c8c --- extract_utils.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/extract_utils.sh b/extract_utils.sh index ce3f0bd..3ccf854 100644 --- a/extract_utils.sh +++ b/extract_utils.sh @@ -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 +}