From 260e214fe0d518d19a7e7980d0775b1622e7a066 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 18 Dec 2023 11:49:52 +0100 Subject: [PATCH] Sorted Series Printing --- src/tui/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tui/mod.rs b/src/tui/mod.rs index ddb1368..36253c3 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -4,6 +4,7 @@ use chrono::{Duration, Utc}; use tokio::sync::{RwLock, RwLockReadGuard}; use tokio::time::sleep; use crate::{SharedData}; +use crate::post_history::{PostHistory, PostHistoryInner}; pub(crate) async fn run<'a>(shared_data: Arc>) { let mut min_len_series: u32 = 0; @@ -36,7 +37,9 @@ async fn print_info<'a>(data: RwLockReadGuard<'a, SharedData>, min_len_series: & data.config.config_reload_seconds ); println!("{:#<1$}", "", separator_width); - data.post_history.series.iter().for_each(|(series, post_history)| { + let mut sorted_series: Vec<(&String, &PostHistory)> = data.post_history.series.iter().collect(); + sorted_series.sort_by(|(a, _), (b, _)| a.cmp(b)); + sorted_series.iter().for_each(|(series, post_history)| { if series.len() > local_min_len_series { local_min_len_series = series.len() + 1; @@ -45,9 +48,11 @@ async fn print_info<'a>(data: RwLockReadGuard<'a, SharedData>, min_len_series: & let series_config = data.config.series .iter() - .find(|ser| {&ser.slug == series}) + .find(|ser| {&&ser.slug == series}) .expect("Config should not parse without this"); - post_history.parts.iter().for_each(|(part, part_history)| { + let mut sorted_parts: Vec<(&String, &PostHistoryInner)> = post_history.parts.iter().collect(); + sorted_parts.sort_by(|(a, _), (b, _)| a.cmp(b)); + sorted_parts.iter().for_each(|(part, part_history)| { if part_history.volume.len() > local_min_len_slug { local_min_len_slug = part_history.chapter.len() + 1;