Every page with a highlight edge-scrolls, with no code of its own

Edge scroll reached only the eight screens that answered cursor_at_edge, one
gate each; the trace screen, the autocomplete prompt and anything built
tomorrow went without. Now no screen says where its edges are. An arrow goes
to the screen like any key, and the next paint reads the answer off the page:
a highlight on the same line, drawn the same, moved nothing, so the page
takes the line instead. Comparing the drawn line, not just its index, keeps a
list that scrolls in its own window from looking stuck. Arrows pressed faster
than the screen paints are judged together. All a screen supplies is its
highlight's line in cursor_line, which keeping it in view asked for already.
The eight gates and row_at_edge are gone.

The snap-back's arrow is now the one pointing at the off-screen highlight,
read from where the paint left it, so it no longer needs to know which edge
the page went past. Home and End take the page to its ends after the screen
has handled them, without assuming the highlight followed.

The remote CLI opts out (edge_scrolls = False): the line it keeps in view is
its prompt, and its arrows recall history. The autocomplete prompt now names
its highlighted suggestion, so a short box follows it; an empty select list's
"no matches" line stands in for the highlight; and the reorder list's Home
and End jump to its first and last rows, as on every list.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-04 17:15:15 -04:00
1 parent bdbf65312a
commit 3095e3b236
14 files changed
+315 -122

No files matched your search

+19 -13
View File
@@ -215,19 +215,25 @@ deliberately, one at a time, and say why in the code.
with no reverse of its own**, which cycles or it dead-ends — Tab on a button row, and
the picocalc-lyra 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.
- **Edge scroll** — what a clamped arrow does instead. With the highlight on the first
selectable row, ↑ scrolls the page up a line, and on the last, ↓ scrolls it down, until
the page's real top or bottom is in view: whatever sits above the first row or below
the last (a node's vitals, a list's lead-in, a closing note) can always be reached.
Home and End go to the page's very top and bottom with the highlight. The frame stops
following the highlight while a page is edge-scrolled, so it may leave the screen —
deliberately. **The snap-back** brings it home: while it is out of view, a key that
would move it or act on it (the other arrow, Enter, Delete) only brings it back into
view, jumping if it must, and does nothing else — nothing runs that can't be seen. Any
other key ends the edge scroll. It lives in `Screen.edge_scroll`, which the session asks
before `handle`; a screen opts in by answering `cursor_at_edge` (`Screen.row_at_edge`
for an index over rows), and one whose ↑↓ move no highlight (a prompt's history
recall) leaves it `None`.
- **Edge scroll** — what a clamped arrow does instead, on every page with a highlight,
screen or dialog. With the highlight on the first selectable row, ↑ scrolls the page up
a line, and on the last, ↓ scrolls it down, until the page's real top or bottom is in
view: whatever sits above the first row or below the last (a node's vitals, a list's
lead-in, a closing note) can always be reached. Home and End go to the page's very top
and bottom with the highlight. The frame stops following the highlight while a page is
edge-scrolled, so it may leave the screen — deliberately. **The snap-back** brings it
home: while it is out of view, a key that would move it toward the window or act on it
(the arrow pointing at it, Enter, Delete) only brings it back into view, jumping if it
must, and does nothing else — nothing runs that can't be seen. Any other key ends the
edge scroll. **No screen says where its edges are**: it lives in `Screen` and the frame,
and an arrow goes to `handle` like any key — the next paint reads the answer off the
page (`Screen.note_highlight`), where a highlight on the same line, drawn the same,
moved nothing, so the page takes the line instead. All a screen supplies is its
highlight's line in `cursor_line`, which keeping it in view asks of it anyway; with no
rows, a list's empty state stands in. A page with no highlight (the map, which pans; a
plain page, whose ↑↓ already scroll) has nothing to edge, and one whose kept line is
not a highlight the arrows walk — the remote CLI's prompt, ↑↓ recalling history — sets
`edge_scrolls = False`.
- Grouped-list section headings use `section_heading("Label")` → `── Label ──` in the
bold `heading` grey, never the frame's accent: a rule in the border's colour reads as
part of the frame. A chat's day divider wears the same dress. That is also what makes a heading *sticky* (it pins to the top row while its section
-9
View File
@@ -360,15 +360,6 @@ class ChatScreen(Screen):
"""Keep the picked reply target in view; otherwise free scroll (managed by stick)."""
return self._selected_line
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the oldest message picked, going up; never going down.
Above the oldest message sit its sender's line and the day it was sent, which ↑ on
it scrolls into view. Below the newest there is only the compose line, always shown,
and ↓ past the newest already leaves the pick for it.
"""
return step < 0 and (not self._messages or self._selected == 0)
# --- outgoing byte budget ------------------------------------------------
def _byte_limit(self) -> int:
-4
View File
@@ -268,10 +268,6 @@ class MessagePathsScreen(Screen):
"""
return self._cursor
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the first arrival going up, the last going down."""
return self.row_at_edge(self._index, len(self._arrivals), step)
# --- rendering -------------------------------------------------------------
def render_body(self, width: int) -> list[str]:
-9
View File
@@ -724,15 +724,6 @@ class NodeDetailScreen(Screen):
"""
return self._cursor
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the tab's first row going up, its last going down.
On a short frame the vitals above the first action and the rows under the last
are what edge scroll brings back into view.
"""
focus = self._focusables()
return self.row_at_edge(self._row_index % len(focus) if focus else 0, len(focus), step)
def _switch_tab(self, delta: int) -> None:
"""Move the active tab, resetting the cursor and list window to that tab's top."""
if len(self._tabs) < 2:
-4
View File
@@ -678,10 +678,6 @@ class PathComposerScreen(Screen):
"""The body line of the highlighted row, so the session keeps it visible."""
return getattr(self, "_cursor_row", None)
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the first suggestion going up, the last going down."""
return self.row_at_edge(self._index, len(self._rows()), step)
# --- input ---------------------------------------------------------------------
def _insert_hop(self, node: str) -> None:
-9
View File
@@ -414,15 +414,6 @@ class RecordScreen(Screen):
"""Keep the selected action visible while arrowing; scroll free once paging."""
return self._cursor if self._follow else None
def cursor_at_edge(self, step: int) -> bool | None:
"""Edge scroll's gate: the first action going up, the last going down.
``None`` on the Area tab, whose keys move nothing.
"""
if self._tab == _TAB_AREA:
return None
return self.row_at_edge(self._index, len(self._actions), step)
def _header(self) -> Text:
"""The one-line identity above the strip: the discipline, the standing, the metric.
+3
View File
@@ -45,6 +45,9 @@ class RemoteCliScreen(Screen):
"""A shell-like screen onto one remote node's CLI. The owner does the radio work."""
floating = False
#: The line kept in view is the prompt, not a highlight: ↑↓ recall history as a shell's
#: do, and the transcript scrolls by the page keys alone — so no edge scroll here.
edge_scrolls = False
@property
def picocalc_lyra_lane(self):
+18 -5
View File
@@ -62,6 +62,16 @@ def _window_start(
return scroll
def _cursor_side(cursor: int | None, start: int, rows: int) -> int:
"""Where a window of ``rows`` lines from ``start`` leaves ``cursor``: 0 in it, -1 above, +1 below.
No highlight at all counts as in view — there is nothing to bring back.
"""
if cursor is None or start <= cursor < start + rows:
return 0
return -1 if cursor < start else 1
def _visible_slice(screen: Screen, lines: list[str], viewport: int) -> tuple[list[str], bool, bool]:
"""Clamp the screen's scroll and return the visible lines plus clip flags.
@@ -86,9 +96,12 @@ def _visible_slice(screen: Screen, lines: list[str], viewport: int) -> tuple[lis
# screenful and clamp to the content (see :meth:`Screen.note_metrics`).
screen.note_metrics(total, viewport)
cursor = screen.cursor_line()
# Edge scroll: a page scrolled past its highlight leaves it where it is, off screen if
# need be, until a key brings it back (see Screen.edge_scroll) — so only a page that
# isn't edge-scrolled has its highlight followed.
# Edge scroll: the arrows pressed since the last paint get their verdict first — one
# that left the highlight where it was scrolls the page instead (Screen.note_highlight).
# A page scrolled past its highlight leaves it where it is, off screen if need be, until
# a key brings it back (see Screen.edge_scroll) — so only a page that isn't
# edge-scrolled has its highlight followed.
screen.note_highlight(cursor, lines)
follow = None if screen.edge_scrolled else cursor
scroll = screen.scroll
@@ -124,13 +137,13 @@ def _visible_slice(screen: Screen, lines: list[str], viewport: int) -> tuple[lis
pinned = screen.sticky_rows(start) or pinned
start = _window_start(scroll, total, viewport, len(pinned), follow)
cap = max(1, viewport - len(pinned))
screen.note_cursor_shown(cursor is None or start <= cursor < start + cap)
screen.note_cursor_side(_cursor_side(cursor, start, cap))
visible = pinned + lines[start : start + cap]
more_below = start + cap < total
visible = visible + [""] * (viewport - len(visible))
return visible, True, more_below
screen.note_cursor_shown(cursor is None or scroll <= cursor < scroll + viewport)
screen.note_cursor_side(_cursor_side(cursor, scroll, viewport))
visible = lines[scroll : scroll + viewport]
more_above = scroll > 0
more_below = scroll + viewport < total
+19 -4
View File
@@ -897,6 +897,8 @@ class AutocompleteScreen(_KeylessDialog):
#: Cap the suggestion list so it never dominates the dialog.
MAX_SUGGESTIONS = 8
#: Home and End move the field's caret, so edge scroll leaves them alone.
home_end_jumps = False
def __init__(
self,
@@ -927,6 +929,7 @@ class AutocompleteScreen(_KeylessDialog):
self._validate = validate
self._error = ""
self._sugg = 0
self._cursor: int | None = None
@property
def dialog_width(self) -> int:
@@ -951,22 +954,34 @@ class AutocompleteScreen(_KeylessDialog):
return matches[: self.MAX_SUGGESTIONS]
def render_body(self, width: int) -> list[str]:
"""Render the optional prompt, the field, the matching suggestions, and any error."""
"""Render the optional prompt, the field, the matching suggestions, and any error.
The suggestions are drawn a row at a time so the highlighted one's body line is
known (see :meth:`cursor_line`).
"""
parts: list[RenderableType] = []
if self._prompt:
parts.append(Text(self._prompt))
parts.append(Text(""))
parts.append(self._editor.render())
lines = render_lines(Group(*parts), width)
suggestions = self._suggestions()
self._sugg = max(0, min(self._sugg, len(suggestions) - 1)) if suggestions else 0
self._cursor = None
for i, sug in enumerate(suggestions):
is_sel = i == self._sugg
row = Text(("❯ " if is_sel else " ") + sug, style="cursor" if is_sel else "muted")
row.truncate(width)
parts.append(row)
if is_sel:
self._cursor = len(lines)
lines.extend(render_lines(row, width))
if self._error:
parts.append(Text(self._error, style="err"))
return render_lines(Group(*parts), width)
lines.extend(render_lines(Text(self._error, style="err"), width))
return lines
def cursor_line(self) -> int | None:
"""The highlighted suggestion's body line, kept in view on a box too short for all."""
return self._cursor
def handle(self, action: str, data: str = "") -> None:
"""Edit the field, move/accept suggestions, submit on Enter, or cancel on Esc."""
+89 -50
View File
@@ -35,11 +35,11 @@ CANCEL = object()
POP_ALL = object()
#: Edge scroll's keys (see :meth:`Screen.edge_scroll`): the arrows and the way each steps,
#: the jumps to either end, and the keys that bring an off-screen highlight back into view
#: before doing anything — every key that would move it or act on it.
#: the jumps to either end, and the keys besides the arrow pointing at it that bring an
#: off-screen highlight back into view before doing anything — the keys that act on it.
_EDGE_STEPS = {"up": -1, "down": 1}
_EDGE_ENDS = {"home": -1, "ctrl_home": -1, "end": 1, "ctrl_end": 1}
_SNAP_BACK_ACTIONS = frozenset({"up", "down", "enter", "delete"})
_SNAP_BACK_ACTIONS = frozenset({"enter", "delete"})
class PopToMenu(BaseException):
@@ -133,9 +133,15 @@ class Screen:
bare: bool = False
banner: Sequence[str] | None = None
footnote: str | None = None
#: Whether Home and End jump the highlight to the first and last row, so edge scroll
#: takes the page to its very top and bottom with it (see :meth:`edge_scroll`). Off where
#: they move a text caret instead — the chat's compose line.
#: Whether the page edge-scrolls (see :meth:`edge_scroll`). On for every screen, and
#: nothing to do on one whose page has no highlight (:meth:`cursor_line` ``None``). Off
#: only where the line :meth:`cursor_line` keeps in view is not a highlight the arrows
#: walk — the remote CLI's prompt, whose ↑↓ recall history the way a shell's do.
edge_scrolls: bool = True
#: Whether Home and End take the page to its very top and bottom once the screen has
#: handled them (see :meth:`edge_scroll`) — a list's Home and End jump its highlight to
#: the first and last row, and the page follows to its ends. Off where they move a text
#: caret instead — the chat's compose line, a prompt's field.
home_end_jumps: bool = True
@property
@@ -223,10 +229,16 @@ class Screen:
self._viewport_floor = 0
self._width_floor = 0
# Edge scroll (see :meth:`edge_scroll`): whether ↑↓ have scrolled the window past the
# highlight, so the frame has stopped pulling it into view; and whether the last
# paint showed it, which decides the snap-back. Recorded by the frame.
# highlight, so the frame has stopped pulling it into view; the arrows handed to
# :meth:`handle` since the last paint, net, awaiting that paint's verdict; the
# highlight as the last paint drew it, ``(body line, drawn line)``, which the verdict
# compares against; and which side of the window the last paint left it on (0 in
# view, -1 above, +1 below), which decides the snap-back. The last two are the
# frame's to record (:meth:`note_highlight`, :meth:`note_cursor_side`).
self._edge_scrolled = False
self._cursor_shown = True
self._edge_steps = 0
self._highlight_mark: tuple[int, str] | None = None
self._cursor_side = 0
# --- rendering -----------------------------------------------------------
@@ -271,7 +283,9 @@ class Screen:
"""Return a body line that must stay visible, or ``None`` for free scrolling.
Selection/text screens return the active row so the session can keep it in view;
plain scroll screens return ``None``.
plain scroll screens return ``None``. Naming the highlight's line here is also all a
screen does to edge-scroll (see :meth:`edge_scroll`): the frame reads its edges off
the page, so no screen says where they are.
"""
return None
@@ -362,76 +376,101 @@ class Screen:
# --- edge scroll ---------------------------------------------------------
def cursor_at_edge(self, step: int) -> bool | None:
"""Whether the highlight can go no further ``step`` way (-1 up, +1 down).
The gate of :meth:`edge_scroll`. ``None`` (the default) where ↑↓ move no highlight —
a plain scroll screen, a prompt whose arrows recall history — and edge scroll stays
out of the way. A screen whose ↑↓ walk a highlight over rows answers for it: ``True``
on the first row going up and the last going down (and either way with no row to
highlight at all), ``False`` everywhere else — most simply through
:meth:`row_at_edge`.
"""
return None
@staticmethod
def row_at_edge(index: int, count: int, step: int) -> bool:
""":meth:`cursor_at_edge`'s answer for a highlight at ``index`` of ``count`` rows."""
if count <= 0:
return True
return index <= 0 if step < 0 else index >= count - 1
def edge_scroll(self, action: str) -> bool:
"""Edge scroll and the snap-back: take ``action`` here, before :meth:`handle` sees it.
**Edge scroll** (JP, 2026-10-04): where the highlight can go no further, an arrow
scrolls the page a line instead, so whatever sits above the first selectable row or
below the last — a node's vitals, a list's lead-in, a closing note — can always be
brought into view. The frame stops pulling the highlight into view while the page is
edge-scrolled, so it may scroll off screen; that is deliberate. **Home** and **End**
go the same way: the highlight jumps to the first or last row as ever, and the page
to its very top or bottom.
**Edge scroll** (JP, 2026-10-04) is how every page with a highlight scrolls: where
the highlight can go no further, an arrow scrolls the page a line instead, so
whatever sits above the first selectable row or below the last — a node's vitals, a
list's lead-in, a closing note — can always be brought into view. The frame stops
pulling the highlight into view while the page is edge-scrolled, so it may scroll
off screen; that is deliberate. **Home** and **End** go the same way: the screen
takes them as ever (a list's highlight jumps to its first or last row), and the
page goes to its very top or bottom.
**The snap-back**: while the highlight is off screen, a key that would move it or act
on it — the opposite arrow, Enter, Delete — first brings it back into view,
jumping if it has to, and does nothing else. Nothing is run that cannot be seen.
**The snap-back**: while the highlight is off screen, a key that would move it toward
the window or act on it — the arrow pointing at it, Enter, Delete — first brings it
back into view, jumping if it has to, and does nothing else. Nothing is run that
cannot be seen.
**No screen says where its edges are** (JP, 2026-10-04: one rule, inherited, never
a gate written screen by screen). An arrow goes to :meth:`handle` like any key, and
the next paint reads the answer off the page (:meth:`note_highlight`): a highlight
that moved is followed as ever, and one that did not was at its edge, so the page
takes the line instead. All a screen supplies is its highlight's line, through
:meth:`cursor_line` — which keeping the highlight in view asked of it already.
Any other key ends the edge scroll before :meth:`handle` sees it (a typed filter, a
tab switch, a page key), so the frame follows the highlight again from there.
tab switch, a page key), so the frame follows the highlight again from there; an
arrow that turns out to be at the edge re-arms it at the paint.
Returns:
Whether the key was taken here; the session passes it to :meth:`handle` only
when it wasn't.
"""
if self.cursor_at_edge(-1) is None:
return False
if not self.edge_scrolls or self._highlight_mark is None:
return False # no highlight on the page: every key is the screen's own
step = _EDGE_STEPS.get(action)
if step is not None and self.cursor_at_edge(step):
self._edge_scrolled = True
self.scroll_lines(step)
return True
if self._edge_scrolled and not self._cursor_shown and action in _SNAP_BACK_ACTIONS:
if (
self._edge_scrolled
and self._cursor_side
and (step == self._cursor_side or action in _SNAP_BACK_ACTIONS)
):
self._edge_scrolled = False # the snap-back: this press only brings it home
self._edge_steps = 0
return True
if action in _EDGE_ENDS and self.home_end_jumps:
self.handle(action)
self._edge_scrolled = True
self._edge_steps = 0
if _EDGE_ENDS[action] < 0:
self.scroll_to_top()
else:
self.scroll = self._scroll_total # the frame clamps it to the last screenful
return True
if step is not None:
self._edge_steps += step # the paint finds whether it moved the highlight
self._edge_scrolled = False
return False
def note_highlight(self, cursor: int | None, lines: Sequence[str]) -> None:
"""Record the highlight as this paint draws it, and judge the arrows pressed since.
The frame calls this each paint, before it decides where the page sits: ``cursor``
is :meth:`cursor_line` and ``lines`` the body just rendered. Every arrow since the
last paint went to :meth:`handle` (see :meth:`edge_scroll`), and each either moved
the highlight or found it at its edge. The page says which: a highlight on the same
body line, *drawn the same*, moved nothing, so the page scrolls those lines instead
and the frame stops following. Comparing the drawn line rather than only its index
is what tells a highlight that stayed put from one in a list that scrolls in its own
window (see :class:`ListWindow`), where it holds one line while the rows pass under
it.
Arrows pressed faster than the screen paints are judged together, so a held arrow
that reaches the last row part-way through a batch scrolls from the next one on.
"""
mark = None
if self.edge_scrolls and cursor is not None and 0 <= cursor < len(lines):
mark = (cursor, lines[cursor])
if mark is None:
self._edge_scrolled = False
elif self._edge_steps and mark == self._highlight_mark:
self._edge_scrolled = True
self.scroll_lines(self._edge_steps)
self._edge_steps = 0
self._highlight_mark = mark
@property
def edge_scrolled(self) -> bool:
"""Whether the page is edge-scrolled, so the frame leaves the highlight where it is."""
return self._edge_scrolled
def note_cursor_shown(self, shown: bool) -> None:
"""Record whether the last paint showed the highlight (the frame calls this)."""
self._cursor_shown = shown
def note_cursor_side(self, side: int) -> None:
"""Record where the last paint left the highlight: 0 in view, -1 above, +1 below.
The frame calls this; it decides the snap-back (see :meth:`edge_scroll`).
"""
self._cursor_side = side
def resolve(self, value: Any) -> None:
"""Resolve this screen's future, committing ``value`` (or :data:`CANCEL`).
+10 -8
View File
@@ -795,6 +795,9 @@ class SelectScreen(Screen):
if detail is not None and _plain(detail):
lines.append(self._detail_drawer(detail, width))
if not choices:
# With no row to highlight the empty state holds its place: kept in view, and
# the page still edge-scrolls past it to whatever sits above and below.
cursor_at = len(lines)
lines.append(render_to_ansi(Text("no matches", style="muted"), width))
# Remember where the highlighted row landed so the session can keep it in view.
self._cursor = cursor_at
@@ -908,10 +911,6 @@ class SelectScreen(Screen):
"""Return the body line index of the highlighted row."""
return getattr(self, "_cursor", None)
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the first choice going up, the last going down."""
return self.row_at_edge(self._index, len(self._choices()), step)
# --- input ---------------------------------------------------------------
def handle(self, action: str, data: str = "") -> None:
@@ -1110,10 +1109,6 @@ class ReorderScreen(Screen):
"""Return the body line index of the cursor row, so the session keeps it in view."""
return getattr(self, "_cursor", None)
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the first row going up, the last action going down."""
return self.row_at_edge(self._index, len(self._order) + len(self._actions()), step)
def handle(self, action: str, data: str = "") -> None:
"""Move the cursor, carry a grabbed row, grab/drop, run an action, or cancel on Esc."""
n = len(self._order)
@@ -1143,6 +1138,13 @@ class ReorderScreen(Screen):
self._index += 1
elif not self._grabbed and total:
self._index = min(total - 1, self._index + 1)
elif action in ("home", "ctrl_home") and not self._grabbed and total:
# Home and End jump to the first row and the last, as on every list, and edge
# scroll takes the page to its ends with them. A grabbed row is carried a step
# at a time only, so they leave it where it is.
self._index = 0
elif action in ("end", "ctrl_end") and not self._grabbed and total:
self._index = total - 1
elif action == "enter":
if self._index < n:
self._grabbed = not self._grabbed # Enter grabs a row, Enter again drops it
+4 -3
View File
@@ -2140,9 +2140,10 @@ class TuiSession:
self._dispatch("paste", text)
return
top = self.top
# Edge scroll and its snap-back get the key first (Screen.edge_scroll): an arrow
# past the last row a highlight can reach scrolls the page instead, and a key that
# would act on a highlight scrolled out of view brings it back before doing anything.
# Edge scroll and its snap-back get the key first (Screen.edge_scroll): a key that
# would act on a highlight scrolled out of view brings it back before doing anything,
# and Home/End take the page to its ends. An arrow goes on to the screen, and the
# next paint scrolls the page instead if it moved nothing (Screen.note_highlight).
if top is not None and not top.edge_scroll(action):
top.handle(action, data)
self.invalidate()
-4
View File
@@ -386,10 +386,6 @@ class TxSweepScreen(Screen):
"""The highlighted action row while ↑/↓ are in use; free scrolling otherwise."""
return getattr(self, "_cursor", None) if self._pin_cursor else None
def cursor_at_edge(self, step: int) -> bool:
"""Edge scroll's gate: the first action going up, the last going down."""
return self.row_at_edge(self._index, len(self._actions), step)
def _action_text(self, key: str, selected: bool) -> Text:
"""One action row: pointer, glyph, and label (current value inlined)."""
text = Text("❯ " if selected else " ", style="cursor" if selected else "")
+153
View File
@@ -397,6 +397,159 @@ def test_a_screen_without_a_highlight_keeps_its_own_arrows() -> None:
assert not screen.edge_scroll(action)
class _Rows(Screen):
"""A screen with no edge-scroll code at all: a lead-in, a highlight over rows, a note.
Its ↑↓ clamp as every cursor's do, its Home and End move nothing, and it names its
highlight's line in ``cursor_line`` — which is all a screen supplies. ``window`` draws
the rows that many at a time, scrolling with the highlight as a ListWindow does.
"""
def __init__(self, count: int = 3, *, window: int | None = None) -> None:
super().__init__()
self._count = count
self._window = window or count
self._index = 0
self._top = 0
self._cursor: int | None = None
def render_body(self, width: int) -> list[str]:
self._top = max(min(self._top, self._index), self._index - self._window + 1)
lines = [f"lead {i}" for i in range(4)]
for i in range(self._top, self._top + self._window):
if i == self._index:
self._cursor = len(lines)
lines.append(("❯ " if i == self._index else " ") + f"row {i}")
lines.append("note")
return lines
def cursor_line(self) -> int | None:
return self._cursor
def handle(self, action: str, data: str = "") -> None:
if action == "up":
self._index = max(0, self._index - 1)
elif action == "down":
self._index = min(self._count - 1, self._index + 1)
def test_every_screen_with_a_highlight_edge_scrolls() -> None:
"""Edge scroll is inherited: a screen that only names its highlight's line has it.
_Rows says nothing about where its edges are — the paint reads them off the page.
"""
screen = _Rows()
assert _view(screen) == ["lead 1", "lead 2", "lead 3", "❯ row 0"]
_press(screen, "up") # row 0 is the first row: the page takes the line
assert _view(screen) == ["lead 0", "lead 1", "lead 2", "lead 3"]
_press(screen, "down") # the snap-back
assert "❯ row 0" in _view(screen)
for _ in range(2):
_press(screen, "down")
_view(screen)
_press(screen, "down") # row 2 is the last: the note comes into view
assert _view(screen) == ["row 0", "row 1", "❯ row 2", "note"]
def test_several_arrows_before_a_paint_scroll_as_many_lines() -> None:
"""Arrows faster than the paint are judged together: three at the edge, three lines."""
screen = _Rows()
_press(screen, "up") # before any paint: nothing on the page to judge yet
_view(screen)
for _ in range(2):
_press(screen, "down")
_view(screen)
for _ in range(3):
_press(screen, "down")
view = _view(screen)
assert view == ["row 0", "row 1", "❯ row 2", "note"] # clamped at the page's end
def test_a_list_scrolling_in_its_own_window_is_not_at_its_edge() -> None:
"""A highlight holding its line while rows pass under it has moved: no edge scroll.
Walking ↓ down a windowed list keeps the highlight on the window's last line, so the
line's index alone can't tell it from one that stayed put; the line as drawn can.
"""
screen = _Rows(6, window=2)
_view(screen)
_press(screen, "down")
_view(screen)
before = screen.scroll
_press(screen, "down") # row 2: the same body line as row 1, drawn differently
assert "❯ row 2" in _view(screen)
assert not screen.edge_scrolled and screen.scroll == before
for _ in range(3):
_press(screen, "down")
_view(screen)
_press(screen, "down") # row 5 is the last
assert _view(screen)[-1] == "note" and screen.edge_scrolled
def test_a_screen_can_keep_its_arrows_from_edge_scroll() -> None:
"""``edge_scrolls`` off — the remote CLI, whose ↑↓ recall history — never scrolls."""
screen = _Rows()
screen.edge_scrolls = False
view = _view(screen)
_press(screen, "up")
assert _view(screen) == view and not screen.edge_scrolled
def test_home_that_moves_no_highlight_leaves_the_arrows_to_it() -> None:
"""Home takes the page to its top; only the page says where the highlight went.
_Rows's Home moves nothing, so ↑ afterwards is still a step up the rows — the arrow
pointing away from an off-screen highlight goes to the screen, and the highlight
comes back into view with it.
"""
screen = _Rows()
_view(screen)
for _ in range(2):
_press(screen, "down")
_view(screen)
_press(screen, "home")
assert _view(screen)[0] == "lead 0"
_press(screen, "up")
assert "❯ row 1" in _view(screen)
def test_a_list_with_no_rows_still_edge_scrolls() -> None:
"""With nothing to highlight, the empty state holds the highlight's place."""
screen = _edge_list()
_view(screen)
_press(screen, "text", "z")
_press(screen, "text", "z")
assert _view(screen)[-1] == "no matches"
_press(screen, "up")
view = _view(screen)
assert "no matches" not in view and view[-1] == "closing note"
def test_reorder_home_and_end_reach_the_ends() -> None:
"""Home and End jump the reorder list's highlight too, as on every list."""
screen = ReorderScreen("order", ["a", "b", "c"])
screen.handle("end")
assert any(line.startswith("❯ c") for line in _view(screen))
screen.handle("home")
assert any(line.startswith("❯ a") for line in _view(screen))
def test_autocomplete_keeps_its_highlighted_suggestion_in_view() -> None:
"""A box too short for every suggestion follows the highlight, and edge-scrolls."""
screen = AutocompleteScreen("t", [f"opt{i}" for i in range(8)], prompt="pick one")
_view(screen, 5)
for _ in range(7):
_press(screen, "down")
_view(screen, 5)
assert _view(screen, 5)[-1] == "❯ opt7"
for _ in range(7):
_press(screen, "up")
_view(screen, 5)
assert _view(screen, 5)[0] == "❯ opt0"
_press(screen, "up") # the first suggestion: the field comes back above it
assert _view(screen, 5)[1] == "❯ opt0"
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)]