From 9dfce9a8c392838f7aa21886de6ef3d16e459e2f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 24 Apr 2019 23:36:25 -0400 Subject: tests: Use more colors --- tests.sh | 71 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'tests.sh') diff --git a/tests.sh b/tests.sh index a986580..c64eacc 100755 --- a/tests.sh +++ b/tests.sh @@ -22,10 +22,21 @@ umask 022 export LC_ALL=C export TZ=UTC +if [ -t 1 ]; then + BLD="$(printf '\033[01m')" + RED="$(printf '\033[01;31m')" + GRN="$(printf '\033[01;32m')" + YLW="$(printf '\033[01;33m')" + BLU="$(printf '\033[01;34m')" + MAG="$(printf '\033[01;35m')" + CYN="$(printf '\033[01;36m')" + RST="$(printf '\033[0m')" +fi + if [ "$EUID" -eq 0 ]; then cat >&2 <&2 + printf "${RED}error:${RST} Unrecognized option '%s'.\n\n" "$arg" >&2 usage >&2 exit 1 ;; @@ -812,24 +823,24 @@ fi function bfs_verbose() { if [ "$VERBOSE" ]; then if [ -t 3 ]; then - printf '\033[1;32m%q\033[0m ' $BFS >&3 + printf "${GRN}%q${RST} " $BFS >&3 local expr_started= for arg; do if [[ $arg == -[A-Z]* ]]; then - printf '\033[1;36m%q\033[0m ' "$arg" >&3 + printf "${CYN}%q${RST} " "$arg" >&3 elif [[ $arg == [\(!] || $arg == -[ao] || $arg == -and || $arg == -or || $arg == -not ]]; then expr_started=yes - printf '\033[1;31m%q\033[0m ' "$arg" >&3 + printf "${RED}%q${RST} " "$arg" >&3 elif [[ $expr_started && $arg == [\),] ]]; then - printf '\033[1;31m%q\033[0m ' "$arg" >&3 + printf "${RED}%q${RST} " "$arg" >&3 elif [[ $arg == -?* ]]; then expr_started=yes - printf '\033[1;34m%q\033[0m ' "$arg" >&3 + printf "${BLU}%q${RST} " "$arg" >&3 elif [ "$expr_started" ]; then - printf '\033[1m%q\033[0m ' "$arg" >&3 + printf "${BLD}%q${RST} " "$arg" >&3 else - printf '\033[1;35m%q\033[0m ' "$arg" >&3 + printf "${MAG}%q${RST} " "$arg" >&3 fi done else @@ -2157,6 +2168,8 @@ function test_L_unique_depth() { bfs_diff -L loops/deeply/nested -unique -depth } + +BOL= EOL='\n' function update_eol() { @@ -2165,16 +2178,10 @@ function update_eol() { EOL="\\033[${COLUMNS}G " } -if [ -t 1 ]; then - RED='\033[01;31m' - GRN='\033[01;32m' - YLW='\033[01;33m' - RST='\033[0m' - if [ ! "$VERBOSE" ]; then - BOL='\r\033[K' - update_eol - trap update_eol WINCH - fi +if [ -t 1 -a ! "$VERBOSE" ]; then + BOL='\r\033[K' + update_eol + trap update_eol WINCH fi passed=0 -- cgit v1.2.3