summaryrefslogtreecommitdiffstats
path: root/src/search_buffer.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-28 20:50:50 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-28 20:50:50 -0400
commit46dff8f4becc9007b073a1f3f412d6a1a544440c (patch)
tree867085ae3daeadbd75235db9427c0e7edb93a03b /src/search_buffer.rs
parent7aa6e87952cfa36168e3fcb02bb009b2d8d52512 (diff)
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.
Diffstat (limited to 'src/search_buffer.rs')
-rw-r--r--src/search_buffer.rs9
1 files changed, 8 insertions, 1 deletions
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;
}
}