Overlay Engine & Pipeline Architecture
Overview
The Overlay Engine provides modal custom views and anchored overlay dialogs in the TUI, built on top of Mordant rendering and coroutine-based session control.
Key Components
-
OverlayManager: Central registry and focus authority for overlay sessions. Manages the active overlay and queues background overlays. -
OverlayCompositor: Composites active overlay panels onto base terminal frames using Mordant cell counts and dimension percentage bounds. -
CustomViewSession<T>: Manages custom view state, coroutine scope, event flow (events), and one-shot completion handling viafinish/cancel. -
MordantExtensionUI: Extension UI adapter bridging script calls (ctx.ui.customView,ctx.ui.overlay) toOverlayManagerandCustomViewSession. -
InputStateMachine: Intercepts keyboard events for the active overlay before evaluating shortcuts or screen dispatch.
Key Event Routing Flow
-
User presses a key in TUI mode.
-
InputStateMachine.handle(event, screen)checksoverlayManager?.active. -
If an active
CustomViewSessionis present, the key event is emitted tosession.emitKey(event)and processing returns immediately (bypassing shortcut guarding, screen navigation keys, and chat key handlers).
Frame Composition Flow
-
RenderLoopbuilds the base frame viaRenderFrameBuilderand Mordant rendering (terminal.render(…)). -
OverlayCompositor.composite(baseFrame)checks for an active, non-hiddenCustomViewSession. -
If active, it calculates panel dimensions (percentage width/height), renders the widget, and splices panel lines onto the base frame buffer while preserving ANSI control sequences.
Custom View & Overlay Lifecycle Sequence
sequenceDiagram
participant User/Script
participant TuiExtensionUI as MordantExtensionUI
participant OverlayManager
participant OverlayCompositor
participant InputStateMachine
participant CustomViewSession
User/Script->>TuiExtensionUI: ctx.ui.overlay(options, view)
TuiExtensionUI->>CustomViewSession: Create session (onFinish callback)
TuiExtensionUI->>OverlayManager: activate(session)
OverlayManager-->>InputStateMachine: active session set
loop Frame Render Loop
InputStateMachine->>CustomViewSession: Input event intercepted (emitKey)
OverlayCompositor->>OverlayManager: Get active session
OverlayCompositor->>BaseFrame: Composite panel onto base frame
end
User/Script->>CustomViewSession: finish(result) or cancel()
CustomViewSession->>OverlayManager: close(session)
CustomViewSession->>TuiExtensionUI: Resume continuation with result / null