diff --git a/meshterm/ui/surface.py b/meshterm/ui/surface.py index 743f733..6df5687 100644 --- a/meshterm/ui/surface.py +++ b/meshterm/ui/surface.py @@ -18,7 +18,7 @@ only), so :class:`PlainUi` leaves them unsupported. from __future__ import annotations -from collections.abc import AsyncIterator, Callable, Mapping +from collections.abc import AsyncIterator, Awaitable, Callable, Mapping from contextlib import asynccontextmanager from typing import Any @@ -222,9 +222,14 @@ class Ui: footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Choose one item on a chromeless startup splash; ``None`` if skipped. + ``live`` is work to run while the splash is up, handed a ``redraw(items)`` that + swaps the rows under the reader and repaints -- the device picker's rescan. It is + cancelled when the splash resolves. + ``keys`` declares bare-key shortcuts the splash answers, resolving with a :class:`~meshterm.ui.tui.select.KeyRequest` (the picker's hide/show-all pair), and ``key_hint`` names them per highlighted row so the footer only advertises a key @@ -516,6 +521,7 @@ class PlainUi(Ui): footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Unsupported in scripted CLI mode.""" raise self._no_prompt() @@ -779,6 +785,7 @@ class TuiUi(Ui): footer_hint: str | None = None, keys: Mapping[str, Any] | None = None, key_hint: Callable[[Any], str] | None = None, + live: Callable[[Callable[[list], None]], Awaitable[None]] | None = None, ) -> Any: """Delegate to the session's chromeless startup select splash.""" return await self.session.select_startup( @@ -789,6 +796,7 @@ class TuiUi(Ui): footnote=footnote, keys=keys, key_hint=key_hint, + live=live, **({} if footer_hint is None else {"footer_hint": footer_hint}), ) diff --git a/tests/test_tui.py b/tests/test_tui.py index 29d6498..d93473a 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -3573,3 +3573,33 @@ def test_bluetooth_is_not_scanned_on_every_poll(tmp_path, monkeypatch) -> None: assert calls["serial"] > calls["ble"], ( f"bluetooth scanned {calls['ble']} time(s) against {calls['serial']} serial poll(s)" ) + + +def test_the_picker_only_passes_arguments_the_splash_surface_accepts(tmp_path) -> None: + """Every keyword `prompt_device` sends must exist on `Ui.select_startup`. + + This is the shape of bug a test double hides. `prompt_device` calls the *surface*, + which delegates to the session; adding an argument to the session alone crashes the + startup path and nothing else, because every fake Ui in this file absorbs unknown + keywords with `**kwargs` and is perfectly happy. So the fake here binds what it is + given against the real signature, and a keyword the surface has never heard of raises + exactly where a running MeshTerm would. + """ + import inspect + + from meshterm.core.device_store import DeviceStore + from meshterm.ui.device_picker import prompt_device + from meshterm.ui.surface import Ui + + signature = inspect.signature(Ui.select_startup) + + class _Ui: + async def select_startup(self, title, items, **kw): # noqa: ANN001, ANN003, ANN201 + signature.bind(self, title, items, **kw) # TypeError on an unknown keyword + return None + + async def _never(_device): + raise AssertionError("verify should not run when selection is skipped") + + store = DeviceStore(tmp_path / "devices.json") + asyncio.run(prompt_device(_Ui(), [], store, _never))