on master help sign in
get_pager(): Simplify use_less_instead expression
commitdc1620d1f0e44ddaefda6bb74899a60160df6de6 authorMartin Nordholts <enselic@gmail.com> dateMon 11 Jan 2021, 18:54 (6 years ago) parentc48e779
1 file changed+12−14
src/pager.rs+12−14
src/pager.rs+12−14
@@ -98,20 +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− let use_less_instead = match source {
102− PagerSource::EnvVarPager => {
103− // 'more' and 'most' do not supports colors; automatically use 'less' instead
104− // if the problematic pager came from the generic PAGER env var
105− let no_color_support = kind == PagerKind::More || kind == PagerKind::Most;
106−
107− // If PAGER=bat, silently use 'less' instead to prevent recursion ...
108− let is_self = kind == PagerKind::Bat;
109−
110− no_color_support || is_self
111− },
112− // Never silently replace with less if bat-specific means to set a pager is used
113− _ => false
114− } ;
101+ let use_less_instead = match (&source, &kind) {
102+ // 'more' and 'most' do not supports colors; automatically use 'less' instead
103+ // if the problematic pager came from the generic PAGER env var
104+ (PagerSource::EnvVarPager, PagerKind::More) => true,
105+ (PagerSource::EnvVarPager, PagerKind::Most) => true,
106+
107+ // If PAGER=bat, silently use 'less' instead to prevent recursion ...
108+ (PagerSource::EnvVarPager, PagerKind::Bat) => true,
109+
110+ // Never silently use less if BAT_PAGER or --pager has been specified
111+ _ => false,
112+ };
115113
116114 Ok(Some(if use_less_instead {
117115 let no_args = vec![];