mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-25 01:03:46 +01:00
Merge pull request #3108 from einfachIrgendwer0815/fix/2731_plain_override
Fix override of --plain and --paging
This commit is contained in:
commit
ce7a3d9f7d
@ -19,6 +19,7 @@
|
||||
- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p)
|
||||
- Fix panel width when line 10000 wraps, see #2854 (@eth-p)
|
||||
- Fix compile issue of `time` dependency caused by standard library regression #3045 (@cyqsimon)
|
||||
- Fix override behavior of --plain and --paging, see issue #2731 and PR #3108 (@einfachIrgendwer0815)
|
||||
|
||||
## Other
|
||||
|
||||
|
@ -98,12 +98,30 @@ impl App {
|
||||
pub fn config(&self, inputs: &[Input]) -> Result<Config> {
|
||||
let style_components = self.style_components()?;
|
||||
|
||||
let extra_plain = self.matches.get_count("plain") > 1;
|
||||
let plain_last_index = self
|
||||
.matches
|
||||
.indices_of("plain")
|
||||
.and_then(Iterator::max)
|
||||
.unwrap_or_default();
|
||||
let paging_last_index = self
|
||||
.matches
|
||||
.indices_of("paging")
|
||||
.and_then(Iterator::max)
|
||||
.unwrap_or_default();
|
||||
|
||||
let paging_mode = match self.matches.get_one::<String>("paging").map(|s| s.as_str()) {
|
||||
Some("always") => PagingMode::Always,
|
||||
Some("always") => {
|
||||
// Disable paging if the second -p (or -pp) is specified after --paging=always
|
||||
if extra_plain && plain_last_index > paging_last_index {
|
||||
PagingMode::Never
|
||||
} else {
|
||||
PagingMode::Always
|
||||
}
|
||||
}
|
||||
Some("never") => PagingMode::Never,
|
||||
Some("auto") | None => {
|
||||
// If we have -pp as an option when in auto mode, the pager should be disabled.
|
||||
let extra_plain = self.matches.get_count("plain") > 1;
|
||||
if extra_plain || self.matches.get_flag("no-paging") {
|
||||
PagingMode::Never
|
||||
} else if inputs.iter().any(Input::is_stdin) {
|
||||
|
@ -97,7 +97,6 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("plain")
|
||||
.overrides_with("plain")
|
||||
.overrides_with("number")
|
||||
.overrides_with("paging")
|
||||
.short('p')
|
||||
.long("plain")
|
||||
.action(ArgAction::Count)
|
||||
@ -322,7 +321,6 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.long("paging")
|
||||
.overrides_with("paging")
|
||||
.overrides_with("no-paging")
|
||||
.overrides_with("plain")
|
||||
.value_name("when")
|
||||
.value_parser(["auto", "never", "always"])
|
||||
.default_value("auto")
|
||||
|
@ -1019,6 +1019,31 @@ fn enable_pager_if_pp_flag_comes_before_paging() {
|
||||
.stdout(predicate::eq("pager-output\n").normalize());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paging_does_not_override_simple_plain() {
|
||||
bat()
|
||||
.env("PAGER", "echo pager-output")
|
||||
.arg("--decorations=always")
|
||||
.arg("--plain")
|
||||
.arg("--paging=never")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq("hello world\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn simple_plain_does_not_override_paging() {
|
||||
bat()
|
||||
.env("PAGER", "echo pager-output")
|
||||
.arg("--paging=always")
|
||||
.arg("--plain")
|
||||
.arg("test.txt")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::eq("pager-output\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pager_failed_to_parse() {
|
||||
bat()
|
||||
|
Loading…
Reference in New Issue
Block a user