diff options
author | sharkdp <davidpeter@web.de> | 2018-05-07 22:59:30 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2018-05-07 23:27:38 +0200 |
commit | 8a399c8d7d7eb7f3ab9dc16ecd462824abf82932 (patch) | |
tree | 6226e17553513a6ed7f3f2c217ce71e318914750 | |
parent | 9a0e444e09e652eccf8603dc477ee80c0c164fbb (diff) |
Disable paging-mode if we read from an interactive TTY
-rw-r--r-- | src/main.rs | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index bfff0bc0..e0923fba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -455,6 +455,21 @@ fn run() -> Result<()> { assets.save()?; } _ => { + let files: Vec<Option<&str>> = app_matches + .values_of("FILE") + .map(|values| { + values + .map(|filename| { + if filename == "-" { + None + } else { + Some(filename) + } + }) + .collect() + }) + .unwrap_or_else(|| vec![None]); // read from stdin (None) if no args are given + let options = Options { true_color: is_truecolor_terminal(), style: match app_matches.value_of("style") { @@ -476,7 +491,14 @@ fn run() -> Result<()> { paging: match app_matches.value_of("paging") { Some("always") => true, Some("never") => false, - Some("auto") | _ => interactive_terminal, + Some("auto") | _ => if files.contains(&None) { + // If we are reading from stdin, only enable paging if we write to an + // interactive terminal and if we do not *read* from an interactive + // terminal. + interactive_terminal && !atty::is(Stream::Stdin) + } else { + interactive_terminal + }, }, }; @@ -490,21 +512,6 @@ fn run() -> Result<()> { ) })?; - let files: Vec<Option<&str>> = app_matches - .values_of("FILE") - .map(|values| { - values - .map(|filename| { - if filename == "-" { - None - } else { - Some(filename) - } - }) - .collect() - }) - .unwrap_or_else(|| vec![None]); // read from stdin (None) if no args are given - let mut output_type = get_output_type(options.paging); let handle = output_type.handle()?; let mut printer = Printer::new(handle, &options); |