From 049d1138c94b1654a80b3afc164bcc5c672560f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 25 Aug 2022 17:58:14 +0200 Subject: [PATCH 1/3] Don't output colours by default if TERM=dumb or NO_COLOR=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches ZFS, and is mostly état d'art Closes #542 --- src/options.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/options.rs b/src/options.rs index 7281a62..4b83a28 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::path::PathBuf; use std::process::{Command, Stdio}; -use std::{cmp, fmt, io}; +use std::{cmp, env, fmt, io}; use anyhow::ensure; use atty::Stream; @@ -298,6 +298,14 @@ impl Options { || !atty::is(Stream::Stdout) { OutputStyleOption::Basic + } else if !(env::var_os("TERM") + .map(|t| t != "unknown" && t != "dumb") + .unwrap_or(false) + && env::var_os("NO_COLOR") + .map(|t| t.is_empty()) + .unwrap_or(true)) + { + OutputStyleOption::NoColor } else { OutputStyleOption::Full } From 9fefe9af314bc7c6e93befa59fa17bc0b135561e Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 7 Sep 2022 08:44:57 +0200 Subject: [PATCH 2/3] Rewrite boolean condition --- src/options.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/options.rs b/src/options.rs index 4b83a28..edd2391 100644 --- a/src/options.rs +++ b/src/options.rs @@ -298,12 +298,12 @@ impl Options { || !atty::is(Stream::Stdout) { OutputStyleOption::Basic - } else if !(env::var_os("TERM") - .map(|t| t != "unknown" && t != "dumb") - .unwrap_or(false) - && env::var_os("NO_COLOR") - .map(|t| t.is_empty()) - .unwrap_or(true)) + } else if env::var_os("TERM") + .map(|t| t == "unknown" || t == "dumb") + .unwrap_or(true) + || env::var_os("NO_COLOR") + .map(|t| !t.is_empty()) + .unwrap_or(false) { OutputStyleOption::NoColor } else { From dc7e0e0240f7ef3da8c8c9088890650a8a696dd6 Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 7 Sep 2022 08:46:35 +0200 Subject: [PATCH 3/3] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be1f775..c3036c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Features +- Disable colorized output in case of `TERM=dumb` or `NO_COLOR=1`, see #542 and #555 (@nabijaczleweli) ## Changes