From 1846c96b86e507b7c862778047422698827d05f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Saparelli?= Date: Sun, 11 Feb 2024 18:13:41 +1300 Subject: [PATCH] feat(cli): Add NO_COLOR support (#779) --- .clippy-lints | 2 +- crates/cli/src/args.rs | 7 +++++++ doc/watchexec.1 | 2 ++ doc/watchexec.1.md | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.clippy-lints b/.clippy-lints index 2ef95a8..8677f17 100644 --- a/.clippy-lints +++ b/.clippy-lints @@ -1,4 +1,3 @@ --D clippy::all -W clippy::nursery -W clippy::pedantic -A clippy::module-name-repetitions @@ -10,3 +9,4 @@ -A clippy::default-trait-access -A clippy::enum-glob-use -A clippy::option-if-let-else +-A clippy::blocks-in-conditions diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 705d5e7..a11b971 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -680,6 +680,8 @@ pub struct Args { pub notify: bool, /// When to use terminal colours + /// + /// Setting the environment variable `NO_COLOR` to any value is equivalent to `--color=never`. #[arg( long, help_heading = OPTSET_OUTPUT, @@ -1104,6 +1106,11 @@ pub fn get_args() -> Args { debug!("parsing arguments"); let mut args = Args::parse_from(args); + // https://no-color.org/ + if args.color == ColourMode::Auto && std::env::var("NO_COLOR").is_ok() { + args.color = ColourMode::Never; + } + if args.ignore_nothing { args.no_global_ignore = true; args.no_vcs_ignore = true; diff --git a/doc/watchexec.1 b/doc/watchexec.1 index 400d207..16676ef 100644 --- a/doc/watchexec.1 +++ b/doc/watchexec.1 @@ -385,6 +385,8 @@ With this, Watchexec will emit a desktop notification when a command starts and .TP \fB\-\-color\fR=\fIMODE\fR [default: auto] When to use terminal colours + +Setting the environment variable `NO_COLOR` to any value is equivalent to `\-\-color=never`. .TP \fB\-\-timings\fR Print how long the command took to run diff --git a/doc/watchexec.1.md b/doc/watchexec.1.md index 468662f..1e24589 100644 --- a/doc/watchexec.1.md +++ b/doc/watchexec.1.md @@ -536,6 +536,9 @@ may silently do nothing, or log a warning. : When to use terminal colours +Setting the environment variable \`NO_COLOR\` to any value is equivalent +to \`\--color=never\`. + **\--timings** : Print how long the command took to run