Skip to content

Commit

Permalink
feat: support NO_COLOR and FORCE_COLOR env vars (#3979)
Browse files Browse the repository at this point in the history
## Summary

Closes #3955

Adds explicit support to `NO_COLOR` and `FORCE_COLOR` via
GlobalSettings.

The order, per specs is now `NO_COLOR` > `FORCE_COLOR` > `color`.

This PR is a backup plan pending rust-cli/anstyle#192.

## Test Plan

Tested all cases locally for now; I didn't see existing tests for
GlobalSettings parsing.
  • Loading branch information
samypr100 authored Jun 4, 2024
1 parent 57ea55d commit 1b3200b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ In addition, uv respects the following environment variables:
- `MACOSX_DEPLOYMENT_TARGET`: Used with `--python-platform macos` and related variants to set the
deployment target (i.e., the minimum supported macOS version). Defaults to `12.0`, the
least-recent non-EOL macOS version at time of writing.
- `NO_COLOR`: Disable colors. Takes precedence over `FORCE_COLOR`. See [no-color.org](https://no-color.org).
- `FORCE_COLOR`: Enforce colors regardless of TTY support. See [force-color.org](https://force-color.org).

## Versioning

Expand Down
14 changes: 13 additions & 1 deletion crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ impl GlobalSettings {
Self {
quiet: args.quiet,
verbose: args.verbose,
color: if args.no_color {
color: if args.no_color
|| std::env::var_os("NO_COLOR")
.filter(|v| !v.is_empty())
.is_some()
{
ColorChoice::Never
} else if std::env::var_os("FORCE_COLOR")
.filter(|v| !v.is_empty())
.is_some()
|| std::env::var_os("CLICOLOR_FORCE")
.filter(|v| !v.is_empty())
.is_some()
{
ColorChoice::Always
} else {
args.color
},
Expand Down

0 comments on commit 1b3200b

Please sign in to comment.