mirror of
https://github.com/sharkdp/bat
synced 2024-11-04 18:00:24 +00:00
get_pager(): Simplify use_less_instead expression
This commit is contained in:
parent
c48e779e8a
commit
dc1620d1f0
22
src/pager.rs
22
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;
|
||||
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 ...
|
||||
let is_self = kind == PagerKind::Bat;
|
||||
// If PAGER=bat, silently use 'less' instead to prevent recursion ...
|
||||
(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 {
|
||||
let no_args = vec![];
|
||||
|
Loading…
Reference in New Issue
Block a user