mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-28 18:53:34 +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 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 panel width when line 10000 wraps, see #2854 (@eth-p)
|
||||||
- Fix compile issue of `time` dependency caused by standard library regression #3045 (@cyqsimon)
|
- 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
|
## Other
|
||||||
|
|
||||||
|
@ -98,12 +98,30 @@ impl App {
|
|||||||
pub fn config(&self, inputs: &[Input]) -> Result<Config> {
|
pub fn config(&self, inputs: &[Input]) -> Result<Config> {
|
||||||
let style_components = self.style_components()?;
|
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()) {
|
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("never") => PagingMode::Never,
|
||||||
Some("auto") | None => {
|
Some("auto") | None => {
|
||||||
// If we have -pp as an option when in auto mode, the pager should be disabled.
|
// 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") {
|
if extra_plain || self.matches.get_flag("no-paging") {
|
||||||
PagingMode::Never
|
PagingMode::Never
|
||||||
} else if inputs.iter().any(Input::is_stdin) {
|
} else if inputs.iter().any(Input::is_stdin) {
|
||||||
|
@ -97,7 +97,6 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
Arg::new("plain")
|
Arg::new("plain")
|
||||||
.overrides_with("plain")
|
.overrides_with("plain")
|
||||||
.overrides_with("number")
|
.overrides_with("number")
|
||||||
.overrides_with("paging")
|
|
||||||
.short('p')
|
.short('p')
|
||||||
.long("plain")
|
.long("plain")
|
||||||
.action(ArgAction::Count)
|
.action(ArgAction::Count)
|
||||||
@ -322,7 +321,6 @@ pub fn build_app(interactive_output: bool) -> Command {
|
|||||||
.long("paging")
|
.long("paging")
|
||||||
.overrides_with("paging")
|
.overrides_with("paging")
|
||||||
.overrides_with("no-paging")
|
.overrides_with("no-paging")
|
||||||
.overrides_with("plain")
|
|
||||||
.value_name("when")
|
.value_name("when")
|
||||||
.value_parser(["auto", "never", "always"])
|
.value_parser(["auto", "never", "always"])
|
||||||
.default_value("auto")
|
.default_value("auto")
|
||||||
|
@ -1019,6 +1019,31 @@ fn enable_pager_if_pp_flag_comes_before_paging() {
|
|||||||
.stdout(predicate::eq("pager-output\n").normalize());
|
.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]
|
#[test]
|
||||||
fn pager_failed_to_parse() {
|
fn pager_failed_to_parse() {
|
||||||
bat()
|
bat()
|
||||||
|
Loading…
Reference in New Issue
Block a user