mirror of
https://github.com/sharkdp/bat.git
synced 2026-10-26 20:16:33 +00:00
Merge pull request #3592 from IMaloney/fix/wrap-never-clean
respect --wrap=never flag when piping to pager
This commit is contained in:
3 files changed
+52
-11
No files matched your search
@@ -10,6 +10,7 @@
|
|||||||
- Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk)
|
- Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk)
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
- Fix `--wrap=never` and `-S` flags being ignored when piping to pager, see #3592 (@IMaloney)
|
||||||
- Fix crash with BusyBox `less` on Windows, see #3527 (@Anchal-T)
|
- Fix crash with BusyBox `less` on Windows, see #3527 (@Anchal-T)
|
||||||
- Fix `bat cache --help` failing with 'unexpected argument' error, see #3580 and #3560 (@NORMAL-EX)
|
- Fix `bat cache --help` failing with 'unexpected argument' error, see #3580 and #3560 (@NORMAL-EX)
|
||||||
- `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall)
|
- `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall)
|
||||||
|
|||||||
+13
-11
@@ -399,27 +399,29 @@ impl App {
|
|||||||
Some("no-printing") => BinaryBehavior::NoPrinting,
|
Some("no-printing") => BinaryBehavior::NoPrinting,
|
||||||
_ => unreachable!("other values for --binary are not allowed"),
|
_ => unreachable!("other values for --binary are not allowed"),
|
||||||
},
|
},
|
||||||
wrapping_mode: if self.interactive_output || maybe_term_width.is_some() {
|
wrapping_mode: {
|
||||||
if !self.matches.get_flag("chop-long-lines") {
|
if self.matches.get_flag("chop-long-lines") {
|
||||||
|
WrappingMode::NoWrapping(true)
|
||||||
|
} else {
|
||||||
match self.matches.get_one::<String>("wrap").map(|s| s.as_str()) {
|
match self.matches.get_one::<String>("wrap").map(|s| s.as_str()) {
|
||||||
Some("character") => WrappingMode::Character,
|
Some("character") => WrappingMode::Character,
|
||||||
Some("never") => WrappingMode::NoWrapping(true),
|
Some("never") => WrappingMode::NoWrapping(true),
|
||||||
Some("auto") | None => {
|
Some("auto") | None => {
|
||||||
if style_components.plain() && maybe_term_width.is_none() {
|
if self.interactive_output || maybe_term_width.is_some() {
|
||||||
WrappingMode::NoWrapping(false)
|
if style_components.plain() && maybe_term_width.is_none() {
|
||||||
|
WrappingMode::NoWrapping(false)
|
||||||
|
} else {
|
||||||
|
WrappingMode::Character
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WrappingMode::Character
|
// We don't have the tty width when piping to another program.
|
||||||
|
// There's no point in wrapping when this is the case.
|
||||||
|
WrappingMode::NoWrapping(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("other values for --wrap are not allowed"),
|
_ => unreachable!("other values for --wrap are not allowed"),
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
WrappingMode::NoWrapping(true)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// We don't have the tty width when piping to another program.
|
|
||||||
// There's no point in wrapping when this is the case.
|
|
||||||
WrappingMode::NoWrapping(false)
|
|
||||||
},
|
},
|
||||||
colored_output: self.matches.get_flag("force-colorization")
|
colored_output: self.matches.get_flag("force-colorization")
|
||||||
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
|
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
|
||||||
|
|||||||
@@ -2884,6 +2884,44 @@ fn no_wrapping_with_chop_long_lines() {
|
|||||||
wrapping_test("--chop-long-lines", false);
|
wrapping_test("--chop-long-lines", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[serial]
|
||||||
|
fn wrap_never_flag_respected_with_paging_always() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
|
bat()
|
||||||
|
.arg("--pager=cat")
|
||||||
|
.arg("--paging=always")
|
||||||
|
.arg("--wrap=never")
|
||||||
|
.arg("--color=never")
|
||||||
|
.arg("--decorations=never")
|
||||||
|
.arg("--style=plain")
|
||||||
|
.write_stdin("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout(predicate::str::contains("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz").normalize())
|
||||||
|
.stderr("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[serial]
|
||||||
|
fn s_flag_respected_with_paging_always() {
|
||||||
|
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||||
|
bat()
|
||||||
|
.arg("--pager=cat")
|
||||||
|
.arg("--paging=always")
|
||||||
|
.arg("-S")
|
||||||
|
.arg("--color=never")
|
||||||
|
.arg("--decorations=never")
|
||||||
|
.arg("--style=plain")
|
||||||
|
.write_stdin("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n")
|
||||||
|
.assert()
|
||||||
|
.success()
|
||||||
|
.stdout(predicate::str::contains("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz").normalize())
|
||||||
|
.stderr("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn theme_arg_overrides_env() {
|
fn theme_arg_overrides_env() {
|
||||||
bat()
|
bat()
|
||||||
|
|||||||
Reference in new issue
Block a user