on master help sign in
Use BAT_PAGER and PAGER environment variables, closes #158
commitd179693d1d4a571d6b5ec3279d09390d6115b39c authorsharkdp <davidpeter@web.de> dateMon 23 Jul 2018, 22:49 (8 years ago) parent268577c
1 file changed+19−7
src/output.rs+19−7
src/output.rs+19−7
@@ -1,5 +1,6 @@
11use app::PagingMode;
22use errors::*;
3+use std::env;
34use std::io::{self, Write};
45use std::process::{Child, Command, Stdio};
56
@@ -20,13 +21,24 @@ impl OutputType {
2021
2122 /// Try to launch the pager. Fall back to stdout in case of errors.
2223 fn try_pager(quit_if_one_screen: bool) -> Self {
23− let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
24− if quit_if_one_screen {
25− args.push("--quit-if-one-screen");
26− }
27− Command::new("less")
28− .args(&args)
29− .env("LESSCHARSET", "UTF-8")
24+ let pager = env::var("BAT_PAGER")
25+ .or_else(|_| env::var("PAGER"))
26+ .unwrap_or(String::from("less"));
27+
28+ let mut process = if pager == "less" {
29+ let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
30+ if quit_if_one_screen {
31+ args.push("--quit-if-one-screen");
32+ }
33+
34+ let mut p = Command::new("less");
35+ p.args(&args).env("LESSCHARSET", "UTF-8");
36+ p
37+ } else {
38+ Command::new(pager)
39+ };
40+
41+ process
3042 .stdin(Stdio::piped())
3143 .spawn()
3244 .map(OutputType::Pager)