diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e460a..344aea1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres) ## Bugfixes +- Turn off the `less` status column (`-J`, e.g. from `$LESS`) so wrapped lines no longer overlap the line numbers, closes #2497, see #4085 (@dualfroz) - Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk) - Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa) - Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128) diff --git a/README.md b/README.md index 8826d4e..7640c13 100644 --- a/README.md +++ b/README.md @@ -666,7 +666,7 @@ Instead of using environment variables, you can also use `bat`'s [configuration When using `less` as a pager, `bat` will automatically pass extra options along to `less` to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--quit-if-one-screen`, -`-K`/`--quit-on-intr` and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. +`-K`/`--quit-on-intr`, `-+J` and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. >[!IMPORTANT] > These options will not be added if: @@ -687,6 +687,9 @@ have to press `q` to quit the pager. The `-K`/`--quit-on-intr` option instructs `less` to exit immediately when an interrupt signal is received. This is useful to ensure that `less` quits together with `bat` on SIGINT. +The `-+J` option turns off the `-J`/`--status-column` option, e.g. when it is set in the `LESS` environment variable. +The status column takes up two columns, so lines that `bat` already wrapped to the terminal width would wrap again. + The `-X`/`--no-init` option is added to versions of `less` older than version 530 (older than 558 on Windows) to fix a bug with the `-F`/`--quit-if-one-screen` feature. Unfortunately, it also breaks mouse-wheel support in `less`. If you want to enable mouse-wheel scrolling on older versions of `less` and do not mind losing diff --git a/src/output.rs b/src/output.rs index 8054be4..98d8c64 100644 --- a/src/output.rs +++ b/src/output.rs @@ -155,6 +155,13 @@ impl OutputType { p.arg("-K"); // Short version of '--quit-on-intr' } + // The status column ('-J', e.g. from $LESS) takes two columns away from + // lines that bat already wrapped to the terminal width, so turn it off. + // The BusyBox version of less does not support '-+'. + if less_version != Some(LessVersion::BusyBox) { + p.arg("-+J"); // Resets '--status-column' to its default + } + // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older // versions of 'less'. Unfortunately, it also breaks mouse-wheel support. // diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 9463be3..33f88ed 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1586,6 +1586,20 @@ fn pager_more() { }); } +/// The status column of less (-J, e.g. from $LESS) makes lines wrap onto +/// the decorations, so it has to be reset when bat builds the less arguments +#[test] +#[cfg(unix)] +fn pager_less_resets_status_column() { + bat() + .arg("--pager=../mocked-pagers/less.sh") + .arg("--paging=always") + .arg("test.txt") + .assert() + .success() + .stdout(predicate::str::contains("-+J")); +} + #[test] fn alias_pager_disable() { bat() diff --git a/tests/mocked-pagers/less.sh b/tests/mocked-pagers/less.sh new file mode 100644 index 0000000..a9f1dcd --- /dev/null +++ b/tests/mocked-pagers/less.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo "$@"