Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. That script's color check doesn't check that the output is a terminal. Also test

    tty -s

2. Don't hardcode escape sequences. Use (e.g.)

    export STDOUT_COLOR_START="`tput setaf 4`".


Yes good points both, thank you. The source code link has more explanation about color choices and my preference of POSIX compatibility. You can also see the color function that checks NO_COLOR, CLICOLOR_FORCE, TERM = "dumb", -t 1, etc.

For color operands, I use raw escape codes because I aim for POSIX compatibility. If I'm working on something that needs more capabilities then I switch to a more powerful programming language e.g. python, rust, etc.

As far as I understand, POSIX tput defines some terminal operands (clear, init, reset, etc.) but not color operands (setaf, setab, sgr0, etc.).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: