From 17912782eea36928569891559a39dabd53ac926d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sun, 22 Nov 2026 14:05:03 -0500 Subject: [PATCH] A filter keeps what a page does, on every screen that filters The rule reached the exit pair of an editor and stopped there. A typed query still took the Actions section of the Device config, the repeater admin and the region editor, the Archive and View archived rows of the Contacts list, the Add rows of Channels and Outbound paths, the bulk sync of the Clock drift page, the Queue and Clear rows of the Courier, the delete rows of the Trophy case, the alert actions of the Watchtower, the whole-mesh row of the Time Machine, Probe all and Keep current path in Trace, and the actions of the Device route popup. Find-as-you-type searches the data of a list: the contacts, the settings, the slots, the queued messages, the records. A row that acts on the page is not in that data, so a query that matches no record hid the way to act and said nothing about how to get it back. Each such row now declares always_shown, and menu_rows takes the flag for a whole section. A list that is a menu keeps the old behaviour. The main menu, the actions of one room, the actions of one outbound path, and the startup offer are made of verbs, and there the query is how a reader finds one. Co-Authored-By: Claude Opus 5 --- CLAUDE.md | 19 ++++++++++++------ meshterm/ui/channels.py | 6 ++++-- meshterm/ui/clocks_screen.py | 6 +++++- meshterm/ui/config_editor.py | 15 ++++++++++----- meshterm/ui/contacts_screen.py | 7 +++++-- meshterm/ui/courier_screen.py | 10 ++++++++-- meshterm/ui/device_route_screen.py | 6 ++++-- meshterm/ui/menus.py | 14 ++++++++++++-- meshterm/ui/outbound_screen.py | 16 ++++++++++----- meshterm/ui/preferences.py | 3 +++ meshterm/ui/records_screen.py | 4 ++++ meshterm/ui/region_editor.py | 9 +++++++-- meshterm/ui/repeater_admin.py | 9 +++++++-- meshterm/ui/timemachine_screen.py | 8 +++++++- meshterm/ui/trace_screen.py | 6 +++++- meshterm/ui/tui/select.py | 4 +--- meshterm/ui/watchtower_screen.py | 20 +++++++++++++++---- tests/test_device_config.py | 24 +++++++++++++++++++++++ tests/test_menus.py | 31 ++++++++++++++++++++++++++++++ tests/test_preferences.py | 9 +++++++-- 20 files changed, 184 insertions(+), 42 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4e87dcb..b563bc3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -226,12 +226,7 @@ deliberately, one at a time, and say why in the code. clean and, once changes are staged, one blank `Separator(" ")` line then `✓ Apply n staged changes` over `✗ Back — discard staged changes` — Apply has no key of its own, so it needs a visible counterpart naming what the other way out costs. Same - shape in `ReorderScreen`. **A filter never hides a way out**: the pair carries - `Choice.always_shown`, so a typed query narrows the content and leaves Apply and the - Back that names its cost (JP, 2026-11-22) — a filter that hid Apply put the only way to - commit behind an Esc nobody knew to press. Same flag on the live-then-save pair and the - sweep's Archive/Back; a verb row a reader *searches for* (an Actions section, a menu) is - content and filters like any row. A **Quit** row is likewise kept (main menu, device splash): + shape in `ReorderScreen`. A **Quit** row is likewise kept (main menu, device splash): it *initiates* the app's terminal action behind a confirm, and on the splash it is the only statement that the app can be left at all. - **An editor has one of two shapes, chosen by who holds the change.** Where MeshTerm @@ -246,6 +241,18 @@ deliberately, one at a time, and say why in the code. holds live: the edits depend on each other there (a region must exist before it can be allowed), and a stage would have to re-implement the firmware's rules to order them. `ui/region_editor.py` is the reference. +- **A filter never hides what a page does** (JP, 2026-11-22). Find-as-you-type searches a + list's **data** — the contacts, the settings, the channel slots, the queued messages, the + records, the alerts, the regions, the paths — and a row that *acts on the page* is not + data: the `✓ Apply`/`✗ Back` pair, a live page's Save pair, an **Actions** section, an Add + or New row, a bulk action, a maintenance row (Contacts' `Archive contacts…` and + `View archived contacts`), a way out of a result list. Those rows carry + `Choice.always_shown` (`menus.menu_rows(…, always_shown=True)` for a whole section), and + `SelectScreen._rows` keeps them exactly as it keeps a separator. A filter that hid them + left Apply, which has no key of its own, reachable only by an Esc that nothing on the + screen named. The other side of the rule: a list that **is** a menu — the main menu, one + room's actions, a path's actions, the startup offer — filters every row, because there the + verbs are the content and the query is how the reader finds one. - **A cursor clamps at both ends — nothing in the app rolls over.** ↓ off the last row and ↑ off the first stay put, in a select list, a hand-drawn action list, a reorder list, a dialog's button row, everywhere. The window follows the highlight, so a roll diff --git a/meshterm/ui/channels.py b/meshterm/ui/channels.py index baf3bcd..2eec589 100644 --- a/meshterm/ui/channels.py +++ b/meshterm/ui/channels.py @@ -780,7 +780,7 @@ def _menu_items( if len(slots) > 1: items.append(section_heading("Organize")) reorder = marked_label("↕", "Reorder channels", "", lane=lane) - items.append(Choice(title=reorder, value=_REORDER)) + items.append(Choice(title=reorder, value=_REORDER, always_shown=True)) # Before "Add a channel", because that section ends early when each slot is full, and an # import still has work then: it puts the channels in the order of its file. @@ -834,7 +834,9 @@ def _menu_items( ) # One call for the rows of the two sections, so that their descriptions start in the same # column. Two calls aligned each section to its own widest label, four cells apart. - aligned = menu_rows(transfer + adds) + # The channel slots are the data of this page, and these rows are what the page does. + # Thus a typed filter narrows the slots and keeps each command (Choice.always_shown). + aligned = menu_rows(transfer + adds, always_shown=True) items.append(section_heading("Export and import")) items.extend(aligned[: len(transfer)]) items.append(section_heading("Add a channel")) diff --git a/meshterm/ui/clocks_screen.py b/meshterm/ui/clocks_screen.py index 4917ccd..92e89d4 100644 --- a/meshterm/ui/clocks_screen.py +++ b/meshterm/ui/clocks_screen.py @@ -385,7 +385,11 @@ def clock_drift_screen(rows: Sequence[ClockRow], *, tolerance_s: float) -> Selec if due: label = marked_label("🕒", "Sync their clocks…", "") label.append(f" · {len(due)} {'node' if len(due) == 1 else 'nodes'}", "muted") - items += [Separator(" "), Choice(title=label, value=SYNC_ALL), Separator(" ")] + items += [ + Separator(" "), + Choice(title=label, value=SYNC_ALL, always_shown=True), + Separator(" "), + ] others = _by_size([r for r in off if not r.managed and r.contact is not None]) items.append(section_heading("Out of sync")) diff --git a/meshterm/ui/config_editor.py b/meshterm/ui/config_editor.py index 97e15d4..550f2f8 100644 --- a/meshterm/ui/config_editor.py +++ b/meshterm/ui/config_editor.py @@ -682,14 +682,19 @@ def _menu_items( ] lane = icon_lane(icon for icon, _, _, _ in actions) items.append(section_heading("Actions")) + # The settings are the data of the page, so a typed filter narrows them and keeps each + # action (Choice.always_shown). items.extend( menu_rows( ( - marked_label(icon, label, "err" if value == _RESET else "", lane=lane), - help_text, - value, - ) - for icon, label, help_text, value in actions + ( + marked_label(icon, label, "err" if value == _RESET else "", lane=lane), + help_text, + value, + ) + for icon, label, help_text, value in actions + ), + always_shown=True, ) ) diff --git a/meshterm/ui/contacts_screen.py b/meshterm/ui/contacts_screen.py index 7d5e8c4..11053f9 100644 --- a/meshterm/ui/contacts_screen.py +++ b/meshterm/ui/contacts_screen.py @@ -166,7 +166,9 @@ class ContactsScreen(ContactListScreen): self._managed = managed self._contacts, self._counts = contacts, counts rows = self._contact_rows_for(locked) - # The maintenance actions close the list, after each contact, for each sort. First + # The maintenance actions close the list, after each contact, for each sort. A typed + # filter narrows the contacts and keeps these two rows (Choice.always_shown): the + # filter searches the list, and the actions of the page are not in it. First # a blank spacer, then the sweep (it has a `…` because it opens more prompts), then # the way to what the sweep already took. The two rows are together because they are # the two halves of one idea. The archived row is *under* the sweep for the same @@ -183,6 +185,7 @@ class ContactsScreen(ContactListScreen): Choice( title=marked_label("💾", "Archive contacts…", "", lane=lane), value=_ARCHIVE, + always_shown=True, ), ] if archived: @@ -191,7 +194,7 @@ class ContactsScreen(ContactListScreen): # of the verb. It is what the row leads to, not what the row does. label = marked_label("📂", "View archived contacts", "", lane=lane) label.append(f" · {archived}", style="muted") - tail.append(Choice(title=label, value=_ARCHIVED)) + tail.append(Choice(title=label, value=_ARCHIVED, always_shown=True)) # The title counts both halves of the contacts of this device: those that are on it # and those that a sweep moved off it. If the frame is too narrow for the words, the # numbers stay and the words go (``Contacts · 198 + 123``). diff --git a/meshterm/ui/courier_screen.py b/meshterm/ui/courier_screen.py index d5fbe99..ecb0045 100644 --- a/meshterm/ui/courier_screen.py +++ b/meshterm/ui/courier_screen.py @@ -415,7 +415,11 @@ def _menu_items(ctx: AppContext, entries: list[QueuedMessage]) -> list: ) ) items.append(Separator(" ")) # put space between the action and the outbox rows above it - items.append(Choice(marked_label("📨", "Queue a message…", "", lane=lane), _QUEUE)) + items.append( + # The queued messages are the data of the page, so a typed filter keeps this row + # and the Clear row below (Choice.always_shown). + Choice(marked_label("📨", "Queue a message…", "", lane=lane), _QUEUE, always_shown=True) + ) if done: items.append(section_heading("Finished")) @@ -429,7 +433,9 @@ def _menu_items(ctx: AppContext, entries: list[QueuedMessage]) -> list: pans=True, ) ) - items.append(Choice(marked_label("🗑", "Clear finished", "", lane=lane), _CLEAR)) + items.append( + Choice(marked_label("🗑", "Clear finished", "", lane=lane), _CLEAR, always_shown=True) + ) return items diff --git a/meshterm/ui/device_route_screen.py b/meshterm/ui/device_route_screen.py index 6fb6cce..42b3d99 100644 --- a/meshterm/ui/device_route_screen.py +++ b/meshterm/ui/device_route_screen.py @@ -318,7 +318,9 @@ def _action_rows(status: RouteStatus, proven: ProvenRoute | None = None) -> list if status.hops is not None: rows.append(("Forget the route", "the next message floods", _FORGET)) rows.append(("Discover routes…", "one flood: the route each way", _DISCOVER)) - return menu_rows(rows) + # The rows above these say what the radio holds, which is the data of the popup. Thus a + # typed filter narrows that and keeps what the popup does. + return menu_rows(rows, always_shown=True) def _scenario_tag(scenario: PathScenario) -> str: @@ -357,7 +359,7 @@ def _picker_rows(env: RouteEnv, status: RouteStatus) -> list[Any]: if scenario.source != "direct": add(tuple(scenario.hops), _scenario_tag(scenario)) add((), "no relays: the contact is a neighbour") - rows.extend(menu_rows([("Compose…", "choose each hop yourself", _COMPOSE)])) + rows.extend(menu_rows([("Compose…", "choose each hop yourself", _COMPOSE)], always_shown=True)) return rows diff --git a/meshterm/ui/menus.py b/meshterm/ui/menus.py index c7121b2..d121682 100644 --- a/meshterm/ui/menus.py +++ b/meshterm/ui/menus.py @@ -318,7 +318,7 @@ def exit_rows(staged: int, *, apply_value: Any, back_value: Any) -> list: ] -def menu_rows(rows: Iterable[tuple[str | Text, str, Any]]) -> list: +def menu_rows(rows: Iterable[tuple[str | Text, str, Any]], *, always_shown: bool = False) -> list: """:class:`Choice` rows with a label and a description, in two aligned lanes. This is the menu form that the channel detail and the Actions of the Device config and @@ -340,6 +340,14 @@ def menu_rows(rows: Iterable[tuple[str | Text, str, Any]]) -> list: Args: rows: ``(label, description, value)`` triples. A :class:`Text` label keeps its own styling (a destructive row with the ``err`` tint, a live unread badge). + always_shown: Whether a typed filter keeps these rows + (:attr:`~meshterm.ui.tui.select.Choice.always_shown`). Set it where the rows + are the **actions of a page whose other rows are data**: the Actions section + of an editor, the Add row of a list. There the filter searches the data, and an + action that it hid was gone until the user cleared a query that nothing names. + Leave it off for a list that *is* a menu (the main menu, the actions of one + room): there the rows are the content, and the filter is how the user finds + one. Returns: One :class:`Choice` for each row, with the lanes aligned across all the rows. @@ -360,7 +368,9 @@ def menu_rows(rows: Iterable[tuple[str | Text, str, Any]]) -> list: # The label lane identifies the row. Only the description overflows, so the # h-scroll moves only the description, and the name does not move (refer to # Choice.hscroll_from). - items.append(Choice(title=row, value=value, hscroll_from=width + 2)) + items.append( + Choice(title=row, value=value, hscroll_from=width + 2, always_shown=always_shown) + ) return items diff --git a/meshterm/ui/outbound_screen.py b/meshterm/ui/outbound_screen.py index 2234597..b0b8d6b 100644 --- a/meshterm/ui/outbound_screen.py +++ b/meshterm/ui/outbound_screen.py @@ -201,8 +201,11 @@ def _page(store: OutboundStore, env: _Env) -> tuple[str, str, list]: items.append( Separator(" no sites yet — a site holds the paths for where you are", style="muted") ) + # The sites and the fixed devices are the data of this page. Thus a typed filter + # narrows them and keeps the rows that add one (Choice.always_shown). items += menu_rows( - [(marked_label("✎", "New site…", "", lane=lane), "Name it, then add its paths", _NEW)] + [(marked_label("✎", "New site…", "", lane=lane), "Name it, then add its paths", _NEW)], + always_shown=True, ) items.append(section_heading("Fixed devices")) @@ -220,7 +223,8 @@ def _page(store: OutboundStore, env: _Env) -> tuple[str, str, list]: "It never moves: give it its own paths", _FIX, ) - ] + ], + always_shown=True, ) return "Outbound paths", prompt, items @@ -427,7 +431,7 @@ def _site_actions(store: OutboundStore, name: str) -> list: _DELETE, ) ) - return [section_heading("Site"), *menu_rows(rows)] + return [section_heading("Site"), *menu_rows(rows, always_shown=True)] def _device_actions() -> list: @@ -442,7 +446,8 @@ def _device_actions() -> list: "Forget its paths: it follows the active site", _UNFIX, ) - ] + ], + always_shown=True, ), ] @@ -463,7 +468,8 @@ def _editor_items(env: _Env, staged: list[OutboundPath], owner: list, changes: i "Compose it hop by hop", _ADD, ) - ] + ], + always_shown=True, ) rows += owner rows += exit_rows(changes, apply_value=_APPLY, back_value=_BACK) diff --git a/meshterm/ui/preferences.py b/meshterm/ui/preferences.py index 3c90e74..341f929 100644 --- a/meshterm/ui/preferences.py +++ b/meshterm/ui/preferences.py @@ -298,6 +298,9 @@ def _menu_items( title=lane_row(label, value, help_text, label_w, value_w), value=key, hscroll_from=description_at, + # The preferences are the data of the page. The reset row is what the + # page does, so a typed filter keeps it (Choice.always_shown). + always_shown=key == _RESET, ) ) if key == _WEEKLY_ADVERT and _effective(prefs, key, pending): diff --git a/meshterm/ui/records_screen.py b/meshterm/ui/records_screen.py index 73e489e..22cc2b9 100644 --- a/meshterm/ui/records_screen.py +++ b/meshterm/ui/records_screen.py @@ -1246,16 +1246,20 @@ async def open_records(ctx: AppContext) -> dict: ) if total: items.append(Separator(" ")) + # The records are the data of the page. Thus a typed filter narrows them and + # keeps these two rows (Choice.always_shown). items.append( Choice( title=marked_label("🗑", "Delete a discipline's records…", "err"), value=("del_cat", None, 0, None), + always_shown=True, ) ) items.append( Choice( title=marked_label("🗑", "Delete all records…", "err"), value=("del_all", None, 0, None), + always_shown=True, ) ) return items diff --git a/meshterm/ui/region_editor.py b/meshterm/ui/region_editor.py index aa95ad2..fe3f419 100644 --- a/meshterm/ui/region_editor.py +++ b/meshterm/ui/region_editor.py @@ -242,10 +242,15 @@ def region_items(node: Contact, table: RegionTable, unsaved: int) -> tuple[str, # list adds no second line after it (Separator.spaced). items.append(Separator(" ")) items.append(section_heading("Actions")) + # The region table is the data of the page, so a typed filter narrows it and keeps each + # action (Choice.always_shown). items.extend( menu_rows( - (marked_label(icon, label, "", lane=lane), help_text, value) - for icon, label, help_text, value in actions + ( + (marked_label(icon, label, "", lane=lane), help_text, value) + for icon, label, help_text, value in actions + ), + always_shown=True, ) ) items.extend(_save_rows(unsaved)) diff --git a/meshterm/ui/repeater_admin.py b/meshterm/ui/repeater_admin.py index 0e8d991..c0fa1de 100644 --- a/meshterm/ui/repeater_admin.py +++ b/meshterm/ui/repeater_admin.py @@ -525,10 +525,15 @@ def _menu_items(node: Contact, cache: dict, pending: dict[str, str]) -> tuple[st ] lane = icon_lane(icon for icon, _, _, _ in actions) items.append(section_heading("Actions")) + # The settings are the data of the page, so a typed filter narrows them and keeps each + # action (Choice.always_shown). items.extend( menu_rows( - (marked_label(icon, label, "", lane=lane), help_text, value) - for icon, label, help_text, value in actions + ( + (marked_label(icon, label, "", lane=lane), help_text, value) + for icon, label, help_text, value in actions + ), + always_shown=True, ) ) diff --git a/meshterm/ui/timemachine_screen.py b/meshterm/ui/timemachine_screen.py index e8decee..9158343 100644 --- a/meshterm/ui/timemachine_screen.py +++ b/meshterm/ui/timemachine_screen.py @@ -1503,7 +1503,13 @@ class TimeMachinePickerScreen(ContactListScreen): sort=sort, prompt=prompt, lead=[ - Choice(command_label("🌐 The whole mesh — days, arrivals, the ledger"), MESH), + # The nodes are the data of the picker. Thus a typed filter narrows them + # and keeps this row (Choice.always_shown). + Choice( + command_label("🌐 The whole mesh — days, arrivals, the ledger"), + MESH, + always_shown=True, + ), section_heading("Nodes"), ], ) diff --git a/meshterm/ui/trace_screen.py b/meshterm/ui/trace_screen.py index a660d5f..6a8682d 100644 --- a/meshterm/ui/trace_screen.py +++ b/meshterm/ui/trace_screen.py @@ -2507,6 +2507,9 @@ async def _open_session( Choice( title=marked_label("⚡", "Probe all — trace each path once and rank", "warn"), value=("probe", None), + # The candidates are the data of the list, so a typed filter keeps this + # row (Choice.always_shown). + always_shown=True, ) ) picked = await session.run_screen( @@ -2547,7 +2550,8 @@ async def _open_session( ) ) result_items.append(Separator(" ")) - result_items.append(Choice(title="Keep current path", value=None)) # the exit: no adoption + # The way out of the results, which a typed filter keeps (Choice.always_shown). + result_items.append(Choice(title="Keep current path", value=None, always_shown=True)) adopted = await session.run_screen( SelectScreen( f"Probe results — {target_label}", diff --git a/meshterm/ui/tui/select.py b/meshterm/ui/tui/select.py index 9452cd4..d90b2e1 100644 --- a/meshterm/ui/tui/select.py +++ b/meshterm/ui/tui/select.py @@ -642,9 +642,7 @@ class SelectScreen(Screen): return [ it for it in self._items - if isinstance(it, Separator) - or it.always_shown - or needle in _plain(it.label).lower() + if isinstance(it, Separator) or it.always_shown or needle in _plain(it.label).lower() ] def _choices(self, rows: list | None = None) -> list: diff --git a/meshterm/ui/watchtower_screen.py b/meshterm/ui/watchtower_screen.py index 78479fd..5360cbb 100644 --- a/meshterm/ui/watchtower_screen.py +++ b/meshterm/ui/watchtower_screen.py @@ -211,28 +211,40 @@ def _menu_items( # toggle for new nodes below them. The set of icons is declared whole and not found from # the rows that are present. Thus the column does not move when the conditional rows # appear and disappear. It is empty where the platform draws no icons. + # The alerts and the watched nodes are the data of the page, so each action row below + # declares that a typed filter keeps it (Choice.always_shown). lane = icon_lane(("✓", "🗑", "⭐", "🔔")) unacked = sum(1 for a in alerts if not a.acked) acked = len(alerts) - unacked if unacked: ack_all = marked_label("✓", f"Acknowledge all ({unacked})", "ok", lane=lane) - items.append(Choice(ack_all, _ACK_ALL)) + items.append(Choice(ack_all, _ACK_ALL, always_shown=True)) if acked: - items.append(Choice(marked_label("🗑", "Clear acknowledged", "err", lane=lane), _CLEAR)) + items.append( + Choice( + marked_label("🗑", "Clear acknowledged", "err", lane=lane), + _CLEAR, + always_shown=True, + ) + ) items.append(section_heading("Watched nodes")) if not watched: items.append(Separator(" none starred yet — silence and SNR rules need one")) for key in sorted(watched, key=lambda k: watched[k].name.casefold()): items.append(Choice(_watched_row(watched[key], type_of), ("node", key))) - items.append(Choice(marked_label("⭐", "Watch a node…", "", lane=lane), _WATCH)) + items.append( + Choice(marked_label("⭐", "Watch a node…", "", lane=lane), _WATCH, always_shown=True) + ) items.append(Separator(" ")) state = "[ok]on[/ok]" if new_node_alerts else "[muted]off[/muted]" toggle = Text.from_markup( f"New-node alerts: {state} [muted]— announce first-ever appearances[/muted]" ) - items.append(Choice(Text.assemble(icon_mark("🔔", "", lane), toggle), _TOGGLE_NEW)) + items.append( + Choice(Text.assemble(icon_mark("🔔", "", lane), toggle), _TOGGLE_NEW, always_shown=True) + ) return items diff --git a/tests/test_device_config.py b/tests/test_device_config.py index 96f796c..fd65ca8 100644 --- a/tests/test_device_config.py +++ b/tests/test_device_config.py @@ -1370,6 +1370,30 @@ def test_contacts_screen_tail_offers_archive_only_when_populated() -> None: assert _ARCHIVE not in values # nothing to archive, so no action row +def test_a_filter_on_the_contacts_narrows_them_and_keeps_the_archive_rows() -> None: + """A typed query hides the contacts that do not match. The two tail rows stay. + + The contacts are the data of the list. What the page *does* is not in the query, so a + filter that hid the actions left them unreachable until the user cleared it. + """ + from meshterm.core.models import Contact + from meshterm.ui.contacts_screen import _ARCHIVE, _ARCHIVED, ContactsScreen + + screen = ContactsScreen( + "Us", + "cc" * 32, + [Contact(name="Alice", public_key="aa" * 32)], + 1, + {}, + _contacts_sort(), + archived=2, + ) + screen.note_viewport(20) + for ch in "zzzz": # a query that no contact matches + screen.handle("text", ch) + assert [c.value for c in screen._choices()] == [_ARCHIVE, _ARCHIVED] + + def test_the_archived_row_appears_only_when_something_is_archived() -> None: """The row for the archived list, with its count, shows only when there is an archived list. diff --git a/tests/test_menus.py b/tests/test_menus.py index aefccf0..28fc326 100644 --- a/tests/test_menus.py +++ b/tests/test_menus.py @@ -47,6 +47,37 @@ def test_exit_rows_staged_state_spells_out_the_consequence() -> None: assert back_row.title.plain == "✗ Back — discard staged changes" +def test_a_filter_keeps_the_way_out_and_the_actions_of_a_page() -> None: + """A typed query narrows the data of a list and keeps the rows that act on the page. + + The exit pair declares it, and so does each command row that a page builds with + ``always_shown``. Apply has no keyboard key of its own, so a filter that hid it left + the staged changes with no way to commit them. + """ + from meshterm.ui.tui import Choice, SelectScreen + + actions = menu_rows([("Read settings", "Ask the device again", "read")], always_shown=True) + items = [ + Choice(title="Airtime budget", value="airtime"), + Choice(title="Radio preset", value="preset"), + *actions, + *exit_rows(2, apply_value="A", back_value="B"), + ] + screen = SelectScreen("Settings", items) + screen.note_viewport(len(items) + 4) + for ch in "zzzz": # a query that no setting matches + screen.handle("text", ch) + assert [choice.value for choice in screen._choices()] == ["read", "A", "B"] + + # A menu is a list of actions, and there the filter is how the user finds one. Thus the + # rows of a plain menu_rows call narrow as before. + menu = SelectScreen("Menu", menu_rows([("Map", "Where the nodes are", "map")])) + menu.note_viewport(8) + for ch in "zzzz": + menu.handle("text", ch) + assert menu._choices() == [] + + def test_menu_rows_align_descriptions_in_display_cells() -> None: """Each description starts at the same cell column, also after a label with a wide emoji.""" rows = menu_rows( diff --git a/tests/test_preferences.py b/tests/test_preferences.py index b3cd1ce..3b03833 100644 --- a/tests/test_preferences.py +++ b/tests/test_preferences.py @@ -364,8 +364,13 @@ def test_a_filter_narrows_the_settings_and_keeps_the_apply_and_back_rows() -> No assert not any("Map tiles" in row for row in rows) assert any("✓ Apply 1 staged change" in row for row in rows) assert any("✗ Back — discard staged changes" in row for row in rows) - # They are still rows that the highlight can reach, and not only drawn lines. - assert [choice.value for choice in screen._choices()] == ["__apply__", "__cancel__"] + # They are still rows that the highlight can reach, and not only drawn lines. The reset + # row is an action of the page too, so the filter keeps it with them. + assert [choice.value for choice in screen._choices()] == [ + "__reset__", + "__apply__", + "__cancel__", + ] def test_a_long_value_is_capped_so_the_descriptions_keep_their_lane() -> None: