use std::io::IsTerminal;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Palette {
pub green: &'static str,
pub red: &'static str,
pub yellow: &'static str,
pub dim: &'static str,
pub bold: &'static str,
pub reset: &'static str,
}
impl Palette {
pub const ANSI: Self = Self {
green: "\x1b[32m",
red: "\x1b[31m",
yellow: "\x1b[33m",
dim: "\x1b[2m",
bold: "\x1b[1m",
reset: "\x1b[0m",
};
pub const PLAIN: Self = Self {
green: "",
red: "",
yellow: "",
dim: "",
bold: "",
reset: "",
};
pub fn for_stdout() -> Self {
Self::resolve(
std::io::stdout().is_terminal(),
std::env::var_os("NO_COLOR").is_some(),
)
}
pub fn resolve(is_tty: bool, no_color: bool) -> Self {
if is_tty && !no_color {
Self::ANSI
} else {
Self::PLAIN
}
}
}