3use std::io::{self, Write};
5use std::process::{Child, Command, Stdio};
16 pub fn from_mode(mode: PagingMode) -> Self {
17 use self::PagingMode::*;
19 Always => OutputType::try_pager(false),
20 QuitIfOneScreen => OutputType::try_pager(true),
21 _ => OutputType::stdout(),
25 /// Try to launch the pager. Fall back to stdout in case of errors.
26 fn try_pager(quit_if_one_screen: bool) -> Self {
27 let pager = env::var("BAT_PAGER")
28 .or_else(|_| env::var("PAGER"))
29 .unwrap_or(String::from("less"));
31 let less_path = PathBuf::from(&pager);
32 let is_less = less_path.file_stem() == Some(&OsString::from("less"));
34 let mut process = if is_less {
35 let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
36 if quit_if_one_screen {
37 args.push("--quit-if-one-screen");
40 let mut p = Command::new(&less_path);
41 p.args(&args).env("LESSCHARSET", "UTF-8");
48 .stdin(Stdio::piped())
50 .map(OutputType::Pager)
51 .unwrap_or_else(|_| OutputType::stdout())
55 OutputType::Stdout(io::stdout())
58 pub fn handle(&mut self) -> Result<&mut Write> {
60 OutputType::Pager(ref mut command) => command
63 .chain_err(|| "Could not open stdin for pager")?,
64 OutputType::Stdout(ref mut handle) => handle,
69impl Drop for OutputType {
71 if let OutputType::Pager(ref mut command) = *self {
72 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