From 345c07c7f83be83358f0ae99758a0d2e97dd0e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 21 Nov 2023 23:36:49 +0100 Subject: [PATCH] rendering improvements --- src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8061a1b..405858d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,12 +171,19 @@ fn render(entries: Vec) { print!("# TODOs\n\n"); - let item_text = |x: &String| { - if x.len() > 0 { - return format!("{x} "); - } + let render_entry = |entry: Entry| { + // todo refactor structs such that Entry is a struct which contains an enum + let (text, location) = match entry { + Entry::Priority(entry) => (entry.text, entry.location), + Entry::Category(entry) => (entry.text, entry.location), + Entry::Generic(entry) => (entry.text, entry.location), + }; - return "".to_string(); + if text.len() > 0 { + println!("- [ ] {} ({}:{})", text, location.file.to_string_lossy(), location.line); + } else { + println!("- [ ] {}:{}", location.file.to_string_lossy(), location.line); + } }; let mut priority_keys = priority_entries.keys().collect::>(); @@ -201,7 +208,7 @@ fn render(entries: Vec) { println!("## {}", priority_notation); for item in priority_entries.get(priority).unwrap() { - println!("- [ ] {}({}:{})", item_text(&item.text), item.location.file.to_string_lossy(), item.location.line); + render_entry(Entry::Priority(item.clone())); } println!(""); @@ -214,7 +221,7 @@ fn render(entries: Vec) { println!("## {}", category); for item in category_entries.get(category).unwrap() { - println!("- [ ] {}({}:{})", item_text(&item.text), item.location.file.to_string_lossy(), item.location.line); + render_entry(Entry::Category(item.clone())); } println!(""); @@ -225,7 +232,7 @@ fn render(entries: Vec) { generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap()); for item in generic_entries { - println!("- [ ] {}({}:{})", item_text(&item.text), item.location.file.to_string_lossy(), item.location.line); + render_entry(Entry::Generic(item.clone())); } }