summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-25 20:00:07 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-25 20:00:29 -0400
commita13ac3e3d49729403a734c9f3eab2d99a66e21b0 (patch)
tree0f2c6ab05d326ab0260e573d6625c518999437d7
parenta72467996bea8c835ef00c173254f429a2cb5f0b (diff)
On Windows, always consider stdin to be a tty.
This means that `rg pat < file` won't do the expected thing and search `fil`. Instead, it will recursively search the current directory for `pat`. This isn't ideal, but is better than the previous behavior, which was to wait for stdin when running `rg pat`, given the appearance of hanging forever. The former is an important use case, but the latter is the *central* use case of ripgrep, so we should make that work. `rg` can still be used to search stdin on Windows, it just needs to be done explicitly. e.g., `rg pat - < file` will search for `pat` in `file`. Fixes #19
-rw-r--r--src/atty.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/atty.rs b/src/atty.rs
index 0e954093..978c3749 100644
--- a/src/atty.rs
+++ b/src/atty.rs
@@ -27,30 +27,35 @@ pub fn stdin_is_readable() -> bool {
true
}
+/// Returns true if there is a tty on stdin.
#[cfg(unix)]
pub fn on_stdin() -> bool {
use libc;
0 < unsafe { libc::isatty(libc::STDIN_FILENO) }
}
+/// Returns true if there is a tty on stdout.
#[cfg(unix)]
pub fn on_stdout() -> bool {
use libc;
0 < unsafe { libc::isatty(libc::STDOUT_FILENO) }
}
+/// Returns true if there is a tty on stdin.
#[cfg(windows)]
pub fn on_stdin() -> bool {
- use kernel32;
- use winapi;
-
- unsafe {
- let fd = winapi::winbase::STD_INPUT_HANDLE;
- let mut out = 0;
- kernel32::GetConsoleMode(kernel32::GetStdHandle(fd), &mut out) != 0
- }
+ // BUG: https://github.com/BurntSushi/ripgrep/issues/19
+ // It's not clear to me how to determine whether there is a tty on stdin.
+ // Checking GetConsoleMode(GetStdHandle(stdin)) != 0 appears to report
+ // that stdin is a pipe, even if it's not in a cygwin terminal, for
+ // example.
+ //
+ // To fix this, we just assume there is always a tty on stdin. If Windows
+ // users need to search stdin, they'll have to pass -. Ug.
+ true
}
+/// Returns true if there is a tty on stdout.
#[cfg(windows)]
pub fn on_stdout() -> bool {
use kernel32;