From 82c2beafbbe1cb82950928dc12a16fddd71421f4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 30 Jun 2019 11:09:18 +0200 Subject: [PATCH] Add "done" marker in "list" output This patch adds a marker in the table when using the "list" command which marks when the task is already done for the list entry. Signed-off-by: Matthias Beyer --- bin/domain/imag-habit/src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs index 10b6c556..fe4fb4b3 100644 --- a/bin/domain/imag-habit/src/main.rs +++ b/bin/domain/imag-habit/src/main.rs @@ -413,16 +413,23 @@ fn list(rt: &Runtime) { let basedate = h.habit_basedate().map_err_trace_exit_unwrap(); let recur = h.habit_recur_spec().map_err_trace_exit_unwrap(); let comm = h.habit_comment().map_err_trace_exit_unwrap(); - let due = h.next_instance_date().map_err_trace_exit_unwrap() - .map(date_to_string_helper) - .unwrap_or_else(|| String::from("")); + let (due, done) = if let Some(date) = h.next_instance_date().map_err_trace_exit_unwrap() { + let done = h.instance_exists_for_date(&date) + .map(|b| if b { "x" } else { "" }) + .map(String::from) + .map_err_trace_exit_unwrap(); + (date_to_string_helper(date), done) + } else { + // "finished" as in "the habit is closed" + (String::from(""), String::from("")) + }; - let v = vec![name, basedate, recur, comm, due]; + let v = vec![name, basedate, recur, comm, due, done]; debug!(" -> {:?}", v); v } - let header = ["#", "Name", "Basedate", "Recurr", "Comment", "Next Due"] + let header = ["#", "Name", "Basedate", "Recurr", "Comment", "Next Due", "Done"] .iter() .map(|s| Cell::new(s)) .collect::>();