slitaz-base-files diff rootfs/lib/libtaz.sh @ rev 131

libtaz.sh: Improve HTML handler and let script overwrite $output
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 13 12:57:44 2012 +0200 (2012-04-13)
parents 32c560235098
children 9ced49ff31fb
line diff
     1.1 --- a/rootfs/lib/libtaz.sh	Thu Apr 12 22:11:05 2012 +0200
     1.2 +++ b/rootfs/lib/libtaz.sh	Fri Apr 13 12:57:44 2012 +0200
     1.3 @@ -27,20 +27,14 @@
     1.4  do
     1.5  	case "$opt" in
     1.6  		--raw-out)
     1.7 -			output="raw"
     1.8 -			done=" $okmsg" 
     1.9 -			error=" $ermsg" ;;
    1.10 +			output="raw" ;;
    1.11  		--gtk-out)
    1.12 -			# Yad/GTK TextView bold or colored text ?
    1.13 -			output="gtk" 
    1.14 -			done=" $okmsg" 
    1.15 -			error=" $ermsg" ;;
    1.16 +			output="gtk" ;;
    1.17  		--html-out)
    1.18 -			output="html" 
    1.19 -			done=" <span class='done'>$okmsg</span>" 
    1.20 -			error=" <span class='error'>$ermsg</span>" ;;
    1.21 +			output="html" ;;
    1.22  	esac
    1.23  done
    1.24 +[ "$HTTP_REFERER" ] && output="html"
    1.25  
    1.26  # Help and usage.
    1.27  libtaz() {
    1.28 @@ -66,12 +60,19 @@
    1.29  # Return command status. Default to colored console output.
    1.30  status() {
    1.31  	local check=$?
    1.32 -	if [ ! "$output" ]; then
    1.33 -		local cols=$(stty -a | head -n 1 | cut -d ";" -f 3 | awk '{print $2}')
    1.34 -		local scol=$(($cols - 10))
    1.35 -		done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]"
    1.36 -		error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]"
    1.37 -	fi
    1.38 +	case $output in
    1.39 +		raw|gtk) 
    1.40 +			done=" $okmsg" 
    1.41 +			error=" $ermsg" ;;
    1.42 +		html)
    1.43 +			done=" <span class='done'>$okmsg</span>" 
    1.44 +			error=" <span class='error'>$ermsg</span>" ;;
    1.45 +		*) 
    1.46 +			local cols=$(stty -a | head -n 1 | cut -d ";" -f 3 | awk '{print $2}')
    1.47 +			local scol=$(($cols - 10))
    1.48 +			done="\\033[${scol}G[ \\033[1;${okcolor}m${okmsg}\\033[0;39m ]"
    1.49 +			error="\\033[${scol}G[ \\033[1;${ercolor}m${ermsg}\\033[0;39m ]" ;;
    1.50 +	esac
    1.51  	if [ $check = 0 ]; then
    1.52  		echo -e "$done"
    1.53  	else
    1.54 @@ -81,9 +82,11 @@
    1.55  
    1.56  # Line separator.
    1.57  separator() {
    1.58 +	sepchar="="
    1.59 +	[ "$HTTP_REFERER" ] && sepchar="<hr />"
    1.60  	local cols=$(stty -a | head -n 1 | cut -d ";" -f 3 | awk '{print $2}')
    1.61  	for c in $(seq 1 $cols); do
    1.62 -		echo -n "="
    1.63 +		echo -n "$sepchar"
    1.64  	done && echo ""
    1.65  }
    1.66