mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 10:11:07 +00:00
Add arguments from PAGER/BAT_PAGER
Solves #352 Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
parent
e956225b4d
commit
67fe833bc8
@ -1,3 +1,5 @@
|
|||||||
|
extern crate shell_words;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
@ -28,23 +30,27 @@ impl OutputType {
|
|||||||
.or_else(|_| env::var("PAGER"))
|
.or_else(|_| env::var("PAGER"))
|
||||||
.unwrap_or(String::from("less"));
|
.unwrap_or(String::from("less"));
|
||||||
|
|
||||||
let less_path = PathBuf::from(&pager);
|
let pagerflags = shell_words::split(&pager).unwrap_or(vec![pager]);
|
||||||
|
|
||||||
|
let less_path = PathBuf::from(&pagerflags[0]);
|
||||||
let is_less = less_path.file_stem() == Some(&OsString::from("less"));
|
let is_less = less_path.file_stem() == Some(&OsString::from("less"));
|
||||||
|
|
||||||
let mut process = if is_less {
|
let mut process = if is_less {
|
||||||
let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
|
|
||||||
if quit_if_one_screen {
|
|
||||||
args.push("--quit-if-one-screen");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut p = Command::new(&less_path);
|
let mut p = Command::new(&less_path);
|
||||||
p.args(&args).env("LESSCHARSET", "UTF-8");
|
if pagerflags.len() == 1 {
|
||||||
|
p.args(vec!["--RAW-CONTROL-CHARS", "--no-init"]);
|
||||||
|
if quit_if_one_screen {
|
||||||
|
p.arg("--quit-if-one-screen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.env("LESSCHARSET", "UTF-8");
|
||||||
p
|
p
|
||||||
} else {
|
} else {
|
||||||
Command::new(pager)
|
Command::new(&less_path)
|
||||||
};
|
};
|
||||||
|
|
||||||
process
|
process
|
||||||
|
.args(&pagerflags[1..])
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.map(OutputType::Pager)
|
.map(OutputType::Pager)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user