[pacman-dev] [PATCH 1/2] makepkg: define escape sequences globally

Allan McRae allan at archlinux.org
Fri Oct 23 10:28:04 EDT 2009


Cedric Staniewski wrote:
> In doing so, it is possible to get rid of all the tests for colored
> messages except for one global one.
>
> Signed-off-by: Cedric Staniewski <cedric at gmx.ca>
> ---

> <snip>

>  
> @@ -1576,7 +1555,16 @@ fi
>  
>  # check if messages are to be printed using color
>  if [ -t 2 -a ! "$USE_COLOR" = "n" -a "$(check_buildenv color)" = "y" ]; then
> -	COLORMSG=1
> +	readonly ALL_OFF="\033[1;0m" \
> +						BOLD="\033[1;1m"
> +	readonly ALL_OFF_BOLD="${ALL_OFF}${BOLD}" \
> +						RED="${BOLD}\033[1;31m" \
> +						BLUE="${BOLD}\033[1;34m" \
> +						GREEN="${BOLD}\033[1;32m" \
> +						YELLOW="${BOLD}\033[1;33m"
> +else
> +	unset ALL_OFF ALL_OFF_BOLD BOLD RED BLUE GREEN YELLOW
> +	readonly ALL_OFF ALL_OFF_BOLD BOLD RED BLUE GREEN YELLOW
>  fi
>  
>  # override settings with an environment variable for batch processing
>   

How about a slight change here:

if [ .... ]; then
    ALL_OFF=
    BOLD=
    ...
else
    unset ....
fi
readonly ...

That cleans up that first part of the if statement somewhat.

I am also not sure about the need for ${ALL_OFF_BOLD}  given it is only 
two less characters that ${ALL_OFF}${BOLD} and that way seems to be 
clearer to me.

Allan


More information about the pacman-dev mailing list