From 46dff8f4becc9007b073a1f3f412d6a1a544440c Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 28 Sep 2016 20:50:50 -0400 Subject: Be better with short circuiting with --quiet. It didn't make sense for --quiet to be part of the printer, because --quiet doesn't just mean "don't print," it also means, "stop after the first match is found." This needs to be wired all the way up through directory traversal, and it also needs to cause all of the search workers to quit as well. We do it with an atomic that is only checked with --quiet is given. Fixes #116. --- src/search_buffer.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/search_buffer.rs') diff --git a/src/search_buffer.rs b/src/search_buffer.rs index efc66cd7..6a32a631 100644 --- a/src/search_buffer.rs +++ b/src/search_buffer.rs @@ -81,6 +81,13 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> { self } + /// If enabled, don't show any output and quit searching after the first + /// match is found. + pub fn quiet(mut self, yes: bool) -> Self { + self.opts.quiet = yes; + self + } + /// If enabled, search binary files as if they were text. pub fn text(mut self, yes: bool) -> Self { self.opts.text = yes; @@ -104,7 +111,7 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> { self.print_match(m.start(), m.end()); } last_end = m.end(); - if self.printer.is_quiet() || self.opts.files_with_matches { + if self.opts.stop_after_first_match() { break; } } -- cgit v1.2.3