Navigation was almost a stack already, and the survey in docs/survey-navigation.md
catalogues where it wasn't. This is the machinery for the strict version, plus
the one shortcut past it.
A screen that owns a loop can now keep itself pushed for the whole visit:
async with session.stay(screen) as visit:
while True:
chosen = await visit.result()
One push, one pop, and the *object* survives its sub-screens — so the cursor,
the sort, the scroll offset and any live filter are simply still there on the
way back, rather than being approximated by a `default=` restore that can only
recover the cursor and only when its row still exists. It also retires the
pop-then-re-push-as-a-backdrop workaround: a screen that never left the stack
already is one.
^W unwinds every frame at once, back to the main menu. It resolves the top
screen with POP_ALL, which each navigation boundary turns into PopToMenu, and
every frame pops itself in a finally on the way out — the same single-pop
discipline applied N times. PopToMenu derives from BaseException so it crosses
the `except Exception` guards that stop a broken tool from taking the menu down;
those must not report an unwind as a tool failure. The flag it sets matters
independently of the future: pressed during a device read there is nothing
armed to carry the sentinel, so the next screen the flow tries to open refuses
to open instead.
It declines to fire over anything modal — an unanswered dialog, a progress bar,
a busy splash — which is what `modal` is for. `floating` is only about being
drawn as a box; a select list floats and is not modal, the busy splash is modal
and does not float.
^Q quits from anywhere. Both chords are deliberately unadvertised: a global verb
has no screen to belong to, so a footer atom or an F-key chip would ride on
every screen, and the lane only has three free slots to begin with. A test
walks every string literal in the package to keep them out of the UI.
Quitting mid-screen used to abandon the coroutine driving the app: the chord
exits the application straight from the key handler, so `run_async` returned
while main() was still parked on a screen, and its finally — which closes the
history and chat runs, stops the services and arms the exit watchdog — never
ran. It is cancelled and awaited now.
The menu is the root: built once, kept for the session, and the one frame that
catches the unwind.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
"""A small, centralized, reusable full-screen text-UI library.
|
|
|
|
Built on prompt_toolkit (for the terminal, input, and resize handling) and Rich (for all
|
|
content rendering), this package gives the interactive app a consistent, bounded, layered
|
|
UI: screens never overflow the terminal, long content scrolls, going deeper stacks dialogs
|
|
over a dimmed parent, and Esc always dismisses the current layer.
|
|
|
|
Navigation is a strict stack: one push per screen entered, one pop per Esc, and the screen
|
|
object survives the whole visit so its cursor, sort and filter are still there when a
|
|
sub-screen closes (:meth:`~meshterm.ui.tui.session.TuiSession.stay`). The one shortcut past
|
|
it is ^W, which unwinds every frame at once by raising
|
|
:class:`~meshterm.ui.tui.screen.PopToMenu` through them.
|
|
|
|
Public API:
|
|
- :class:`~meshterm.ui.tui.session.TuiSession` — the running session and prompt helpers.
|
|
- :class:`~meshterm.ui.tui.select.Choice` / :class:`~meshterm.ui.tui.select.Separator`
|
|
— items for ``session.select``.
|
|
- Screen classes for advanced/custom layers.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from .overlay import BusyOverlay
|
|
from .progress import ProgressScreen
|
|
from .prompt import (
|
|
CHANNEL_BYTE_LIMIT,
|
|
DM_BYTE_LIMIT,
|
|
AutocompleteScreen,
|
|
ConfirmScreen,
|
|
ReconnectDialog,
|
|
TextScreen,
|
|
TypedConfirmDialog,
|
|
byte_counter,
|
|
)
|
|
from .screen import CANCEL, BusyScreen, PopToMenu, Screen, ScrollScreen
|
|
from .select import Choice, DeleteRequest, SelectScreen, Separator
|
|
from .session import TuiSession, Visit
|
|
from .spinner import Spinner
|
|
|
|
__all__ = [
|
|
"TuiSession",
|
|
"Screen",
|
|
"ScrollScreen",
|
|
"BusyScreen",
|
|
"SelectScreen",
|
|
"Choice",
|
|
"DeleteRequest",
|
|
"Separator",
|
|
"TextScreen",
|
|
"ConfirmScreen",
|
|
"AutocompleteScreen",
|
|
"ReconnectDialog",
|
|
"TypedConfirmDialog",
|
|
"ProgressScreen",
|
|
"Spinner",
|
|
"BusyOverlay",
|
|
"CANCEL",
|
|
"PopToMenu",
|
|
"Visit",
|
|
"DM_BYTE_LIMIT",
|
|
"CHANNEL_BYTE_LIMIT",
|
|
"byte_counter",
|
|
]
|