use console::Style;
use std::fmt;
pub struct UiStyle {
pub success: Style,
pub warning: Style,
pub error: Style,
pub info: Style,
pub bold: Style,
}
impl UiStyle {
pub fn new() -> Self {
Self {
success: Style::new().green().bold(),
warning: Style::new().yellow().bold(),
error: Style::new().red().bold(),
info: Style::new().cyan().bold(),
bold: Style::new().bold(),
}
}
}
impl Default for UiStyle {
fn default() -> Self {
Self::new()
}
}
impl UiStyle {
pub fn action<T: fmt::Display>(&self, label: &str, message: T) {
println!("{:>12} {}", self.success.apply_to(label), message);
}
pub fn info<T: fmt::Display>(&self, label: &str, message: T) {
println!("{:>12} {}", self.info.apply_to(label), message);
}
pub fn warn<T: fmt::Display>(&self, message: T) {
eprintln!("{:>12} {}", self.warning.apply_to("Warning"), message);
}
pub fn error<T: fmt::Display>(&self, message: T) {
eprintln!("{:>12} {}", self.error.apply_to("Error"), message);
}
pub fn finished<T: fmt::Display>(&self, message: T) {
println!("{:>12} {}", self.success.apply_to("Finished"), message);
}
}
lazy_static::lazy_static! {
pub static ref UI: UiStyle = UiStyle::new();
}