git-issue
git-issue copied to clipboard
WIP: Add color to test.sh output for easier readability
#86 Not sure how to test it in a non colorized terminal
@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
Nice! I'd be glad to integrate this, following the change.