diff options
author | Martin Nordholts <enselic@gmail.com> | 2021-01-11 18:54:54 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2021-01-11 21:56:10 +0100 |
commit | dc1620d1f0e44ddaefda6bb74899a60160df6de6 (patch) | |
tree | e463034dfe53e97752e8cd9c020baff2b6702aba | |
parent | c48e779e8a01d50ef6967c226322efc15d8997c7 (diff) |
get_pager(): Simplify use_less_instead expression
-rw-r--r-- | src/pager.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/pager.rs b/src/pager.rs index e1658864..c6a4170d 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -98,20 +98,18 @@ 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 => { - // '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; - - // If PAGER=bat, silently use 'less' instead to prevent recursion ... - let is_self = kind == PagerKind::Bat; - - no_color_support || is_self - }, - // Never silently replace with less if bat-specific means to set a pager is used - _ => false - } ; + 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 + (PagerSource::EnvVarPager, PagerKind::More) => true, + (PagerSource::EnvVarPager, PagerKind::Most) => true, + + // If PAGER=bat, silently use 'less' instead to prevent recursion ... + (PagerSource::EnvVarPager, PagerKind::Bat) => true, + + // Never silently use less if BAT_PAGER or --pager has been specified + _ => false, + }; Ok(Some(if use_less_instead { let no_args = vec![]; |