Add interactive LineEditor with arrow key support#132
Add interactive LineEditor with arrow key support#132dirtyhenry wants to merge 4 commits intomainfrom
Conversation
Implement a raw-mode terminal line editor that intercepts escape sequences for cursor navigation, replacing Swift.readLine() for interactive use. Supports arrow keys, Home/End, Alt+arrows for word movement, Ctrl-A/E/C/D/U/K/W, UTF-8 input, and Delete key. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 103f0dfb1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Cast raw-mode bitmask to tcflag_t for Linux compatibility - Replace naive displayWidth heuristic with proper East Asian Wide character detection for correct cursor positioning with CJK text - Add display width tests for ASCII, CJK, and mixed content Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7133108f7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Check stdout is a TTY before enabling LineEditor to avoid emitting escape sequences when output is redirected - Use display width instead of character count for prompt cursor positioning to handle wide Unicode characters correctly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2bf282f48
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| guard let next = tryReadByte(timeoutMs: 50) else { | ||
| return // Standalone ESC, ignore |
There was a problem hiding this comment.
Parse ESC sequences without fixed 50ms timeout
Using a hardcoded 50ms timeout to decide whether 0x1B starts an escape sequence will drop legitimate arrow/Alt key input on slower links (for example, remote SSH sessions with >50ms latency or transient jitter). In that case handleEscape returns early, and the remaining bytes (like [/D) are processed as normal text, so cursor navigation intermittently inserts characters instead of moving the cursor.
Useful? React with 👍 / 👎.
Summary
LineEditor, a readline-style interactive line editor for terminal input with arrow key navigation, word movement (Alt+arrows), and editing keybindings (Ctrl-A/E/U/K/W)TerminalModehelper for raw terminal mode managementCLIUtils.editLine(prompt:)as the public API, with automatic fallback toSwift.readLine()for non-TTY inputReadLineCommandto BlocksCLI for testingBuffertype🤖 Generated with Claude Code