get_pager(): Simplify use_less_instead expression

This commit is contained in:
Martin Nordholts 2021-01-11 18:54:54 +01:00 committed by David Peter
parent c48e779e8a
commit dc1620d1f0

View File

@ -98,19 +98,17 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
Some((bin, args)) => {
let kind = PagerKind::from_bin(bin);
let use_less_instead = match source {
PagerSource::EnvVarPager => {
let use_less_instead = match (&source, &kind) {
// 'more' and 'most' do 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;
(PagerSource::EnvVarPager, PagerKind::More) => true,
(PagerSource::EnvVarPager, PagerKind::Most) => true,
// If PAGER=bat, silently use 'less' instead to prevent recursion ...
let is_self = kind == PagerKind::Bat;
(PagerSource::EnvVarPager, PagerKind::Bat) => true,
no_color_support || is_self
},
// Never silently replace with less if bat-specific means to set a pager is used
_ => false
// Never silently use less if BAT_PAGER or --pager has been specified
_ => false,
};
Ok(Some(if use_less_instead {