use crate::config::{Color, Config};
macro_rules! sgr_const {
(
$(
$(#[$meta:meta])*
$vis:vis $ident:ident = $sgr:expr
),* $(,)?
) => {
$(
$(#[$meta])*
$vis const $ident: &'static str = std::concat!("\x1b[", $sgr, "m");
)*
}
}
sgr_const! {
COLOR_ERROR = "1;31",
COLOR_WARN = "1;33",
COLOR_INFO = "1;36",
COLOR_DEBUG = "35",
COLOR_TRACE = "32",
COLOR_NONE = "0"
}
pub fn stdout_isatty() -> bool {
atty::is(atty::Stream::Stdout)
}
pub fn color_enabled(config: &Config) -> bool {
match config.color {
Color::Off => false,
Color::On => true,
Color::Auto => stdout_isatty()
}
}
pub fn get_colors(level: log::Level) -> (&'static str, &'static str) {
let color = match level {
log::Level::Error => COLOR_ERROR,
log::Level::Warn => COLOR_WARN,
log::Level::Info => COLOR_INFO,
log::Level::Debug => COLOR_DEBUG,
log::Level::Trace => COLOR_TRACE,
};
(color, COLOR_NONE)
}