use std::{
env,
io::{self, IsTerminal},
};
fn should_color() -> bool {
if env::var("CLICOLOR_FORCE").is_ok_and(|v| v != "0") {
return true;
}
io::stdout().is_terminal() && env::var("NO_COLOR").is_err() && env::var("CLICOLOR").map_or(true, |v| v != "0") && env::var("TERM").map_or(true, |v| v != "dumb") }
pub(crate) fn success(s: &str) -> String {
if should_color() {
format!("\x1b[32m{}\x1b[0m", s)
} else {
s.to_string()
}
}
pub(crate) fn error(s: &str) -> String {
if should_color() {
format!("\x1b[31m{}\x1b[0m", s)
} else {
s.to_string()
}
}
pub(crate) fn warning(s: &str) -> String {
if should_color() {
format!("\x1b[33m{}\x1b[0m", s)
} else {
s.to_string()
}
}
pub(crate) fn dim(s: &str) -> String {
if should_color() {
format!("\x1b[2m{}\x1b[0m", s)
} else {
s.to_string()
}
}
pub(crate) fn bold(s: &str) -> String {
if should_color() {
format!("\x1b[1m{}\x1b[0m", s)
} else {
s.to_string()
}
}
pub(crate) fn check_mark() -> String {
success("✓")
}
pub(crate) fn cross_mark() -> String {
error("✗")
}
pub(crate) fn warning_mark() -> String {
warning("⚠")
}