mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-22 04:48:48 +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)) => {
|
Some((bin, args)) => {
|
||||||
let kind = PagerKind::from_bin(bin);
|
let kind = PagerKind::from_bin(bin);
|
||||||
|
|
||||||
let use_less_instead = match source {
|
let use_less_instead = match (&source, &kind) {
|
||||||
PagerSource::EnvVarPager => {
|
// 'more' and 'most' do not supports colors; automatically use 'less' instead
|
||||||
// 'more' and 'most' do not supports colors; automatically use 'less' instead
|
// if the problematic pager came from the generic PAGER env var
|
||||||
// if the problematic pager came from the generic PAGER env var
|
(PagerSource::EnvVarPager, PagerKind::More) => true,
|
||||||
let no_color_support = kind == PagerKind::More || kind == PagerKind::Most;
|
(PagerSource::EnvVarPager, PagerKind::Most) => true,
|
||||||
|
|
||||||
// If PAGER=bat, silently use 'less' instead to prevent recursion ...
|
// 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 use less if BAT_PAGER or --pager has been specified
|
||||||
},
|
_ => false,
|
||||||
// Never silently replace with less if bat-specific means to set a pager is used
|
};
|
||||||
_ => false
|
|
||||||
} ;
|
|
||||||
|
|
||||||
Ok(Some(if use_less_instead {
|
Ok(Some(if use_less_instead {
|
||||||
let no_args = vec![];
|
let no_args = vec![];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user