use std::{fmt, path::PathBuf}; use crate::error::EntryError; use ansi_term::{Color, Style}; #[derive(Debug)] pub struct PullStatus { pub title: String, pub count: usize, pub errors: Vec, } impl PullStatus { pub fn new(title: String, count: usize, errors: Vec) -> Self { Self { title, count, errors, } } pub fn is_empty(&self) -> bool { self.count == 0 } } impl fmt::Display for PullStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "{}", Style::new().dimmed().paint(self.title.to_ascii_lowercase()), )?; write!( f, " {:>2}", Style::new() .fg(Color::Cyan) .paint(self.count.to_string() + " new"), )?; if !self.errors.is_empty() { write!( f, " {:>2}", Style::new() .fg(Color::Red) .paint(self.errors.len().to_string() + " err"), )?; } Ok(()) } } #[derive(Debug)] pub struct StoreStatus { count: usize, location: PathBuf, } impl StoreStatus { pub fn new(count: usize, location: PathBuf) -> Self { Self { count, location } } } impl fmt::Display for StoreStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "cached {:>4} feeds to {}", Style::new().bold().paint(self.count.to_string()), Style::new() .bold() .paint(self.location.display().to_string()) ) } }