summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-10 00:05:20 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-10 00:05:20 -0400
commit5b36c86c15933a6f55fd4d49712461c263a3de1c (patch)
treeeba98c8e2ddf6f8637eae6af9e0a8389ca80c8dc /src
parent76331e5feca2520f4a7a70f573fce9dcdef44d90 (diff)
Rejigger the atty detection stuff.
Diffstat (limited to 'src')
-rw-r--r--src/args.rs11
-rw-r--r--src/atty.rs (renamed from src/sys.rs)15
-rw-r--r--src/main.rs2
3 files changed, 14 insertions, 14 deletions
diff --git a/src/args.rs b/src/args.rs
index ea7299fe..0341cef7 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -12,13 +12,13 @@ use regex;
use term::Terminal;
use walkdir::WalkDir;
+use atty;
use gitignore::{Gitignore, GitignoreBuilder};
use ignore::Ignore;
use out::{Out, OutBuffer};
use printer::Printer;
use search::{InputBuffer, Searcher};
use search_buffer::BufferSearcher;
-use sys;
use types::{FileTypeDef, Types, TypesBuilder};
use walk;
@@ -104,7 +104,8 @@ Less common options:
Don't show any file name heading.
--hidden
- Search hidden directories and files.
+ Search hidden directories and files. (Hidden directories and files are
+ skipped by default.)
-L, --follow
Follow symlinks.
@@ -243,7 +244,7 @@ impl RawArgs {
};
let paths =
if self.arg_path.is_empty() {
- if sys::stdin_is_atty()
+ if atty::on_stdin()
|| self.flag_files
|| self.flag_type_list {
vec![Path::new("./").to_path_buf()]
@@ -293,7 +294,7 @@ impl RawArgs {
};
let color =
if self.flag_color == "auto" {
- sys::stdout_is_atty() || self.flag_pretty
+ atty::on_stdout() || self.flag_pretty
} else {
self.flag_color == "always"
};
@@ -344,7 +345,7 @@ impl RawArgs {
with_filename: with_filename,
};
// If stdout is a tty, then apply some special default options.
- if sys::stdout_is_atty() || self.flag_pretty {
+ if atty::on_stdout() || self.flag_pretty {
if !self.flag_no_line_number && !args.count {
args.line_number = true;
}
diff --git a/src/sys.rs b/src/atty.rs
index 4f53039e..c2db4292 100644
--- a/src/sys.rs
+++ b/src/atty.rs
@@ -1,24 +1,23 @@
/*!
-This io module contains various platform specific functions for detecting
-how ripgrep is being used. e.g., Is stdin being piped into it? Is stdout being
-redirected to a file? etc... We use this information to tweak various default
-configuration parameters such as colors and match formatting.
+This atty module contains functions for detecting whether ripgrep is being fed
+from (or to) a terminal. Windows and Unix do this differently, so implement
+both here.
*/
#[cfg(unix)]
-pub fn stdin_is_atty() -> bool {
+pub fn on_stdin() -> bool {
use libc;
0 < unsafe { libc::isatty(libc::STDIN_FILENO) }
}
#[cfg(unix)]
-pub fn stdout_is_atty() -> bool {
+pub fn on_stdout() -> bool {
use libc;
0 < unsafe { libc::isatty(libc::STDOUT_FILENO) }
}
#[cfg(windows)]
-pub fn stdin_is_atty() -> bool {
+pub fn on_stdin() -> bool {
use kernel32;
use winapi;
@@ -30,7 +29,7 @@ pub fn stdin_is_atty() -> bool {
}
#[cfg(windows)]
-pub fn stdout_is_atty() -> bool {
+pub fn on_stdout() -> bool {
use kernel32;
use winapi;
diff --git a/src/main.rs b/src/main.rs
index 493256f0..46ff894d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -57,6 +57,7 @@ macro_rules! eprintln {
}
mod args;
+mod atty;
mod gitignore;
mod glob;
mod ignore;
@@ -64,7 +65,6 @@ mod out;
mod printer;
mod search;
mod search_buffer;
-mod sys;
mod terminal;
mod types;
mod walk;