Implement imag-todo-show table view by default
By passing -T, plaintext output can be generated. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
8e0be9f1f7
commit
611fcbc774
3 changed files with 83 additions and 9 deletions
|
@ -30,6 +30,7 @@ filters = "0.3"
|
||||||
kairos = "0.3"
|
kairos = "0.3"
|
||||||
resiter = "0.4.0"
|
resiter = "0.4.0"
|
||||||
handlebars = "2"
|
handlebars = "2"
|
||||||
|
prettytable-rs = "0.8.0"
|
||||||
|
|
||||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
|
|
|
@ -44,6 +44,7 @@ extern crate kairos;
|
||||||
#[macro_use] extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
extern crate resiter;
|
extern crate resiter;
|
||||||
extern crate handlebars;
|
extern crate handlebars;
|
||||||
|
extern crate prettytable;
|
||||||
|
|
||||||
#[cfg(feature = "import-taskwarrior")]
|
#[cfg(feature = "import-taskwarrior")]
|
||||||
extern crate task_hookrs;
|
extern crate task_hookrs;
|
||||||
|
@ -78,6 +79,9 @@ use failure::err_msg;
|
||||||
use clap::App;
|
use clap::App;
|
||||||
use resiter::AndThen;
|
use resiter::AndThen;
|
||||||
use resiter::IterInnerOkOrElse;
|
use resiter::IterInnerOkOrElse;
|
||||||
|
use prettytable::Table;
|
||||||
|
use prettytable::Cell;
|
||||||
|
use prettytable::Row;
|
||||||
|
|
||||||
use libimagentryedit::edit::Edit;
|
use libimagentryedit::edit::Edit;
|
||||||
use libimagentryview::viewer::Viewer;
|
use libimagentryview::viewer::Viewer;
|
||||||
|
@ -390,7 +394,62 @@ fn show(rt: &Runtime) -> Result<()> {
|
||||||
let out = rt.stdout();
|
let out = rt.stdout();
|
||||||
let mut outlock = out.lock();
|
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"))?
|
.ok_or_else(|| err_msg("No ids supplied"))?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Ok)
|
.map(Ok)
|
||||||
|
@ -398,14 +457,19 @@ fn show(rt: &Runtime) -> Result<()> {
|
||||||
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
|
.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))
|
.and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
|
||||||
.collect::<Result<Vec<_>>>()?
|
.collect::<Result<Vec<_>>>()?
|
||||||
.into_iter()
|
.into_iter();
|
||||||
.enumerate()
|
|
||||||
|
if scmd.is_present("show-no-table") {
|
||||||
|
iter.enumerate()
|
||||||
.map(|(i, elem)| {
|
.map(|(i, elem)| {
|
||||||
let data = util::build_data_object_for_handlebars(i, elem.deref())?;
|
let data = util::build_data_object_for_handlebars(i, elem.deref())?;
|
||||||
let s = show_format.render("format", &data)?;
|
let s = show_format.render("format", &data)?;
|
||||||
writeln!(outlock, "{}", s).map_err(Error::from)
|
writeln!(outlock, "{}", s).map_err(Error::from)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
} else {
|
||||||
|
show_with_table(rt, iter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -146,6 +146,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.help("Output format string")
|
.help("Output format string")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.arg(Arg::with_name("show-no-table")
|
||||||
|
.long("no-table")
|
||||||
|
.short("T")
|
||||||
|
.takes_value(false)
|
||||||
|
.required(false)
|
||||||
|
.multiple(false)
|
||||||
|
.help("Show the entries raw, without the ascii-table")
|
||||||
|
)
|
||||||
|
|
||||||
.arg(Arg::with_name("todos")
|
.arg(Arg::with_name("todos")
|
||||||
.index(1)
|
.index(1)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
|
Loading…
Reference in a new issue