mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-23 00:03:27 +01:00
PagerSource: [Bat]PagerEnvVar -> EnvVar[Bat]Pager
This commit is contained in:
parent
fc30277cfa
commit
dfe7a60140
@ -73,7 +73,7 @@ impl OutputType {
|
||||
//
|
||||
// We only do this for PAGER (as it is not specific to 'bat'), not for BAT_PAGER
|
||||
// or bats '--pager' command line option.
|
||||
let replace_arguments_to_less = pager.source == PagerSource::PagerEnvVar;
|
||||
let replace_arguments_to_less = pager.source == PagerSource::EnvVarPager;
|
||||
|
||||
if args.is_empty() || replace_arguments_to_less {
|
||||
p.arg("--RAW-CONTROL-CHARS");
|
||||
|
12
src/pager.rs
12
src/pager.rs
@ -8,10 +8,10 @@ pub(crate) enum PagerSource {
|
||||
Config,
|
||||
|
||||
/// From the env var BAT_PAGER
|
||||
BatPagerEnvVar,
|
||||
EnvVarBatPager,
|
||||
|
||||
/// From the env var PAGER
|
||||
PagerEnvVar,
|
||||
EnvVarPager,
|
||||
|
||||
/// No pager was specified, default is used
|
||||
Default,
|
||||
@ -93,8 +93,8 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
|
||||
|
||||
let (cmd, source) = match (config_pager, &bat_pager, &pager) {
|
||||
(Some(config_pager), _, _) => (config_pager, PagerSource::Config),
|
||||
(_, Ok(bat_pager), _) => (bat_pager.as_str(), PagerSource::BatPagerEnvVar),
|
||||
(_, _, Ok(pager)) => (pager.as_str(), PagerSource::PagerEnvVar),
|
||||
(_, Ok(bat_pager), _) => (bat_pager.as_str(), PagerSource::EnvVarBatPager),
|
||||
(_, _, Ok(pager)) => (pager.as_str(), PagerSource::EnvVarPager),
|
||||
_ => ("less", PagerSource::Default),
|
||||
};
|
||||
|
||||
@ -106,11 +106,11 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
|
||||
// 'more' and 'most' does not supports colors; automatically use 'less' instead
|
||||
// if the problematic pager came from the generic PAGER env var
|
||||
let no_color_support = kind == PagerKind::More || kind == PagerKind::Most;
|
||||
let use_less_instead = no_color_support && source == PagerSource::PagerEnvVar;
|
||||
let use_less_instead = no_color_support && source == PagerSource::EnvVarPager;
|
||||
|
||||
Ok(Some(if use_less_instead {
|
||||
let no_args = vec![];
|
||||
Pager::new("less", &no_args, PagerKind::Less, PagerSource::PagerEnvVar)
|
||||
Pager::new("less", &no_args, PagerKind::Less, PagerSource::EnvVarPager)
|
||||
} else {
|
||||
Pager::new(bin, args, kind, source)
|
||||
}))
|
||||
|
Loading…
Reference in New Issue
Block a user