Rejigger the atty detection stuff.

This commit is contained in:
Andrew Gallant 2016-09-10 00:05:20 -04:00
parent 76331e5fec
commit 5b36c86c15
3 changed files with 14 additions and 14 deletions

View File

@ -12,13 +12,13 @@ use regex;
use term::Terminal; use term::Terminal;
use walkdir::WalkDir; use walkdir::WalkDir;
use atty;
use gitignore::{Gitignore, GitignoreBuilder}; use gitignore::{Gitignore, GitignoreBuilder};
use ignore::Ignore; use ignore::Ignore;
use out::{Out, OutBuffer}; use out::{Out, OutBuffer};
use printer::Printer; use printer::Printer;
use search::{InputBuffer, Searcher}; use search::{InputBuffer, Searcher};
use search_buffer::BufferSearcher; use search_buffer::BufferSearcher;
use sys;
use types::{FileTypeDef, Types, TypesBuilder}; use types::{FileTypeDef, Types, TypesBuilder};
use walk; use walk;
@ -104,7 +104,8 @@ Less common options:
Don't show any file name heading. Don't show any file name heading.
--hidden --hidden
Search hidden directories and files. Search hidden directories and files. (Hidden directories and files are
skipped by default.)
-L, --follow -L, --follow
Follow symlinks. Follow symlinks.
@ -243,7 +244,7 @@ impl RawArgs {
}; };
let paths = let paths =
if self.arg_path.is_empty() { if self.arg_path.is_empty() {
if sys::stdin_is_atty() if atty::on_stdin()
|| self.flag_files || self.flag_files
|| self.flag_type_list { || self.flag_type_list {
vec![Path::new("./").to_path_buf()] vec![Path::new("./").to_path_buf()]
@ -293,7 +294,7 @@ impl RawArgs {
}; };
let color = let color =
if self.flag_color == "auto" { if self.flag_color == "auto" {
sys::stdout_is_atty() || self.flag_pretty atty::on_stdout() || self.flag_pretty
} else { } else {
self.flag_color == "always" self.flag_color == "always"
}; };
@ -344,7 +345,7 @@ impl RawArgs {
with_filename: with_filename, with_filename: with_filename,
}; };
// If stdout is a tty, then apply some special default options. // 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 { if !self.flag_no_line_number && !args.count {
args.line_number = true; args.line_number = true;
} }

View File

@ -1,24 +1,23 @@
/*! /*!
This io module contains various platform specific functions for detecting This atty module contains functions for detecting whether ripgrep is being fed
how ripgrep is being used. e.g., Is stdin being piped into it? Is stdout being from (or to) a terminal. Windows and Unix do this differently, so implement
redirected to a file? etc... We use this information to tweak various default both here.
configuration parameters such as colors and match formatting.
*/ */
#[cfg(unix)] #[cfg(unix)]
pub fn stdin_is_atty() -> bool { pub fn on_stdin() -> bool {
use libc; use libc;
0 < unsafe { libc::isatty(libc::STDIN_FILENO) } 0 < unsafe { libc::isatty(libc::STDIN_FILENO) }
} }
#[cfg(unix)] #[cfg(unix)]
pub fn stdout_is_atty() -> bool { pub fn on_stdout() -> bool {
use libc; use libc;
0 < unsafe { libc::isatty(libc::STDOUT_FILENO) } 0 < unsafe { libc::isatty(libc::STDOUT_FILENO) }
} }
#[cfg(windows)] #[cfg(windows)]
pub fn stdin_is_atty() -> bool { pub fn on_stdin() -> bool {
use kernel32; use kernel32;
use winapi; use winapi;
@ -30,7 +29,7 @@ pub fn stdin_is_atty() -> bool {
} }
#[cfg(windows)] #[cfg(windows)]
pub fn stdout_is_atty() -> bool { pub fn on_stdout() -> bool {
use kernel32; use kernel32;
use winapi; use winapi;

View File

@ -57,6 +57,7 @@ macro_rules! eprintln {
} }
mod args; mod args;
mod atty;
mod gitignore; mod gitignore;
mod glob; mod glob;
mod ignore; mod ignore;
@ -64,7 +65,6 @@ mod out;
mod printer; mod printer;
mod search; mod search;
mod search_buffer; mod search_buffer;
mod sys;
mod terminal; mod terminal;
mod types; mod types;
mod walk; mod walk;