mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-29 03:02:14 +00:00
Support FORCE_COLOR env var (#10839)
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`.
This commit is contained in:
parent
3fd22973da
commit
42d52ebbec
2 changed files with 10 additions and 2 deletions
|
|
@ -149,6 +149,13 @@ pub fn run(
|
|||
#[cfg(windows)]
|
||||
assert!(colored::control::set_virtual_terminal(true).is_ok());
|
||||
|
||||
// support FORCE_COLOR env var
|
||||
if let Some(force_color) = std::env::var_os("FORCE_COLOR") {
|
||||
if force_color.len() > 0 {
|
||||
colored::control::set_override(true);
|
||||
}
|
||||
}
|
||||
|
||||
set_up_logging(global_options.log_level())?;
|
||||
|
||||
if let Some(deprecated_alias_warning) = deprecated_alias_warning {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue