ctx.ui.custom(), style components with the active theme, and reuse Atomic’s built-in patterns for selectors, loaders, widgets, status indicators, footers, and custom editors.
For low-level rendering primitives (TuiMainScreen, TuiAltScreen, Component, Focusable, matchesKey, and layout primitives), see @bastani/atomic-tui. For full extension contracts (ToolBlock, ExtensionCustomComponent, advanced ctx.ui.custom() options, theme invalidation, debug logging, and host-native dialogs), see TUI API reference.
Before you begin
Before you build custom TUI components, confirm that you have:- An Atomic extension entry point (see Author extensions).
- An interactive terminal session (
ctx.mode === "tui"). Guard terminal-only calls such asctx.ui.custom()withctx.mode === "tui"so your extension degrades cleanly in headless Remote Procedure Call (RPC) or print mode (see Handle extension UI over RPC).
Show a custom component with ctx.ui.custom()
Pass a synchronous or async component factory (ExtensionCustomComponent | Promise<ExtensionCustomComponent>) to ctx.ui.custom(). The factory receives (tui, theme, keybindings, done), and ctx.ui.custom() resolves with the value you pass to done(). Components can also implement dispose?(): void for cleanup when dismissed.
The following extension hook opens a custom component on session start and shows the chosen value in a notification:
ctx.ui.custom(factory, options?):
For advanced options (
purpose, handlesInternalUiAction, deferInlineCustomUiFocus, reserveTranscriptRows, OVERLAY_ACTIVE_ROW_MARKER, and HostCustomUiState), see Custom component options.
Don’t rely on host process globals from
render() or handleInput(), and pass only JSON-safe values to done(). Return true for consumed viewport keys or overlay mouse events and false to let the transcript handle them. Non-overlay components leave mouse scrolling and selection with the transcript.Show floating overlays
Overlays render components on top of existing content without clearing the screen. To mount a component as an overlay, pass{ overlay: true } to ctx.ui.custom():
overlayOptions (either a static object or a () => OverlayOptions function) and onHandle:
Overlay focus and lifecycle
A focused visible overlay keeps input ownership across temporary non-overlay UI: if it opens another inlinectx.ui.custom() component, that component receives input while active, and the overlay reclaims input when it closes. Call handle.unfocus() to release input to the fallback target, or handle.unfocus({ target }) to focus a specific component (or null for none).
Atomic disposes of overlay components when they close, so always create fresh instances instead of reusing closed references:
Use built-in primitives
Import layout and content primitives from@bastani/atomic-tui (provided by Atomic without an extra install):
See
@bastani/atomic-tui built-in components for full constructor signatures, options, and additional primitives (Input, Editor, Loader, CancellableLoader, TruncatedText, WindowedContainer, VStack, HStack, ScrollView).
Build a custom component
Implementrender(width), invalidate(), and optional handleInput(data) to build a custom interactive component. Always keep every rendered line within width columns using truncateToWidth() or wrapTextWithAnsi():
tui.requestRender() whenever handleInput() updates state:
/pick in an interactive session opens the selector, moves focus with the arrow keys, and notifies you of the chosen branch on Enter.
Style components with the active theme
Always use thetheme passed to your callback (ctx.ui.custom, ctx.ui.setWidget, renderCall, or renderResult) instead of importing a theme singleton directly:
theme.fg(color, text):
Background tokens accepted by
theme.bg(color, text) are selectedBg, userMessageBg, customMessageBg, toolPendingBg, toolSuccessBg, toolErrorBg, scrollbarThumb, and searchMatchBg.
For Markdown components, call getMarkdownTheme() from @bastani/atomic:
invalidate() so live theme switches take effect. See Invalidation and theme changes.
Reuse common UI patterns
Prefer these built-in Atomic components over writing interactive controls from scratch.Selection dialog (Selector)
Use Selector from @bastani/atomic for searchable, keyboard- and mouse-accessible pickers (the same component behind /model, /login, /thinking, /trust, and ctx.ui.select and confirm):
Ctrl+C, mouse click, and wheel scrolling. Without a search box, ? opens key help and j / k navigate.
The following table lists the key SelectorOptions and item fields:
For live updates, call
selector.setItems(nextItems) and tui.requestRender(); selection stays on the same id when still enabled and matching. Call selector.setNotice({ text, tone }) for a one-line status under the list, and call selector.retrySelection() if an async onSelect or onConfirm callback fails and should re-enable input. For headless testing (SelectorState, selectorHintEntries) and UserMessageSelectorComponent, see Selector helpers.
Bare list (SelectList)
Use SelectList from @bastani/atomic-tui when you need a minimal list inside your own layout (such as custom autocomplete rows) framed with DynamicBorder:
Cancellable loader (BorderedLoader)
Use BorderedLoader for cancellable async operations where Esc aborts the request:
Settings toggles (SettingsList)
Use SettingsList from @bastani/atomic-tui with getSettingsListTheme() from @bastani/atomic:
Status indicator
To display or clear persistent mode indicators in the footer, callctx.ui.setStatus():
Customize the working indicator
To customize the inline Working indicator shown from accepted prompt submission through response streaming, callctx.ui.setWorkingIndicator():
∀ pulse beside a turn status message in a standalone row (custom editors can embed it in their top border with embedWorkingStatus: true). NO_COLOR disables colors and text styles, and ATOMIC_REDUCED_MOTION=1 freezes the built-in pulse (custom frames and intervals render verbatim).
Working appears during prompt startup and response streaming and disappears on completion, failure, or a no-turn result. Automatic retry, fallback, and compaction loaders use their own built-in indicators and take precedence; successful mid-turn compaction restores Working automatically.
See working-indicator.ts for a complete example.
Editor widgets
To display persistent content above or below the input editor (such as todo lists or progress panels), callctx.ui.setWidget():
ctx.ui.onWidgetRelease(key, listener) when available (replacing a widget with another factory doesn’t trigger release). For ordinary updates, mutate your component state and call requestRender() instead of re-registering setWidget().
Scrollable widgets
Passscroll: { maxHeight: 6 } (or { maxHeight: 10, maxHeightFraction: 1 / 3 } to scale with live terminal rows) to give a widget its own fullscreen viewport with mouse-wheel scrolling and a one-column overflow scrollbar. Render the full content instead of a pre-clipped slice:
getScrollRequest and onScroll are optional, and installReactiveWidget accepts the same scroll options. Keep version unchanged during ordinary content updates so user wheel scrolling stays intact. Native wheel scrolling requires fullscreen mode and a mouse-capable terminal.
See plan-mode/index.ts for a complete example.
Custom footer
To replace the footer and read live Git branch and extension statuses fromfooterData, call ctx.ui.setFooter():
ctx.ui.getFooterDataProvider() exposes the same read-only provider to embedded extension UIs. For a viewer showing a different working directory (viewerCwd), pass viewerCwd to both footerData.onBranchChange(listener, viewerCwd) and footerData.getGitBranch(viewerCwd), and call the returned unsubscribe function on disposal (never call the parent provider’s dispose()). An unsubscribed getGitBranch(viewerCwd) lookup is transient and doesn’t retain a branch watcher.
See custom-footer.ts for a complete example.
Custom editor (Vim mode)
ExtendCustomEditor (not base Editor) to customize editing while keeping Atomic’s app keybindings (Esc to abort, Ctrl+D to exit, model switching, and autocomplete):
undefined to ctx.ui.setEditorComponent(undefined) to restore the default editor. Custom editors exposing setAutocompleteMaxVisible() inherit the active autocompleteMaxVisible setting.
The following table lists the CustomEditorOptions accepted by new CustomEditor(tui, theme, keybindings, options?):
setEditorComponent, setFooter, setHeader, onTerminalInput, and addAutocompleteProvider require synchronous terminal callbacks and run only in single-process TUI hosts (they warn and don’t run in default isolated interactive mode). See Extension UI.Attached composer
When an extension or custom SDK host embeds a secondary chat editor, useapplyAttachedComposer(style, label, placeholder, lines) to style its rules with accent color, add a bold label to the top rule, and display a dim placeholder while empty:
applyAttachedComposer() replaces plain ─ rules and editor overflow rules (↑ N more / ↓ N more). For the bottom border, it scans upward from the end of lines to find and recolor the last rule line even when non-rule lines (such as a hint or autocomplete menu) follow it. It inserts placeholder only when the editor has a single empty prompt row (the bottom rule is at line index 2 and line 1 is bare ❯). Long labels truncate with …, and when the terminal is narrower than INPUT_LABEL_MIN_COLUMNS (40) columns, the rules render without the label. Pass undefined for label or placeholder to omit either.
For buildInputLabel() and applyInputLabelToEditorTopRule(), see Input label helpers.
Key rules
Troubleshooting
Use the following table to resolve common TUI component issues:Examples and next steps
Browse complete working extensions in the repository:- Selection UI: preset.ts (
SelectListwithDynamicBorder) - Async with cancel: qna.ts (
BorderedLoader) - Settings toggles: tools.ts (
SettingsList) - Status and widgets: plan-mode/index.ts (
setStatus,setWidget) - Working indicator: working-indicator.ts (
setWorkingIndicator) - Custom footer: custom-footer.ts (
setFooter) - Custom editor: modal-editor.ts (Vim-like modal editing)
- Interactive game loop: snake.ts (keyboard input and loop)
- Custom tool rendering: todo.ts (
renderCallandrenderResult)
TUI API reference
Look up
ToolBlock, ExtensionCustomComponent, theme invalidation, debug logging, and host-native UI contracts.@bastani/atomic-tui
Explore low-level rendering, mouse events, IME focus, and keyboard utilities.