Repository navigation
Make -r and -H use file line numbers with -b - #4084
cindykrafft wants to merge 17 commits into
Conversation
With --number-nonblank the controller's line counter skipped blank lines, and that counter also drives --line-range, --highlight-line and the line-1 BOM strip, so ranges and highlights addressed non-blank line numbers. Count file lines again and keep a separate non-blank count in the printer for the displayed number. Also fill in sharkdp#4076 in its CHANGELOG entry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
|
Additional CLI checks of @cindykrafft's fix compared A 14-line fixture has nonblank content on physical lines 1, 3, 6, 7, 9, 11 and 14. With For All 16 comparisons (32 CLI processes) produced these expected results. Paging/config loading were disabled and an ANSI theme exposed highlighting. Clean package builds avoided cached same-version base-library reuse. This is focused CLI evidence; the full suite, fmt/clippy, CI and other platforms were not run. |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Resolve the CHANGELOG conflict by keeping the new sharkdp#4091 entry along with the filled-in sharkdp#4076 and sharkdp#4084 entries. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Resolve the CHANGELOG conflict with sharkdp#4102 and sharkdp#4103: keep their new entries, keep this PR's sharkdp#4084 entry, and point the UTF-16BE entry back at sharkdp#4076 (the merge of sharkdp#4102 had filled its placeholder with sharkdp#4102). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Brings in sharkdp#4038, sharkdp#4048 and sharkdp#4070. The merge of sharkdp#4048 re-added the old UTF-16BE CHANGELOG entry with its "#XXXX" placeholder at the top of Bugfixes, so drop that duplicate; the entry this PR corrects to sharkdp#4076 stays. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
agammann
left a comment
There was a problem hiding this comment.
[P2] Keep physical line numbers for Git change decorations
The new line_number is the file line, but display_line_number is still passed to every Decoration::generate call. LineChangesDecoration::generate uses that argument as a key into printer.line_changes, which is indexed by physical file line. After a blank line, bat -b --style=changes,numbers therefore looks up the nonblank ordinal and can omit or misplace +/~ markers even though ranges and highlights now use the right line. For example, a change on physical line 3 after a blank line at line 2 is looked up as line 2. Please pass the physical line to the Git decoration and the nonblank count only to LineNumberDecoration, with a regression test combining -b and --style=changes.
agammann
left a comment
There was a problem hiding this comment.
I found one edge case in the new nonblank line counter.
| // In number-nonblank mode, the displayed number counts non-blank lines only | ||
| // (content-free lines that contain only the line terminator are skipped). | ||
| // `line_number` stays the line number in the file, which is what line ranges, | ||
| // highlighted lines and Git changes refer to. |
There was a problem hiding this comment.
[P2] Detect blank lines after decoding UTF-16. line_buffer still contains the original UTF-16 bytes here, so even an empty UTF-16LE line is 0A 00 (or 0D 00 0A 00) and fails this byte-only check. With bat -b on a UTF-16 file, those blank lines now receive visible line numbers and advance nonblank_line_count; the following nonblank lines are numbered too high. The old printer checked the decoded line before suppressing its number. Please classify blankness from the decoded text (or handle the input encoding here) and cover a UTF-16 file with an interior blank line.
There was a problem hiding this comment.
Thanks, you are right, and it was a regression from this PR: blank lines were detected on the raw bytes, so the NUL bytes in a UTF-16 terminator made a blank line look non-blank and every later number came out one too high. Fixed in d2d97d4: the check now runs on the decoded line (line.trim_end_matches(['\r', '\n']).is_empty(), as before this PR), so -A also behaves as on master. Added number_nonblank_skips_blank_utf16_lines, which writes UTF-16LE and UTF-16BE files with blank \n and \r\n lines and checks the numbering; it fails without the change. cargo test, cargo fmt --check and cargo clippy --all-targets are clean.
Disclosure: this fix and reply were produced by an AI agent (Claude Code), which ran the tests mentioned.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
…changes Two follow-ups from review: - With -b, blank lines were detected on the raw line bytes, so a blank UTF-16 line (whose terminator contains NUL bytes) got a number and shifted every later number. Detect them on the decoded line instead, as before this change. - Only the line number decoration uses the displayed (non-blank) number. Other decorations, such as the Git change markers, get the line number in the file, which is what their lookups use. The command line enables only the numbers column with -b, so this matters when the library Config combines number_nonblank with other style components. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Resolve the CHANGELOG conflict: keep the sharkdp#4111 and sharkdp#4110 entries and drop the stale UTF-16BE '#XXXX' duplicate (the entry is listed as sharkdp#4076). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Resolve the src/controller.rs conflict with sharkdp#4118: keep this branch's plain line counter (blank-line handling for -b now lives in the printer, which decodes UTF-16 before checking), and drop the ContentType and UTF_16LE/BE imports that only sharkdp#4118's controller check used. sharkdp#4118's CHANGELOG entry and number_nonblank_utf16 test are kept and pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
|
I rechecked head |
With number_nonblank, the line number column shows the count of non-blank lines, but the Git change marker must stay on the line that changed in the file. The command line enables only the numbers column with -b, so the test builds a library Config with LineNumbers and Changes, commits a file to a temporary repository and modifies the line after a blank line. Without the fix in d2d97d4 the marker moves to the following line. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
|
Thanks for rechecking. Added the regression test in 4803929: The per-target build jobs are red on this push for an unrelated reason: their test steps pass (including the new test), then the packaging step fails on Disclosure: this test and reply were produced by an AI agent (Claude Code), which ran the tests mentioned. |
|
Thanks for adding the Git decoration regression. I rechecked |
Picks up the CI packaging fix (sharkdp#4128) so the per-target build jobs can pass again. No conflicts. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
|
I found another numbering case on head printf 'alpha\n\nbeta\n' > fixture.txt
bat --no-config --paging=never --color=never --decorations=always -b -A fixture.txtThe PR displays the nonblank The counter appears to check blankness after I reproduced this with Windows CI binaries for the PR head and a commit with the same tree as base |
With --show-all, the line terminator is rendered as a visible character, so the blank-line check on the rendered line never matched and blank lines were counted: `-b -A` numbered the line after a blank line one too high. Check the input instead (decoded for UTF-16, raw bytes otherwise), which is the same condition the controller used before this branch. Blank lines now also stay unnumbered under `-b -A`, as with `cat -bA`. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Brings in the gix upgrade (sharkdp#4132). No conflicts. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
|
I rechecked |
Brings in sharkdp#4141, which moves line decoding in print_line into decode_line(). No conflicts; the blank-line check for -b still runs on the input before the line is rendered. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
v0.27.0 was released, so the changelog entry for this fix moves from the v0.27.0 section to "unreleased". Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Resolve the CHANGELOG conflict with sharkdp#4164 by keeping both entries. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
With the new
-b/--number-nonblank(#3857, unreleased),--line-rangeand--highlight-lineaddress the non-blank line count instead of file lines, so the same range shows different lines than with-n:and
bat -b -H 5 f.txthighlights nothing (there is no 5th non-blank line) instead offive.cat -bonly changes the displayed numbers, and neither #3857 nor #3856 mentions ranges or highlights, so I assumed this wasn't intended; happy to be told otherwise.Cause: in
src/controller.rsthe line counter skipped blank lines in-bmode, but the same counter drives the range and highlight checks (and the line-1 BOM strip). This counts file lines again and keeps a separate non-blank counter in the printer for the displayed number, so-boutput is unchanged without-r/-H.Tests:
number_nonblank_line_range_uses_file_line_numbersandnumber_nonblank_highlight_line_uses_file_line_numbersintests/integration_tests.rsfail on master and pass with the change; the existing-btests are unchanged. Fullcargo test(458 passed),cargo fmt --checkandcargo clippy --all-targetsare clean. The CHANGELOG also fills in#4076for my earlier entry, which was merged with a placeholder.Disclosure: this was found, reproduced and patched by an AI agent (Claude Code), which ran the reproduction and tests quoted above. It has not been separately reviewed by a human.