Browse Source

Displaying events is main job now

master
Julio Biason 5 years ago
parent
commit
232d6c35ad
  1. 20
      src/eventlist/event.rs
  2. 15
      src/main.rs

20
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 {

15
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.");
}

Loading…
Cancel
Save