Closed varungandhi-src closed 8 months ago
Given you're already touching this code, would be good to follow the CLI conventions (https://clig.dev/#output) and at least handle NO_COLOR env variable as well:
Use color with intention. For example, you might want to highlight some text so the user notices it, or use red to indicate an error. Don’t overuse it—if everything is a different color, then the color means nothing and only makes it harder to read.
Disable color if your program is not in a terminal or the user requested it. These things should disable colors:
stdout or stderr is not an interactive terminal (a TTY). It’s best to individually check—if you’re piping stdout to another program, it’s still useful to get colors on stderr.
The NO_COLOR environment variable is set.
The TERM environment variable has the value dumb.
The user passes the option --no-color.
You may also want to add a MYAPP_NO_COLOR environment variable in case users want to disable color specifically for your program.
Added handling for NO_COLOR
.
It is a bit annoying to copy the colored output into something like Markdown.
Test plan
Manually checked.
With
scip print
orscip print --color=true
:With
scip print --color=false