Support DELTA_PAGER env var

This commit is contained in:
Dan Davison 2020-10-04 13:34:19 -04:00
parent 166d31a7d3
commit 31e2661cde
3 changed files with 15 additions and 12 deletions

View File

@ -50,15 +50,18 @@ impl OutputType {
) -> Result<Self> {
let mut replace_arguments_to_less = false;
let pager_from_env = match (env::get_env_var("BAT_PAGER"), env::get_env_var("PAGER")) {
(Some(bat_pager), _) => Some(bat_pager),
(_, Some(pager)) => {
// less needs to be called with the '-R' option in order to properly interpret the
// ANSI color sequences printed by bat. If someone has set PAGER="less -F", we
// therefore need to overwrite the arguments and add '-R'.
//
// We only do this for PAGER (as it is not specific to 'bat'), not for BAT_PAGER
// or bats '--pager' command line option.
let pager_from_env = match (
env::get_env_var("DELTA_PAGER"),
env::get_env_var("BAT_PAGER"),
env::get_env_var("PAGER"),
) {
(Some(delta_pager), _, _) => Some(delta_pager),
(None, Some(bat_pager), _) => Some(bat_pager),
(None, None, Some(pager)) => {
// less needs to be called with the '-R' option in order to properly interpret ANSI
// color sequences. If someone has set PAGER="less -F", we therefore need to
// overwrite the arguments and add '-R'.
// We only do this for PAGER, since it is used in other contexts.
replace_arguments_to_less = true;
Some(pager)
}

View File

@ -477,8 +477,8 @@ pub struct Opt {
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 BAT_PAGER
/// or PAGER (BAT_PAGER has priority).
/// 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 = "paging", default_value = "auto")]
pub paging_mode: String,

View File

@ -65,7 +65,7 @@ fn is_no_syntax_highlighting_syntax_theme_name(theme_name: &str) -> bool {
///
/// Basically:
/// 1. The theme is specified by the `--theme` option. If this isn't supplied then it is specified
/// by the `BAT_PAGER` environment variable.
/// by the `BAT_THEME` environment variable.
/// 2. Light vs dark mode is specified by the `--light` or `--dark` options. If these aren't
/// supplied then it is inferred from the chosen theme.
///