Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use std::rc::Rc;

use chrono::{self, DateTime};
use ratatui::backend::Backend;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Span, Text};
use ratatui::widgets::{Block, Borders, LineGauge, List, ListItem, Paragraph, Wrap};
use ratatui::Frame;
use std::rc::Rc;

use crate::app::AppImpl;
use crate::modes::{Mode, ReadMode, Selected};
use crate::rss::EntryMeta;

const PINK: Color = Color::Rgb(255, 150, 167);

/// Date format used that is YY-MM-DD HH:MM:SS.
const DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";

pub fn predraw<B: Backend>(f: &Frame<B>) -> Rc<[Rect]> {
Layout::default()
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)].as_ref())
Expand Down Expand Up @@ -241,7 +246,7 @@ where
.current_feed
.as_ref()
.and_then(|feed| feed.refreshed_at)
.map(|timestamp| timestamp.to_string())
.map(|timestamp| format_time(&timestamp))
.or_else(|| Some("Never refreshed".to_string()))
{
text.push_str("Refreshed at: ");
Expand Down Expand Up @@ -511,6 +516,11 @@ where
}
}

/// Format the given time in local timezone with seconds precision.
fn format_time<Tz: chrono::TimeZone>(t: &DateTime<Tz>) -> String {
t.with_timezone(&chrono::Local).format(DATETIME_FORMAT).to_string()
}

fn error_text(errors: &[anyhow::Error]) -> String {
errors
.iter()
Expand Down