From eb08fd76ffbb5f16c5644547aaaa9e7f1249ee4d Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 21 May 2023 18:52:29 +0530 Subject: spice up ui --- src/feed.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/feed.rs') 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::{ status::PullStatus, }; +use ansi_term::{Color, Style}; use chrono::prelude::*; use feed_rs::{ model::{Entry as ChannelEntry, Feed as Channel}, @@ -40,6 +41,14 @@ impl Feed { self.entries.len() } + pub fn last_updated(&self) -> DateTime { + self.entries + .iter() + .map(|e| e.published) + .max() + .unwrap_or(DateTime::::MIN_UTC) + } + pub fn unread_count(&self) -> usize { self.entries.iter().filter(|e| e.unread).count() } @@ -102,7 +111,15 @@ impl Feed { impl fmt::Display for Feed { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.title.to_lowercase()) + write!( + f, + "{} {} {}", + self.last_updated().format(crate::DATE_FMT), + Style::new().dimmed().paint(self.title.to_ascii_lowercase()), + Style::new() + .fg(Color::Cyan) + .paint(self.entries.len().to_string()), + ) } } @@ -148,9 +165,17 @@ impl fmt::Display for Entry { write!( f, "{} {} {}", - self.published.format("%v"), - self.link, - self.title.to_lowercase(), + self.published.format(crate::DATE_FMT), + Style::new().fg(Color::Cyan).paint( + self.link + .as_str() + .trim_end_matches('/') + .trim_start_matches("http://") + .trim_start_matches("https://") + .trim_start_matches("http://www.") + .trim_start_matches("https://www.") + ), + Style::new().dimmed().paint(self.title.to_ascii_lowercase()), ) } } -- cgit v1.2.3