From dfc8e146672fcae0a1d0a918dfb831d92392ebbb Mon Sep 17 00:00:00 2001 From: Florian Hars Date: Mon, 4 Apr 2022 16:43:51 +0000 Subject: [PATCH] query terminfo color capabilities --- Cargo.toml | 3 ++- src/control.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 886b29e..6e8d81f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "colored" description = "The most simple way to add colors in your terminal" -version = "2.0.0" +version = "2.0.1" authors = ["Thomas Wickham "] license = "MPL-2.0" homepage = "https://github.com/mackwic/colored" @@ -16,6 +16,7 @@ no-color = [] [dependencies] atty = "0.2" lazy_static = "1" +terminfo = "0.7" [target.'cfg(windows)'.dependencies.winapi] version = "0.3" diff --git a/src/control.rs b/src/control.rs index 7ad6e62..0aae563 100644 --- a/src/control.rs +++ b/src/control.rs @@ -104,8 +104,15 @@ impl ShouldColorize { /// followed by `CLICOLOR` combined with tty check. pub fn from_env() -> Self { ShouldColorize { - clicolor: ShouldColorize::normalize_env(env::var("CLICOLOR")).unwrap_or_else(|| true) - && atty::is(atty::Stream::Stdout), + clicolor: (ShouldColorize::normalize_env(env::var("CLICOLOR")).unwrap_or(true)) + && atty::is(atty::Stream::Stdout) + && (if let Ok(db) = terminfo::Database::from_env() { + db.get::() + .map(|mc| 2 < mc.into()) + .unwrap_or(false) + } else { + true + }), clicolor_force: ShouldColorize::resolve_clicolor_force( env::var("NO_COLOR"), env::var("CLICOLOR_FORCE"), -- 2.25.1