git-issue icon indicating copy to clipboard operation
git-issue copied to clipboard

WIP: Add color to test.sh output for easier readability

Open FrazerClews opened this issue 3 years ago • 2 comments

#86 Not sure how to test it in a non colorized terminal

FrazerClews avatar Aug 17 '20 22:08 FrazerClews

@FrazerClews To check if the stdout is being written to a tty you can use test -t 1 and to test if that tty supports colors you can use tput colors (if tput is installed at least, but on most distributions it comes with the ncurses package which is often installed by default) The escape codes you use right now may or may not work depending on the terminal. It's better to use an utility to query the terminal to check what the right escape code is.

I think it's best to do something like this:

RED=''
GREEN=''
NC=''
if [ -t 1 ] && command -v tput &> /dev/null && [ `tput colors` -gt 2 ] ; then
  RED=`tput setaf 1`
  GREEN=`tput setaf 2`
  NC=`tput sgr0`
fi

hansalves avatar May 28 '22 08:05 hansalves

Nice! I'd be glad to integrate this, following the change.

dspinellis avatar May 28 '22 12:05 dspinellis