summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-todo/src/lib.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-01 12:54:11 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-01 12:54:11 +0100
commitcadd9f894478b4c5a9c173655e506c5f4794e04a (patch)
tree5844cb3559cd664ef4ef7b8e3153b031f10efcf9 /bin/domain/imag-todo/src/lib.rs
parentc2d4ec5fefe5de8871d974e7dd61af0fa618ae91 (diff)
downloadimag-cadd9f894478b4c5a9c173655e506c5f4794e04a.tar.gz
imag-cadd9f894478b4c5a9c173655e506c5f4794e04a.tar.xz
Diffstat (limited to 'bin/domain/imag-todo/src/lib.rs')
-rw-r--r--bin/domain/imag-todo/src/lib.rs66
1 files changed, 18 insertions, 48 deletions
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index 1ee53439..0943e8c7 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -43,6 +43,7 @@ extern crate kairos;
#[macro_use] extern crate log;
#[macro_use] extern crate failure;
extern crate resiter;
+extern crate handlebars;
#[cfg(feature = "import-taskwarrior")]
extern crate task_hookrs;
@@ -63,7 +64,9 @@ extern crate libimagentryedit;
extern crate libimagtodo;
extern crate libimagutil;
extern crate libimagentryview;
+extern crate libimaginteraction;
+use std::ops::Deref;
use std::io::Write;
use std::result::Result as RResult;
@@ -77,7 +80,6 @@ use resiter::AndThen;
use resiter::IterInnerOkOrElse;
use libimagentryedit::edit::Edit;
-use libimagentryview::viewer::ViewFromIter;
use libimagentryview::viewer::Viewer;
use libimagrt::application::ImagApplication;
use libimagrt::runtime::Runtime;
@@ -88,10 +90,10 @@ use libimagtodo::entry::Todo;
use libimagtodo::priority::Priority;
use libimagtodo::status::Status;
use libimagtodo::store::TodoStore;
-use libimagutil::date::datetime_to_string;
mod ui;
mod import;
+mod util;
/// Marker enum for implementing ImagApplication on
///
@@ -287,9 +289,9 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
status = status,
first_line = first_line)
} else {
- let sched = get_dt_str(entry.get_scheduled(), "Not scheduled")?;
- let hidden = get_dt_str(entry.get_hidden(), "Not hidden")?;
- let due = get_dt_str(entry.get_due(), "No due")?;
+ let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?;
+ let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?;
+ let due = util::get_dt_str(entry.get_due(), "No due")?;
let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
.unwrap_or("No prio".to_string());
@@ -357,41 +359,10 @@ fn list(rt: &Runtime) -> Result<()> {
}
fn show(rt: &Runtime) -> Result<()> {
- #[derive(Default)]
- struct TodoShow;
- impl Viewer for TodoShow {
-
- fn view_entry<W>(&self, entry: &Entry, sink: &mut W) -> RResult<(), libimagentryview::error::Error>
- where W: Write
- {
- use libimagentryview::error::Error as E;
-
- if !entry.is_todo().map_err(E::from)? {
- return Err(format_err!("Not a Todo: {}", entry.get_location())).map_err(E::from);
- }
-
- let uuid = entry.get_uuid().map_err(E::from)?;
- let status = entry.get_status().map_err(E::from)?;
- let status = status.as_str();
- let text = entry.get_content();
- let sched = get_dt_str(entry.get_scheduled(), "Not scheduled")?;
- let hidden = get_dt_str(entry.get_hidden(), "Not hidden")?;
- let due = get_dt_str(entry.get_due(), "No due")?;
- let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string())
- .unwrap_or("No prio".to_string());
-
- writeln!(sink, "{uuid}\nStatus: {status}\nPriority: {prio}\nScheduled: {sched}\nHidden: {hidden}\nDue: {due}\n\n{text}",
- uuid = uuid,
- status = status,
- sched = sched,
- hidden = hidden,
- due = due,
- prio = priority,
- text = text)
- .map_err(Error::from)
- .map_err(libimagentryview::error::Error::from)
- }
- }
+ let scmd = rt.cli().subcommand_matches("show").unwrap();
+ let show_format = util::get_todo_print_format("todo.show_format", rt, &scmd)?;
+ let out = rt.stdout();
+ let mut outlock = out.lock();
rt.ids::<crate::ui::PathProvider>()?
.ok_or_else(|| err_msg("No ids supplied"))?
@@ -402,8 +373,13 @@ fn show(rt: &Runtime) -> Result<()> {
.and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
.collect::<Result<Vec<_>>>()?
.into_iter()
- .view::<TodoShow, _>(&mut rt.stdout())
- .map_err(Error::from)
+ .enumerate()
+ .map(|(i, elem)| {
+ let data = util::build_data_object_for_handlebars(i, elem.deref())?;
+ let s = show_format.render("format", &data)?;
+ writeln!(outlock, "{}", s).map_err(Error::from)
+ })
+ .collect()
}
//
@@ -437,9 +413,3 @@ fn prio_from_str<S: AsRef<str>>(s: S) -> Result<Priority> {
}
}
-fn get_dt_str(d: Result<Option<NaiveDateTime>>, s: &str) -> RResult<String, libimagentryview::error::Error> {
- Ok(d.map_err(libimagentryview::error::Error::from)?
- .map(|v| datetime_to_string(&v))
- .unwrap_or(s.to_string()))
-}
-