on master help sign in
When PAGER=most, don't print a warning to stderr, silently use less instead
commit22bdc7c20f21108ddc7be18775a8050059459ebf authorMartin Nordholts <enselic@gmail.com> dateWed 30 Dec 2020, 08:11 (6 years ago) parent552545f
3 files changed+9−8
CHANGELOG.md+1−1 src/output.rs+6−5 tests/integration_tests.rs+2−2
CHANGELOG.md+1−1
@@ -11,7 +11,7 @@
1111- Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
1212- VimL syntax highlighting fix, see #1450 (@esensar)
1313- Print an 'Invalid syntax theme settings' error message if a custom theme is broken, see #614 (@Enselic)
14−- Ignore PAGER=most with a warning to stderr, but allow override with BAT_PAGER or --config, see #1063 (@Enselic)
14+- If `PAGER=most` (but not `BAT_PAGER` or `--pager`), silently use `less` instead since `most` does not support colors, see #1063 (@Enselic)
1515
1616## Other
1717
src/output.rs+6−5
@@ -52,7 +52,6 @@ impl OutputType {
5252 use std::path::PathBuf;
5353 use std::process::{Command, Stdio};
5454 use crate::pager::*;
55− use crate::bat_warning;
5655
5756 let Pager { pager, source } = get_pager(pager_from_config);
5857
@@ -60,16 +59,18 @@ impl OutputType {
6059 shell_words::split(&pager).chain_err(|| "Could not parse pager command.")?;
6160
6261 match pagerflags.split_first() {
63− Some((pager_name, args)) => {
64− let pager_path = PathBuf::from(pager_name);
62+ Some((pager_name, pager_args)) => {
63+ let mut pager_path = PathBuf::from(pager_name);
64+ let mut args = pager_args;
65+ let empty_args = vec![];
6566
6667 if pager_path.file_stem() == Some(&OsString::from("bat")) {
6768 return Err(ErrorKind::InvalidPagerValueBat.into());
6869 }
6970
7071 if pager_path.file_stem() == Some(&OsString::from("most")) && source == PagerSource::PagerEnvVar {
71− bat_warning!("Ignoring PAGER=\"{}\": Coloring not supported. Override with BAT_PAGER=\"{}\" or --pager \"{}\"", pager, pager, pager);
72− return Ok(OutputType::stdout());
72+ pager_path = PathBuf::from("less");
73+ args = &empty_args;
7374 }
7475
7576 let is_less = pager_path.file_stem() == Some(&OsString::from("less"));
tests/integration_tests.rs+2−2
@@ -423,8 +423,8 @@ fn pager_most() {
423423 .arg("test.txt")
424424 .assert()
425425 .success()
426− .stderr(predicate::eq("\x1b[33m[bat warning]\x1b[0m: Ignoring PAGER=\"most\": Coloring not supported. Override with BAT_PAGER=\"most\" or --pager \"most\"\n").normalize())
427426 .stdout(predicate::eq("hello world\n").normalize());
427+ // TODO: How to ensure less is used?
428428}
429429
430430#[test]
@@ -435,8 +435,8 @@ fn pager_most_with_arg() {
435435 .arg("test.txt")
436436 .assert()
437437 .success()
438− .stderr(predicate::eq("\x1b[33m[bat warning]\x1b[0m: Ignoring PAGER=\"most -w\": Coloring not supported. Override with BAT_PAGER=\"most -w\" or --pager \"most -w\"\n").normalize())
439438 .stdout(predicate::eq("hello world\n").normalize());
439+ // TODO: How to ensure less is used?
440440}
441441
442442#[test]