@@ -37,7 +37,7 @@ use syntect::easy::HighlightLines;
3737use syntect::highlighting::Theme;
3838use syntect::parsing::SyntaxDefinition;
3939
40−use app::App;
40+use app::{App, PagingMode};
4141use assets::{config_dir, syntax_set_path, theme_set_path, HighlightingAssets};
4242use diff::get_git_diff;
4343use printer::Printer;
@@ -59,12 +59,27 @@ enum OutputType {
5959}
6060
6161impl OutputType {
62− fn pager() -> Result<Self> {
63− Ok(OutputType::Pager(Command::new("less")
64− .args(&["--quit-if-one-screen", "--RAW-CONTROL-CHARS", "--no-init"])
62+ fn from_mode(mode: PagingMode) -> Self {
63+ use PagingMode::*;
64+ match mode {
65+ Always => OutputType::try_pager(false),
66+ QuitIfOneScreen => OutputType::try_pager(true),
67+ _ => OutputType::stdout(),
68+ }
69+ }
70+
71+ /// Try to launch the pager. Fall back to stdout in case of errors.
72+ fn try_pager(quit_if_one_screen: bool) -> Self {
73+ let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
74+ if quit_if_one_screen {
75+ args.push("--quit-if-one-screen");
76+ }
77+ Command::new("less")
78+ .args(&args)
6579 .stdin(Stdio::piped())
6680 .spawn()
67− .chain_err(|| "Could not spawn pager")?))
81+ .map(OutputType::Pager)
82+ .unwrap_or_else(|_| OutputType::stdout())
6883 }
6984
7085 fn stdout() -> Self {
@@ -153,14 +168,6 @@ fn print_file(
153168 Ok(())
154169}
155170
156−fn get_output_type(paging: bool) -> OutputType {
157− if paging {
158− OutputType::pager().unwrap_or_else(|_| OutputType::stdout())
159− } else {
160− OutputType::stdout()
161− }
162−}
163−
164171fn run() -> Result<()> {
165172 let app = App::new();
166173
@@ -243,7 +250,7 @@ fn run() -> Result<()> {
243250 return Ok(());
244251 }
245252
246− let mut output_type = get_output_type(config.paging);
253+ let mut output_type = OutputType::from_mode(config.paging_mode);
247254 let handle = output_type.handle()?;
248255 let mut printer = Printer::new(handle, &config);
249256