diff options
| author | Daniel Baumann <daniel@debian.org> | 2008-11-01 16:31:26 +0100 | 
|---|---|---|
| committer | Daniel Baumann <daniel@debian.org> | 2011-03-09 19:03:44 +0100 | 
| commit | c225229f2910ee138873ecb05b43e8ec3021918d (patch) | |
| tree | 0d356298e9e443cd3141ff04ee359ee04faf1224 | |
| parent | 776a7b22271178949bf6f2676e26eefb6144ce11 (diff) | |
| download | vyos-live-build-c225229f2910ee138873ecb05b43e8ec3021918d.tar.gz vyos-live-build-c225229f2910ee138873ecb05b43e8ec3021918d.zip | |
Implementing colorful output (currently disabled by default, though).
| -rwxr-xr-x | functions/color.sh | 41 | ||||
| -rwxr-xr-x | functions/defaults.sh | 1 | ||||
| -rwxr-xr-x | functions/echo.sh | 173 | ||||
| -rwxr-xr-x | helpers/lh_config | 9 | 
4 files changed, 182 insertions, 42 deletions
| diff --git a/functions/color.sh b/functions/color.sh index feac48bb0..03d333c79 100755 --- a/functions/color.sh +++ b/functions/color.sh @@ -7,34 +7,31 @@  # This is free software, and you are welcome to redistribute it  # under certain conditions; see COPYING for details. -if [ "${LH_COLOR}" != "disabled" ] -then -	NO_COLOR="\033[0m" +NO_COLOR="\033[0m" -	UNDERSCORE="\033[4m" -	BLINK="\033[5m" +UNDERSCORE="\033[4m" +BLINK="\033[5m" -	BLACK="\033[0;30m" -	DARK_GRAY="\033[1;30m" +BLACK="\033[0;30m" +DARK_GRAY="\033[1;30m" -	RED="\033[0;31m" -	LIGHT_RED="\033[1;31m" +RED="\033[0;31m" +LIGHT_RED="\033[1;31m" -	GREEN="\033[0;32m" -	LIGHT_GREEN="\033[1;32m" +GREEN="\033[0;32m" +LIGHT_GREEN="\033[1;32m" -	BROWN="\033[0;33m" -	YELLOW="\033[1;33m" +BROWN="\033[0;33m" +YELLOW="\033[1;33m" -	BLUE="\033[0;34m" -	LIGHT_BLUE="\033[1;34m" +BLUE="\033[0;34m" +LIGHT_BLUE="\033[1;34m" -	PURPLE="\033[0;35m" -	LIGHT_PURPLE="\033[1;35m" +PURPLE="\033[0;35m" +LIGHT_PURPLE="\033[1;35m" -	CYAN="\033[0;36m" -	LIGHT_CYAN="\033[1;36m" +CYAN="\033[0;36m" +LIGHT_CYAN="\033[1;36m" -	GRAY="\033[0;37m" -	WHITE="\033[1;37m" -fi +GRAY="\033[0;37m" +WHITE="\033[1;37m" diff --git a/functions/defaults.sh b/functions/defaults.sh index 4592d2163..3636c219d 100755 --- a/functions/defaults.sh +++ b/functions/defaults.sh @@ -221,6 +221,7 @@ Set_defaults ()  	# Setting live helper options  	_BREAKPOINTS="${_BREAKPOINTS:-disabled}" +	_COLOR="${_COLOR:-disabled}"  	_DEBUG="${_DEBUG:-disabled}"  	_FORCE="${_FORCE:-disabled}"  	_QUIET="${_QUIET:-disabled}" diff --git a/functions/echo.sh b/functions/echo.sh index 816221262..e5787231f 100755 --- a/functions/echo.sh +++ b/functions/echo.sh @@ -22,11 +22,11 @@ Echo ()  Echo_debug ()  { -	STRING="${1}" -	shift -  	if [ "${_DEBUG}" = "enabled" ]  	then +		STRING="${1}" +		shift +  		if [ "${_L10N}" = "false" ]  		then  			printf "D: ${STRING}\n" @@ -36,42 +36,109 @@ Echo_debug ()  	fi  } +Echo_debug_running () +{ +	if [ "${_DEBUG}" = "enabled" ] +	then +		STRING="${1}" +		shift + +		if [ "${_L10N}" = "false" ] +		then +			printf "D: ${STRING}" +		else +			printf "D: $(eval_gettext "${STRING}")" "${@}" +		fi + +		if [ "${_COLOR}" = "false" ] +		then +			printf "..." +		else +			printf "... ${YELLOW}${BLINK}running${NO_COLOR}" +		fi +	fi +} +  Echo_error ()  {  	STRING="${1}"  	shift +	if [ "${_COLOR}" = "false" ] +	then +		printf "E:" +	else +		printf "${RED}E${NO_COLOR}:" +	fi +  	if [ "${_L10N}" = "false" ]  	then -		printf "E: ${STRING}\n" >&2 +		printf " ${STRING}" >&2  	else -		(printf "E: $(eval_gettext "${STRING}")" "${@}"; echo;) >&2 +		(printf " $(eval_gettext "${STRING}")" "${@}";) >&2  	fi  }  Echo_message ()  { -	STRING="${1}" -	shift +	if [ "${_QUIET}" != "enabled" ] +	then +		STRING="${1}" +		shift +		if [ "${_COLOR}" = "false" ] +		then +			printf "P:" +		else +			printf "${WHITE}P${NO_COLOR}:" +		fi + +		if [ "${_L10N}" = "false" ] +		then +			printf " ${STRING}\n" +		else +			printf " $(eval_gettext "${STRING}")" "${@}"; echo; +		fi +	fi +} + +Echo_message_running () +{  	if [ "${_QUIET}" != "enabled" ]  	then +		STRING="${1}" +		shift + +		if [ "${_COLOR}" = "false" ] +		then +			printf "P:" +		else +			printf "${WHITE}P${NO_COLOR}:" +		fi +  		if [ "${_L10N}" = "false" ]  		then -			printf "P: ${STRING}\n" +			printf " ${STRING}" +		else +			printf " $(eval_gettext "${STRING}")" "${@}"; +		fi + +		if [ "${_COLOR}" = "false" ] +		then +			printf "...\n"  		else -			printf "P: $(eval_gettext "${STRING}")" "${@}"; echo; +			printf "... ${YELLOW}${BLINK}running${NO_COLOR}"  		fi  	fi  }  Echo_verbose ()  { -	STRING="${1}" -	shift -  	if [ "${_VERBOSE}" = "enabled" ]  	then +		STRING="${1}" +		shift +  		if [ "${_L10N}" = "false" ]  		then  			printf "I: ${STRING}\n" @@ -81,11 +148,41 @@ Echo_verbose ()  	fi  } +Echo_verbose_running () +{ +	if [ "${_VERBOSE}" != "enabled" ] +	then +		STRING="${1}" +		shift + +		if [ "${_L10N}" = "false" ] +		then +			printf "I: ${STRING}" +		else +			printf "I: $(eval_gettext "${STRING}")" "${@}"; +		fi + +		if [ "${_COLOR}" = "false" ] +		then +			printf "...\n" +		else +			printf "... ${YELLOW}${BLINK}running${NO_COLOR}" +		fi +	fi +} +  Echo_warning ()  {  	STRING="${1}"  	shift +	if [ "${_COLOR}" = "false" ] +	then +		printf "W:" +	else +		printf "${YELLOW}W${NO_COLOR}:" +	fi +  	if [ "${_L10N}" = "false" ]  	then  		printf "W: ${STRING}\n" @@ -94,6 +191,50 @@ Echo_warning ()  	fi  } +Echo_status () +{ +	__RETURN="${?}" + +	if [ "${_COLOR}" = "false" ] +	then +		if [ "${__RETURN}" = "0" ] +		then +			printf " done.\n" +		else +			printf " failed.\n" +		fi +	else +		Cursor_columns_backward 8 + +		if [ "${__RETURN}" = "0" ] +		then +			printf " ${GREEN}done${NO_COLOR}.  \n" +		else +			printf " ${RED}failed${NO_COLOR}.\n" +		fi +	fi +} + +Echo_done () +{ +	if [ "${_COLOR}" = "false" ] +	then +		printf " already done.\n" +	else +		Cursor_columns_backward 8 + +		printf " ${GREEN}already done${NO_COLOR}.\n" +	fi +} + +Echo_file () +{ +	while read LINE +	do +		echo "${1}: ${LINE}" +	done < "${1}" +} +  Echo_breakage ()  {  	case "${LH_DISTRIBUTION}" in @@ -107,11 +248,3 @@ Echo_breakage ()  	Echo_message "${@}"  } - -Echo_file () -{ -	while read LINE -	do -		echo "${1}: ${LINE}" -	done < "${1}" -} diff --git a/helpers/lh_config b/helpers/lh_config index 5911a91dd..557f2bf19 100755 --- a/helpers/lh_config +++ b/helpers/lh_config @@ -647,6 +647,11 @@ Local_arguments ()  				shift 2  				;; +			--color) +				_COLOR="enabled" +				shift +				;; +  			--debug)  				_DEBUG="enabled"  				shift @@ -837,6 +842,10 @@ LH_TEMPLATES="${LH_TEMPLATES}"  # (Default: ${_DEBUG})  #_DEBUG="${_DEBUG}" +# \$_COLOR: enable color +# (Default: ${_COLOR}) +#_COLOR="${_COLOR}" +  # \$_FORCE: enable force  # (Default: ${_FORCE})  #_FORCE="${_FORCE}" | 
