Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

3 participants