mirror of
https://github.com/sharkdp/bat
synced 2026-06-09 10:03:18 +00:00
fix: respect --wrap=never flag when paging is enabled
When output is piped to a pager, the wrapping_mode logic was not checking the explicit --wrap=never flag and would always default to NoWrapping(false). This meant the -S flag was not passed to less, causing lines to wrap despite the user's explicit request. The fix prioritizes explicit CLI flags (--wrap=never, --chop-long-lines) over the interactive_output-based logic, ensuring they are always respected. Fixes #3587
This commit is contained in:
@@ -2884,6 +2884,52 @@ fn no_wrapping_with_chop_long_lines() {
|
||||
wrapping_test("--chop-long-lines", false);
|
||||
}
|
||||
|
||||
// Regression test for issue #3587: --wrap=never should be respected when paging is enabled
|
||||
// The fix ensures that bat respects the --wrap=never flag even when output is piped to a pager
|
||||
// by passing the -S flag to less to disable wrapping in the pager
|
||||
#[test]
|
||||
#[serial]
|
||||
fn wrap_never_flag_respected_with_paging_always() {
|
||||
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||
bat()
|
||||
// Use cat as pager to pass through the output (avoiding the echo pager issue)
|
||||
.arg("--pager=cat")
|
||||
.arg("--paging=always")
|
||||
.arg("--wrap=never")
|
||||
.arg("--color=never")
|
||||
.arg("--decorations=never")
|
||||
.arg("--style=plain")
|
||||
.write_stdin("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n")
|
||||
.assert()
|
||||
.success()
|
||||
// With --wrap=never and cat pager, the line should NOT wrap
|
||||
.stdout(predicate::str::contains("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz").normalize())
|
||||
.stderr("");
|
||||
});
|
||||
}
|
||||
|
||||
// Regression test for issue #3587: -S flag should be respected when paging is enabled
|
||||
#[test]
|
||||
#[serial]
|
||||
fn s_flag_respected_with_paging_always() {
|
||||
mocked_pagers::with_mocked_versions_of_more_and_most_in_path(|| {
|
||||
bat()
|
||||
// Use cat as pager to pass through the output
|
||||
.arg("--pager=cat")
|
||||
.arg("--paging=always")
|
||||
.arg("-S")
|
||||
.arg("--color=never")
|
||||
.arg("--decorations=never")
|
||||
.arg("--style=plain")
|
||||
.write_stdin("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz\n")
|
||||
.assert()
|
||||
.success()
|
||||
// With -S flag and cat pager, the line should NOT wrap
|
||||
.stdout(predicate::str::contains("abcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyzabcdefghigklmnopqrstuvxyz").normalize())
|
||||
.stderr("");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theme_arg_overrides_env() {
|
||||
bat()
|
||||
|
||||
Reference in New Issue
Block a user