summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-todo/src/lib.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-13 19:58:44 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-01 14:48:41 +0100
commit611fcbc7746e4a1ebaf4faec83caf1e1c78f31f3 (patch)
tree29e323561ad6041a7f6173071c9ef53a54658321 /bin/domain/imag-todo/src/lib.rs
parent8e0be9f1f7d5ad7e3ea8d1288d3d45f8f3a56d47 (diff)
downloadimag-611fcbc7746e4a1ebaf4faec83caf1e1c78f31f3.tar.gz
imag-611fcbc7746e4a1ebaf4faec83caf1e1c78f31f3.tar.xz
Diffstat (limited to 'bin/domain/imag-todo/src/lib.rs')
-rw-r--r--bin/domain/imag-todo/src/lib.rs82
1 files changed, 73 insertions, 9 deletions
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index aa163dff..ff6ba777 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -44,6 +44,7 @@ extern crate kairos;
#[macro_use] extern crate failure;
extern crate resiter;
extern crate handlebars;
+extern crate prettytable;
#[cfg(feature = "import-taskwarrior")]
extern crate task_hookrs;
@@ -78,6 +79,9 @@ use failure::err_msg;
use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
+use prettytable::Table;
+use prettytable::Cell;
+use prettytable::Row;
use libimagentryedit::edit::Edit;
use libimagentryview::viewer::Viewer;
@@ -390,7 +394,62 @@ fn show(rt: &Runtime) -> Result<()> {
let out = rt.stdout();
let mut outlock = out.lock();
- rt.ids::<crate::ui::PathProvider>()?
+ fn show_with_table<'a, I>(rt: &Runtime, iter: I) -> Result<()>
+ where I: Iterator<Item = FileLockEntry<'a>>
+ {
+ const HEADER: &'static [&'static str] = &[
+ "uuid",
+ "status",
+ "sched",
+ "hidden",
+ "due",
+ "priority",
+ "text",
+ ];
+
+ let mut table = {
+ let mut t = Table::new();
+ let header = HEADER.iter().map(|s| Cell::new(s)).collect::<Vec<Cell>>();
+ t.set_titles(Row::from(header));
+ t
+ };
+
+ iter.map(|entry| {
+ use libimagentryview::error::Error as E;
+
+ let uuid = entry.get_uuid().map_err(E::from)?.to_hyphenated().to_string();
+ let status = entry.get_status().map_err(E::from)?;
+ let status = status.as_str().to_string();
+ let sched = util::get_dt_str(entry.get_scheduled(), "Not scheduled")?.to_string();
+ let hidden = util::get_dt_str(entry.get_hidden(), "Not hidden")?.to_string();
+ let due = util::get_dt_str(entry.get_due(), "No due")?.to_string();
+ let priority = entry.get_priority().map_err(E::from)?.map(|p| p.as_str().to_string()).unwrap_or("No prio".to_string());
+
+ let text = entry.get_content().to_owned();
+
+ let v = [
+ uuid,
+ status,
+ sched,
+ hidden,
+ due,
+ priority,
+ text,
+ ];
+ table.add_row(v.iter().map(|s| Cell::new(s)).collect());
+
+ Ok(entry)
+ })
+ .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
+ .collect::<Result<Vec<_>>>()?;
+
+ table.print(&mut rt.stdout())
+ .map(|_| ())
+ .map_err(Error::from)
+ }
+
+ let iter = rt
+ .ids::<crate::ui::PathProvider>()?
.ok_or_else(|| err_msg("No ids supplied"))?
.into_iter()
.map(Ok)
@@ -398,14 +457,19 @@ fn show(rt: &Runtime) -> Result<()> {
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
.and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
.collect::<Result<Vec<_>>>()?
- .into_iter()
- .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()
+ .into_iter();
+
+ if scmd.is_present("show-no-table") {
+ iter.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()
+ } else {
+ show_with_table(rt, iter)
+ }
}
//