diff options
author | stuebinm | 2022-01-23 23:17:25 +0100 |
---|---|---|
committer | stuebinm | 2022-01-23 23:17:25 +0100 |
commit | 5200c5aa1bdd9b6c5ef6f1feecf6c5b3ecd0fdd2 (patch) | |
tree | 7bbc0591ec066c948b7c08a561f3e9055ab84b0c /src | |
parent | be71912380176043a49a90487e9ce8e5a2d61d45 (diff) |
display calendar names alongside events
Diffstat (limited to 'src')
-rw-r--r-- | src/calendar.rs | 13 | ||||
-rw-r--r-- | src/event.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | src/periodic.rs | 2 |
4 files changed, 22 insertions, 7 deletions
diff --git a/src/calendar.rs b/src/calendar.rs index 303a2f8..d04c9ba 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -21,8 +21,17 @@ impl Calendar { let mut periodic = Vec::new(); for line in reader { - for ev in line?.events { - let mut event = Event::new(); + let calendar = line?; + let name = calendar + .properties + .iter() + .filter(|prop| prop.name == "X-WR-CALNAME") + .map(|prop| prop.value.clone()) + .flatten() + .next(); + + for ev in calendar.events { + let mut event = Event::new(&name); let mut maybe_periodic = None; for property in ev.properties { diff --git a/src/event.rs b/src/event.rs index e8cfceb..f58519a 100644 --- a/src/event.rs +++ b/src/event.rs @@ -16,6 +16,7 @@ pub struct Event { pub location: String, pub description: String, pub status: Status, + pub calendar: String } #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq)] @@ -33,7 +34,7 @@ pub enum End { impl Event { - pub fn new() -> Event { + pub fn new(calendar: &Option<String>) -> Event { return Event { summary: "".to_string(), location: "".to_string(), @@ -41,6 +42,10 @@ impl Event { status: Status::Confirmed, start: Date::new(), end: End::Date(Date::new()), + calendar: match calendar { + None => "[unknown calendar]".to_string(), + Some(a) => a.to_string() + } }; } diff --git a/src/main.rs b/src/main.rs index 4dfe1d0..2a2070b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -135,15 +135,16 @@ fn print_event(event: &Event, ustart: bool, uend: bool) { }; println!( - " {}-{} {} {}", + " {}-{} {}\n {} {}", start.yellow(), end.yellow(), + event.calendar.cyan(), event.summary, event.location.purple() ); if !event.description.is_empty() { - let description = str::replace(&event.description, "\\n", &format!("\n{}", " ".repeat(16))); - println!("{}{}", " ".repeat(16), description.cyan()); + let description = str::replace(&event.description, "\\n", &format!("\n{}", " ".repeat(8))); + println!("{}{}", " ".repeat(8), description.cyan()); } } diff --git a/src/periodic.rs b/src/periodic.rs index 2891bed..3eada26 100644 --- a/src/periodic.rs +++ b/src/periodic.rs @@ -37,7 +37,7 @@ pub enum Freq { impl Periodic { pub fn new() -> Self { Self { - event: Event::new(), + event: Event::new(&None), freq: Freq::Secondly, interval: 1, count: None, |