Skip to content

Commit

Permalink
Respect the NO_COLOR env. arg.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel committed Sep 17, 2021
1 parent 55aa65d commit b099e4a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
/*
Expand Down
18 changes: 15 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

1 comment on commit b099e4a

@marcospb19
Copy link
Member

@marcospb19 marcospb19 commented on b099e4a Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to https://no-color.org/ 🙂

PR link: jcs/no_color#135

Please sign in to comment.