diff --git a/Cargo.lock b/Cargo.lock index 9aa2198..25a148f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,6 +104,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.98" @@ -148,6 +154,7 @@ version = "0.1.6" dependencies = [ "bzip2", "flate2", + "lazy_static", "rand", "strsim", "tar", diff --git a/Cargo.toml b/Cargo.toml index e5a87cf..8fd356f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,14 @@ 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] -walkdir = "2.3.2" -strsim = "0.10.0" -flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] } -bzip2 = "0.4.3" -tar = "0.4.37" -xz2 = "0.1.6" -zip = { version = "0.5.13", default-features = false, features = ["deflate-miniz"] } +walkdir = "2.3.2" +strsim = "0.10.0" +flate2 = { version = "1.0.22", default-features = false, features = ["zlib"] } +bzip2 = "0.4.3" +tar = "0.4.37" +xz2 = "0.1.6" +zip = { version = "0.5.13", default-features = false, features = ["deflate-miniz"] } +lazy_static = "1.4.0" [dev-dependencies] tempfile = "3.2.0" diff --git a/src/lib.rs b/src/lib.rs index 2a1e4d5..f7d04aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,10 +13,20 @@ mod utils; pub use error::{Error, Result}; +use lazy_static::lazy_static; + pub const EXIT_FAILURE: i32 = 127; const VERSION: &str = "0.1.5"; +lazy_static! { + static ref NO_COLOR_IS_SET: bool = { + use std::env; + + env::var("NO_COLOR").is_ok() + }; +} + fn help_command() { use utils::colors::*; /* diff --git a/src/macros.rs b/src/macros.rs index eb3fb02..723f364 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,13 +1,25 @@ +use crate::NO_COLOR_IS_SET; + #[macro_export] macro_rules! info { ($writer:expr, $($arg:tt)*) => { - use crate::utils::colors::{reset, yellow}; - print!("{}[INFO]{} ", yellow(), reset()); + use crate::macros::_info_helper; + _info_helper(); println!($writer, $($arg)*); }; ($writer:expr) => { - print!("{}[INFO]{} ", yellow(), reset()); + _info_helper(); println!($writer); }; } + +pub fn _info_helper() { + use crate::utils::colors::{reset, yellow}; + + if *NO_COLOR_IS_SET { + print!("[INFO] "); + } else { + print!("{}[INFO]{} ", yellow(), reset()); + } +} diff --git a/src/utils.rs b/src/utils.rs index e0cbcaf..9a15fd5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,7 +10,7 @@ use crate::{dialogs::Confirmation, info, oof}; pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { if !path.exists() { fs::create_dir_all(path)?; - info!("directory {:#?} created.", to_utf(path)); + info!("directory {} created.", to_utf(path)); } Ok(()) }