From 8a399c8d7d7eb7f3ab9dc16ecd462824abf82932 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Mon, 7 May 2018 22:59:30 +0200 Subject: [PATCH] Disable paging-mode if we read from an interactive TTY --- src/main.rs | 39 +++++++++++++++++++++++---------------- 1 file 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> = 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> = 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);