1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-04-02 20:45:38 +02:00

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 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;
}

View File

@ -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;

View File

@ -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;