Decompress files in parallel
[ouch.git] / src / utils / colors.rs
blobebe6c7dd489102fd7c3948e9055294117b00a42b
1 //! Colored output in ouch with bright colors.
3 #![allow(dead_code)]
5 use std::env;
7 use once_cell::sync::Lazy;
9 static DISABLE_COLORED_TEXT: Lazy<bool> = Lazy::new(|| {
10     env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr)
11 });
13 macro_rules! color {
14     ($name:ident = $value:literal) => {
15         #[cfg(target_family = "unix")]
16         /// Inserts color onto text based on configuration
17         pub static $name: Lazy<&str> = Lazy::new(|| if *DISABLE_COLORED_TEXT { "" } else { $value });
18         #[cfg(not(target_family = "unix"))]
19         pub static $name: &&str = &"";
20     };
23 color!(RESET = "\u{1b}[39m");
24 color!(BLACK = "\u{1b}[38;5;8m");
25 color!(BLUE = "\u{1b}[38;5;12m");
26 color!(CYAN = "\u{1b}[38;5;14m");
27 color!(GREEN = "\u{1b}[38;5;10m");
28 color!(MAGENTA = "\u{1b}[38;5;13m");
29 color!(RED = "\u{1b}[38;5;9m");
30 color!(WHITE = "\u{1b}[38;5;15m");
31 color!(YELLOW = "\u{1b}[38;5;11m");
32 // Requires true color support
33 color!(ORANGE = "\u{1b}[38;2;255;165;0m");
34 color!(STYLE_BOLD = "\u{1b}[1m");
35 color!(STYLE_RESET = "\u{1b}[0m");
36 color!(ALL_RESET = "\u{1b}[0;39m");