Respect the NO_COLOR env. arg.

This commit is contained in:
Vinícius Rodrigues Miguel 2021-09-17 00:38:16 -03:00
parent 55aa65dcea
commit b099e4ac20
5 changed files with 41 additions and 11 deletions

7
Cargo.lock generated
View File

@ -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",

View File

@ -20,6 +20,7 @@ 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"

View File

@ -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::*;
/*

View File

@ -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());
}
}

View File

@ -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(())
}