use std::io::IsTerminal;
use std::sync::OnceLock;
const GREEN_BOLD: &str = "\x1b[1;32m";
const CYAN: &str = "\x1b[36m";
const DIM: &str = "\x1b[2m";
const RESET: &str = "\x1b[0m";
pub fn enabled() -> bool {
static ENABLED: OnceLock<bool> = OnceLock::new();
*ENABLED
.get_or_init(|| std::env::var_os("NO_COLOR").is_none() && std::io::stdout().is_terminal())
}
fn paint(code: &str, s: &str) -> String {
if enabled() {
format!("{code}{s}{RESET}")
} else {
s.to_string()
}
}
pub fn header(s: &str) -> String {
paint(GREEN_BOLD, s)
}
pub fn label(s: &str) -> String {
paint(CYAN, s)
}
pub fn dim(s: &str) -> String {
paint(DIM, s)
}