-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShouldColorize::from_env()
does not look the TERM environment variable
#108
Comments
This patch fixes it for me, no idea what it does on windows: 0001-query-terminfo-color-capabilities.txt (And how stupid is it that github does not allow to attach patches to issues?) |
To be fair, if you embed it inside a code block with the From dfc8e146672fcae0a1d0a918dfb831d92392ebbb Mon Sep 17 00:00:00 2001
From: Florian Hars <[email protected]>
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 <[email protected]>"]
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::<terminfo::capability::MaxColors>()
+ .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 As for the purpose itself, I'm not the best to answer it - so far I always made sure to define the "standard" |
Emacs compilation mode doesn't, it allocates a pty and sets TERM=dumb, which has been the standard way to do this since 1978. |
The current version of the colored crate ignores the capabilities of the terminal (see colored-rs/colored#108), which makes the outupt of probe-run unparseable in e.g. emacs compilation mode. As a temporary workaround, this patch overrides colorization if probe-run is called from a terminal without color support.
The current version of the colored crate ignores the capabilities of the terminal (see colored-rs/colored#108), which makes the outupt of probe-run unparseable in e.g. emacs compilation mode. As a temporary workaround, this patch overrides colorization if probe-run is called from a terminal without color support.
320: Disable terminal colorization if `TERM=dumb` is set r=jonas-schievink a=Urhengulas This PR fixes the problem `@fhars` described in #318: > The current version of the colored crate ignores the capabilities of the terminal (see colored-rs/colored#108), which makes the outupt of probe-run unparseable in e.g. emacs compilation mode. It also supersedes #318 as a fix to the problem. The reason for not going with #318 is that it adds the `terminfo` crate as a dependency which seems unmaintained and with many outdated dependencies. Co-authored-by: Urhengulas <[email protected]>
ShouldColorize::from_env()
ignores the environmentShouldColorize::from_env()
does not look the TERM environment variable
Hi @fhars thank you for the feature request. It seems that you're not familiar with Github, keep in mind that everyone here is a benevolent contributor, please be nice and respectful of the others. |
ShouldColorize::from_env()
completly ignores wether it runs in an environment that is capable of displaying colors or not and always generates color control codes.Steps to reproduce:
TERM=dumb ./my-test-program
Expected behavior:
Observed behavior:
The text was updated successfully, but these errors were encountered: