sourcegraph / scip

SCIP Code Intelligence Protocol
Apache License 2.0
231 stars 32 forks source link

feat: Add flag for turning off colors in TTY printing #214

Closed varungandhi-src closed 8 months ago

varungandhi-src commented 8 months ago

It is a bit annoying to copy the colored output into something like Markdown.

Test plan

Manually checked.

With scip print or scip print --color=true:

image

With scip print --color=false

image
keynmol commented 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.
varungandhi-src commented 8 months ago

Added handling for NO_COLOR.