mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-01 11:48:35 +02:00
Refactor "Use matches
macro"
This commit is contained in:
parent
cf7d9ef962
commit
aa74d19940
21
src/pager.rs
21
src/pager.rs
@ -98,21 +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);
|
||||||
|
|
||||||
// Is false if the given expression does not match any of the
|
let use_less_instead = if source == PagerSource::EnvVarPager {
|
||||||
// patterns; this ensures 'less' is never silently used if BAT_PAGER
|
|
||||||
// or --pager has been specified.
|
|
||||||
let use_less_instead = matches!(
|
|
||||||
(&source, &kind),
|
|
||||||
// 'more' and 'most' do not supports colors; automatically use
|
// 'more' and 'most' do not supports colors; automatically use
|
||||||
// 'less' instead if the problematic pager came from the
|
// 'less' instead if the problematic pager came from the
|
||||||
// generic PAGER env var
|
// generic PAGER env var.
|
||||||
(PagerSource::EnvVarPager, PagerKind::More)
|
|
||||||
| (PagerSource::EnvVarPager, PagerKind::Most)
|
|
||||||
|
|
||||||
// If PAGER=bat, silently use 'less' instead to prevent
|
// If PAGER=bat, silently use 'less' instead to prevent
|
||||||
// recursion ...
|
// recursion.
|
||||||
| (PagerSource::EnvVarPager, PagerKind::Bat)
|
// Never silently use 'less' if BAT_PAGER or --pager has been
|
||||||
);
|
// specified.
|
||||||
|
matches!(kind, PagerKind::More | PagerKind::Most | PagerKind::Bat)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Some(if use_less_instead {
|
Ok(Some(if use_less_instead {
|
||||||
let no_args = vec![];
|
let no_args = vec![];
|
||||||
|
Loading…
Reference in New Issue
Block a user