From 986d0e9777a77b309ffc55de24fcb665adfa3bb7 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Fri, 27 Nov 2020 06:47:46 +0100 Subject: [PATCH] Ignore PAGER=most by default with a warning to stderr closes #1063 --- CHANGELOG.md | 2 ++ src/output.rs | 5 +++++ tests/integration_tests.rs | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c866a5f..fa29e5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ## Bugfixes +- Ignore PAGER=most by default with a warning to stderr, but allow override with BAT_PAGER or --config, see #1063 (@Enselic) + ## Other ## Syntaxes diff --git a/src/output.rs b/src/output.rs index a9fe865e..ac3047c2 100644 --- a/src/output.rs +++ b/src/output.rs @@ -66,6 +66,11 @@ impl OutputType { return Err(ErrorKind::InvalidPagerValueBat.into()); } + if pager_path.file_stem() == Some(&OsString::from("most")) && source == PagerSource::PagerEnvVar { + eprintln!("WARNING: Ignoring PAGER=\"{}\": Coloring not supported. Override with BAT_PAGER=\"{}\" or --pager \"{}\"", pager, pager, pager); + return Ok(OutputType::stdout()); + } + let is_less = pager_path.file_stem() == Some(&OsString::from("less")); let mut process = if is_less { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index ac11efb4..18c4dcc6 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -415,6 +415,30 @@ fn pager_value_bat() { .failure(); } +#[test] +fn pager_most() { + bat() + .env("PAGER", "most") + .arg("--paging=always") + .arg("test.txt") + .assert() + .success() + .stderr(predicate::eq("WARNING: Ignoring PAGER=\"most\": Coloring not supported. Override with BAT_PAGER=\"most\" or --pager \"most\"\n").normalize()) + .stdout(predicate::eq("hello world\n").normalize()); +} + +#[test] +fn pager_most_with_arg() { + bat() + .env("PAGER", "most -w") + .arg("--paging=always") + .arg("test.txt") + .assert() + .success() + .stderr(predicate::eq("WARNING: Ignoring PAGER=\"most -w\": Coloring not supported. Override with BAT_PAGER=\"most -w\" or --pager \"most -w\"\n").normalize()) + .stdout(predicate::eq("hello world\n").normalize()); +} + #[test] fn alias_pager_disable() { bat()