use is_terminal::IsTerminal;
use owo_colors::OwoColorize;
pub fn should_use_color(no_color_flag: bool) -> bool {
if no_color_flag {
return false;
}
std::io::stdout().is_terminal()
}
pub fn pass(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_green().bold())
} else {
text.to_string()
}
}
pub fn warn(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_yellow().bold())
} else {
text.to_string()
}
}
pub fn fail(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_red().bold())
} else {
text.to_string()
}
}
pub fn critical(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_magenta().bold())
} else {
text.to_string()
}
}
pub fn info(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_cyan())
} else {
text.to_string()
}
}
pub fn alert(text: &str, no_color: bool) -> String {
if should_use_color(no_color) {
format!("{}", text.bright_yellow())
} else {
text.to_string()
}
}
pub fn level_critical(message: &str, no_color: bool) -> String {
format!("[{}] {}", critical("CRITICAL", no_color), message)
}
pub fn level_high(message: &str, no_color: bool) -> String {
format!("[{}] {}", fail("HIGH", no_color), message)
}
pub fn level_medium(message: &str, no_color: bool) -> String {
format!("[{}] {}", warn("MEDIUM", no_color), message)
}
pub fn level_low(message: &str, no_color: bool) -> String {
format!("[{}] {}", pass("LOW", no_color), message)
}
pub fn level_warning(message: &str, no_color: bool) -> String {
format!("[{}] {}", warn("WARNING", no_color), message)
}
pub fn level_pass(message: &str, no_color: bool) -> String {
format!("[{}] {}", pass("PASS", no_color), message)
}
#[allow(dead_code)]
pub fn level_conflict(message: &str, no_color: bool) -> String {
format!("[{}] {}", fail("CONFLICT", no_color), message)
}
pub fn level_fail(message: &str, no_color: bool) -> String {
format!("[{}] {}", fail("FAIL", no_color), message)
}
pub fn level_warn(message: &str, no_color: bool) -> String {
format!("[{}] {}", warn("WARN", no_color), message)
}
#[allow(dead_code)]
pub fn bold(text: &str) -> String {
format!("{}", text.bold())
}
#[allow(dead_code)]
pub fn red(text: &str) -> String {
format!("{}", text.red())
}
#[allow(dead_code)]
pub fn yellow(text: &str) -> String {
format!("{}", text.yellow())
}
#[allow(dead_code)]
pub fn green(text: &str) -> String {
format!("{}", text.green())
}
#[allow(dead_code)]
pub fn cyan(text: &str) -> String {
format!("{}", text.cyan())
}