Skip to content

fix: support TUI apps (vim, nano, htop) in terminal panels#88

Closed
parsakhaz wants to merge 5 commits intomainfrom
vim-crashes-terminal-repro-vim-codexconfigtoml
Closed

fix: support TUI apps (vim, nano, htop) in terminal panels#88
parsakhaz wants to merge 5 commits intomainfrom
vim-crashes-terminal-repro-vim-codexconfigtoml

Conversation

@parsakhaz
Copy link
Copy Markdown
Member

@parsakhaz parsakhaz commented Mar 24, 2026

Summary

  • Fix flow control: Move acks inside xterm.write() callback for proper backpressure; remove 1MB data-drop hard limit that corrupted escape sequences mid-stream for TUI apps
  • Universal TUI detection via alternate screen buffer: Detect \x1b[?1049h (enter) / \x1b[?1049l (leave) escape sequences — works for ALL full-screen apps (vim, nano, htop, tmux, any ncurses/crossterm app), through SSH, on WSL, no hardcoded app list needed
  • Key passthrough in TUI mode: When alternate screen is active, pass all keys to PTY (except Ctrl+V for native paste) so vim/nano/htop keybindings work
  • Handle terminal:exited: Frontend shows [Process exited with code N] when PTY dies, instead of silently hanging
  • Use actual container dimensions: PTY spawns at the real terminal size instead of hardcoded 80x30
  • Fix PTY name mismatch: name field now matches TERM env var (xterm-256color)

All existing battery optimizations preserved: 32ms output batching, active-panel-only resize, low scrollback.

Test plan

  • `vim ~/.codex/config.toml` — renders correctly, all keys work, `:q` exits cleanly
  • `htop` — full-screen TUI renders, keys work, `q` exits, Pane shortcuts resume after exit
  • `ssh remote-host` then `vim` on remote — TUI detected through SSH tunnel
  • `cat /dev/urandom | xxd` — high-throughput output doesn't freeze or crash
  • Normal shell usage — feels identical to before (ls, cd, git, etc.)
  • Ctrl+V paste works both in normal shell and inside vim
  • Exit a shell with `exit` — shows exit code message
  • Resize terminal while vim is open — redraws correctly

- Move acks inside xterm.write() callback for proper backpressure
- Remove 1MB data-drop hard limit that corrupted escape sequences
- Auto-detect TUI apps via process title for key passthrough
- Add terminal:exited handler so frontend shows exit status
- Pass actual container dimensions at PTY spawn instead of 80x30
- Fix PTY name field mismatch (xterm-color → xterm-256color)
- Allow Ctrl/Cmd+V to use browser paste path even when a TUI app
  (vim, nano, etc.) is running, so users can paste normally
- Query current foreground process title on panel mount via new
  terminal:getProcessTitle IPC handler, so TUI detection works
  when returning to an already-running editor session
Extract a helper that splits on both / and \ separators and strips
the .exe suffix, so TUI apps like nvim.exe on Windows are correctly
detected by the key passthrough logic.
… on exit

- Detect alternate screen buffer escape sequences (\e[?1049h/l) in
  the PTY data stream, providing reliable TUI detection that works
  on WSL where pty.process only reports wsl.exe
- Emit terminal:alternateScreen events to the renderer as a
  complementary signal alongside process title changes
- Query both process title and alternate screen state on panel mount
  via terminal:getProcessInfo for correct initialization
- Reset tuiActiveRef to false when the terminal process exits so
  Pane shortcuts are not permanently blocked on a dead terminal
…een detection

Remove TUI_APPS set, extractProcessName helper, process title tracking
(lastProcessTitle, terminal:titleChanged, onTerminalTitleChanged), and
terminal:getProcessInfo IPC. TUI detection now relies solely on the
alternate screen buffer escape sequences (\x1b[?1049h / \x1b[?1049l),
which all well-behaved full-screen apps use. This works universally —
including through SSH, on WSL, and for any future TUI app.
@parsakhaz parsakhaz force-pushed the vim-crashes-terminal-repro-vim-codexconfigtoml branch from e049897 to 16ad6ce Compare March 24, 2026 20:08
@parsakhaz parsakhaz marked this pull request as ready for review March 24, 2026 20:09
parsakhaz added a commit that referenced this pull request Mar 24, 2026
- Fix flow control: move acks inside xterm.write() callback for proper
  backpressure; remove 1MB data-drop that corrupted escape sequences
- Universal TUI detection via alternate screen buffer (\x1b[?1049h/l)
  — works for all full-screen apps, through SSH, on WSL
- Key passthrough in TUI mode (except Ctrl+V for native paste)
- Handle terminal:exited in frontend
- Use actual container dimensions at PTY spawn instead of 80x30
- Fix PTY name mismatch (xterm-color → xterm-256color)
@parsakhaz parsakhaz closed this Apr 12, 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