Skip to content

Support FORCE_COLOR env var#10839

Merged
carljm merged 2 commits intomainfrom
cjm/force-color
Apr 8, 2024
Merged

Support FORCE_COLOR env var#10839
carljm merged 2 commits intomainfrom
cjm/force-color

Conversation

@carljm
Copy link
Copy Markdown
Contributor

@carljm carljm commented Apr 8, 2024

Fixes #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.

@carljm carljm added the cli Related to the command-line interface label Apr 8, 2024
@carljm carljm changed the title Cjm/force color Support FORCE_COLOR Apr 8, 2024
@carljm carljm changed the title Support FORCE_COLOR Support FORCE_COLOR env var Apr 8, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@carljm carljm merged commit 42d52eb into main Apr 8, 2024
@carljm carljm deleted the cjm/force-color branch April 8, 2024 21:29
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request 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 this pull request may close these issues.

Support FORCE_COLOR env var

2 participants