on master help sign in
Disable paging-mode if we read from an interactive TTY
commit8a399c8d7d7eb7f3ab9dc16ecd462824abf82932 authorsharkdp <davidpeter@web.de> dateMon 7 May 2018, 22:59 (9 years ago) parent9a0e444
1 file changed+23−16
src/main.rs+23−16
src/main.rs+23−16
@@ -455,6 +455,21 @@ fn run() -> Result<()> {
455455 assets.save()?;
456456 }
457457 _ => {
458+ let files: Vec<Option<&str>> = app_matches
459+ .values_of("FILE")
460+ .map(|values| {
461+ values
462+ .map(|filename| {
463+ if filename == "-" {
464+ None
465+ } else {
466+ Some(filename)
467+ }
468+ })
469+ .collect()
470+ })
471+ .unwrap_or_else(|| vec![None]); // read from stdin (None) if no args are given
472+
458473 let options = Options {
459474 true_color: is_truecolor_terminal(),
460475 style: match app_matches.value_of("style") {
@@ -476,7 +491,14 @@ fn run() -> Result<()> {
476491 paging: match app_matches.value_of("paging") {
477492 Some("always") => true,
478493 Some("never") => false,
479− Some("auto") | _ => interactive_terminal,
494+ Some("auto") | _ => if files.contains(&None) {
495+ // If we are reading from stdin, only enable paging if we write to an
496+ // interactive terminal and if we do not *read* from an interactive
497+ // terminal.
498+ interactive_terminal && !atty::is(Stream::Stdin)
499+ } else {
500+ interactive_terminal
501+ },
480502 },
481503 };
482504
@@ -490,21 +512,6 @@ fn run() -> Result<()> {
490512 )
491513 })?;
492514
493− let files: Vec<Option<&str>> = app_matches
494− .values_of("FILE")
495− .map(|values| {
496− values
497− .map(|filename| {
498− if filename == "-" {
499− None
500− } else {
501− Some(filename)
502− }
503− })
504− .collect()
505− })
506− .unwrap_or_else(|| vec![None]); // read from stdin (None) if no args are given
507−
508515 let mut output_type = get_output_type(options.paging);
509516 let handle = output_type.handle()?;
510517 let mut printer = Printer::new(handle, &options);