ObjTUI provides shared utilities for Rich-based terminal dashboards: theme loading,
startup banners, a managed layout loop (TUI_Manager), and two reusable stream helpers
(TuiStream, AtomicWriter) that any TUI module can import.
Module: factory.core/ObjTUI.py
Dependencies: rich
| Name | Type | Purpose |
|---|---|---|
can_use_tui() |
function | Guard — returns False under supervisord or non-TTY stdout |
TuiTheme |
dataclass | Semantic color mapping loaded from the active ObjPalette |
build_axion_logo() |
function | Returns a Rich Text neofetch-style aXion logo |
print_service_banner() |
function | Prints a one-time startup banner for a named service |
TUI_Manager |
class | Full-screen managed TUI with header/footer/console/log panels |
TuiStream |
class | Captures sys.stdout/sys.stderr writes into a TUI log |
AtomicWriter |
class | Buffers Rich write() calls and flushes them as one atomic frame |
can_use_tui()Returns True only when a Rich full-screen TUI can safely run. Returns False when:
SUPERVISOR_PROCESS_NAME or SUPERVISOR_ENABLED is set in the environmentsys.stdout.isatty() is False (pipe, redirect, background daemon)Always call this before constructing any TUI instance.
TuiThemeDataclass that maps ObjPalette semantic colors to TUI display roles. All fields are
Rich-compatible color strings (named colors or #rrggbb hex).
theme = TuiTheme.load() # load active palette; fall back to built-in defaults
theme = TuiTheme.load("dark") # load a specific palette by name
TuiTheme.from_palette(colors) accepts the dict[str, str] returned by ObjPalette.read().
Key fields: background, header_border, ok_color, fail_color, warn_color, accent,
bar_ok, bar_warn, bar_crit.
Helper methods:
panel_style — Rich style string for panel backgroundcell(fg) — Combines a foreground color with the panel backgroundTUI_ManagerFull-screen TUI built on rich.live.Live. Redirects sys.stdout so that print() calls
appear inside the console panel rather than on the raw terminal.
tui = TUI_Manager()
tui.start()
tui.set_status("Running...")
# ... application logic ...
tui.stop()
Layout: header | side (system info) | body (console output + log) | footer.
TuiStreamFile-like object that captures raw write() calls (e.g. from print()) and routes them
into a TUI log panel instead of the terminal. Prevents flicker caused by raw writes
mixing with a Rich Live-managed screen.
The dashboard argument must expose a log(message: str, level: str) method.
import sys
sys.stdout = TuiStream(dashboard, level="INFO")
sys.stderr = TuiStream(dashboard, level="ERROR")
Restore originals in a finally block:
saved = sys.stdout
sys.stdout = TuiStream(dashboard)
try:
...
finally:
sys.stdout = saved
AtomicWriterWraps an underlying TextIO (typically the real sys.stdout) and buffers all write()
calls between begin() and end() into a single flush, wrapped in DECSET 2026
synchronized-output markers (TuiConstants.SYNC_START / TuiConstants.SYNC_END).
Terminals that support DECSET 2026 defer rendering until the end marker, eliminating
flicker from partial frame writes. Terminals that do not support it silently ignore
both escape sequences.
Pass the AtomicWriter instance as the file= argument to rich.console.Console so
every Rich write goes through the buffer:
writer = AtomicWriter(sys.stdout)
console = Console(file=writer)
live = Live(layout, console=console, auto_refresh=False)
# In the refresh loop:
writer.begin()
live.refresh() # Rich calls writer.write() many times
writer.end() # one flush, frame delivered atomically
ObjConstants.TuiConstants — shared constants (refresh rate, sync markers, layout sizes)ObjEnum.TuiLogLevel — log level strings (INFO, WARN, ERROR)factory.workflow/extend.tui/ObjWorkflowSimulTUI.py — uses TuiStream and AtomicWriter