diff options
author | ippsav <69125922+ippsav@users.noreply.github.com> | 2023-07-30 00:25:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-29 19:25:02 -0400 |
commit | 3c55764215feb54b09bc11ff445acf5ef23afe00 (patch) | |
tree | 820b8781d83c47817ea33864749bb1efaa46933f /src/env.rs | |
parent | fdaf4bfe1d8b59b397b069429b48c655bfc358a8 (diff) |
Fix issue where pager would be set to `more` or `most` (#1494)
fix pager env in case of `more/most`
Diffstat (limited to 'src/env.rs')
-rw-r--r-- | src/env.rs | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -9,8 +9,6 @@ const DELTA_NAVIGATE: &str = "DELTA_NAVIGATE"; const DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES: &str = "DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES"; const DELTA_PAGER: &str = "DELTA_PAGER"; -const BAT_PAGER: &str = "BAT_PAGER"; -const PAGER: &str = "PAGER"; #[derive(Default, Clone)] pub struct DeltaEnv { @@ -22,7 +20,7 @@ pub struct DeltaEnv { pub git_config_parameters: Option<String>, pub git_prefix: Option<String>, pub navigate: Option<String>, - pub pagers: (Option<String>, Option<String>, Option<String>), + pub pagers: (Option<String>, Option<String>), } impl DeltaEnv { @@ -40,8 +38,11 @@ impl DeltaEnv { let current_dir = env::current_dir().ok(); let pagers = ( env::var(DELTA_PAGER).ok(), - env::var(BAT_PAGER).ok(), - env::var(PAGER).ok(), + // We're using `bat::config::get_pager_executable` here instead of just returning + // the pager from the environment variables, because we want to make sure + // that the pager is a valid pager from env and handle the case of + // the PAGER being set to something invalid like "most" and "more". + bat::config::get_pager_executable(None), ); Self { @@ -70,4 +71,25 @@ pub mod tests { let env = DeltaEnv::init(); assert_eq!(env.features, Some(feature.into())); } + + #[test] + fn test_env_parsing_with_pager_set_to_bat() { + env::set_var("PAGER", "bat"); + let env = DeltaEnv::init(); + assert_eq!(env.pagers.1, Some("bat".into())); + } + + #[test] + fn test_env_parsing_with_pager_set_to_more() { + env::set_var("PAGER", "more"); + let env = DeltaEnv::init(); + assert_eq!(env.pagers.1, Some("less".into())); + } + + #[test] + fn test_env_parsing_with_pager_set_to_most() { + env::set_var("PAGER", "most"); + let env = DeltaEnv::init(); + assert_eq!(env.pagers.1, Some("less".into())); + } } |