on master help sign in
Omit launching of pager if NO file exists

closes #387

commit397def13204cbd983cab9ea6edff41a452406f79 authorsharkdp <davidpeter@web.de> dateFri 14 Dec 2018, 21:44 (8 years ago) parentd2d2918
1 file changed+18−2
src/controller.rs+18−2
src/controller.rs+18−2
@@ -1,6 +1,7 @@
11use std::io::{self, Write};
2+use std::path::Path;
23
3−use app::Config;
4+use app::{Config, PagingMode};
45use assets::HighlightingAssets;
56use errors::*;
67use inputfile::{InputFile, InputFileReader};
@@ -19,7 +20,22 @@ impl<'b> Controller<'b> {
1920 }
2021
2122 pub fn run(&self) -> Result<bool> {
22− let mut output_type = OutputType::from_mode(self.config.paging_mode, self.config.pager)?;
23+ // Do not launch the pager if NONE of the input files exist
24+ let mut paging_mode = self.config.paging_mode;
25+ if self.config.paging_mode != PagingMode::Never {
26+ let call_pager = self.config.files.iter().any(|file| {
27+ if let InputFile::Ordinary(path) = file {
28+ return Path::new(path).exists();
29+ } else {
30+ return true;
31+ }
32+ });
33+ if !call_pager {
34+ paging_mode = PagingMode::Never;
35+ }
36+ }
37+
38+ let mut output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
2339 let writer = output_type.handle()?;
2440 let mut no_errors: bool = true;
2541