summaryrefslogtreecommitdiff
path: root/src/status.rs
blob: 7e51160bed6852e23544ce756d23f20dcc17dcef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::{fmt, path::PathBuf};

use crate::error::EntryError;

use ansi_term::Style;

#[derive(Debug)]
pub struct PullStatus {
    title: String,
    count: usize,
    errors: Vec<EntryError>,
}

impl PullStatus {
    pub fn new(title: String, count: usize, errors: Vec<EntryError>) -> Self {
        Self {
            title,
            count,
            errors,
        }
    }
}

impl fmt::Display for PullStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{:<20}: pulled {:>4} entries with {:>4} errors",
            Style::new().bold().paint(self.title.to_ascii_lowercase()),
            Style::new().bold().paint(self.count.to_string()),
            Style::new().bold().paint(self.errors.len().to_string())
        )
    }
}

#[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())
        )
    }
}