@@ -1,28 +1,27 @@
1+/// If we use a pager, this enum tells us from where we were told to use it.
1#[derive(Debug, PartialEq)]
2#[derive(Debug, PartialEq)]
2pub enum PagerSource {
3pub enum PagerSource {
3 /// From the env var BAT_PAGER
7 /// From the env var BAT_PAGER
4 BatPagerEnvVar,
8 BatPagerEnvVar,
6 /// From the env var PAGER
10 /// From the env var PAGER
7 PagerEnvVar,
11 PagerEnvVar,
12 /// No pager was specified, default is used
13 /// No pager was specified, default is used
17+/// A pager such as 'less', and from where we got it.
16pub struct Pager {
18pub struct Pager {
17 pub pager: String,
19 pub pager: String,
18 pub source: PagerSource,
20 pub source: PagerSource,
21impl Pager {
23impl Pager {
24− source: PagerSource
24+ fn new(pager: &str, source: PagerSource) -> Pager {
27 pager: String::from(pager),
26 pager: String::from(pager),
@@ -30,16 +29,16 @@ impl Pager {
33−pub fn get_pager(
32+/// Returns what pager to use, after looking at both config and environment variables.
34− pager_from_config: Option<&str>,
33+pub fn get_pager(pager_from_config: Option<&str>) -> Pager {
35−) -> Pager {
34+ match (
36− if pager_from_config.is_some() {
35+ pager_from_config,
37− return Pager::new(pager_from_config.unwrap(), PagerSource::Config);
39− return match (std::env::var("BAT_PAGER"), std::env::var("PAGER")) {
36+ std::env::var("BAT_PAGER"),
37+ std::env::var("PAGER"),
39+ (Some(config), _, _) => Pager::new(config, PagerSource::Config),
40− (Ok(bat_pager), _) => Pager::new(&bat_pager, PagerSource::BatPagerEnvVar),
40+ (_, Ok(bat_pager), _) => Pager::new(&bat_pager, PagerSource::BatPagerEnvVar),
41− (_, Ok(pager)) => Pager::new(&pager, PagerSource::PagerEnvVar),
41+ (_, _, Ok(pager)) => Pager::new(&pager, PagerSource::PagerEnvVar),
42− _ => Pager::new("less", PagerSource::Default),
42+ _ => Pager::new("less", PagerSource::Default),