diff options
author | Mohamed Abdelnour <mohamed.k.abdelnour@gmail.com> | 2021-05-21 14:53:39 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2021-05-27 12:05:07 +0200 |
commit | 23fd11e806b52dbea8c4e1d635a80ceb1f98aafa (patch) | |
tree | 70c04062b7a4a9d53b5d0c85ae34bb5facd4f34b | |
parent | 304ee1489c360f6d852fbf4954a401ab887921c6 (diff) |
Use `matches` macro
-rw-r--r-- | src/pager.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/pager.rs b/src/pager.rs index c6a4170d..3bd294ad 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -98,18 +98,21 @@ 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, &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, - }; + // Is false if the given expression does not match any of the + // 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 + // 'less' instead if the problematic pager came from the + // generic PAGER env var + (PagerSource::EnvVarPager, PagerKind::More) + | (PagerSource::EnvVarPager, PagerKind::Most) + + // If PAGER=bat, silently use 'less' instead to prevent + // recursion ... + | (PagerSource::EnvVarPager, PagerKind::Bat) + ); Ok(Some(if use_less_instead { let no_args = vec![]; |