Repository navigation
fix(read): separate line numbers with a tab - #4647
Conversation
📊 Automated PR Analysis
SummaryReplaces the box-drawing Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
`--line-numbers` formatted each prefix as `{:>width$} │ `, and the
box-drawing bar is three bytes in UTF-8. That made `rtk read -n` about
4% larger than `cat -n` on a minified source file — the only negative
case in scripts/benchmark.sh, so the benchmark currently fails against
develop's tree.
Use a tab instead, keeping the width alignment. The output now matches
`cat -n`'s shape and is about 4% smaller than it (50,360 -> 47,947
tokens on src/main.rs), so the benchmark case turns from negative to
good.
Update the two line-number expectations in read_window_bytes_test.
027c9bc to
975103a
Compare
A 12-line input pins both the tab separator and the right-aligned width. Reverting either the tab or the width padding fails the test.
|
Hey @KuSh 👋 Small one for you when you get a sec — just swaps the │ separator in read -n for a tab, saves a few bytes/line, no logic changes. Tests are green and CI passed. Would appreciate a look whenever you're free, thanks! |
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — APPROVED, follow-ups filed
Claim: rtk read -n separates the line number from the text with a tab instead of │, and the benchmark's read rows target src/lib.rs instead of the 3-line src/main.rs shim.
Scope: accept (round 1, frozen). #3689 also edits format_with_line_numbers and adds two new │ gutters; this PR lands first and #3689 (already conflicting) switches to the tab on rebase. Maintainer PRs: checked against #4153 (merged with this PR on develop: no conflict, both sets of read and tracking tests pass, 224 tests), and against #4593 and #4341, which change the cat rewrite guard but keep cat -n FILE → rtk read -n FILE; nothing contradicts.
Ran: cat -n FILE through rtk rewrite and then the rewritten rtk read -n command, on develop 41e6912 and on this PR merged into it. 10 files (src/lib.rs, read.rs, CRLF, embedded tabs, empty, no final newline, 9/10/100 lines, Latin-1) plus -l minimal, -l aggressive, --max-lines 50, --head-lines 12, --tail-lines 12, stdin and two files at once. Invariants checked: through the hook, every path the separator takes (windowed, filtered, capped, stdin, file), same exit codes and same stderr on both binaries. src/lib.rs: cat -n 255,855 B, develop 267,893 B (+4.7%), this PR 243,817 B (−4.7%). The 20% floor in CONTRIBUTING.md does not apply: this changes a format, it adds no filter.
Pins: 0 decisions (only the separator's formatting changes); 5 mutations of the formatting line (restore │, use a space, drop the width, fix the width at 6, left-align): 0 survived, all caught by read_line_numbers_align_multi_digit_widths_with_a_tab
Matrix: executed this round; pin check: executed this round
CI @931571a6d: all green (run 39563655818, benchmark read -n 63,452 → 60,466)
Blocks merge (0)
Filed as follow-ups
- #4889
cat -n a brewritten tortk read -n a brestarts numbering for each file — outside this PR's hunks; same on develop - #4065 —
cat -non a non-UTF-8 file goes through the same exit-1 path; already on develop; comment added - #3427 —
--tail-lines N -nnumbers the window from 1, not with the file's line numbers; already on develop and already reported there - #4816 — CRLF and final newline under
-n, already tracked; this PR covers only the separator, as #4816 says
Checked and correct — no need to re-verify
format_with_line_numbersis the only producer of the separator; the windowed, filtered,--max-linesand stdin paths all go through it and all print the tab.- Tracking compares rtk's numbered raw text with rtk's numbered output, so the change applies to both sides and recorded ratios stay the same.
- The engine's
strip-line-numbersnow treats the tab as a file-coordinate separator, but it only runs on Read tool results and is off by default. The shell posthook skips rtk commands. - The PR merges cleanly into develop 41e6912. On that merge, fmt and clippy are clean (0 warnings) and
cargo test --allpasses with 0 failures.
Next
nothing — approving.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
Summary
rtk read -nformatted line numbers as{:>width$} │. The box-drawing│is three bytes in UTF-8; a tab is one. Each numbered line therefore carried four more bytes than the same output with a tab.Use a tab instead, keeping the width alignment. The tab is also what
cat -nitself uses, so the output now looks like the native command rather than an rtk-specific marker:The read benchmark rows now target
src/lib.rs(5,971 lines) instead ofsrc/main.rs, which is a 3-line shim since 5d8102a moved the CLI.scripts/benchmark.shestimates tokens with${#input}. On the CI runner's UTF-8 locale that counts characters, so CI reportscat -nat 63,452 and the tab row at 60,466. The old│separator is three bytes; with its two surrounding spaces it adds four bytes per line over the tab. In a C/POSIX locale (byte counting) the old row is 66,460 (+4.7% vscat -n). In the CI runner's UTF-8 locale│counts as one character, so the old row tiescat -nat 63,451-63,452. Either way the tab removes the four-byte overhead and puts the row 4.7% belowcat -n:cat -n│formatThe derived rows use the same measured output; the
│rows add the separator difference (two characters per line under the script's estimate, four bytes per line in the emitted output).Test plan
cargo fmt --all --checkandcargo clippy --workspace --all-targetspasscargo test --test read_window_bytes_test: 6 passed. The two existing expectations now use the tab, and a 12-line case pins both the tab separator and the right-aligned width; reverting either the tab or the width padding fails itrtk read -noutput inspected; it matchescat -n's shapeformat_with_line_numbersis the only producer of the separator; no other source, test, snapshot or doc asserts the old formatscripts/benchmark.shon CI (run 39563655818): 41 good / 33 warn / 0 negative / 0 fail (41/74, 55%); exit 0read53,003/53,003,read -l minimal49,604/53,003,read -l aggressive5,991/53,003,read -n60,466/63,452 (rtk/cat); no NEGATIVE