Skip to content

Conversation

FrazerClews
Copy link
Contributor

@FrazerClews FrazerClews commented Aug 17, 2020

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

@hansalves
Copy link
Contributor

@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

@dspinellis
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants