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

Dan McGee dpmcgee at gmail.com
Thu Jul 8 01:41:42 EDT 2010


On Thu, Jun 24, 2010 at 5:01 AM, Cedric Staniewski <cedric at gmx.ca> 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.

Easy way to get a non-color terminal for testing: TERM=xterm-bold

I'd definitely prefer a graceful fallback; Nezmer's patch isn't the
prettiest but it gets close to that ideal.

Alternatively, would it be awful to fall out of -e mode here and just
reset it after we get our colors straightened out? Otherwise I think
|| true is our best option.

> 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)"
> --
> 1.7.1


More information about the pacman-dev mailing list