slitaz-base-files diff rootfs/lib/libtaz.sh @ rev 167
Add colorize() to libtaz.sh
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue May 15 15:48:14 2012 +0200 (2012-05-15) |
parents | 581ddfa0d620 |
children | 3a6613021c40 |
line diff
1.1 --- a/rootfs/lib/libtaz.sh Sat May 12 21:08:08 2012 +0100 1.2 +++ b/rootfs/lib/libtaz.sh Tue May 15 15:48:14 2012 +0200 1.3 @@ -39,8 +39,8 @@ 1.4 done=" $okmsg" 1.5 error=" $ermsg" ;; 1.6 html) 1.7 - done=" <span class='done'>$okmsg</span>" 1.8 - error=" <span class='error'>$ermsg</span>" ;; 1.9 + done=" <span style='color: $okcolor;'>$okmsg</span>" 1.10 + error=" <span style='color: $ercolor;'>$ermsg</span>" ;; 1.11 *) 1.12 cols=$(stty -a -F /dev/tty | head -n 1 | cut -d ";" -f 3 | awk '{print $2}') 1.13 local scol=$(($cols - 10)) 1.14 @@ -83,6 +83,19 @@ 1.15 esac 1.16 } 1.17 1.18 +# Usage: colorize "Message" colorNB or use --color=NB option 1.19 +# when running a tool. Default to white/38 and no html or gtk. 1.20 +colorize() { 1.21 + : ${color=$2} 1.22 + case $output in 1.23 + raw|gtk|html) echo "$1" ;; 1.24 + *) 1.25 + : ${color=38} 1.26 + echo -e "\\033[1;${color}m${1}\\033[0;39m" ;; 1.27 + esac 1.28 + unset color 1.29 +} 1.30 + 1.31 # Indent text $1 spaces 1.32 indent() { 1.33 local in="$1"