summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/domain/imag-todo/src/lib.rs44
-rw-r--r--bin/domain/imag-todo/src/ui.rs11
-rw-r--r--lib/core/libimagrt/src/runtime.rs56
3 files changed, 91 insertions, 20 deletions
diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs
index b2007b49..f8611200 100644
--- a/bin/domain/imag-todo/src/lib.rs
+++ b/bin/domain/imag-todo/src/lib.rs
@@ -159,22 +159,14 @@ impl StatusMatcher {
}
pub fn is(mut self, s: Status) -> Self {
- self.add_is(s);
- self
- }
-
- pub fn add_is(&mut self, s: Status) {
self.is.push(s);
+ self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_not(mut self, s: Status) -> Self {
- self.add_is_not(s);
- self
- }
-
- pub fn add_is_not(&mut self, s: Status) {
self.is_not.push(s);
+ self
}
pub fn matches(&self, todo: Status) -> bool {
@@ -182,10 +174,7 @@ impl StatusMatcher {
// On blacklist
false
} else {
- // No whitelist or on whitelist
- // or
- // Not on blacklist, but whitelist exists and not on it either
- self.is.is_empty() || self.is.iter().any(|t| *t == todo)
+ self.is.iter().any(|t| *t == todo)
}
}
}
@@ -327,7 +316,9 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
}
})
.and_then_ok(|entry| {
- if !rt.output_is_pipe() && (show_hidden || filter_hidden.filter(&entry)?) {
+ trace!("Processing {}", entry.get_location());
+ if (!rt.output_is_pipe() || rt.output_data_pipe()) && (show_hidden || filter_hidden.filter(&entry)?) {
+ trace!("Printing {}", entry.get_location());
if let Err(e) = viewer.view_entry(&entry, &mut rt.stdout()) {
use libimagentryview::error::Error;
match e {
@@ -345,6 +336,7 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
};
if rt.ids_from_stdin() {
+ trace!("Getting IDs from stdin");
let iter = rt.ids::<crate::ui::PathProvider>()?
.ok_or_else(|| err_msg("No ids supplied"))?
.into_iter()
@@ -354,6 +346,7 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
process(&rt, matcher, show_hidden, iter)
} else {
+ trace!("Getting IDs from store");
let iter = rt.store().get_todos()?
.into_get_iter()
.map_inner_ok_or_else(|| err_msg("Did not find one entry"));
@@ -372,15 +365,30 @@ fn list(rt: &Runtime) -> Result<()> {
let hidden = scmd.map(|s| s.is_present("list-hidden")).unwrap_or(false);
let done = scmd.map(|s| s.is_present("list-done")).unwrap_or(false);
let nopending = scmd.map(|s| s.is_present("list-nopending")).unwrap_or(true);
+ let deleted = scmd.map(|s| s.is_present("list-deleted")).unwrap_or(true);
trace!("table = {}", table);
trace!("hidden = {}", hidden);
trace!("done = {}", done);
trace!("nopending = {}", nopending);
- let mut matcher = StatusMatcher::new();
- if !done { matcher.add_is_not(Status::Done); }
- if nopending { matcher.add_is_not(Status::Pending); }
+ let matcher = {
+ let mut matcher = if nopending {
+ StatusMatcher::new().is_not(Status::Pending)
+ } else {
+ StatusMatcher::new().is(Status::Pending)
+ };
+
+ if done {
+ matcher = matcher.is(Status::Done)
+ }
+
+ if deleted {
+ matcher = matcher.is(Status::Deleted)
+ }
+
+ matcher
+ };
// TODO: Support printing as ASCII table
list_todos(rt, &matcher, hidden)
diff --git a/bin/domain/imag-todo/src/ui.rs b/bin/domain/imag-todo/src/ui.rs
index 7d0affd5..1172bb60 100644
--- a/bin/domain/imag-todo/src/ui.rs
+++ b/bin/domain/imag-todo/src/ui.rs
@@ -116,7 +116,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.short("H")
.takes_value(false)
.required(false)
- .help("Print also hidden todos")
+ .help("Print hidden todos")
)
.arg(Arg::with_name("list-done")
@@ -124,7 +124,14 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.short("D")
.takes_value(false)
.required(false)
- .help("Print also done todos")
+ .help("Print done todos")
+ )
+
+ .arg(Arg::with_name("list-deleted")
+ .long("deleted")
+ .takes_value(false)
+ .required(false)
+ .help("Print deleted todos")
)
.arg(Arg::with_name("list-nopending")
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 4522a1f0..c29a2846 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -577,6 +577,62 @@ impl<'a> Runtime<'a> {
}
}
+pub trait IntoTouchIterator<E, F>
+ where Self: Iterator<Item = E> + Sized,
+ E: Sized,
+ F: Fn(&E) -> Option<StoreId>
+{
+ fn report_entries_touched<'a>(self, rt: &'a Runtime<'a>, func: F) -> TouchIterator<'a, Self, E, F> {
+ TouchIterator {
+ inner: self,
+ rt,
+ func
+ }
+ }
+}
+
+impl<I, E, F> IntoTouchIterator<E, F> for I
+ where I: Iterator<Item = E>,
+ E: Sized,
+ F: Fn(&E) -> Option<StoreId>
+{
+ // default implementation
+}
+
+pub struct TouchIterator<'a, I, E, F>
+ where I: Iterator<Item = E>,
+ E: Sized,
+ F: Fn(&E) -> Option<StoreId>
+{
+ inner: I,
+ rt: &'a Runtime<'a>,
+ func: F
+}
+
+impl<'a, I, E, F> Iterator for TouchIterator<'a, I, E, F>
+ where I: Iterator<Item = E>,
+ E: Sized,
+ F: Fn(&E) -> Option<StoreId>
+{
+ type Item = Result<E>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ while let Some(next) = self.inner.next() {
+ match (self.func)(&next) {
+ Some(id) => if let Err(e) = self.rt.report_touched(&id) {
+ return Some(Err(e))
+ } else {
+ return Some(Ok(next))
+ },
+
+ None => continue,
+ }
+ }
+
+ None
+ }
+}
+
/// A trait for providing ids from clap argument matches
///
/// This trait can be implement on a type so that it can provide IDs when given a ArgMatches