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

Support NO_COLOR and FORCE_COLOR env variables for color enabling/disabling #352

Open
G-Rath opened this issue Feb 6, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@G-Rath
Copy link

G-Rath commented Feb 6, 2025

Is your feature request related to a problem? Please describe.
I'm switching over to this library from another, as it's both smaller and uses the idiomatic Sprintf pattern which means my IDE provides help around substitutions and tokens.

However, now color is always enabled regardless of if the terminal supports it or if common variables like NO_COLOR and FORCE_COLOR are set.

Describe the solution you'd like
I'm not super well versed on the differences between control codes, terminals, feature support, etc beyond knowing it's generally not as easy as calling e.g. os.doWeSupportColor, but my understanding is that NO_COLOR and FORCE_COLOR env variables are supported by a lot of software so at least checking for those would be great.

The previous library also checks if the code is being run in a terminal (vs a subprocess), and if TERM is (not) set to dumb, which sound reasonable to me.

Describe alternatives you've considered
I should be able to handle this within my codebase, but that feels a bit sad given for everything else I can just do NO_COLOR=1 and away we go.

Additional context
I'm happy to have a go at a PR for this, at least for the first two variables.

Personally I ran into this because I'm working on a CLI which has snapshot-based tests for its output which previously wouldn't have the color codes as in that context it's not running in a terminal - while there are valid arguments to be made that having color disabled in that context means the tests are not as real-life, there's also valid arguments around the readability of those tests when they've got control codes throughout them which is why having the ability enable and disable color via env variables I think is a good idea.

@jedib0t
Copy link
Owner

jedib0t commented Feb 6, 2025

Great point! Will try to honor those environment variables soon. For now, you can use text.DisableColors().

@jedib0t jedib0t added the bug Something isn't working label Feb 6, 2025
@jedib0t jedib0t self-assigned this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants