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 FORCE_COLOR env var #5499

Closed
MicaelJarniac opened this issue Jul 4, 2023 · 3 comments · Fixed by #10839
Closed

Support FORCE_COLOR env var #5499

MicaelJarniac opened this issue Jul 4, 2023 · 3 comments · Fixed by #10839
Labels
cli Related to the command-line interface

Comments

@MicaelJarniac
Copy link
Contributor

MicaelJarniac commented Jul 4, 2023

Feature Request

Add support for the FORCE_COLOR environment variable. When set, regardless of value, all output should have colors enabled, as if the terminal supported them.

As far as I can tell, Ruff does support a similar environment variable, CLICOLOR_FORCE.
It seems to me, though, that FORCE_COLOR is a lot more common.
In my opinion, it'd be worth supporting both.

Some projects that use this:

Related:

@MichaReiser
Copy link
Member

We use colored that only supports CLICOLOR_FORCE out of the box.

We could either manually set the override when FORCE_COLOR is set or, more generally, explore if we want to migrate away from colored (I always found the API a bit clumsy, owo-colors, termcolor, possibly more).

@charliermarsh
Copy link
Member

Happy to move to a different crate, no objection from me.

@charliermarsh charliermarsh added the cli Related to the command-line interface label Jul 4, 2023
@ofek
Copy link
Contributor

ofek commented Oct 8, 2023

This would be a nice feature to have. I have had good experiences with using owo-colors.

@carljm carljm closed this as completed in 42d52eb Apr 8, 2024
Glyphack pushed a commit to Glyphack/ruff that referenced this issue Apr 12, 2024
Fixes astral-sh#5499 

## Summary

Add support for `FORCE_COLOR` env var, as specified at
https://force-color.org/

## Test Plan

I wrote an integration test for this, and then realized that can't work,
since we use a dev-dependency on `colored` with the `no-color` feature
to avoid ANSI color codes in test snapshots.

So this is just tested manually.

`cargo run --features test-rules -- check --no-cache --isolated -
--select RUF901 --diff < /dev/null` shows a colored diff.
`cargo run --features test-rules -- check --no-cache --isolated -
--select RUF901 --diff < /dev/null | less` does not have color, since we
pipe it to `less`.
`FORCE_COLOR=1 cargo run --features test-rules -- check --no-cache
--isolated - --select RUF901 --diff < /dev/null | less` does have color
(after this diff), even though we pipe it to `less`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command-line interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants