From f2b0e6581497957c95e8b8188d962d1445695653 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 6 Apr 2020 17:55:33 +0200 Subject: Fix: Do not print data if output is pipe, except if that behaviour is overridden Signed-off-by: Matthias Beyer Fixes: b48c45ec4ba2 ("Change implementation to use the iterator extensions") --- bin/domain/imag-todo/src/lib.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/domain/imag-todo/src/lib.rs b/bin/domain/imag-todo/src/lib.rs index db93004d..2b960650 100644 --- a/bin/domain/imag-todo/src/lib.rs +++ b/bin/domain/imag-todo/src/lib.rs @@ -308,7 +308,7 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul Ok(todo.get_hidden()?.map(|hid| hid > now).unwrap_or(true)) }; - iter + let iter = iter .filter_map(|r| { match r.and_then(|e| e.get_status().map(|s| (s, e))) { Err(e) => Some(Err(e)), @@ -327,13 +327,21 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul Ok(false) => None, Err(err) => Some(Err(err)), }, - }) - .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.output_is_pipe() && !rt.output_data_pipe() { + iter.report_entries_touched(rt, |r| r.as_ref().ok().map(|e| e.get_location().clone())) + .and_then_ok(|e| e) + .collect::>>() + .map(|_| ()) + } else { + iter.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