From 232d6c35ad809da85950dc68cdbcdb54b34e0997 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 15 May 2020 21:07:04 -0300 Subject: [PATCH] Displaying events is main job now --- src/eventlist/event.rs | 20 ++------------------ src/main.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/eventlist/event.rs b/src/eventlist/event.rs index 548eea9..143468a 100644 --- a/src/eventlist/event.rs +++ b/src/eventlist/event.rs @@ -18,7 +18,6 @@ use std::cmp::Ordering; use std::convert::From; -use std::fmt; use chrono::prelude::*; use chrono::DateTime; @@ -91,8 +90,8 @@ impl From<&EventDateType> for String { #[derive(Serialize, Deserialize, Debug)] pub struct Event { - id: String, - description: String, + pub id: String, + pub description: String, due: EventDateType, } @@ -151,21 +150,6 @@ impl Event { } } -impl fmt::Display for Event { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{:8} - {:>6} - {}", - self.id, - match self.eta() { - Some(x) => x, - None => "".into(), - }, - self.description - ) - } -} - impl Eq for Event {} impl PartialEq for Event { diff --git a/src/main.rs b/src/main.rs index 2488b4b..39e7929 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,9 +40,16 @@ fn main() { } fn list() { - let event_list = EventList::load(); // TODO hide this + let event_list = EventList::load(); // TODO hide load from outside + println!("{:^8} | {:^7} | {}", "ID", "ETA", "Description"); for record in event_list.into_iter() { - println!("{}", record); // TODO remove display + let eta = if let Some(eta) = record.eta() { + eta + } else { + "Over".into() + }; + + println!("{:>8} | {:>7} | {}", record.id, eta, record.description); } } @@ -58,12 +65,10 @@ fn add_with_date_time(description: &str, date: &str, time: &str) { } fn add_event(event: Event) { - println!("Adding event {}", event); + println!("Adding event {}", event.id); let mut event_list = EventList::load(); log::debug!("EventList: {:?}", event_list); event_list.push(event); event_list.save(); - - println!("Done."); }