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 environment variable #2207

Closed
mmessmore opened this issue Feb 27, 2022 · 5 comments
Closed

Support NO_COLOR environment variable #2207

mmessmore opened this issue Feb 27, 2022 · 5 comments

Comments

@mmessmore
Copy link

Support disabling color output globally using the NO_COLOR environment variable as specified here: https://no-color.org/

In particular it would be useful for CI output and users who dislike stylized output for my CLIs.

@davidism
Copy link
Member

davidism commented Feb 27, 2022

Duplicate of #1498. While I understand the intention of the proposal, it's not clear that it's an actual accepted standard (there are plenty of other env vars across projects), or the correct thing to do. See linked discussions on the previous issue. For example, Click doesn't provide a --color option, so every project would still need to implement turning color back on manually. At that point, why not also do this:

if __name__ == "__main__":
    color = os.environ.get("NO_COLOR")
    color = color in {"1", "true"} if color is not None else None
    cli(color=color)

I did see that Rich implements this, but that alone isn't a convincing reason for it.

@mmessmore
Copy link
Author

mmessmore commented Feb 27, 2022

Sorry, I should have found the prior issue. It really doesn’t need to be supported directly, I guess, but easy to implement support without logic around every style or secho. It may be already. To me, ideally there should be a simple pattern for support or direct support.

And thank you. This library has made me happy and more productive for so long.

@davidism
Copy link
Member

No problem.

The color parameter shown above will tell Click to not output color codes. So if you want to support that env var, reading it and setting the parameter will do the right thing.

@kdeldycke
Copy link
Contributor

If you're interested @mmessmore, I've created a ready-to-use --color/--no-color flag option for Click that is supporting the NO_COLOR convention. It is available as a part of click-extra.

@mmessmore
Copy link
Author

Oh, thank you. That’s great.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants