use crate::findings::types::Severity;
use std::io::IsTerminal;
pub fn severity_label(label: &str) -> String {
if !std::io::stdout().is_terminal() {
return label.to_string();
}
match label {
"Critical" | "CRITICAL" => format!("\x1b[1;31m{label}\x1b[0m"),
"High" | "HIGH" => format!("\x1b[31m{label}\x1b[0m"),
"Medium" | "MEDIUM" => format!("\x1b[33m{label}\x1b[0m"),
"Low" | "LOW" => format!("\x1b[36m{label}\x1b[0m"),
_ => format!("\x1b[90m{label}\x1b[0m"),
}
}
pub fn dim(text: &str) -> String {
if !std::io::stdout().is_terminal() {
return text.to_string();
}
format!("\x1b[2m{text}\x1b[0m")
}
pub fn severity_count(severity: Severity, n: usize) -> String {
let text = format!("{n} {}", severity.lowercase_label());
if !std::io::stdout().is_terminal() {
return text;
}
match severity {
Severity::Critical => format!("\x1b[1;31m{text}\x1b[0m"),
Severity::High => format!("\x1b[31m{text}\x1b[0m"),
Severity::Medium => format!("\x1b[33m{text}\x1b[0m"),
Severity::Low => format!("\x1b[36m{text}\x1b[0m"),
Severity::Info => format!("\x1b[90m{text}\x1b[0m"),
}
}