summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKangwook Lee (이강욱) <pbzweihander@gmail.com>2021-06-09 23:33:59 +0900
committerGitHub <noreply@github.com>2021-06-09 10:33:59 -0400
commit61f180c8314ec59b35453aeb9a32e63ec3f29145 (patch)
tree49544fb8f1c32447b5e60cf9269d6a743291bf9c /src
parentfb1d16ef44600c3cef496cb9e9c6ad61381f6192 (diff)
Add pager option for customizing pager without environment variables (#627)
* Add pager option * Use config.pager for output
Diffstat (limited to 'src')
-rw-r--r--src/bat_utils/output.rs6
-rw-r--r--src/cli.rs11
-rw-r--r--src/config.rs2
-rw-r--r--src/main.rs5
-rw-r--r--src/options/set.rs1
5 files changed, 17 insertions, 8 deletions
diff --git a/src/bat_utils/output.rs b/src/bat_utils/output.rs
index 388bc0c9..1166b4e2 100644
--- a/src/bat_utils/output.rs
+++ b/src/bat_utils/output.rs
@@ -29,7 +29,7 @@ pub enum OutputType {
impl OutputType {
pub fn from_mode(
mode: PagingMode,
- pager: Option<&str>,
+ pager: Option<String>,
config: &config::Config,
) -> Result<Self> {
use self::PagingMode::*;
@@ -43,7 +43,7 @@ impl OutputType {
/// Try to launch the pager. Fall back to stdout in case of errors.
fn try_pager(
quit_if_one_screen: bool,
- pager_from_config: Option<&str>,
+ pager_from_config: Option<String>,
config: &config::Config,
) -> Result<Self> {
let mut replace_arguments_to_less = false;
@@ -66,8 +66,6 @@ impl OutputType {
_ => None,
};
- let pager_from_config = pager_from_config.map(|p| p.to_string());
-
if pager_from_config.is_some() {
replace_arguments_to_less = false;
}
diff --git a/src/cli.rs b/src/cli.rs
index d9873d3c..72e91b5a 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -532,9 +532,14 @@ pub struct Opt {
#[structopt(long = "inspect-raw-lines", default_value = "true")]
pub inspect_raw_lines: String,
- /// Whether to use a pager when displaying output. Options are: auto, always, and never. The
- /// default pager is `less`: this can be altered by setting the environment variables
- /// DELTA_PAGER, BAT_PAGER, or PAGER (and that is their order of priority).
+ #[structopt(long)]
+ /// Which pager to use. The default pager is `less`. You can also change pager
+ /// by setting the environment variables DELTA_PAGER, BAT_PAGER, or PAGER
+ /// (and that is their order of priority). This option overrides all environment
+ /// variables above.
+ pub pager: Option<String>,
+
+ /// Whether to use a pager when displaying output. Options are: auto, always, and never.
#[structopt(long = "paging", default_value = "auto")]
pub paging_mode: String,
diff --git a/src/config.rs b/src/config.rs
index 0b8ab6d1..573a08ed 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -66,6 +66,7 @@ pub struct Config {
pub navigate_regexp: Option<String>,
pub null_style: Style,
pub null_syntect_style: SyntectStyle,
+ pub pager: Option<String>,
pub paging_mode: PagingMode,
pub plus_emph_style: Style,
pub plus_empty_line_marker_style: Style,
@@ -246,6 +247,7 @@ impl From<cli::Opt> for Config {
navigate_regexp,
null_style: Style::new(),
null_syntect_style: SyntectStyle::default(),
+ pager: opt.pager,
paging_mode: opt.computed.paging_mode,
plus_emph_style,
plus_empty_line_marker_style,
diff --git a/src/main.rs b/src/main.rs
index cbeb0bcf..d6ed0aa2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -82,7 +82,8 @@ fn run_app() -> std::io::Result<i32> {
return Ok(0);
}
- let mut output_type = OutputType::from_mode(config.paging_mode, None, &config).unwrap();
+ let mut output_type =
+ OutputType::from_mode(config.paging_mode, config.pager.clone(), &config).unwrap();
let mut writer = output_type.handle().unwrap();
if atty::is(atty::Stream::Stdin) {
@@ -246,6 +247,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu
max-line-length = {max_line_length}
navigate = {navigate}
navigate-regexp = {navigate_regexp}
+ pager = {pager}
paging = {paging_mode}
side-by-side = {side_by_side}
syntax-theme = {syntax_theme}
@@ -259,6 +261,7 @@ fn show_config(config: &config::Config, writer: &mut dyn Write) -> std::io::Resu
None => "".to_string(),
Some(s) => s.to_string(),
},
+ pager = config.pager.clone().unwrap_or_else(|| "none".to_string()),
paging_mode = match config.paging_mode {
PagingMode::Always => "always",
PagingMode::Never => "never",
diff --git a/src/options/set.rs b/src/options/set.rs
index a737fd4b..ef0a259c 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -165,6 +165,7 @@ pub fn set_options(
line_numbers_right_format,
line_numbers_right_style,
line_numbers_zero_style,
+ pager,
paging_mode,
// Hack: plus-style must come before plus-*emph-style because the latter default
// dynamically to the value of the former.