From 6bdfa26160a35cd006f081add522093d1ae57c5c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sat, 12 Sep 2026 02:25:17 -0400 Subject: [PATCH] The trace target picker is a popup, gone before the trace screen opens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The third lead-in picker kept pushed as a hub, and the one the ledger said would stay: a contact list under the trace screen, so Esc out of a trace landed on the list — two places where the trace is the whole visit. It is a question, and asks like the other two: the contact list floats over the menu as a one-shot (run_dialog, public now; the list stays a full-screen place everywhere else), the trace screen opens over the menu, and Esc from it lands there. The typed fallback floats the same way instead of filling the frame. Co-Authored-By: Claude Fable 5.1 --- docs/survey-navigation.md | 7 ++++ meshterm/tools/trace.py | 73 +++++++++++++++----------------------- meshterm/ui/contactlist.py | 5 +-- meshterm/ui/tui/session.py | 25 +++++++------ tests/test_navigation.py | 25 +++++++------ 5 files changed, 64 insertions(+), 71 deletions(-) diff --git a/docs/survey-navigation.md b/docs/survey-navigation.md index 64b51a9..ae33a30 100644 --- a/docs/survey-navigation.md +++ b/docs/survey-navigation.md @@ -104,6 +104,13 @@ reconnect dialog draws over it too. A blank base survives only for a session wit browser was full-frame from the menu only by the compositor's fallback; opened from a trace it came up as a box. It declares `floating = False` now, like the contact list. +*Same day — Trace target.* The third of the three pickers finding H kept pushed, and the +one the previous note said would stay: JP's call is that it is a question too. The contact +list floats over the menu as a one-shot (`session.run_dialog`, public now), the trace screen +opens over the menu, Esc from it lands there; tracing another node is opening the tool +again. The typed fallback floats the same way. `ContactListScreen` stays a full-screen place +everywhere else. + **I. An entry chain of prompts was not a stack.** Five flows asked two or more things in a row, and Esc on any of them abandoned the whole flow rather than stepping back one — a mistyped 32-hex channel key cost the name typed before it. `menus.run_steps` now runs a diff --git a/meshterm/tools/trace.py b/meshterm/tools/trace.py index 50b9dc5..ced6bdc 100644 --- a/meshterm/tools/trace.py +++ b/meshterm/tools/trace.py @@ -66,10 +66,9 @@ class TraceTool(Tool): async def prompt_params(self, ctx: AppContext) -> dict[str, Any] | None: """Nothing to gather here — the target picker lives inside :meth:`run`. - The picker has to *stay pushed* while the live screen it opens runs: that is what - makes Esc out of a trace one pop back onto the row it was launched from. A prompt - gathered here would have to resolve — and pop — before the tool runs, so the picker - moved into :meth:`_run_live` along with the loop that owns it. + The pick and the screen it opens share the contacts read and the routing width, + and the live path skips the base class's run row (see :meth:`execute`), so the + whole entry flow sits in :meth:`_run_live` rather than half of it here. Args: ctx: Shared application context. @@ -116,57 +115,41 @@ class TraceTool(Tool): # -- interactive (menu) ------------------------------------------------------- async def _run_live(self, ctx: AppContext) -> ToolResult: - """Loop the target picker and the live screen until the picker itself is left. + """Ask for the target in a popup, then run the live screen over the menu. - The picker **stays pushed** for the whole visit (the app's hub idiom), so the live - trace screen nests *above* it: Esc out of a trace is one pop, landing back on the - row it was launched from with the cursor, the sort and any typed filter intact, and - Esc from the picker is the second pop, out to the menu. The picker used to be a - one-shot prompt that resolved and popped before the screen opened, which left the - trace screen sitting directly on the menu — so a single Esc skipped the picker - entirely and there was no way back to the list except reopening the tool. - - Every returning trace ages the row it walked, and the list is *sorted* by that - column, so the lanes are re-read and swapped in place afterwards: the node just - traced rises to the top of the ``TRACED`` sort with the highlight riding it. The - ages come from stored history alone, so coming back costs no device round-trip. + The picker is a *question*, not a place: a floating list over the menu, gone the + moment a target is picked, so the trace screen opens straight over the menu and + Esc from it lands there. It used to stay pushed as a hub under the trace screen — + Esc out of a trace landed back on the list, which read as two places where the + trace is the whole visit; tracing another node is opening the tool again. Args: ctx: Shared application context. Returns: - A :class:`ToolResult` counting the screens opened and the traces run. + A :class:`ToolResult` counting the screen opened and the traces run. """ from ..ui.trace_screen import open_trace from ..ui.tui.screen import CANCEL - built = await self._build_picker(ctx) - if built is None: - # Nothing to list (or no full-screen session): the free-text prompt is a - # one-shot, with no list underneath to come back to. + picker = await self._build_picker(ctx) + if picker is None: + # Nothing to list (or no full-screen session): the target is typed instead. target = await self._prompt_target(ctx) - if target is None: - return ToolResult(summary={}) - return ToolResult(summary={"sessions": 1, "traces": await open_trace(ctx, target)}) - - picker, contacts = built - sessions = 0 - traces = 0 - async with ctx.ui.session.stay(picker) as visit: - while True: - chosen = await visit.result() - if chosen is CANCEL or chosen is None: # Esc — the pop out to the menu - return ToolResult(summary={"sessions": sessions, "traces": traces}) - traces += await open_trace(ctx, chosen.name) - sessions += 1 - picker.update_rows(self._picker_rows(ctx, contacts)) + else: + chosen = await ctx.ui.session.run_dialog(picker) + target = None if chosen is CANCEL or chosen is None else chosen.name + if target is None: + return ToolResult(summary={}) + return ToolResult(summary={"sessions": 1, "traces": await open_trace(ctx, target)}) async def _prompt_target(self, ctx: AppContext) -> str | None: """Ask for a target by hand — the way in when there is no list to pick from. Reached with no known contacts at all (an empty list would be nothing to pick from) and on any surface without a full-screen session. It is also the only way to trace a - bare key prefix for a node the device doesn't carry as a contact. + bare key prefix for a node the device doesn't carry as a contact. A question like + the list it stands in for, so it floats over the menu rather than filling the frame. Args: ctx: Shared application context. @@ -174,12 +157,10 @@ class TraceTool(Tool): Returns: The typed target, or ``None`` if it was left blank or cancelled. """ - entered = await ctx.ui.text("Target node (name or key prefix):") + entered = await ctx.ui.text("Target node (name or key prefix):", floating=True) return entered.strip() if entered else None - async def _build_picker( - self, ctx: AppContext - ) -> tuple[ContactListScreen, list[Contact]] | None: + async def _build_picker(self, ctx: AppContext) -> ContactListScreen | None: """Build the trace-target picker, or ``None`` when there is no list to draw. The same ``NAME · TRACED · HEARD · PKTS · KEY`` lanes, Ctrl+arrow sort ring, and @@ -194,8 +175,7 @@ class TraceTool(Tool): ctx: Shared application context. Returns: - The screen paired with the contacts it lists (kept so the lanes can be - re-read after a trace), or ``None`` when there is nothing to list — see + The picker, or ``None`` when there is nothing to list — see :meth:`_prompt_target`. """ from ..ui.contactlist import ( @@ -224,7 +204,10 @@ class TraceTool(Tool): footer_hint="↑↓ move · ^←→↑↓ sort · type to filter · Enter select · Esc back", lanes=TRACE_LANES, ) - return picker, contacts + # The contact list is a full-screen page everywhere else; here it is a question + # asked on the way in, so it floats over the menu like every other lead-in pick. + picker.floating = True + return picker @staticmethod def _picker_rows(ctx: AppContext, contacts: list[Contact]) -> list[ContactRow]: diff --git a/meshterm/ui/contactlist.py b/meshterm/ui/contactlist.py index 480d770..75735f6 100644 --- a/meshterm/ui/contactlist.py +++ b/meshterm/ui/contactlist.py @@ -432,8 +432,9 @@ class ContactListScreen(SelectScreen): KEY``. Pair the set with a ``sort`` whose ring spans it. The lanes anchor to the left: the name lane is sized to its widest name (not the terminal), so the columns stay put as the window widens and the freed width flows to the key lane, which shows each key as - fully as it fits (see :meth:`_lane_widths`). It is a full-screen list, not a floating - popup. + fully as it fits (see :meth:`_lane_widths`). It is a full-screen list — a place — by + default; the one instance that is a *question* (the trace target picker) sets + ``floating`` on itself and is drawn as a popup over the menu. The sort rides the Ctrl+arrows, leaving the plain arrows for the highlight and the letters for type-to-filter: **Ctrl+←/→** pick the column (each adopting its natural diff --git a/meshterm/ui/tui/session.py b/meshterm/ui/tui/session.py index b568490..1c50cb9 100644 --- a/meshterm/ui/tui/session.py +++ b/meshterm/ui/tui/session.py @@ -702,7 +702,7 @@ class TuiSession: dialog: The visit is a *popup's* — a stepped dialog turning its pages (:func:`~meshterm.ui.menus.run_wizard`) rather than a hub — so it must draw as a box even when it is the only thing on the stack: a blank base goes under - it for the visit, exactly as :meth:`_run_dialog_screen` does for a one-shot. + it for the visit, exactly as :meth:`run_dialog` does for a one-shot. Yields: A :class:`Visit` whose :meth:`~Visit.result` awaits one round of the screen. @@ -901,7 +901,7 @@ class TuiSession: ) if footer_hint is not None: kwargs["footer_hint"] = footer_hint - runner = self._run_dialog_screen if floating else self.run_screen + runner = self.run_dialog if floating else self.run_screen result = await runner(SelectScreen(title, items, **kwargs)) return None if result is CANCEL else result @@ -1212,11 +1212,10 @@ class TuiSession: """Show a text prompt; return the string or ``None`` if cancelled. ``floating`` guarantees the prompt draws as a centered popup even on an empty stack - — a modal step mid-flow (a remote-admin password) rather than a tool's full-frame - entry screen. It then floats over a blank base the way :meth:`button_dialog` and - :meth:`typed_confirm` do (see :meth:`_run_dialog_screen`); with a screen already - beneath it there is no difference, so leave it ``False`` for a prompt that is itself - a tool's primary screen (the Trace target's typed fallback). + — a question asked on the way in (a remote-admin password, a typed trace target) + rather than a tool's own page. It then floats over the menu the way + :meth:`button_dialog` and :meth:`typed_confirm` do (see :meth:`run_dialog`); with + a screen already beneath it there is no difference. ``byte_limit`` puts the shared UTF-8 byte gauge on the field and blocks submission past it — for a field that feeds a size-capped packet (see :class:`TextScreen`). @@ -1230,7 +1229,7 @@ class TuiSession: password=password, byte_limit=byte_limit, ) - runner = self._run_dialog_screen if floating else self.run_screen + runner = self.run_dialog if floating else self.run_screen result = await runner(screen) return None if result is CANCEL else result @@ -1273,7 +1272,7 @@ class TuiSession: button_idle_style=button_idle_style, border_style=border_style, ) - result = await self._run_dialog_screen(screen) + result = await self.run_dialog(screen) return None if result is CANCEL else result @asynccontextmanager @@ -1300,7 +1299,7 @@ class TuiSession: if backdrop is not None: self.pop(backdrop) - async def _run_dialog_screen(self, screen: Screen) -> Any: + async def run_dialog(self, screen: Screen) -> Any: """Run a floating dialog as a one-shot, drawn as a centered box (see :meth:`_floated`).""" async with self._floated(): return await self.run_screen(screen) @@ -1312,7 +1311,7 @@ class TuiSession: collapses its result to a plain bool: ``True`` only when the user typed the word, ``False`` when they backed out with Esc. """ - result = await self._run_dialog_screen(TypedConfirmDialog(warning, word, title=title)) + result = await self.run_dialog(TypedConfirmDialog(warning, word, title=title)) return result is True async def autocomplete( @@ -1325,7 +1324,7 @@ class TuiSession: validate: Validator | None = None, ) -> str | None: """Show a free-text prompt with suggestions; return text or ``None`` if cancelled.""" - result = await self._run_dialog_screen( + result = await self.run_dialog( AutocompleteScreen(title, choices, prompt=prompt, default=default, validate=validate) ) return None if result is CANCEL else result @@ -1494,7 +1493,7 @@ class TuiSession: screen = BusyDialog(message, title=title) # A lone floating screen on an empty stack is drawn *as* the background, framed and # full-frame rather than as a box, so it gets the same blank backdrop every other - # dialog uses (see :meth:`_run_dialog_screen`). + # dialog uses (see :meth:`run_dialog`). backdrop = None if not self._stack: backdrop = ScrollScreen("", floating=False, footer_hint="") diff --git a/tests/test_navigation.py b/tests/test_navigation.py index 5432d13..27479e1 100644 --- a/tests/test_navigation.py +++ b/tests/test_navigation.py @@ -139,13 +139,15 @@ async def test_a_visited_screen_is_armed_from_the_moment_it_is_pushed() -> None: await asyncio.wait_for(session.run(main()), timeout=5) -async def test_the_trace_target_picker_stays_pushed_under_the_live_screen(monkeypatch) -> None: - """Esc out of a trace is one pop, back onto the picker — not a drop to the menu. +async def test_the_trace_target_picker_is_a_popup_gone_before_the_live_screen( + monkeypatch, +) -> None: + """The target pick is a floating question, answered and gone; the trace opens over the menu. - The picker used to be a one-shot prompt gathered in ``prompt_params``: it resolved and - popped *before* the live screen opened, so the trace screen sat straight on the menu and - a single Esc skipped the list it was launched from. Now the tool keeps the picker for the - whole visit and the live screen nests above it. + The picker was kept pushed as a hub under the trace screen, so Esc out of a trace landed + on the list — two places where the trace is the whole visit. It draws as a box now (over + a base, since the menu is popped while a tool runs), comes down on Enter, and the trace + screen has nothing under it. """ from meshterm.core.models import Contact from meshterm.tools.trace import TraceTool @@ -181,9 +183,8 @@ async def test_the_trace_target_picker_stays_pushed_under_the_live_screen(monkey ctx.ui = TuiUi(session) async def fake_open_trace(_ctx, target: str, *, initial_spec: str = "") -> int: - """Stand in for the live screen: note the stack under it, then Esc out of it.""" + """Stand in for the live screen: note what is under it.""" depths.append(len(session._stack)) - inp.send_text(ESC) # the Esc that used to land on the main menu return 2 monkeypatch.setattr("meshterm.ui.trace_screen.open_trace", fake_open_trace) @@ -194,15 +195,17 @@ async def test_the_trace_target_picker_stays_pushed_under_the_live_screen(monkey # and lost about one full-suite run in six. `_screen_at` exists for exactly # this — wait until the picker is on the stack, *then* press Enter on it. running = asyncio.create_task(TraceTool()._run_live(ctx)) - await _screen_at(session, 1) + picker = await _screen_at(session, 2) + assert picker.floating and session._has_float(), "a box…" + assert not session._base_screen().floating, "…over a base" inp.send_text(ENTER) # Enter on the leading row commits it as the target result = await running assert result.summary == {"sessions": 1, "traces": 2} await asyncio.wait_for(session.run(main()), timeout=5) - assert depths == [1], "the picker is still on the stack while the trace screen runs" - assert session._stack == [], "and the visit pops it on the way out" + assert depths == [0], "the picker is gone before the trace screen opens" + assert session._stack == [] async def _screen_at(session: TuiSession, depth: int, timeout: float = 2.0):