Terminal internals
How Terminal emulates with alacritty_terminal, renders with the framework's GPU terminal view, handles input and keeps its persistence bounded.
Terminal pairs alacritty_terminal with the framework’s GPU terminal view, and keeps keyboard handling, selection, find and persistence in the app. This page summarises that design. For using Terminal, see Terminal.
Build and check
Terminal pins enzUI and its foundation forks in Cargo.toml and Cargo.lock. Fetch the locked sources before building offline:
cargo fetch --locked
cargo build --locked --offline --release
ICED_TEST_BACKEND=software cargo test --locked --offline --features center -- --test-threads=1The serial test harness keeps real PTY tests within the process file-descriptor limit. The suite concentrates on SSH and credential boundaries, PTY and session ownership, untrusted terminal input and persistence integrity, plus a few broad user workflows and accessibility checks.
The executable is terminal-emulator and the application ID is io.github.enzui.Terminal. It runs as the logged-in user, with no root service or privileged shell.
Emulation
The emulator core is alacritty_terminal, wrapped behind the app's own screen API in src/emulator.rs.
- The emulator itself keeps no history.
emulator/handler.rscopies rows that scroll off into a compact retained scrollback, bounded by the scrollback setting in rows. emulator/scan.rsremoves a few sequences from the stream so the app can handle them itself: working-directory reports (OSC 7), command completion marks (OSC 133 D), the shell-integration command channel (OSC 777),CSI 3 J(clear history only) andESC c.- Clipboard writes from programs (OSC 52) and palette queries are ignored. Only primary device attributes and cursor-position reports are answered.
- The alternate screen is supported through mode
?1049.
The supported VT editing set is a practical subset; Terminal does not claim complete xterm emulation.
Rendering
Each pane is drawn by the framework's GPU terminal view. The view does not take keyboard or selection itself; the app keeps keys, input methods, selection, find and links.
There are two update paths that share one cell-styling function:
- Live path. A pane following live output is written directly by its PTY reader, at most every 8 ms. While every pane is live, the app's own refresh (titles, find, selection) drops to 10 Hz.
- App path. Otherwise, the app writes the visible window with the cursor, find highlights and selection already applied.
Rendering also works under the software renderer used in tests. The rendering design document in the repository records measurements against Alacritty, kitty and foot; replacing the previous emulator backend made a large cat several times faster.
Input
Keys use the legacy xterm encoding (not the kitty protocol, CSI-u or modifyOtherKeys). App shortcuts are matched before a key is sent to the shell, which is why they use Ctrl+Shift and plain Ctrl+letter combinations always reach the shell. While an input method has an uncommitted composition, key output to the shell is held until the text is committed.
Shell integration
Command history does not read the shell's history file or watch keystrokes. Instead, an interactive Bash (4.4 or newer, using PS0) or Fish reports each command through an OSC 777 sequence, bounded to 4096 bytes. Unsupported shells, or an integration that fails at startup, show that history is unavailable.
SSH and endpoints
- SSH hosts come from saved profiles or from a read-only, bounded parse of the OpenSSH configuration. Only literal
Hostaliases are listed,Includeis followed, andMatchis not evaluated. Exceeding a file, total-size, depth or alias limit refuses the whole result. - The configuration is read again before connecting; a changed endpoint or fingerprint is refused.
- A split of an SSH pane clones its endpoint. If the saved profile was edited or deleted, the pane stays disconnected and asks the user to reconnect explicitly; it never silently falls back to a local shell.
Persistence
| Store | Bound |
|---|---|
| Session file | about 8 MiB |
| Settings file | 1 MiB |
| Saved SSH profiles | 128 |
| Shortcut overrides | 128 |
| Pinned output (per session, in the keyring) | 1 MiB, 8 panes, 20,000 rows, 128 commands per pane |
Files that are too large or invalid are refused and protected from being overwritten: the app starts with defaults and blocks saving rather than replacing data it could not read. Pinned output is stored only in the Secret Service, never in the session file, and restoring a pin starts no process.
Localization
Terminal ships English and Spanish Fluent catalogs, embedded for offline use, including Spanish text for the framework controls. Regional Spanish locales fall back to es, and missing translations fall back to English.