From: Andre Noll Date: Fri, 17 Jan 2014 01:27:14 +0000 (+0100) Subject: test-lib: Make colors work on FreeBSD. X-Git-Tag: v0.5.3~21^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=2197a21a857c39f976f852612be62a637c688a2e;p=paraslash.git test-lib: Make colors work on FreeBSD. Some implementations of tput don't accept capnames (bold, setaf, sgr0) but only the older termcap capability names (md, AF, me). This patch teaches test-lib.sh to try both variants and succeed if either variant works. --- diff --git a/t/test-lib.sh b/t/test-lib.sh index f3768b65..0e702b53 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -21,22 +21,22 @@ say_color() if [[ "$o_nocolor" != "true" && -n "$1" ]]; then export TERM=$ORIGINAL_TERM case "$1" in - error) tput bold; tput setaf 1;; - skip) tput setaf 5;; + error) tput $C_BOLD; tput $C_SETAF 1;; + skip) tput $C_SETAF 5;; ok) (($o_verbose == 0)) && return - tput setaf 2;; - pass) tput bold; tput setaf 2;; - info) tput setaf 3;; + tput $C_SETAF 2;; + pass) tput $C_BOLD; tput $C_SETAF 2;; + info) tput $C_SETAF 3;; run) (($o_verbose == 0)) && return - tput setaf 6;; + tput $C_SETAF 6;; esac fi shift printf "%s\n" "$*" if [[ "$o_nocolor" != "true" && -n "$1" ]]; then - tput sgr0 + tput $C_SGR0 export TERM=dumb fi } @@ -218,9 +218,21 @@ can_use_colors() result="false" [[ "$TERM" == "dumb" ]] && return [[ -t 1 ]] || return - tput bold >/dev/null 2>&1 || return - tput setaf 1 >/dev/null 2>&1 || return - tput sgr0 >/dev/null 2>&1 || return + C_BOLD='bold' + tput $C_BOLD &>/dev/null || { + C_BOLD='md' + tput $C_BOLD &>/dev/null + } || return + C_SETAF='setaf' + tput $C_SETAF 1 &>/dev/null || { + C_SETAF='AF' + tput $C_SETAF 1 &>/dev/null + } || return + C_SGR0='sgr0' + tput $C_SGR0 >/dev/null 2>&1 || { + C_SGR0='me' + tput $C_SGR0 &>/dev/null + } || return result="true" }