Date: 2026-05-11
Time: 15:52
This module provides a full-screen terminal UI (TUI) for ftl2-htop, a system monitoring dashboard built on FTL2's automation framework. It uses the Textual library to render a live-updating dashboard showing host metrics, and is designed to be compatible with textual-serve for web-based access. It's an alternative to the Rich live.Live rendering mode, activated via the --tui flag.
The primary entry point is run_tui(args), which accepts a parsed argument namespace and launches the Textual app:
from ftl2_htop.tui import run_tui
run_tui(args) # args from argparse with hosts, inventory, interval, etc.
The app is typically launched from the CLI when the --tui flag is passed. It spawns a background thread that runs the FTL2 automation listener, while the main thread handles TUI rendering. Press q to quit.
The args namespace controls behavior through these fields:
| Arg | Purpose |
|-----|---------|
| args.hosts | List of hostnames — builds an inline inventory |
| args.inventory | Path or dict for FTL2 inventory |
| args.state | State file path (alternative to inventory) |
| args.groups | Specific groups to monitor; defaults to all groups |
| args.interval | Polling interval for the monitor() call |
| args.no_processes | If true, skips per-process metrics |
Inventory resolution priority: hosts > inventory > state > fallback to "localhost,".
callfromthread.SystemMetrics events via proxy.on(). Each event updates metricsstore (a shared dict keyed by hostname) and records history via record_history._finished flag is set regardless of success or failure.ftl2htop: Uses metricsstore (shared dict) and renderdashboard() (Rich renderable generator) from the parent package. Also uses record_history for metric time-series tracking.ftl2: Uses ftl2.automation context manager as the core automation engine — sets up inventory, connects to hosts, and subscribes to metric events.App, uses Header, Static, Binding. Compatible with textual-serve for browser-based rendering.ftl2_htop when --tui is passed.