summaryrefslogtreecommitdiff
path: root/src/feed.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/feed.rs')
-rw-r--r--src/feed.rs33
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
8use ansi_term::{Color, Style};
8use chrono::prelude::*; 9use chrono::prelude::*;
9use feed_rs::{ 10use 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
103impl fmt::Display for Feed { 112impl 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}