Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Standard Library as Architecture

Enums define subsystem protocols

ScreenInstruction, PtyInstruction, PtyWriteInstruction, PluginInstruction, and BackgroundJob make cross-thread commands explicit. An owner loop matches the complete vocabulary of operations it accepts. Data needed later travels inside the variant as owned values.

HashMap represents identity-indexed session state

Tabs, clients, terminal child PIDs, async task handles, pending events, and per-terminal write queues are maps because messages refer to stable IDs across thread boundaries. The ID is the shared language; a Rust reference cannot safely span those independent owners.

VecDeque makes per-pane FIFO visible

The PTY writer’s HashMap<u32, VecDeque<PendingWrite>> preserves byte order within each terminal while allowing round-robin progress between terminals. The data structure expresses both ordering and fairness policy.

Arc and atomics for narrow shared observations

PTY reader tasks and owners share small activity flags with Arc<AtomicBool>. Large pane state does not become globally shared merely because one activity bit must cross threads.

Drop closes protocols

Dropping the original NotificationEnd sends action completion. Dropping SessionMetaData broadcasts Exit to each owner and joins its threads. Dropping Pty closes its child panes. These types own lifecycle obligations, so RAII covers early return as well as the happy path.

OnceLock and process-wide facilities

The async runtime and selected shared configuration are initialized once. This is appropriate for truly process-wide infrastructure; per-session pane state remains owned by the session threads.

The pattern worth copying is restraint: share tiny facts, send owned commands, and keep large mutable models behind one owner.