From 9de428f6ca0b2406d3e3a21252b92867cc76365d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sat, 5 Sep 2026 16:04:17 -0400 Subject: [PATCH] A cursor stops at the end of its list Down off the last row wrapped to the first on a good third of the app's lists, and the select screen shipped that as its default -- twenty-one call sites had already opted out one at a time, each writing wrap=False for its own reason. The reasons were all the same one, so the flag is gone and clamping is simply what a cursor does. The window follows the highlight, so a roll doesn't move a pointer: it hauls the whole list back to the other end and flips its edge markers, which reads as the screen changing under you rather than as one step. Held-down arrows now settle at an end instead of looping past what you were trying to reach. The hand-rolled cursors came along: the trophy case's, the trace and TX optimize action rows, the reorder list -- where the ungrabbed cursor wrapped while the grabbed one clamped, so the same two keys meant opposite things in the two modes -- a prompt's completion list, and a dialog's buttons. Tab is the exception, and it stays a ring: it has no reverse of its own, so on the last chip it comes round or it dead-ends. Same for the three picocalc F-lane chips that are single-key advancers -- Sort, the node page's tab strip, the Time Machine's window -- where the lane offers no way back. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 9 +++++ meshterm/tools/chat.py | 1 - meshterm/tools/tx_optimize.py | 1 - meshterm/ui/admin_picker.py | 4 +-- meshterm/ui/channels.py | 3 +- meshterm/ui/config_editor.py | 3 +- meshterm/ui/contactlist.py | 1 - meshterm/ui/courier_screen.py | 1 - meshterm/ui/preferences.py | 2 +- meshterm/ui/purge_screen.py | 2 -- meshterm/ui/records_screen.py | 8 ++--- meshterm/ui/repeater_admin.py | 2 +- meshterm/ui/surface.py | 5 +-- meshterm/ui/trace_screen.py | 10 +++--- meshterm/ui/tui/prompt.py | 15 +++++--- meshterm/ui/tui/screen.py | 4 +-- meshterm/ui/tui/select.py | 26 +++++++------- meshterm/ui/tui/session.py | 3 +- meshterm/ui/tx_screen.py | 9 +++-- meshterm/ui/watchtower_screen.py | 1 - tests/test_chat.py | 2 +- tests/test_config_editor.py | 3 +- tests/test_gallery.py | 3 +- tests/test_live_screens.py | 3 +- tests/test_preferences.py | 4 +-- tests/test_repeater_admin.py | 2 +- tests/test_tui.py | 59 +++++++++++++++++++------------- 27 files changed, 99 insertions(+), 87 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 09b0656..f746a9f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -131,6 +131,15 @@ deliberately, one at a time, and say why in the code. 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. +- **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 + hauls the whole list back to the other end and flips its edge markers: the one move + that reads as the screen changing under you rather than as one step, and held-down + arrows should settle at an end rather than loop. The exception is a **forward-only key + with no reverse of its own**, which cycles or it dead-ends — Tab on a button row, and + the picocalc F-lane's single-chip advancers (`Sort →`, the node page's tab chip, the + Time Machine's window chip). Those state it in the code. - Grouped-list section headings use `section_heading("Label")` → `── Label ──` accent. That is also what makes a heading *sticky* (it pins to the top row while its section scrolls, and the ^PgUp/^PgDn jumps step by it), so build them through it — a hand-rolled diff --git a/meshterm/tools/chat.py b/meshterm/tools/chat.py index 8b16b8c..81aa138 100644 --- a/meshterm/tools/chat.py +++ b/meshterm/tools/chat.py @@ -120,7 +120,6 @@ class ChatTool(Tool): picker = SelectScreen( "Chat — pick a conversation", await self._picker_items(ctx), - wrap=False, delete_hint="Del delete history", ) opened = 0 diff --git a/meshterm/tools/tx_optimize.py b/meshterm/tools/tx_optimize.py index 494db88..41a4f4e 100644 --- a/meshterm/tools/tx_optimize.py +++ b/meshterm/tools/tx_optimize.py @@ -176,7 +176,6 @@ class TxOptimizeTool(Tool): "TX optimize — measure at", items, prompt=f"The node whose reception of {admin_node.name} gets optimized:", - wrap=False, ) summary: dict[str, Any] = {} async with ctx.ui.session.stay(screen) as visit: diff --git a/meshterm/ui/admin_picker.py b/meshterm/ui/admin_picker.py index c5610c1..3676b3d 100644 --- a/meshterm/ui/admin_picker.py +++ b/meshterm/ui/admin_picker.py @@ -113,7 +113,7 @@ async def pick_admin_node( await _note_nothing_to_pick(ctx, title) return None - choice = await ctx.ui.select(title, items, prompt=prompt, wrap=False) + choice = await ctx.ui.select(title, items, prompt=prompt) return _resolve(candidates, choice) @@ -150,7 +150,7 @@ async def admin_node_visit( await _note_nothing_to_pick(ctx, title) yield None return - screen = SelectScreen(title, items, prompt=prompt, wrap=False) + screen = SelectScreen(title, items, prompt=prompt) async with ctx.ui.session.stay(screen) as visit: yield _AdminNodePicker(visit, candidates) diff --git a/meshterm/ui/channels.py b/meshterm/ui/channels.py index e8ab927..2a05d6e 100644 --- a/meshterm/ui/channels.py +++ b/meshterm/ui/channels.py @@ -227,7 +227,7 @@ async def manage_channels(ctx: "AppContext") -> int: if not await _menu_round(ctx, title, items, default=highlight, handle=handle): return changes title, items = await reload() - menu = SelectScreen(title, items, wrap=False) + menu = SelectScreen(title, items) async with session.stay(menu) as visit: while True: choice = await visit.result() @@ -743,7 +743,6 @@ async def _channel_detail( title, _detail_items(ctx, slot), prompt=_detail_summary(ctx, slot, stats), - wrap=False, ) async with session.stay(menu) as visit: while True: diff --git a/meshterm/ui/config_editor.py b/meshterm/ui/config_editor.py index 60634ef..94bb50e 100644 --- a/meshterm/ui/config_editor.py +++ b/meshterm/ui/config_editor.py @@ -166,7 +166,6 @@ async def edit_config(ctx: "AppContext") -> Optional[list[tuple]]: snapshot, pending, len(pending) + len(extra_ops), policy, reveal ), conceals=has_pin(snapshot), - wrap=False, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) async with session.stay(menu) as visit: @@ -933,7 +932,7 @@ async def device_actions(ctx: "AppContext") -> None: # One screen for the whole visit: the action rows are fixed, so nothing here needs # rebuilding — and the cursor and any typed filter simply stay where the reader left them # while each action's prompts float over the list. - menu = SelectScreen("Device actions", _action_items(), wrap=False) + menu = SelectScreen("Device actions", _action_items()) async with session.stay(menu) as visit: while True: choice = await visit.result() diff --git a/meshterm/ui/contactlist.py b/meshterm/ui/contactlist.py index 960ba9f..c10194a 100644 --- a/meshterm/ui/contactlist.py +++ b/meshterm/ui/contactlist.py @@ -513,7 +513,6 @@ class ContactListScreen(SelectScreen): self._compose_items(), prompt=prompt, footer_hint=footer_hint, - wrap=False, ) def _compose_items(self) -> list: diff --git a/meshterm/ui/courier_screen.py b/meshterm/ui/courier_screen.py index 9c861fa..55e7aee 100644 --- a/meshterm/ui/courier_screen.py +++ b/meshterm/ui/courier_screen.py @@ -187,7 +187,6 @@ class CourierOutboxScreen(SelectScreen): "Courier — store-and-forward outbox", _menu_items(ctx, ctx.courier_store.entries()), default=default, - wrap=False, footer_hint="↑↓ move · Enter select · Esc back", ) diff --git a/meshterm/ui/preferences.py b/meshterm/ui/preferences.py index 418965e..4ee22c4 100644 --- a/meshterm/ui/preferences.py +++ b/meshterm/ui/preferences.py @@ -89,7 +89,7 @@ async def edit_preferences(ctx: "AppContext") -> Optional[dict[str, Any]]: # whole visit means the typed filter survives editing a preference, not just the cursor. title, items = _menu_items(prefs, pending) menu = SelectScreen( - title, items, wrap=False, + title, items, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) async with session.stay(menu) as visit: diff --git a/meshterm/ui/purge_screen.py b/meshterm/ui/purge_screen.py index a315424..f633794 100644 --- a/meshterm/ui/purge_screen.py +++ b/meshterm/ui/purge_screen.py @@ -368,7 +368,6 @@ def _target_screen(ranked: list[ScoredContact], sweepable: list[ScoredContact]): ), footer_hint="↑↓ move · Enter select · Esc back", filterable=False, - wrap=False, ) @@ -417,7 +416,6 @@ def _preview_screen(victims: list[ScoredContact]): footer_hint="↑↓ move · type to filter · Enter select · Esc back", delete_hint="Del keep", default=_APPLY, - wrap=False, hscroll=True, hscroll_hint="←→ scroll", ) diff --git a/meshterm/ui/records_screen.py b/meshterm/ui/records_screen.py index 153f4f1..54814db 100644 --- a/meshterm/ui/records_screen.py +++ b/meshterm/ui/records_screen.py @@ -227,10 +227,12 @@ class RecordDialog(Screen): """Move the action cursor, scroll the card, commit the selection, or dismiss.""" if action == "up": self._follow = True - self._index = (self._index - 1) % len(self._actions) + # Both ends clamp rather than wrap — the app-wide rule for a row cursor: + # a highlight that leaps end to end takes the results window with it. + self._index = max(0, self._index - 1) elif action == "down": self._follow = True - self._index = (self._index + 1) % len(self._actions) + self._index = min(len(self._actions) - 1, self._index + 1) elif action in ("pageup", "ctrl_pageup"): self._follow = False self.scroll_pages(-1) @@ -788,7 +790,6 @@ async def open_records(ctx: "AppContext") -> dict: rows, footer_hint="↑↓ move · Enter select · Esc back", filterable=False, - wrap=False, ) ) if picked is CANCEL or picked is None: # Esc @@ -845,7 +846,6 @@ async def open_records(ctx: "AppContext") -> dict: "Trophy case", items, footer_hint="↑↓ move · Enter open · Esc back", - wrap=False, hscroll=True, # a long walk slides under ←→ instead of dying at the fold ) # The browser stays pushed for the whole visit, so every dialog that belongs *over* diff --git a/meshterm/ui/repeater_admin.py b/meshterm/ui/repeater_admin.py index b92f912..7fd149e 100644 --- a/meshterm/ui/repeater_admin.py +++ b/meshterm/ui/repeater_admin.py @@ -192,7 +192,7 @@ async def _admin_session( cache = ctx.remote_store.settings(node) title, items = _menu_items(node, cache, pending) menu = SelectScreen( - title, items, wrap=False, + title, items, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) async with session.stay(menu) as visit: diff --git a/meshterm/ui/surface.py b/meshterm/ui/surface.py index 6e76eed..1c4f6bd 100644 --- a/meshterm/ui/surface.py +++ b/meshterm/ui/surface.py @@ -125,7 +125,6 @@ class Ui: *, prompt: str = "", default: Any = None, - wrap: bool = True, filterable: bool = True, delete_hint: str = "", ) -> Any: @@ -406,7 +405,6 @@ class PlainUi(Ui): *, prompt: str = "", default: Any = None, - wrap: bool = True, filterable: bool = True, delete_hint: str = "", ) -> Any: @@ -652,13 +650,12 @@ class TuiUi(Ui): *, prompt: str = "", default: Any = None, - wrap: bool = True, filterable: bool = True, delete_hint: str = "", ) -> Any: """Delegate to the session's select screen.""" return await self.session.select( - title, items, prompt=prompt, default=default, wrap=wrap, + title, items, prompt=prompt, default=default, filterable=filterable, delete_hint=delete_hint, ) diff --git a/meshterm/ui/trace_screen.py b/meshterm/ui/trace_screen.py index 8d9140d..7b6225a 100644 --- a/meshterm/ui/trace_screen.py +++ b/meshterm/ui/trace_screen.py @@ -672,10 +672,12 @@ class TraceScreen(Screen): if action == "enter": self._commit_action() elif action == "up": - self._index = (self._index - 1) % len(self._actions) + # Both ends clamp rather than wrap — the app-wide rule for a row cursor: + # a highlight that leaps end to end takes the results window with it. + self._index = max(0, self._index - 1) self._pin_cursor = True elif action == "down": - self._index = (self._index + 1) % len(self._actions) + self._index = min(len(self._actions) - 1, self._index + 1) self._pin_cursor = True elif action == "pageup": self._pin_cursor = False @@ -1800,7 +1802,6 @@ async def _open_session( default=width_bytes, footer_hint="↑↓ move · Enter set · Esc keep", filterable=False, - wrap=False, ) ) if picked is CANCEL or picked is None or int(picked) == width_bytes: @@ -1837,7 +1838,6 @@ async def _open_session( default=sample_count, footer_hint="↑↓ move · Enter set · Esc keep", filterable=False, - wrap=False, ) ) if picked is not CANCEL and picked is not None: @@ -2026,7 +2026,6 @@ async def _open_session( items, prompt="Choose the outbound leg — the return mirrors it.", footer_hint="↑↓ move · Enter adopt/probe · Esc back", - wrap=False, hscroll=True, # a long candidate row slides under ←→ instead of truncating ) ) @@ -2064,7 +2063,6 @@ async def _open_session( f"Probe results — {target_label}", result_items, footer_hint="↑↓ move · Enter adopt path · Esc keep", - wrap=False, # ←→ read the tail of a long spec; the ranking lanes in front of it stay # pinned (each row declares their width — see outcome_lanes). hscroll=True, diff --git a/meshterm/ui/tui/prompt.py b/meshterm/ui/tui/prompt.py index 3c3b4ff..a2e296b 100644 --- a/meshterm/ui/tui/prompt.py +++ b/meshterm/ui/tui/prompt.py @@ -585,9 +585,16 @@ class ButtonDialog(_KeylessDialog): def handle(self, action: str, data: str = "") -> None: """Move the highlight, commit on Enter or a shortcut key, or cancel on Esc.""" - if action in ("left", "right", "tab") and self._buttons: + if action in ("left", "right") and self._buttons: + # ←→ clamp, like every other cursor the app steers with a directional pair — + # a highlight that leaps end to end is the one move that reads as the screen + # changing rather than as one step. step = -1 if action == "left" else 1 - self._index = (self._index + step) % len(self._buttons) + self._index = max(0, min(len(self._buttons) - 1, self._index + step)) + elif action == "tab" and self._buttons: + # Tab is the exception the rule allows: a forward-only key with no reverse of + # its own, so it cycles or it dead-ends on the last chip. + self._index = (self._index + 1) % len(self._buttons) elif action == "text" and data.lower() in self._keys: self.resolve(self._keys[data.lower()]) elif action == "enter" and self._buttons: @@ -828,9 +835,9 @@ class AutocompleteScreen(_KeylessDialog): """Edit the field, move/accept suggestions, submit on Enter, or cancel on Esc.""" suggestions = self._suggestions() if action == "up": - self._sugg = (self._sugg - 1) % len(suggestions) if suggestions else 0 + self._sugg = max(0, self._sugg - 1) if suggestions else 0 elif action == "down": - self._sugg = (self._sugg + 1) % len(suggestions) if suggestions else 0 + self._sugg = min(len(suggestions) - 1, self._sugg + 1) if suggestions else 0 elif action == "tab": if suggestions: self._editor = _LineEditor(suggestions[self._sugg]) diff --git a/meshterm/ui/tui/screen.py b/meshterm/ui/tui/screen.py index c35c3de..fc77c6b 100644 --- a/meshterm/ui/tui/screen.py +++ b/meshterm/ui/tui/screen.py @@ -444,8 +444,8 @@ class ListWindow: stride a PgUp/PgDn should move by. A highlight over such a list **clamps at both ends rather than wrapping** (as - :class:`~meshterm.ui.tui.select.SelectScreen` does with ``wrap=False``, and for a - sharper reason): the window follows the highlight, so a ↓ off the last row would not + :class:`~meshterm.ui.tui.select.SelectScreen` does, and for the same reason, sharper + here): the window follows the highlight, so a ↓ off the last row would not merely move the pointer — it would haul the whole window back to the head, flipping the edge markers as it went, which reads as the screen changing under the reader rather than as one step. Held-down arrows settle at an end instead (JP, 2026-09-04). diff --git a/meshterm/ui/tui/select.py b/meshterm/ui/tui/select.py index 829d342..75b8ac0 100644 --- a/meshterm/ui/tui/select.py +++ b/meshterm/ui/tui/select.py @@ -288,7 +288,6 @@ class SelectScreen(Screen): footer_hint: Optional[str] = None, delete_hint: str = "", filterable: bool = True, - wrap: bool = True, hscroll: bool = False, hscroll_hint: str = "←→ scroll", ) -> None: @@ -308,9 +307,6 @@ class SelectScreen(Screen): touch. Empty (the default) leaves the footer fixed. filterable: Whether typing narrows the list. Off for short, fixed lists (e.g. the startup device picker) where type-to-filter would only get in the way. - wrap: Whether the highlight wraps around the ends (Down from the last row jumps - to the first, and vice versa). Off for grouped lists where wrapping across the - section headings reads as a jarring jump rather than continuing to scroll. hscroll: Whether ←/→ horizontally scroll the *highlighted* row so an over-long line can be read to its end (the Watchtower's alert log). Off by default — rows simply ellipsize at the right edge and ←/→ stay inert. Only a row that @@ -350,7 +346,6 @@ class SelectScreen(Screen): self._delete_hint = delete_hint self._prompt = prompt self._filterable = filterable - self._wrap = wrap self._items = items self._filter = "" # Index into the currently-selectable (filtered) choices. @@ -801,14 +796,16 @@ class SelectScreen(Screen): self._hshift = 0 # moving off a row abandons its scroll — each row scrolls alone if action == "up": if choices: - self._index = (self._index - 1) % len(choices) if self._wrap else max( - 0, self._index - 1 - ) + # Both ends clamp; nothing in the app rolls a highlight over. A ↓ off the + # last row would haul the window back to the head and flip the edge + # markers with it, which reads as the screen changing under the reader + # rather than as one step — and across a grouped list's section headings + # it reads as a jump rather than as continuing to scroll. Held-down arrows + # settle at an end instead. + self._index = max(0, self._index - 1) elif action == "down": if choices: - self._index = (self._index + 1) % len(choices) if self._wrap else min( - len(choices) - 1, self._index + 1 - ) + self._index = min(len(choices) - 1, self._index + 1) elif action == "pageup": self._index = max(0, self._index - self._page_step) elif action == "pagedown": @@ -995,14 +992,17 @@ class ReorderScreen(Screen): self._order[self._index], self._order[self._index - 1]) self._index -= 1 elif not self._grabbed and total: - self._index = (self._index - 1) % total + # Clamps like every other row cursor, and like the grabbed one just above: + # the same two keys must not mean "stop at the end" in one mode and "leap + # to the other end" in the other. + self._index = max(0, self._index - 1) elif action == "down": if self._grabbed and self._index < n - 1: self._order[self._index + 1], self._order[self._index] = ( self._order[self._index], self._order[self._index + 1]) self._index += 1 elif not self._grabbed and total: - self._index = (self._index + 1) % total + self._index = min(total - 1, self._index + 1) elif action == "enter": if self._index < n: self._grabbed = not self._grabbed # Enter grabs a row, Enter again drops it diff --git a/meshterm/ui/tui/session.py b/meshterm/ui/tui/session.py index 5705c9c..3c9ecca 100644 --- a/meshterm/ui/tui/session.py +++ b/meshterm/ui/tui/session.py @@ -783,7 +783,6 @@ class TuiSession: *, prompt: str = "", default: Any = None, - wrap: bool = True, filterable: bool = True, footer_hint: Optional[str] = None, delete_hint: str = "", @@ -798,7 +797,7 @@ class TuiSession: :class:`~meshterm.ui.tui.select.DeleteRequest` the caller unwraps. """ kwargs: dict[str, Any] = dict( - prompt=prompt, default=default, wrap=wrap, filterable=filterable, + prompt=prompt, default=default, filterable=filterable, delete_hint=delete_hint, ) if footer_hint is not None: diff --git a/meshterm/ui/tx_screen.py b/meshterm/ui/tx_screen.py index b3d69fc..e54afc6 100644 --- a/meshterm/ui/tx_screen.py +++ b/meshterm/ui/tx_screen.py @@ -295,10 +295,12 @@ class TxSweepScreen(Screen): if action == "enter": self._commit_action() elif action == "up": - self._index = (self._index - 1) % len(self._actions) + # Both ends clamp rather than wrap — the app-wide rule for a row cursor: + # a highlight that leaps end to end takes the results window with it. + self._index = max(0, self._index - 1) self._pin_cursor = True elif action == "down": - self._index = (self._index + 1) % len(self._actions) + self._index = min(len(self._actions) - 1, self._index + 1) self._pin_cursor = True elif action == "pageup": self._pin_cursor = False @@ -710,7 +712,6 @@ async def open_tx_optimize( default=(screen.tx_min, screen.tx_max), footer_hint="↑↓ move · Enter set · Esc keep", filterable=False, - wrap=False, ) ) if picked is CANCEL or picked is None: @@ -749,7 +750,6 @@ async def open_tx_optimize( default=screen.step, footer_hint="↑↓ move · Enter set · Esc keep", filterable=False, - wrap=False, ) ) if picked is not CANCEL and picked is not None: @@ -774,7 +774,6 @@ async def open_tx_optimize( default=screen.samples, footer_hint="↑↓ move · Enter set · Esc keep", filterable=False, - wrap=False, ) ) if picked is not CANCEL and picked is not None: diff --git a/meshterm/ui/watchtower_screen.py b/meshterm/ui/watchtower_screen.py index 4687840..bbe92f3 100644 --- a/meshterm/ui/watchtower_screen.py +++ b/meshterm/ui/watchtower_screen.py @@ -122,7 +122,6 @@ async def open_watchtower(ctx: "AppContext") -> Optional[dict[str, Any]]: menu = SelectScreen( "Watchtower — alerts & watched nodes", rows(), - wrap=False, hscroll=True, # ←→ scroll is surfaced by the list itself, but only while the highlighted # alert actually overflows the width (see SelectScreen.hscroll_hint) — and it diff --git a/tests/test_chat.py b/tests/test_chat.py index a265688..b653108 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -1755,7 +1755,7 @@ async def test_picker_pins_its_column_header_over_the_group_heading( header = items[0] assert header.pinned # the lanes mean the same in both groups — pinned for the list - screen = SelectScreen("Chat", items, wrap=False) + screen = SelectScreen("Chat", items) for _ in range(8): # down past the Direct heading screen.handle("down") visible, above, _below = frame._visible_slice(screen, screen.render_body(72), 8) diff --git a/tests/test_config_editor.py b/tests/test_config_editor.py index 7517fe4..e7cf87d 100644 --- a/tests/test_config_editor.py +++ b/tests/test_config_editor.py @@ -270,7 +270,6 @@ def _editor(snapshot: dict, pending: dict | None = None) -> _ConfigMenu: _StubSession(), lambda reveal: _menu_items(snapshot, pending, len(pending), AdvertPolicy(), reveal), conceals=has_pin(snapshot), - wrap=False, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) @@ -777,7 +776,7 @@ async def test_editor_menu_pins_the_column_header_over_the_category(ctx: AppCont menu = ui.session.pushed[0] # Re-open the same rows highlighting a row in the last category, so the list scrolls # past both the column header and the earlier headings. - deep = SelectScreen(menu.title, menu._items, default="__advert_flood__", wrap=False) + deep = SelectScreen(menu.title, menu._items, default="__advert_flood__") visible, above, _below = frame._visible_slice(deep, deep.render_body(100), 6) top = [_ANSI.sub("", row).strip() for row in visible[:2]] assert top[0].startswith("SETTING") and top[0].endswith("DESCRIPTION") diff --git a/tests/test_gallery.py b/tests/test_gallery.py index c8929cb..a515dad 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -542,7 +542,6 @@ def _config_editor(cols: int, rows: int) -> Screen: _DEVICE_SNAPSHOT, {"tx_power": 14}, 1, AdvertPolicy(), reveal ), conceals=has_pin(_DEVICE_SNAPSHOT), - wrap=False, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) @@ -560,7 +559,7 @@ def _preferences(cols: int, rows: int) -> Screen: prefs.set("trace_cooldown_s", 2.5) title, items = _preference_items(prefs, {"history_days": 90}) return SelectScreen( - title, items, wrap=False, + title, items, footer_hint="↑↓ move · type to filter · Enter select · Esc back", ) diff --git a/tests/test_live_screens.py b/tests/test_live_screens.py index 3be5d67..0ef6ae0 100644 --- a/tests/test_live_screens.py +++ b/tests/test_live_screens.py @@ -366,7 +366,8 @@ async def test_trace_screen_composer_updates_the_spec() -> None: return "3d,f2,3d" # one forced hop: outbound, target, then the mirrored return screen, _ = _trace_screen(compose_path=compose) - screen.handle("down") # Trace is the last row, so ↓ wraps onto Compose path + for _ in range(len(screen._actions) - 1): + screen.handle("up") # the cursor opens on Trace, the last row; walk it up to Compose screen.handle("enter") await asyncio.sleep(0) assert asked == [""] diff --git a/tests/test_preferences.py b/tests/test_preferences.py index 522d579..d54ce3f 100644 --- a/tests/test_preferences.py +++ b/tests/test_preferences.py @@ -251,7 +251,7 @@ def _rows(prefs: Preferences, pending: Optional[dict] = None) -> tuple[str, list from meshterm.ui.tui import SelectScreen title, items = _menu_items(prefs, pending or {}) - screen = SelectScreen(title, items, wrap=False) + screen = SelectScreen(title, items) screen.note_viewport(len(items) + 4) # no paging: every row on screen at once return title, [line.strip() for line in _plain(screen.render_body(_WIDE)).splitlines()] @@ -316,7 +316,7 @@ def test_a_description_scrolls_under_a_pinned_setting_and_value() -> None: from meshterm.ui.tui import SelectScreen title, items = _menu_items(Preferences(), {}) - screen = SelectScreen(title, items, wrap=False) + screen = SelectScreen(title, items) screen.note_viewport(len(items) + 4) before = _plain(screen.render_body(72)).splitlines() cursor = next(line for line in before if line.lstrip().startswith("❯")) diff --git a/tests/test_repeater_admin.py b/tests/test_repeater_admin.py index f6f6c55..89c2278 100644 --- a/tests/test_repeater_admin.py +++ b/tests/test_repeater_admin.py @@ -353,7 +353,7 @@ def test_admin_menu_pins_the_column_header_over_the_category() -> None: ansi = re.compile(r"\x1b\[[0-9;]*m") title, items = _menu_items(NODE, {}, {}) - screen = SelectScreen(title, items, wrap=False) + screen = SelectScreen(title, items) for _ in range(18): # down past the first categories screen.handle("down") visible, above, _below = frame._visible_slice(screen, screen.render_body(72), 10) diff --git a/tests/test_tui.py b/tests/test_tui.py index f7e5ff3..ab5912d 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -95,13 +95,14 @@ def _menu() -> SelectScreen: return SelectScreen("pick", items, default=2) -def test_select_default_and_arrow_wrap() -> None: - """The default choice is preselected and Down wraps around the selectable choices.""" +def test_select_default_and_arrows_walk_the_choices() -> None: + """The default choice is preselected and the arrows step over the selectable choices.""" screen = _menu() assert _run(screen, "enter") == 2 # default is beta screen = _menu() screen.handle("down") # beta -> gamma - screen.handle("down") # gamma -> alpha (wrap) + screen.handle("up") # gamma -> beta + screen.handle("up") # beta -> alpha assert _run(screen, "enter") == 1 @@ -148,7 +149,6 @@ def test_select_delete_hint_follows_the_highlight() -> None: footer_hint="↑↓ move · Enter select · Esc quit", delete_hint="Del remove", filterable=False, - wrap=False, ) # On the non-deletable row, the footer is the plain base hint. assert "Del remove" not in screen.footer_hint @@ -247,13 +247,13 @@ def test_select_filter_matches_callable_title() -> None: assert _run(screen, "enter") == 1 -def test_select_no_wrap_clamps_at_the_ends() -> None: - """With wrap off, Up on the first row and Down on the last stay put (no cycling).""" +def test_select_clamps_at_the_ends() -> None: + """Up on the first row and Down on the last stay put — no cursor in the app rolls over.""" items = [Choice("alpha", 1), Choice("beta", 2), Choice("gamma", 3)] - screen = SelectScreen("pick", items, wrap=False) + screen = SelectScreen("pick", items) screen.handle("up") # already on the first choice — must not jump to the last assert _run(screen, "enter") == 1 - screen = SelectScreen("pick", items, default=3, wrap=False) # last choice + screen = SelectScreen("pick", items, default=3) # last choice screen.handle("down") # already on the last — must not wrap to the first assert _run(screen, "enter") == 3 @@ -312,7 +312,7 @@ def _trophy_shaped() -> SelectScreen: items += [Choice(f"rec{i}", ("l", i)) for i in range(6)] items += [section_heading("Widest arc"), Separator(" no records yet", style="muted")] items += [Choice(f"arc{i}", ("a", i)) for i in range(6)] - return SelectScreen("Trophy case", items, default=("l", 5), wrap=False) + return SelectScreen("Trophy case", items, default=("l", 5)) def _blocks(screen: SelectScreen) -> list[list[str]]: @@ -399,7 +399,7 @@ def _columned_menu(default: object = None) -> SelectScreen: items += [Choice(f"chan{i}", ("c", i)) for i in range(6)] items += [section_heading("Direct")] items += [Choice(f"peer{i}", ("d", i)) for i in range(8)] - return SelectScreen("pick", items, default=default, wrap=False) + return SelectScreen("pick", items, default=default) def test_select_pins_a_column_header_above_the_section_heading() -> None: @@ -636,26 +636,29 @@ def test_reorder_back_row_and_escape_cancel_discarding_moves() -> None: assert _run(screen, "enter") is CANCEL -def test_reorder_cursor_wraps_through_the_action_rows() -> None: - """↑ from the first row lands on the last row; ↓ from there wraps back to the top. +def test_reorder_cursor_runs_into_the_action_rows_and_clamps() -> None: + """↑ on the first row stays put; ↓ walks the list and on into the action rows, then stops. Clean, the list is the whole cursor space; once dirty the two action rows join it and - the wrap runs through them. + the cursor runs on through them to the bottom — never round to the top. """ screen = ReorderScreen("order", ["a", "b"]) - screen.handle("up") # wrap: onto the last list row, there being no action rows - assert screen._index == 1 - screen.handle("down") # wrap forward to the first list row + screen.handle("up") # already atop: no last row to fall onto assert screen._index == 0 + screen.handle("down") # onto the last list row, there being no action rows + assert screen._index == 1 + screen.handle("down") # and stop there + assert screen._index == 1 - screen.handle("enter") # grab row 0… - screen.handle("down") # …and carry it down: dirty, so Apply and Back join the space - screen.handle("enter") # drop it — the cursor rode it to the last list row + screen.handle("enter") # grab row 1… + screen.handle("up") # …and carry it up: dirty, so Apply and Back join the space + screen.handle("enter") # drop it — the cursor rode it to the first list row + screen.handle("down") # onto the second list row screen.handle("down") # off the list, onto Apply screen.handle("down") # …then the discard-Back row below it assert screen._index == 3 - screen.handle("down") # and round to the top again - assert screen._index == 0 + screen.handle("down") # the bottom of the space: it stays + assert screen._index == 3 def test_reorder_ignores_typed_characters_including_space() -> None: @@ -1110,13 +1113,23 @@ def test_button_dialog_enter_commits_highlighted() -> None: def test_button_dialog_arrows_move_highlight() -> None: - """←/→ (and Tab) move the highlight between the buttons, wrapping at the ends.""" + """←/→ move the highlight between the buttons and clamp at the ends; Tab still cycles. + + Tab is the exception: it has no reverse of its own, so on the last chip it comes round + rather than dead-ending. + """ screen = ButtonDialog("quit?", [("Yes", True), ("No", False)], default=0) screen.handle("right") # → No assert _run(screen, "enter") is False screen = ButtonDialog("quit?", [("Yes", True), ("No", False)], default=0) - screen.handle("left") # wraps → No + screen.handle("left") # already leftmost — stays on Yes + assert _run(screen, "enter") is True + screen = ButtonDialog("quit?", [("Yes", True), ("No", False)], default=1) + screen.handle("right") # already rightmost — stays on No assert _run(screen, "enter") is False + screen = ButtonDialog("quit?", [("Yes", True), ("No", False)], default=1) + screen.handle("tab") # No -> round to Yes + assert _run(screen, "enter") is True def test_button_dialog_shortcut_keys_commit_instantly() -> None: