summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2017-03-12 20:21:38 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-03-12 20:21:40 -0400
commit4ef481813084b83e04ece4ed44ccb38b49f7e817 (patch)
tree8cc5dd85fa5cfcd47fdcba68176de07b85e0a5cf
parent8db24e135375a2510e3eca85c72005172788471e (diff)
No line numbers when searching only stdin.
This changes the default behavior of ripgrep to *not* show line numbers when it is printing to a tty and is only searching stdin. Fixes #380 [breaking-change]
-rw-r--r--src/args.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/args.rs b/src/args.rs
index 7e60cd7d..cc48b7ad 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -319,6 +319,7 @@ impl<'a> ArgMatches<'a> {
/// configuration.
fn to_args(&self) -> Result<Args> {
let paths = self.paths();
+ let line_number = self.line_number(&paths);
let mmap = try!(self.mmap(&paths));
let with_filename = self.with_filename(&paths);
let (before_context, after_context) = try!(self.contexts());
@@ -345,7 +346,7 @@ impl<'a> ArgMatches<'a> {
hidden: self.hidden(),
ignore_files: self.ignore_files(),
invert_match: self.is_present("invert-match"),
- line_number: self.line_number(),
+ line_number: line_number,
line_per_match: self.is_present("vimgrep"),
max_count: try!(self.usize_of("max-count")).map(|max| max as u64),
max_filesize: try!(self.max_filesize()),
@@ -593,13 +594,14 @@ impl<'a> ArgMatches<'a> {
}
/// Returns true if and only if line numbers should be shown.
- fn line_number(&self) -> bool {
+ fn line_number(&self, paths: &[PathBuf]) -> bool {
if self.is_present("no-line-number") || self.is_present("count") {
false
} else {
+ let only_stdin = paths == &[Path::new("-")];
self.is_present("line-number")
|| self.is_present("column")
- || atty::is(atty::Stream::Stdout)
+ || (atty::is(atty::Stream::Stdout) && !only_stdin)
|| self.is_present("pretty")
|| self.is_present("vimgrep")
}