Make the empty escape buffer explicit without changing incremental key handling. This removes the maybe-uninitialized warning found by the DGX Spark QA build.
Buffer complete terminal updates, repaint status without erasing live input, and retain pending redraws across throttling. Preserve fragmented UTF-8, navigation and paste input, and bound tab completion safely.
Use shared Unicode width handling for input, output and queued prompts. Preserve unmatched Markdown delimiters and publish code recoloring as one update. Add focused terminal regression tests.
Three fixes for regressions introduced by the raw-mode restoration
commit (ce5b70b):
1. agent_prompt_yes_no_ex: handle non-blocking stdin
editor_start sets O_NONBLOCK on stdin; fgets() returned NULL
immediately (EAGAIN) causing the save prompt to exit without
waiting for user input. Temporarily switch to blocking mode
around the fgets call.
2. /quit handler: stop editor before prompting
editor_restore_terminal_layout resets the scroll region but does
not disable raw mode or restore stdin flags. Call editor_stop
first so that raw mode is off and stdin is blocking when we
prompt the user. Handle AGENT_EXIT_CANCEL by restarting the
editor instead of leaving it half-stopped.
3. linenoiseRestoreRawMode: do not corrupt orig_termios
The function unconditionally overwrote orig_termios with the
current terminal attributes via tcgetattr. While the editor is
active those are the raw-mode settings (OPOST cleared). Later,
disableRawMode restores this corrupted orig_termios, leaving the
terminal in raw mode after editor_stop. puts output then lacks
carriage returns, causing garbled display (e.g. /help).
Only update orig_termios when rawmode == 0 (child process
changed terminal to cooked).
Use an ANSI scroll region for streamed agent output, resize it as linenoise input wraps or shrinks, and anchor the prompt/status block at the terminal bottom. This also fixes cursor placement at exact column boundaries and removes the prompt/output overwrite cases seen during multiline editing.