Files
zed/crates/terminal_view
Ben Brandt f2cdf3d5bd acp_thread: Add authoritative terminal display updates (#64976)
Add a shared, byte-oriented terminal display update boundary without
enabling v2 transport. References, output-first updates, and snapshots
reuse the existing terminal registry and the same model, renderer, and
read-only view.

- Add tri-state terminal patches for command, cwd, decoded output
snapshots, exit information, and metadata. Keep terminal, snapshot,
exit, and content-reference metadata in their own scopes; consume
appended bytes without another raw-output history store.
- Create display placeholders for unseen v2 tool-content terminal
references. Existing v1 missing references remain errors.
Native/client-owned terminals, including no-PTY wrappers, reject display
patches.
- Keep append separate from replacement. Replacement rebuilds the
emulator/parser at the latest requested bounds, preserves configuration
and entity/view identity, and invalidates selection, search, hover,
scrolling, and cursor blinking.
- Stamp parser events with the output generation so queued old titles
cannot resurface. Drop all obsolete internal events, including
historical resizes, rather than applying them to the new screen.
- Preserve legacy first-Created/first-Exit behavior through independent
event markers. Late creation fills a placeholder without replacing its
renderer; pending legacy bytes drain before later snapshots. Reported
command values and explicit clears outrank caption fallbacks.

## Review guide

1. [Shared model and decoded patch
types](https://github.com/zed-industries/zed/blob/99eb1f22a5f3210d00b4253582c589b60d4a0cb2/crates/acp_thread/src/terminal.rs#L427),
then [registry/upsert entry
points](https://github.com/zed-industries/zed/blob/99eb1f22a5f3210d00b4253582c589b60d4a0cb2/crates/acp_thread/src/acp_thread.rs#L6768):
identity, metadata, output/exit independence, and legacy compatibility.
2. [Renderer
replacement](https://github.com/zed-industries/zed/blob/99eb1f22a5f3210d00b4253582c589b60d4a0cb2/crates/terminal/src/terminal.rs#L2007):
configuration/bounds, parser reset, process isolation, and stale-event
invalidation.
3. [View
invalidation](https://github.com/zed-industries/zed/blob/99eb1f22a5f3210d00b4253582c589b60d4a0cb2/crates/terminal_view/src/terminal_view.rs#L1211)
and the rendered tool-card regression: the existing read-only view
survives replacement and completion changes.

Release Notes:

- N/A
2026-09-30 13:05:18 +00:00
..
…

Terminal View

Design Notes

This crate is split into two conceptual halves:

  • The terminal.rs file and the src/mappings/ folder, these contain the code for interacting with terminal emulator backends and maintaining the pty event loop. Some behavior in this file is constrained by terminal protocols and standards. The Zed init function is also placed here.
  • Everything else. These other files integrate the Terminal struct created in terminal.rs into the rest of GPUI. The main entry point for GPUI is the terminal_view.rs file and the modal.rs file.

ttys are created externally, and so can fail in unexpected ways. However, GPUI currently does not have an API for models than can fail to instantiate. TerminalBuilder solves this by using Rust's type system to split tty instantiation into a 2 step process: first attempt to create the file handles with TerminalBuilder::new(), check the result, then call TerminalBuilder::subscribe(cx) from within a model context.

The TerminalView struct abstracts over failed and successful terminals, passing focus through to the associated view and allowing clients to build a terminal without worrying about errors.

Backend Boundary

terminal.rs exposes backend-neutral domain types such as terminal content, cells, modes, points, ranges, scroll commands, vi motions, hyperlinks, and search matches. UI code should depend on those types instead of importing backend-specific terminal types directly.

The current implementation is still Alacritty-backed, but the abstraction boundary keeps backend details concentrated in the terminal crate:

  • terminal_view renders TerminalContent and dispatches backend-neutral actions.
  • Panels and tools use terminal-domain types for mode, cursor, range, hyperlink, and search behavior.
  • Backend-specific conversions stay near the terminal event loop and render snapshot code.

This keeps the user-facing terminal behavior unchanged while making future backend experiments reviewable as backend implementations instead of UI-wide refactors.

Input

There are currently many distinct paths for getting keystrokes to the terminal:

  1. Terminal specific characters and bindings. Things like ctrl-a mapping to ASCII control character 1, ANSI escape codes associated with the function keys, etc. These are caught with a raw key-down handler in the element and are processed immediately. This is done with the try_keystroke() method on Terminal

  2. GPU Action handlers. GPUI clobbers a few vital keys by adding bindings to them in the global context. These keys are synthesized and then dispatched through the same try_keystroke() API as the above mappings

  3. IME text. When the special character mappings fail, we pass the keystroke back to GPUI to hand it to the IME system. This comes back to us in the View::replace_text_in_range() method, and we then send that to the terminal directly, bypassing try_keystroke().

  4. Pasted text has a separate pathway.

Generally, there's a distinction between 'keystrokes that need to be mapped' and 'strings which need to be written'. I've attempted to unify these under the '.try_keystroke()' API and the .input() API (which try_keystroke uses) so we have consistent input handling across the terminal