From a531d44e2b4add69f4a7bc505310994051de61d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20M=2E=20Bezerra?= Date: Wed, 10 Nov 2021 09:55:31 -0300 Subject: [PATCH] Move colors module to it's own file --- src/utils/colors.rs | 36 ++++++++++++++++++++++++++++++++++++ src/utils/fs.rs | 37 ------------------------------------- src/utils/mod.rs | 3 ++- 3 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 src/utils/colors.rs diff --git a/src/utils/colors.rs b/src/utils/colors.rs new file mode 100644 index 0000000..ebe6c7d --- /dev/null +++ b/src/utils/colors.rs @@ -0,0 +1,36 @@ +//! Colored output in ouch with bright colors. + +#![allow(dead_code)] + +use std::env; + +use once_cell::sync::Lazy; + +static DISABLE_COLORED_TEXT: Lazy = Lazy::new(|| { + env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr) +}); + +macro_rules! color { + ($name:ident = $value:literal) => { + #[cfg(target_family = "unix")] + /// Inserts color onto text based on configuration + pub static $name: Lazy<&str> = Lazy::new(|| if *DISABLE_COLORED_TEXT { "" } else { $value }); + #[cfg(not(target_family = "unix"))] + pub static $name: &&str = &""; + }; +} + +color!(RESET = "\u{1b}[39m"); +color!(BLACK = "\u{1b}[38;5;8m"); +color!(BLUE = "\u{1b}[38;5;12m"); +color!(CYAN = "\u{1b}[38;5;14m"); +color!(GREEN = "\u{1b}[38;5;10m"); +color!(MAGENTA = "\u{1b}[38;5;13m"); +color!(RED = "\u{1b}[38;5;9m"); +color!(WHITE = "\u{1b}[38;5;15m"); +color!(YELLOW = "\u{1b}[38;5;11m"); +// Requires true color support +color!(ORANGE = "\u{1b}[38;2;255;165;0m"); +color!(STYLE_BOLD = "\u{1b}[1m"); +color!(STYLE_RESET = "\u{1b}[0m"); +color!(ALL_RESET = "\u{1b}[0;39m"); diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 4055995..875619e 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -103,40 +103,3 @@ pub fn try_infer_extension(path: &Path) -> Option { None } } - -/// Module with a list of bright colors. -#[allow(dead_code)] -pub mod colors { - use std::env; - - use once_cell::sync::Lazy; - - static DISABLE_COLORED_TEXT: Lazy = Lazy::new(|| { - env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr) - }); - - macro_rules! color { - ($name:ident = $value:literal) => { - #[cfg(target_family = "unix")] - /// Inserts color onto text based on configuration - pub static $name: Lazy<&str> = Lazy::new(|| if *DISABLE_COLORED_TEXT { "" } else { $value }); - #[cfg(not(target_family = "unix"))] - pub static $name: &&str = &""; - }; - } - - color!(RESET = "\u{1b}[39m"); - color!(BLACK = "\u{1b}[38;5;8m"); - color!(BLUE = "\u{1b}[38;5;12m"); - color!(CYAN = "\u{1b}[38;5;14m"); - color!(GREEN = "\u{1b}[38;5;10m"); - color!(MAGENTA = "\u{1b}[38;5;13m"); - color!(RED = "\u{1b}[38;5;9m"); - color!(WHITE = "\u{1b}[38;5;15m"); - color!(YELLOW = "\u{1b}[38;5;11m"); - // Requires true color support - color!(ORANGE = "\u{1b}[38;2;255;165;0m"); - color!(STYLE_BOLD = "\u{1b}[1m"); - color!(STYLE_RESET = "\u{1b}[0m"); - color!(ALL_RESET = "\u{1b}[0;39m"); -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index c0c99ec..edb97c8 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,11 +1,12 @@ //! Random and miscellaneous utils used in ouch. +pub mod colors; mod formatting; mod fs; mod question; pub use formatting::{concatenate_os_str_list, nice_directory_display, strip_cur_dir, to_utf, Bytes}; -pub use fs::{cd_into_same_dir_as, colors, create_dir_if_non_existent, dir_is_empty, try_infer_extension}; +pub use fs::{cd_into_same_dir_as, create_dir_if_non_existent, dir_is_empty, try_infer_extension}; pub use question::{ create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy, }; -- 2.11.4.GIT