Skip to content

Add history and standard Ctrl & Alt commands to the REPL#9823

Open
ageron wants to merge 11 commits into
roc-lang:mainfrom
ageron:add-ctrl-commands
Open

Add history and standard Ctrl & Alt commands to the REPL#9823
ageron wants to merge 11 commits into
roc-lang:mainfrom
ageron:add-ctrl-commands

Conversation

@ageron

@ageron ageron commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This PR activates the REPL history and adds several Ctrl & Alt commands.

History

  • The history was implemented, but not used. Now every command is appended to the history.
  • When running the same command several times in a row, only the first command is appended to the history.
  • When moving up the history then back all the way down, we get back the current line.
  • After replaying command N, pressing down will select command N+1 (similar to Julia's REPL).
  • Supports multiline commands (one line at a time).

Ctrl & Alt commands

  • Ctrl-A: move cursor to start of line
  • Ctrl-E: move cursor to end of line
  • Ctrl-K: delete line to end
  • Ctrl-U: delete line to start
  • Ctrl-W: delete word backward
  • Ctrl-Y: yank (i.e., paste whatever was deleted)
  • Ctrl-B: move cursor left
  • Ctrl-F: move cursor right
  • Ctrl-H: delete character before
  • Alt-B: move word left
  • Alt-F: move word right
  • Alt-D: delete word forward

This makes editing very pleasant on Mac and Linux as the terminals are often configured to generate these commands when typing common keystrokes (e.g., Cmd-Backspace generates Ctrl-U).

Note that I edited Unix.zig to set new_termios.lflag.ISIG and new_termios.lflag.IEXTEN to false to ensure that the REPL receives key combos like Ctrl-Y (or else this suspends the process).

Implemented mostly by antigravity. I reviewed all the code.

@ageron ageron mentioned this pull request Jun 26, 2026
@ageron ageron changed the title Add standard Ctrl and Alt commands to the REPL for line navigation and editing Add history and standard Ctrl & Alt commands to the REPL Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant