Now I have a complete understanding of the issue.
Issue #732 Analysis: "Prompts larger than the screen fuck up everything"
Summary
When setEditorText loads text that produces more lines than fit in the terminal, the TUI rendering breaks completely, causing visual corruption (doubled/overlapping lines) and ESC stops working.
Root Cause
The Editor component has no height constraint. It renders ALL layout lines regardless of terminal size:
In packages/tui/src/components/editor.ts (lines 318-390):
When the total rendered lines exceed terminal height:
- The TUI writes lines sequentially with
\r\n, causing terminal scrolling
- The cursor position tracking (
cursorRow in TUI) becomes desynchronized
- Differential rendering then writes to wrong positions, creating the ghosting/corruption seen in the screenshot
- Input handling breaks because the TUI state is inconsistent
Why ESC Stops Working
The TUI's input forwarding depends on consistent state. When rendering breaks, the component may not receive or correctly process input. Ctrl+C still works because it triggers SIGINT at the OS level.
Proposed Fix
Add vertical scrolling with a max height constraint to the Editor, following the same pattern as SelectList which already has maxVisible:
Changes to packages/tui/src/components/editor.ts:
- Add new state:
- Add setter method:
- Add scroll adjustment method:
- Modify
render() to slice visible lines:
- Call
ensureCursorVisible() after cursor movements (or just let render() handle it)
Changes to packages/coding-agent/src/modes/interactive/interactive-mode.ts:
In init() or wherever the editor is configured, calculate and set a reasonable max height based on terminal dimensions minus other UI elements (header, footer, status, etc.).
Alternative Consideration
A more invasive fix would change the Component interface to pass both width and height:
However, this is a breaking change and affects all components. The maxLines approach is self-contained to the Editor.
Files Affected
packages/tui/src/components/editor.ts - Add scrolling logic (~30-40 lines)
packages/coding-agent/src/modes/interactive/interactive-mode.ts - Set editor max height (optional, could use a sensible default like terminal height - 10)