Repository navigation
Conversation
|
Updated 3:52 AM PT - Oct 21st, 2026
✅ @robobun, your commit cf3cfefb74bc26b9452184becd50d2e9bd1c8ec3 passed in 🧪 To try this PR locally: bunx bun-pr 46083That installs a local version of the PR into your bun-46083 --bun |
|
Status Reproduced on Linux x64, on a pty and on piped stdin, with the released build and with a debug build of main:
Byte |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 13 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…rl+D in editor mode Ctrl+C in a continuation or in editor mode dropped the earlier lines but left the line being typed in the line editor, so it stood at the next prompt and the next input was appended to it. handle_ctrl_c now clears the line editor once, before it looks at the mode. Ctrl+D in editor mode evaluated the entered lines and also left the line being typed at the next prompt. It now appends that line to the editor input before the evaluation. It also resets the history position, as Ctrl+C, .break and an evaluating Enter do when they return to the plain prompt.
11ab2d5 to
cf3cfef
Compare
Problem
bun repl, Ctrl+C in a continuation or.editormode keeps the line being typed.foo(Enter,bar, Ctrl+C,2+2Enter answersReferenceError: bar2 is not defined..editormode leaves that line at the next prompt.handle_ctrl_c(src/runtime/cli/repl.rs:2621) clearsline_editoronly in its plain-prompt arm. The Ctrl+D editor arm (:2361) never reads it.Fix
handle_ctrl_cclears the line editor before thematchon the mode. The Ctrl+D editor arm appends the typed line toeditor_buffer, then resets the history position..editor"buffers all input until you pressCtrl+D", and Node does both.test/js/bun/repl/repl.test.ts, 10 new tests, 9 fail without the fix.Background
multiline_buffer) and an editor mode (editor_buffer).line_editorholds the typed line.reset_positionreturns Up and Down to the newest entry.Downsides
Repl::run_with_vm+218 B. Ctrl+C at an empty prompt: 973 to 979 instructions. Editor Ctrl+D, empty line: 417 to 426.>prompt.Notes
Repro (piped stdin reads the same keys as a terminal: byte 0x03 is Ctrl+C, 0x04 is Ctrl+D)
foo(Enter,bar, Ctrl+C,2 + 2EnterReferenceError: bar2 is not defined44.editor,1Enter,bar, Ctrl+C,3 + 3EnterReferenceError: bar3 is not defined66.editor,1 + 1Enter,40 + 2, Ctrl+D2, and40 + 2stays at the prompt4242printf 'foo(\nbar\0032 + 2\n' | bun replshows the first row. On a pty the fresh prompt reads> baron main and>with this change.What stays the same
^Cis echoed behind a line cancelled at the plain prompt. A line cancelled in a continuation or in editor mode gets no echo, as before.// Editor mode cancelled, and the history reset on Ctrl+C.Not changed here
.is always read as a command (.5 + 1answersUnknown command: .5)..editoris not added to the history.{ a: 1 } // cprints1at the plain prompt: replMode: decide between an object literal and a block in the parser #43770.// don'topens a continuation: REPL doesn't know how to handle regex literals #37326, repl: recognize regex literals and comments in continuation detection #37327. Ctrl+C on a Windows console does not reachhandle_ctrl_c: repl: handle Ctrl+C at the prompt on Windows instead of exiting #38073.Each of the first five is handed to its own follow-up change. None of them is a GitHub issue.
Ctrl+D rule: Ctrl+D with text on the line behaves as Enter, then Ctrl+D. The line is added with its newline, blanks count as input (
.editor, three spaces, Ctrl+D printsundefined, as blanks, Enter, Ctrl+D did before), and an empty line adds nothing. Editor mode never dispatched dot-commands on entered lines, so the typed line is not dispatched either.Each clause of the Ctrl+D arm is pinned by a test (checked by removing the clause, then running the Ctrl+D tests)
Ctrl+D in editor mode evaluates the line being typedfails (.editor, Ctrl+D printsundefined)Ctrl+D in editor mode takes the line being typed the way Enter takes a linefails ({ a: 1 } // cprints1)Ctrl+D in editor mode resets the history positionfails (Up recalls100 + 11)handle_ctrl_cand the append are pinned by the tests that fail on mainMeasurements. Release builds of 6bb5dc1 and of the same tree with this change to
repl.rs, built in one directory with one toolchain, Linux x64.llvm-nm -S): thereplmodule has 35 symbols in both builds, 38,982 B against 39,200 B. The +218 B are all inRepl::run_with_vm(15,360 to 15,578 B). No new symbol, no new host function. Text of the whole binary: +256 B. The stripped file is 107,235,040 B in both.stepiover one iteration of the key loop, piped stdin, one key perread(2), 3 identical runs per build): 973 against 979 instructions, 108 conditional branches, 24 calls and 7 syscalls in both.mi_*entry points, 50 against 100 cycles):barCtrl+C 0,foo(Enter.breakEnter 2,foo(EnterbarCtrl+C 1, the same in both builds. The evaluating scripts (1Enter, and.editor1+1Enter Ctrl+D) make about 23mi_mallocand 4mi_reallocper cycle in both builds. They vary by about 0.2 per cycle from run to run. Ctrl+D with a typed line, the new path: 23 and 4.cmp): identical on the 27 piped inputs of the existing tests and on four scripts that do not hit the bug. Per cancelled continuation line the PR writes 3write(2)and 4 bytes, main 2 and 2 (from/proc/<pid>/io).write(2)(main 13). The terminal receives\r ESC[7C \r\n \r ESC[J > \r ESC[2C(main:... > bar \r ESC[5C).Platform. No
cfgarm is touched. The six piped tests are not gated and run on Windows in CI. The four pty tests are in the existingdescribe.todoIf(isWindows)block. Nothing was run on Windows or macOS locally.Suites run:
bun bd test test/js/bun/repl/repl.test.ts(139 pass). With the released bun the same file fails 9 of the 10 new tests. The tenth pins the double Ctrl+C exit, which did not change.