Repository navigation
feat(repl): raw-console readline editing for the standalone interactive shell (rubash#419 readline leg) - #482
Merged
Conversation
…ve shell (rubash#419 readline leg) The console branch already routed through run_interactive_stdin (PS1/PS2 rendered on stderr, --rcfile honored) — but stdin stayed in cooked line-input mode, so conhost owned the editing: the arrow keys drove conhost's own line buffer and every shell binding (history recall, cursor motion, isearch) never fired. - src/console_readline.rs (new): RawConsole flips the console to raw mode between the prompt and the accepted line, translates key events to the character stream the edit dispatcher already understands (arrows as CSI, Home/End/Delete, control chars), repaints the edit line per keystroke (raw mode owns the echo), and restores the cooked mode before each command so children keep a line-discipline console. Pure helpers (key translation, ANSI-aware prompt width, redraw) are unit-tested off-console. - src/script_driver.rs: the readline edit dispatch is factored out of the reader loop into apply_edit_char/EditState (ESC handling becomes a cross-keystroke state machine); the cooked byte-stream path keeps the #434 bridge semantics byte-for-byte and shares the same bindings. - tests/issue419_real_readline_regressions.rs: driver-level pins for rubout (byte- and char-safe), C-c discard, C-d EOF, pending-line accept at EOF, and the pinned bridge semantics for piped arrows. - scripts/smoke-console-readline-pty.py: pywinpty+pyte ConPTY legs — --rcfile PS1 prompt, backspace edit, Up-arrow history recall, C-a re-edit — all green against target/debug/rubash.exe. Layered follow-ups (noted for the tracker): raw-mode tab completion display, isearch prompt rendering, and wrapped-line redraw. Closes #419
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #419.
Problem
A bare
rubash.exeon a real console reachedrun_interactive_stdinafter #419's first fix (53e0065) — expanded PS1/PS2 on stderr,--rcfilesourced and honored, no banner — but stdin stayed in cooked line-input mode: conhost owned the editing, the arrow keys drove conhost's own line buffer, and every shell binding (↑/↓ history recall, ←/→/C-a/C-e cursor motion, C-r isearch) never fired. GNU renders PS1 through readline with raw-mode line editing; the themesweep ConPTY harness had no readline leg to drive.Change
src/console_readline.rs(new) —RawConsole:ENABLE_LINE_INPUT/ENABLE_ECHO_INPUT/ENABLE_PROCESSED_INPUToff) between the prompt and the accepted line;ReadConsoleInputW) into the character stream the engine's edit dispatcher already consumes: arrows as CSI sequences, Home/End/Delete, control chars (conhost pre-encodes Ctrl-letters inuChar), UTF-16 surrogate pairs assembled;cat, editors) see a normal line-discipline console — readline's save_tty_state shape;None→ the cooked reader and the [P2][input] literal \1 byte typed via winpty bridge reaches the shell as 0x01 (console Ctrl-A) — input-layer encoding #434 byte semantics unchanged.src/script_driver.rs— the readline edit dispatch is factored out of the reader loop intoapply_edit_char/EditState(ESC sequences become a cross-keystroke state machine); the cooked path and the raw console path now share one set of bindings. C-o operate-and-get-next's post-accept preload moved to a shared helper.Layered scope (follow-ups)
Tab completion rendering and isearch prompt rendering under raw mode, and wrapped-line (past terminal width) redraw are intentionally left as follow-up layers; keys are delivered to the dispatcher and are non-corrupting today.
Verification
tests/issue419_real_readline_regressions.rs(new): rubout byte-safe and multibyte-safe, C-c discard + survive, C-d EOF, EOF accepts pending line, piped arrows keep [P2][input] literal \1 byte typed via winpty bridge reaches the shell as 0x01 (console Ctrl-A) — input-layer encoding #434 bridge semantics.scripts/smoke-console-readline-pty.py(new, pywinpty+pyte, screens undertarget/issue-suites/results/wt64-repl/): all 4 legs green —--rcfilePS1 prompt with single echo, backspace edit (echo AB+BS+C→AC), Up-arrow history recall re-runs the entry, C-a re-edit.scripts/smoke-console-repl-pty.py: rubash-simple and rubash-theme legs green through the new raw path (single echo preserved).cargo test --lib(636 pass; the 2 failures are the pre-existing env-dependent pwd/path cases, verified failing on pristine master),--test cli_tests(identical 29 pre-existing bashdb failures, failure-set diffed against master),tests/conformance(same single pre-existing failure on master), and all adjacent interactive suites ([bug] exit inside --rcfile init does not terminate the interactive shell: stdin lines execute afterwards (GNU exits) — OMB runs leave prompt-echo + spurious 'unexpected EOF looking for )' stderr #297/300, [bug] Interactive no-tty startup defaults: emacs editing mode off + H missing in $- for --rcfile/-s paths (kills ble.sh at its noediting gate; -i -c $- diverges the other way: hBc vs himBH) #312, [bug] cd updates shell PWD but external children keep the stale process cwd (cd dir && ls lists the OLD dir) #423, [bug] unmatched extglob redirect target >?(zz)out creates a literal file (GNU: syntax error near unexpected token) #424, [bug] sourced 'exit 0' does not terminate niu -i (GNU bash exits) #426, [engine-surface] Bare rubash.exe interactive on a real console is a placeholder REPL: banner + hardcoded '$ ' prompt, --rcfile PS1 ignored (GNU renders PS1 via readline) #419, [P2][input] literal \1 byte typed via winpty bridge reaches the shell as 0x01 (console Ctrl-A) — input-layer encoding #434) green.cargo fmtapplied; pre-commit hooks passed.