diff options
author | Akshay <[email protected]> | 2023-05-21 14:22:29 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2023-05-21 14:22:29 +0100 |
commit | eb08fd76ffbb5f16c5644547aaaa9e7f1249ee4d (patch) | |
tree | 69fb16eaec9e986bb77b53080652b8e5962d02b6 /src/feed.rs | |
parent | dbd914d6b5e0d1a566ffa12489f6327dc0eacc47 (diff) |
spice up ui
Diffstat (limited to 'src/feed.rs')
-rw-r--r-- | src/feed.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/feed.rs b/src/feed.rs index c3c5408..f9a7893 100644 --- a/src/feed.rs +++ b/src/feed.rs | |||
@@ -5,6 +5,7 @@ use crate::{ | |||
5 | status::PullStatus, | 5 | status::PullStatus, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ansi_term::{Color, Style}; | ||
8 | use chrono::prelude::*; | 9 | use chrono::prelude::*; |
9 | use feed_rs::{ | 10 | use feed_rs::{ |
10 | model::{Entry as ChannelEntry, Feed as Channel}, | 11 | model::{Entry as ChannelEntry, Feed as Channel}, |
@@ -40,6 +41,14 @@ impl Feed { | |||
40 | self.entries.len() | 41 | self.entries.len() |
41 | } | 42 | } |
42 | 43 | ||
44 | pub fn last_updated(&self) -> DateTime<Utc> { | ||
45 | self.entries | ||
46 | .iter() | ||
47 | .map(|e| e.published) | ||
48 | .max() | ||
49 | .unwrap_or(DateTime::<Utc>::MIN_UTC) | ||
50 | } | ||
51 | |||
43 | pub fn unread_count(&self) -> usize { | 52 | pub fn unread_count(&self) -> usize { |
44 | self.entries.iter().filter(|e| e.unread).count() | 53 | self.entries.iter().filter(|e| e.unread).count() |
45 | } | 54 | } |
@@ -102,7 +111,15 @@ impl Feed { | |||
102 | 111 | ||
103 | impl fmt::Display for Feed { | 112 | impl fmt::Display for Feed { |
104 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 113 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
105 | write!(f, "{}", self.title.to_lowercase()) | 114 | write!( |
115 | f, | ||
116 | "{} {} {}", | ||
117 | self.last_updated().format(crate::DATE_FMT), | ||
118 | Style::new().dimmed().paint(self.title.to_ascii_lowercase()), | ||
119 | Style::new() | ||
120 | .fg(Color::Cyan) | ||
121 | .paint(self.entries.len().to_string()), | ||
122 | ) | ||
106 | } | 123 | } |
107 | } | 124 | } |
108 | 125 | ||
@@ -148,9 +165,17 @@ impl fmt::Display for Entry { | |||
148 | write!( | 165 | write!( |
149 | f, | 166 | f, |
150 | "{} {} {}", | 167 | "{} {} {}", |
151 | self.published.format("%v"), | 168 | self.published.format(crate::DATE_FMT), |
152 | self.link, | 169 | Style::new().fg(Color::Cyan).paint( |
153 | self.title.to_lowercase(), | 170 | self.link |
171 | .as_str() | ||
172 | .trim_end_matches('/') | ||
173 | .trim_start_matches("http://") | ||
174 | .trim_start_matches("https://") | ||
175 | .trim_start_matches("http://www.") | ||
176 | .trim_start_matches("https://www.") | ||
177 | ), | ||
178 | Style::new().dimmed().paint(self.title.to_ascii_lowercase()), | ||
154 | ) | 179 | ) |
155 | } | 180 | } |
156 | } | 181 | } |