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) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-05 16:04:17 -04:00
1 parent 407b893819
commit 9de428f6ca
27 files changed
+99 -87

No files matched your search

+9
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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:
+2 -2
View File
@@ -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)
+1 -2
View File
@@ -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:
+1 -2
View File
@@ -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()
-1
View File
@@ -513,7 +513,6 @@ class ContactListScreen(SelectScreen):
self._compose_items(),
prompt=prompt,
footer_hint=footer_hint,
wrap=False,
)
def _compose_items(self) -> list:
-1
View File
@@ -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",
)
+1 -1
View File
@@ -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:
-2
View File
@@ -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",
)
+4 -4
View File
@@ -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*
+1 -1
View File
@@ -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:
+1 -4
View File
@@ -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,
)
+4 -6
View File
@@ -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,
+11 -4
View File
@@ -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])
+2 -2
View File
@@ -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).
+13 -13
View File
@@ -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
+1 -2
View File
@@ -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:
+4 -5
View File
@@ -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:
-1
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -2
View File
@@ -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")
+1 -2
View File
@@ -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",
)
+2 -1
View File
@@ -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 == [""]
+2 -2
View File
@@ -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("❯"))
+1 -1
View File
@@ -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)
+36 -23
View File
@@ -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: