StackTextualApp / StackTUI
What it is
A terminal UI (TUI) built with textual to monitor and manage a Docker Compose “stack”:
- Lists services and their compose state.
- Probes per-service readiness (HTTP/TCP) using a service catalog.
- Shows selected service details and streams or fetches its logs.
- Provides key bindings to run common
docker composeactions (up/down/stop/restart) and open a service URL.
Public API
Classes
-
class StackTextualApp(App[None])- Textual application implementing the TUI.
- Key actions (invoked via bindings):
action_cursor_down()/action_cursor_up(): move selection.action_toggle_pause(): pause/resume UI refresh rendering.action_restart_service():docker compose restart <service>.action_up_service():docker compose up -d <service>.action_up_stack():docker compose up -d.action_stop_service():docker compose stop <service>.action_down_service():docker compose rm -s -f <service>.action_down_stack():docker compose down -v.action_open_url(): open first URL fromSERVICE_CATALOG[service].urlsin a browser.
- Lifecycle hooks:
compose(): builds layout (services table, selected panel, logs panel, header/footer).on_mount(): initializes table, starts background threads, schedules UI refresh.on_unmount(): stops threads and terminates any log-follow process.
-
class StackTUI- Thin wrapper around
StackTextualApp. - Methods:
__init__(refresh_interval: float = 1.5): store refresh interval.run(): instantiate and runStackTextualApp.
- Thin wrapper around
Key bindings
- Navigation:
j/down,k/up - Actions:
u: up serviceU: up stackr: restart selected servicesorS: stop selected serviced: down (rm) selected serviceD: down stack with volumes (down -v)o: open service URL (first URL in catalog)p: pause UI renderingq: quit
Configuration/Dependencies
- Runtime dependencies:
textual(UI framework)- Docker Compose available via
docker composeon PATH
- Internal dependencies (same package):
.stack_runtime:compose_service_list(),compose_service_states(),run_compose(),ComposeServiceState
.stack_services:SERVICE_CATALOG,evaluate_service_readiness(),ReadinessResult
- Notable internal intervals/timeouts (hardcoded in
StackTextualApp):- Service list refresh:
15.0s - State refresh loop:
refresh_interval(min0.5s) - Readiness probe refresh:
1.2s(selected service:0.25s) - Probe timeouts: HTTP
0.35s, TCP0.30s - Logs polling:
0.2s
- Service list refresh:
- Log retrieval:
- When running: spawns
docker compose logs -f --no-color --tail=80 <service>and streams output. - When not running: calls
run_compose(["logs", "--no-color", "--tail=120", <service>], capture_output=True).
- When running: spawns
Usage
Minimal runnable example:
from naas_abi_cli.cli.stack_tui import StackTUI
if __name__ == "__main__":
StackTUI(refresh_interval=1.5).run()
Caveats
- Requires a working Docker environment; errors are surfaced in the UI as “Docker Error”.
- Uses background threads plus a spawned
docker compose logs -fsubprocess; the log follower is terminated on unmount or when switching to a non-running service. - “Pause” stops UI rendering updates but background workers continue collecting state/logs/readiness.