summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-25 15:01:27 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-25 15:01:29 -0400
commit9dc5464c84cf96c8e7cba96e2b470ebd066c2393 (patch)
tree4016714c5d55db24824f6c38139aa7877f3f8c60
parent95edcd4d3a7c98d5679c890ed9875a17e54ca001 (diff)
Stop after first match is found with --quiet.
Fixes #77.
-rw-r--r--doc/rg.11
-rw-r--r--doc/rg.1.md3
-rw-r--r--src/args.rs3
-rw-r--r--src/printer.rs5
-rw-r--r--src/search_buffer.rs2
-rw-r--r--src/search_stream.rs3
6 files changed, 13 insertions, 4 deletions
diff --git a/doc/rg.1 b/doc/rg.1
index 1b437b94..375b4662 100644
--- a/doc/rg.1
+++ b/doc/rg.1
@@ -91,6 +91,7 @@ Suppress line numbers.
.TP
.B \-q, \-\-quiet
Do not print anything to stdout.
+If a match is found in a file, stop searching that file.
.RS
.RE
.TP
diff --git a/doc/rg.1.md b/doc/rg.1.md
index ddc563dc..4c38ddf7 100644
--- a/doc/rg.1.md
+++ b/doc/rg.1.md
@@ -61,7 +61,8 @@ the raw speed of grep.
: Suppress line numbers.
-q, --quiet
-: Do not print anything to stdout.
+: Do not print anything to stdout. If a match is found in a file, stop
+ searching that file.
-r, --replace *ARG*
: Replace every match with the string given. Capture group indices (e.g., $5)
diff --git a/src/args.rs b/src/args.rs
index 72d4fdd8..5c3376a6 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -66,7 +66,8 @@ Common options:
-n, --line-number Show line numbers (1-based). This is enabled
by default at a tty.
-N, --no-line-number Suppress line numbers.
- -q, --quiet Do not print anything to stdout.
+ -q, --quiet Do not print anything to stdout. If a match is
+ found in a file, stop searching that file.
-r, --replace ARG Replace every match with the string given.
Capture group indices (e.g., $5) and names
(e.g., $foo) are supported.
diff --git a/src/printer.rs b/src/printer.rs
index 999e078a..a690eaa0 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -116,6 +116,11 @@ impl<W: Terminal + Send> Printer<W> {
self.has_printed
}
+ /// Returns true if the printer has been configured to be quiet.
+ pub fn is_quiet(&self) -> bool {
+ self.quiet
+ }
+
/// Flushes the underlying writer and returns it.
pub fn into_inner(mut self) -> W {
let _ = self.wtr.flush();
diff --git a/src/search_buffer.rs b/src/search_buffer.rs
index a3edbcb0..efc66cd7 100644
--- a/src/search_buffer.rs
+++ b/src/search_buffer.rs
@@ -104,7 +104,7 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> {
self.print_match(m.start(), m.end());
}
last_end = m.end();
- if self.opts.files_with_matches {
+ if self.printer.is_quiet() || self.opts.files_with_matches {
break;
}
}
diff --git a/src/search_stream.rs b/src/search_stream.rs
index 7b661808..0b5bfaf6 100644
--- a/src/search_stream.rs
+++ b/src/search_stream.rs
@@ -265,7 +265,8 @@ impl<'a, R: io::Read, W: Terminal + Send> Searcher<'a, R, W> {
#[inline(always)]
fn terminate(&self) -> bool {
- return self.opts.files_with_matches && self.match_count > 0;
+ self.match_count > 0
+ && (self.printer.is_quiet() || self.opts.files_with_matches)
}
#[inline(always)]