[PR #4585] fix(tui): prevent dead keystrokes when spawning editor from TUI #11025

Closed
opened 2026-02-16 18:15:48 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4585

State: closed
Merged: No


Fixes intermittent dead keystrokes when opening editors (neovim, vim, etc.) from the TUI, and prevents terminal corruption on editor failures.

Root cause: OpenTUI's stdin event listeners remained active during renderer.suspend(), causing a race condition where both the TUI handlers and the spawned editor competed for keystrokes.

Changes:

  • Remove all stdin event listeners before spawning editor (prevents race)
  • Use spawnSync instead of Bun.spawn for proper exclusive stdio access
  • Use shell: true for proper command parsing (handles flags, quoted paths)
  • Add error handling to restore terminal state on spawn failures
  • Add TTY check to fail gracefully when stdin is not a TTY
  • Save/restore terminal state with both stty and setRawMode (complementary)

This fix ensures:

  • Editors like 'nvim -u NONE' with flags work correctly
  • Paths with spaces are handled properly
  • Terminal doesn't get corrupted if editor fails to spawn
  • Clean error behavior in non-TTY environments

Tested with neovim, verified keystroke handling is now reliable.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4585 **State:** closed **Merged:** No --- Fixes intermittent dead keystrokes when opening editors (neovim, vim, etc.) from the TUI, and prevents terminal corruption on editor failures. Root cause: OpenTUI's stdin event listeners remained active during renderer.suspend(), causing a race condition where both the TUI handlers and the spawned editor competed for keystrokes. Changes: - Remove all stdin event listeners before spawning editor (prevents race) - Use spawnSync instead of Bun.spawn for proper exclusive stdio access - Use shell: true for proper command parsing (handles flags, quoted paths) - Add error handling to restore terminal state on spawn failures - Add TTY check to fail gracefully when stdin is not a TTY - Save/restore terminal state with both stty and setRawMode (complementary) This fix ensures: - Editors like 'nvim -u NONE' with flags work correctly - Paths with spaces are handled properly - Terminal doesn't get corrupted if editor fails to spawn - Clean error behavior in non-TTY environments Tested with neovim, verified keystroke handling is now reliable.
yindo added the pull-request label 2026-02-16 18:15:48 -05:00
yindo closed this issue 2026-02-16 18:15:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11025