[pacman-dev] [PATCH] makepkg: check explicitly if the terminal supports colors

Allan McRae allan at archlinux.org
Tue Jun 29 01:27:58 EDT 2010


On 24/06/10 20:01, Cedric Staniewski wrote:
> Currently, makepkg aborts when colors are enabled (the default) and it
> runs in a terminal that does not support it, because tput returns a
> non-zero exit code.
> ---
>
> Another solution would be appending "|| true" to each tput line or disabling errexit in this section, so we get at
> least bold. Not sure if this is a real improvement, when the color option makes
> text bold but not colored.

 From your comment it seems there terminals that do not support colour 
but do support bold.  It seems to me that keeping bold text would be 
best in that situation.

OK...  here comes a potentially stupid question...  Are there terminals 
that do not support colour and do not support bold.  Would that still 
give an error here (seems so...)?  And do all terminals supporting bold 
but not colours support "tput sgr0"?

Once that is cleared up, this is a good candidate for maint.

> scripts/makepkg.sh.in |    5 ++++-
>   1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index dbc4047..1795b54 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -1620,8 +1620,11 @@ fi
>   PACMAN=${PACMAN:-pacman}
>
>   # check if messages are to be printed using color
> +# It is needed to explicitly check if the terminal supports colors, because
> +# otherwise, tput will return a non-zero exit code that stops makepkg due to
> +# bash's errexit option.
>   unset ALL_OFF BOLD BLUE GREEN RED YELLOW
> -if [[ -t 2&&  ! $USE_COLOR = "n"&&  $(check_buildenv color) = "y" ]]; then
> +if [[ -t 2&&  ! $USE_COLOR = "n"&&  $(check_buildenv color) = "y" ]]&&  tput setaf 0&>/dev/null; then
>   	ALL_OFF="$(tput sgr0)"
>   	BOLD="$(tput bold)"
>   	BLUE="${BOLD}$(tput setaf 4)"


More information about the pacman-dev mailing list