2use std::io::{self, Write};
3use std::process::{Child, Command, Stdio};
14 pub fn from_mode(mode: PagingMode) -> Self {
15 use self::PagingMode::*;
17 Always => OutputType::try_pager(false),
18 QuitIfOneScreen => OutputType::try_pager(true),
19 _ => OutputType::stdout(),
23 /// Try to launch the pager. Fall back to stdout in case of errors.
24 fn try_pager(quit_if_one_screen: bool) -> Self {
25 let pager = env::var("BAT_PAGER")
26 .or_else(|_| env::var("PAGER"))
27 .unwrap_or(String::from("less"));
29 let mut process = if pager == "less" {
30 let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
31 if quit_if_one_screen {
32 args.push("--quit-if-one-screen");
35 let mut p = Command::new("less");
36 p.args(&args).env("LESSCHARSET", "UTF-8");
43 .stdin(Stdio::piped())
45 .map(OutputType::Pager)
46 .unwrap_or_else(|_| OutputType::stdout())
50 OutputType::Stdout(io::stdout())
53 pub fn handle(&mut self) -> Result<&mut Write> {
55 OutputType::Pager(ref mut command) => command
58 .chain_err(|| "Could not open stdin for pager")?,
59 OutputType::Stdout(ref mut handle) => handle,
64impl Drop for OutputType {
66 if let OutputType::Pager(ref mut command) = *self {
67 let _ = command.wait();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list