on master help sign in
Refactor "Use `matches` macro"
commitaa74d199400b5f711545a96c9b3e229dd3993176 authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com> dateSat 22 May 2021, 12:13 (5 years ago) parentcf7d9ef
1 file changed+9−12
src/pager.rs+9−12
src/pager.rs+9−12
@@ -98,21 +98,18 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
9898 Some((bin, args)) => {
9999 let kind = PagerKind::from_bin(bin);
100100
101− // Is false if the given expression does not match any of the
102− // patterns; this ensures 'less' is never silently used if BAT_PAGER
103− // or --pager has been specified.
104− let use_less_instead = matches!(
105− (&source, &kind),
101+ let use_less_instead = if source == PagerSource::EnvVarPager {
106102 // 'more' and 'most' do not supports colors; automatically use
107103 // 'less' instead if the problematic pager came from the
108− // generic PAGER env var
109− (PagerSource::EnvVarPager, PagerKind::More)
110− | (PagerSource::EnvVarPager, PagerKind::Most)
111−
104+ // generic PAGER env var.
112105 // If PAGER=bat, silently use 'less' instead to prevent
113− // recursion ...
114− | (PagerSource::EnvVarPager, PagerKind::Bat)
115− );
106+ // recursion.
107+ // Never silently use 'less' if BAT_PAGER or --pager has been
108+ // specified.
109+ matches!(kind, PagerKind::More | PagerKind::Most | PagerKind::Bat)
110+ } else {
111+ false
112+ };
116113
117114 Ok(Some(if use_less_instead {
118115 let no_args = vec![];