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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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<EntryError>,
}
impl PullStatus {
pub fn new(title: String, count: usize, errors: Vec<EntryError>) -> 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 {
if self.is_empty() {
return Ok(());
}
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())
)
}
}
|