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] 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 7281a6201..4b83a2843 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 }