pub mod json;
pub mod sarif;
pub mod text;
use crate::model::Repo;
pub fn repo_label(repo: Option<&Repo>, remote: bool) -> String {
match repo {
None => "(no repository)".into(),
Some(r) if !remote => r.name.clone(),
Some(r) => r.remote.clone().unwrap_or_else(|| format!("{} (no remote)", r.path)),
}
}
#[derive(Clone, Copy)]
pub struct Style {
enabled: bool,
}
impl Style {
pub fn detect() -> Self {
use std::io::IsTerminal;
Self { enabled: std::io::stdout().is_terminal() && std::env::var_os("NO_COLOR").is_none() }
}
fn paint(self, code: &str, s: &str) -> String {
if self.enabled {
format!("\x1b[{code}m{s}\x1b[0m")
} else {
s.to_string()
}
}
pub fn bad(self, s: &str) -> String {
self.paint("31", s)
}
pub fn warn(self, s: &str) -> String {
self.paint("33", s)
}
pub fn good(self, s: &str) -> String {
self.paint("32", s)
}
pub fn dim(self, s: &str) -> String {
self.paint("2", s)
}
pub fn bold(self, s: &str) -> String {
self.paint("1", s)
}
}
pub fn plural(n: usize, word: &str) -> String {
format!("{n} {word}{}", if n == 1 { "" } else { "s" })
}