Skip to content

feat(repl): raw-console readline editing for the standalone interactive shell (rubash#419 readline leg) - #482

Merged
caomengxuan666 merged 1 commit into
masterfrom
feat/real-readline-repl
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
feat/real-readline-repl

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #419.

Problem

A bare rubash.exe on a real console reached run_interactive_stdin after #419's first fix (53e0065) — expanded PS1/PS2 on stderr, --rcfile sourced 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:
    • flips the console to raw mode (ENABLE_LINE_INPUT/ENABLE_ECHO_INPUT/ENABLE_PROCESSED_INPUT off) between the prompt and the accepted line;
    • translates key events (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 in uChar), UTF-16 surrogate pairs assembled;
    • repaints the edit line per keystroke (raw mode owns the echo), with ANSI-sequence-aware and East Asian-wide prompt width accounting;
    • restores the cooked mode before each accepted command runs, so children (cat, editors) see a normal line-discipline console — readline's save_tty_state shape;
    • pipe/redirect/ConPTY-bridge stdin keeps 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 into apply_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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant