From b48c45ec4ba26ed987e60ddd1b5e0c32f1225463 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 1 Mar 2020 18:40:35 +0100 Subject: Change implementation to use the iterator extensions Signed-off-by: Matthias Beyer --- bin/domain/imag-todo/src/lib.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs index f8611200..cc17a1db 100644 --- a/bin/domain/imag-todo/src/lib.rs +++ b/bin/domain/imag-todo/src/lib.rs @@ -86,6 +86,7 @@ use prettytable::Row; use libimagentryedit::edit::Edit; use libimagentryview::viewer::Viewer; +use libimagentryview::viewer::IntoViewIter; use libimagrt::application::ImagApplication; use libimagrt::runtime::Runtime; use libimagstore::iter::get::*; @@ -95,6 +96,7 @@ use libimagtodo::entry::Todo; use libimagtodo::priority::Priority; use libimagtodo::status::Status; use libimagtodo::store::TodoStore; +use libimagrt::runtime::IntoTouchIterator; mod ui; mod import; @@ -241,7 +243,6 @@ fn mark(rt: &Runtime) -> Result<()> { /// /// Supports filtering of todos by status using the passed in StatusMatcher fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Result<()> { - use filters::failable::filter::FailableFilter; debug!("Listing todos with status filter {:?}", matcher); struct TodoViewer { @@ -315,24 +316,21 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul } } }) - .and_then_ok(|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 { - Error::Other(e) => return Err(e), - Error::Io(e) => if e.kind() != std::io::ErrorKind::BrokenPipe { - return Err(failure::Error::from(e)) - }, - } - } - } - - rt.report_touched(entry.get_location()) + .inspect(|e| trace!("Processing: {:?}", e)) + .filter_map(|r| match r { + Err(err) => Some(Err(err)), + Ok(entry) => match filter_hidden(&entry).map(|b| b || show_hidden) { + Ok(true) => Some(Ok(entry)), + Ok(false) => None, + Err(err) => Some(Err(err)), + }, }) - .collect() + .view_all_if(viewer, &mut rt.stdout(), |r| r.as_ref().ok()) + .and_then_ok(|e| e) + .report_entries_touched(rt, |r| r.as_ref().ok().map(|e| e.get_location().clone())) + .and_then_ok(|e| e) + .collect::>>() + .map(|_| ()) }; if rt.ids_from_stdin() { -- cgit v1.2.3