Skip to content

Add interactive LineEditor with arrow key support#132

Open
dirtyhenry wants to merge 4 commits intomainfrom
readline
Open

Add interactive LineEditor with arrow key support#132
dirtyhenry wants to merge 4 commits intomainfrom
readline

Conversation

@dirtyhenry
Copy link
Copy Markdown
Owner

Summary

  • Add 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)
  • Add TerminalMode helper for raw terminal mode management
  • Add CLIUtils.editLine(prompt:) as the public API, with automatic fallback to Swift.readLine() for non-TTY input
  • Add ReadLineCommand to BlocksCLI for testing
  • Add unit tests for the Buffer type

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Sources/Blocks/CLIUtils/TerminalMode.swift Outdated
Comment thread Sources/Blocks/CLIUtils/LineEditor.swift Outdated
dirtyhenry and others added 2 commits March 4, 2026 22:03
- 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>
@dirtyhenry
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Sources/Blocks/CLIUtils/CLIUtils.swift Outdated
Comment thread Sources/Blocks/CLIUtils/LineEditor.swift Outdated
- 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>
@dirtyhenry
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +91 to +92
guard let next = tryReadByte(timeoutMs: 50) else {
return // Standalone ESC, ignore
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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