From 8ecfbc865d27dce90e72729a7f903162551727d8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sat, 11 Jul 2026 03:32:47 -0400 Subject: [PATCH] Send advert floats over the menu; the actions screen drops its copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main-menu advert entry ran the same flow as Device actions but replaced the screen instead of floating over it. Tools can now declare popup = True to run while the menu stays pushed — their prompts and result draw as modal dialogs over it, the quit-dialog pattern — and the advert tool does, so both doors into the flow looked and felt the same. With the popup one keystroke away there was no reason to keep the second door: the Device actions row is gone, leaving that screen to the box-level operations (clock, backup, key, reboot, reset). Co-Authored-By: Claude Fable 5 --- meshterm/tools/advert.py | 8 +++--- meshterm/tools/base.py | 5 ++++ meshterm/ui/config_editor.py | 39 +++++++++++----------------- meshterm/ui/menu.py | 10 +++++++- tests/test_config_editor.py | 49 ++++++++++-------------------------- 5 files changed, 45 insertions(+), 66 deletions(-) diff --git a/meshterm/tools/advert.py b/meshterm/tools/advert.py index 0385472..6cd7a0b 100644 --- a/meshterm/tools/advert.py +++ b/meshterm/tools/advert.py @@ -2,10 +2,9 @@ Opens the Send advert flow (see :func:`meshterm.ui.config_editor.send_advert`) — a zero-hop or flood advertisement, or this node's shareable contact card as a QR code. -The same flow also lives inside the Device actions screen; it gets its own menu entry -because sending an advert is the everyday operation in that bucket, promoted to the top -level so it sits one keystroke (and one type-to-filter match) away instead of two -screens deep. +A ``popup`` tool: the flow's prompts and result float over the still-pushed main menu +as modal dialogs (the quit-dialog pattern), so the everyday action stays a quick +in-place popup rather than a screen change. Menu-only: the scripted equivalents are ``config advert`` and ``config share``, so no duplicate subcommand is registered here (the same pattern as ``device-actions``). @@ -31,6 +30,7 @@ class SendAdvertTool(Tool): help = "Announce this node to the mesh — zero-hop, flood, or share as QR" category = "Device" order = 10 # right after Device actions, before Device info + popup = True # dialog-sized: float over the menu instead of replacing it async def prompt_params(self, ctx: AppContext) -> Optional[dict[str, Any]]: """Run the interactive advert flow; there are never parameters to collect. diff --git a/meshterm/tools/base.py b/meshterm/tools/base.py index 1d6446f..5e383e5 100644 --- a/meshterm/tools/base.py +++ b/meshterm/tools/base.py @@ -51,6 +51,10 @@ class Tool(ABC): menu_visible: Whether the tool appears in the interactive menu. Set ``False`` for CLI-only tools (e.g. startup-time diagnostics with no place in a connected session); such tools still register a CLI subcommand as usual. + popup: Whether the menu stays pushed while this tool runs, so the tool's prompts + and result float over it as modal popups (the quit-dialog pattern) instead of + replacing the screen. For quick dialog-sized tools; a tool that pushes its + own full screen keeps the default. """ name: str = "" @@ -60,6 +64,7 @@ class Tool(ABC): category: str = "General" order: int = 100 menu_visible: bool = True + popup: bool = False @abstractmethod async def run(self, ctx: "AppContext", params: dict[str, Any]) -> ToolResult: diff --git a/meshterm/ui/config_editor.py b/meshterm/ui/config_editor.py index 32196c5..997c97e 100644 --- a/meshterm/ui/config_editor.py +++ b/meshterm/ui/config_editor.py @@ -9,15 +9,14 @@ Two sibling screens live here, deliberately kept distinct: backing out with staged changes asks before discarding them. The editor returns the staged operations for :class:`~meshterm.tools.config.ConfigTool` to execute and log. * **Device actions** (:func:`device_actions`, behind the ``device-actions`` tool) — the - operations that act on the box itself rather than a value: adverts, backup/restore, the - identity key, reboot, and factory reset. These *run immediately* (after their own - confirmation dialog — destructive ones gate behind typing a confirmation word); they - have no meaningful "preview", so their result is shown at once. They share the settings - snapshot and :func:`~meshterm.tools.config.apply_ops` executor with the editor, which is - why both screens live in this module. The everyday advert action is *also* promoted to - its own main-menu entry (the ``advert`` tool, via :func:`send_advert`), so it is one - keystroke away instead of two screens deep; the row here stays so the actions screen - remains the complete inventory of immediate operations. + operations that act on the box itself rather than a value: backup/restore, the + identity key, clock sync, reboot, and factory reset. These *run immediately* (after + their own confirmation dialog — destructive ones gate behind typing a confirmation + word); they have no meaningful "preview", so their result is shown at once. They share + the settings snapshot and :func:`~meshterm.tools.config.apply_ops` executor with the + editor, which is why both screens live in this module. The everyday advert action + lives in its own main-menu entry instead (the ``advert`` tool, via + :func:`send_advert`), one keystroke away as a popup over the menu. Multiple-choice values are picked in dialogs (booleans as an On/Off button pair, enums as a floating select), the node's location can be set by pointing at the full-screen map (see @@ -68,7 +67,6 @@ _PRESETS = "__presets__" _CUSTOM = "__custom__" _ADVERT_DIRECT = "__advert_direct__" _ADVERT_FLOOD = "__advert_flood__" -_ADVERT = "__advert__" _SYNC_CLOCK = "__sync_clock__" _REBOOT = "__reboot__" _BACKUP = "__backup__" @@ -700,9 +698,7 @@ async def device_actions(ctx: "AppContext") -> None: if choice is CANCEL or choice in (None, _CANCEL): return cursor = choice - if choice == _ADVERT: - await _advert_menu(ctx, device, snapshot) - elif choice == _SYNC_CLOCK: + if choice == _SYNC_CLOCK: await _sync_clock(ctx, device, snapshot) elif choice == _BACKUP: await _backup_now(ctx, device, snapshot) @@ -730,7 +726,6 @@ def _action_items() -> list: reset keeps its err-tinted label so the one irreversible row reads as such. """ actions: list[tuple[str, str, str, str]] = [ - ("📡 Send advert…", "Zero-hop, flood, or share this node as a QR code", _ADVERT, ""), ("🕒 Sync clock…", "Set the device clock from this computer", _SYNC_CLOCK, ""), ("💾 Back up config to a file…", "Write every setting to TOML", _BACKUP, ""), ("📂 Restore config from a backup…", "Preview or apply a saved TOML", _RESTORE, ""), @@ -773,13 +768,12 @@ async def _run_now( async def send_advert(ctx: "AppContext") -> None: - """Run the Send advert flow standalone, behind the main menu's ``advert`` tool. + """Run the Send advert flow, behind the main menu's ``advert`` popup tool. - The same flow the Device actions screen opens (see :func:`_advert_menu`), promoted to - a top-level menu entry because announcing the node is the everyday action in that - bucket. Only ``SELF_INFO`` is read here: the advert command itself never consults the - snapshot, and the contact card needs just the name, public key, and advert type — so - opening this skips the tuning/path-hash reads of a full + Send an advert (zero-hop or flood) or show this node's shareable contact card. Only + ``SELF_INFO`` is read here: the advert command itself never consults the snapshot, + and the contact card needs just the name, public key, and advert type — so opening + this skips the tuning/path-hash reads of a full :func:`~meshterm.core.device_config.build_snapshot` and stays snappy over Bluetooth. Args: @@ -787,11 +781,6 @@ async def send_advert(ctx: "AppContext") -> None: """ device = await ctx.device() snapshot = dict(await device.get_self_info()) - await _advert_menu(ctx, device, snapshot) - - -async def _advert_menu(ctx: "AppContext", device: "Device", snapshot: dict) -> None: - """Send an advert (zero-hop or flood) or show this node's shareable contact card.""" choice = await ctx.ui.select( "📡 Send advert", [ diff --git a/meshterm/ui/menu.py b/meshterm/ui/menu.py index b6f39f7..2bec28e 100644 --- a/meshterm/ui/menu.py +++ b/meshterm/ui/menu.py @@ -354,6 +354,7 @@ async def _menu_loop(ctx: AppContext, session: TuiSession) -> None: ) menu.future = loop.create_future() session.push(menu) + ran_over_menu = False try: selection = await menu.future if selection is CANCEL: # Esc at the top level @@ -396,9 +397,16 @@ async def _menu_loop(ctx: AppContext, session: TuiSession) -> None: last_selection = "__quit__" continue last_selection = selection + # A popup tool runs while the menu is still pushed, so its prompts and + # result float over it as modal dialogs instead of replacing the screen. + tool = next((t for t in tools if t.name == selection), None) + if tool is not None and tool.popup: + ran_over_menu = True + await _run_selection(ctx, selection) finally: session.pop(menu) - await _run_selection(ctx, selection) + if not ran_over_menu: + await _run_selection(ctx, selection) async def _startup(ctx: AppContext) -> bool: diff --git a/tests/test_config_editor.py b/tests/test_config_editor.py index 4c89b96..a1fe907 100644 --- a/tests/test_config_editor.py +++ b/tests/test_config_editor.py @@ -459,41 +459,8 @@ async def test_editor_location_clear_stages_the_no_fix_pair(ctx: AppContext) -> assert ("set", "adv_lon", 0.0) in ops -async def test_actions_advert_zero_hop_and_flood_run_immediately(ctx: AppContext) -> None: - """The advert dialog sends immediately: zero-hop by default, flood when chosen.""" - device = await ctx.device() - sent: list[bool] = [] - - async def _record(flood: bool = False) -> None: - sent.append(flood) - - device.send_advert = _record # type: ignore[method-assign] - ui = _install(ctx, [ - ("select", "__advert__"), - ("select", "zero"), - ("select", "__advert__"), - ("select", "flood"), - ("select", "__cancel__"), - ]) - await device_actions(ctx) - assert sent == [False, True] - assert any("zero-hop" in n for n in ui.notes) - assert any("flood" in n for n in ui.notes) - - -async def test_actions_advert_share_shows_the_contact_card(ctx: AppContext) -> None: - """The share option opens the QR/URI view built from the node's own identity.""" - ui = _install(ctx, [ - ("select", "__advert__"), - ("select", "share"), - ("select", "__cancel__"), - ]) - await device_actions(ctx) - assert any(v.startswith("Share ") for v in ui.views) - - -async def test_send_advert_standalone_sends_without_the_actions_screen(ctx: AppContext) -> None: - """The promoted main-menu flow sends an advert directly — no Device actions hop.""" +async def test_send_advert_sends_zero_hop_and_flood_immediately(ctx: AppContext) -> None: + """The advert popup sends immediately: zero-hop by default, flood when chosen.""" device = await ctx.device() sent: list[bool] = [] @@ -501,12 +468,22 @@ async def test_send_advert_standalone_sends_without_the_actions_screen(ctx: AppC sent.append(flood) device.send_advert = _record # type: ignore[method-assign] + ui = _install(ctx, [("select", "zero")]) + await send_advert(ctx) ui = _install(ctx, [("select", "flood")]) await send_advert(ctx) - assert sent == [True] + assert sent == [False, True] assert any("flood" in n for n in ui.notes) +async def test_device_actions_no_longer_lists_the_advert_row(ctx: AppContext) -> None: + """The advert action lives only in the main menu now — the actions screen dropped it.""" + from meshterm.ui.config_editor import _action_items + + labels = [str(getattr(item, "title", "")) for item in _action_items()] + assert not any("advert" in label.lower() for label in labels) + + async def test_send_advert_standalone_shares_the_contact_card(ctx: AppContext) -> None: """The standalone flow's share option opens the same QR/URI contact-card view.""" ui = _install(ctx, [("select", "share")])