use std::path::Path;
use owo_colors::OwoColorize;
const LABEL_WIDTH: usize = 8;
const PREFIX: &str = " · ";
pub struct Printer {
pub verbose: bool,
}
#[allow(clippy::unused_self)]
impl Printer {
pub fn new(verbose: bool) -> Self {
Self { verbose }
}
pub fn action(&self, label: &str, path: &Path) {
println!(
"{PREFIX}{:>width$} {}",
label.blue(),
path.display(),
width = LABEL_WIDTH,
);
}
pub fn arrow(&self, label: &str, src: &Path, dest: &Path) {
println!(
"{PREFIX}{:>width$} {} → {}",
label.blue(),
src.display(),
dest.display(),
width = LABEL_WIDTH,
);
}
pub fn ok(&self, label: &str, path: &Path) {
println!(
"{PREFIX}{:>width$} {}",
label.green(),
path.display(),
width = LABEL_WIDTH,
);
}
pub fn skipped(&self, label: &str, path: &Path) {
println!(
"{PREFIX}{:>width$} {}",
label.yellow(),
path.display(),
width = LABEL_WIDTH,
);
}
pub fn warn(&self, label: &str, msg: &str) {
println!(
"{PREFIX}{:>width$} {}",
label.yellow(),
msg,
width = LABEL_WIDTH,
);
}
pub fn error_line(&self, label: &str, path: &Path) {
println!(
"{PREFIX}{:>width$} {}",
label.red(),
path.display(),
width = LABEL_WIDTH,
);
}
pub fn missing(&self, path: &Path) {
println!(
"{PREFIX}{:>width$} {}",
"missing".red(),
path.display(),
width = LABEL_WIDTH,
);
}
pub fn group_header(&self, name: &str) {
println!("\n {}:", name.purple().bold());
}
pub fn annotation(&self, msg: &str) {
println!(" {}", msg.dimmed());
}
pub fn summary(&self, ok: usize, modified: usize, missing: usize) {
println!(
"\n {}",
format!("{ok} ok · {modified} modified · {missing} missing").dimmed(),
);
}
pub fn success(&self, msg: &str) {
println!("\n {}", msg.green().bold());
}
pub fn error_msg(&self, msg: &str) {
println!(" {}", msg.red().bold());
}
pub fn warn_msg(&self, msg: &str) {
println!(" {}", msg.yellow());
}
pub fn hint(&self, msg: &str) {
if self.verbose {
println!(" {}", msg.dimmed());
}
}
}