Skip to content

Commit

Permalink
Don't use colors when stdout or stderr are being redirected
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel committed Oct 6, 2021
1 parent f713954 commit e7dd6f2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = "A command-line utility for easily compressing and decompressing f
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atty = "0.2.14"
lazy_static = "1.4.0"
walkdir = "2.3.2"
strsim = "0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lazy_static! {
static ref NO_COLOR_IS_SET: bool = {
use std::env;

env::var("NO_COLOR").is_ok()
env::var("NO_COLOR").is_ok() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr)
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub mod colors {
#[allow(dead_code, non_upper_case_globals)]
#[cfg(not(target_family = "unix"))]
pub mod colors {
pub fn empty() -> &'static str {
pub const fn empty() -> &'static str {
""
}
pub const reset: fn() -> &'static str = empty;
Expand Down

0 comments on commit e7dd6f2

Please sign in to comment.