Skip to content

Commit b099e4a

Browse files
committed
Respect the NO_COLOR env. arg.
1 parent 55aa65d commit b099e4a

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ description = "A command-line utility for easily compressing and decompressing f
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
walkdir = "2.3.2"
17-
strsim = "0.10.0"
18-
flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] }
19-
bzip2 = "0.4.3"
20-
tar = "0.4.37"
21-
xz2 = "0.1.6"
22-
zip = { version = "0.5.13", default-features = false, features = ["deflate-miniz"] }
16+
walkdir = "2.3.2"
17+
strsim = "0.10.0"
18+
flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] }
19+
bzip2 = "0.4.3"
20+
tar = "0.4.37"
21+
xz2 = "0.1.6"
22+
zip = { version = "0.5.13", default-features = false, features = ["deflate-miniz"] }
23+
lazy_static = "1.4.0"
2324

2425
[dev-dependencies]
2526
tempfile = "3.2.0"

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ mod utils;
1313

1414
pub use error::{Error, Result};
1515

16+
use lazy_static::lazy_static;
17+
1618
pub const EXIT_FAILURE: i32 = 127;
1719

1820
const VERSION: &str = "0.1.5";
1921

22+
lazy_static! {
23+
static ref NO_COLOR_IS_SET: bool = {
24+
use std::env;
25+
26+
env::var("NO_COLOR").is_ok()
27+
};
28+
}
29+
2030
fn help_command() {
2131
use utils::colors::*;
2232
/*

src/macros.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
use crate::NO_COLOR_IS_SET;
2+
13
#[macro_export]
24
macro_rules! info {
35

46
($writer:expr, $($arg:tt)*) => {
5-
use crate::utils::colors::{reset, yellow};
6-
print!("{}[INFO]{} ", yellow(), reset());
7+
use crate::macros::_info_helper;
8+
_info_helper();
79
println!($writer, $($arg)*);
810
};
911
($writer:expr) => {
10-
print!("{}[INFO]{} ", yellow(), reset());
12+
_info_helper();
1113
println!($writer);
1214
};
1315
}
16+
17+
pub fn _info_helper() {
18+
use crate::utils::colors::{reset, yellow};
19+
20+
if *NO_COLOR_IS_SET {
21+
print!("[INFO] ");
22+
} else {
23+
print!("{}[INFO]{} ", yellow(), reset());
24+
}
25+
}

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{dialogs::Confirmation, info, oof};
1010
pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> {
1111
if !path.exists() {
1212
fs::create_dir_all(path)?;
13-
info!("directory {:#?} created.", to_utf(path));
13+
info!("directory {} created.", to_utf(path));
1414
}
1515
Ok(())
1616
}

0 commit comments

Comments
 (0)