diff --git a/CLAUDE.md b/CLAUDE.md index 805ede5..fb2c5a3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -233,7 +233,12 @@ deliberately, one at a time, and say why in the code. 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`. + `edge_scrolls = False`. **What no arrow walks is page, never a private window.** A + `ListWindow` is for a list the highlight walks (`fit` takes the highlight, with no + default), since every row it hides must be one an arrow reaches by walking onto it. + A log or a results table goes on the page, where the frame scrolls it. The trace + screen's results were once windowed under its actions: the page came out exactly the + screen's height, so ↓ on the last action did nothing while `↓ n more` sat under it. - 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 diff --git a/meshterm/ui/trace_screen.py b/meshterm/ui/trace_screen.py index 160f1ed..aa5e73b 100644 --- a/meshterm/ui/trace_screen.py +++ b/meshterm/ui/trace_screen.py @@ -64,9 +64,9 @@ the next Trace will walk — composed by hand, or auto-resolved from the device' route or the stored history and labelled with that provenance — else the most recent stored trace), the run's robust aggregates, the wire spec that route amounts to, the action list, then the results — per-hop median SNR with quality bars and the -individual traces newest-first — scrolling in a window beneath the pinned controls: -PgUp/PgDn/Home/End slide it (↑/↓ belong to the action cursor), and faint ``↑/↓ n -more`` markers count what the window hides. +individual traces newest-first — on the same page: ↑/↓ belong to the action cursor and +edge-scroll on into the results past the last action, and PgUp/PgDn/Home/End page the +whole screen. Both path lanes draw through THE path widget (:mod:`~meshterm.ui.pathline`) and break at hop boundaries under their own value column: a route folds between nodes — never @@ -102,7 +102,7 @@ from .menus import icon_lane, icon_mark, marked_label, section_heading from .pathline import PathHop, PathLine, cut_to, hops_atom, path_line from .theme import snr_style from .tui.render import render_lines, render_to_ansi -from .tui.screen import ListWindow, Screen +from .tui.screen import Screen from .tui.spinner import Spinner, spinner_interval from .widgets import NodeResolver, highlighted_hash, link_text, route_path @@ -363,9 +363,10 @@ class TraceScreen(Screen): ↑/↓ move the cursor over the action rows and Enter commits the selected one — the cursor opens on Trace, so plain Enter still just traces. The results (per-hop - medians and the trace log) scroll in a window beneath the pinned controls with - PgUp/PgDn/Home/End, and Esc (or the Back row) backs out, cancelling any - in-flight trace; already-recorded traces are kept. + medians and the trace log) follow the actions on the page: ↓ off the last action + edge-scrolls on into them, PgUp/PgDn/Home/End page the whole screen, and Esc (or + the Back row) backs out, cancelling any in-flight trace; already-recorded traces + are kept. """ floating = False @@ -498,9 +499,6 @@ class TraceScreen(Screen): self._actions: tuple[str, ...] = tuple(actions) self._index = self._actions.index("trace") self._pin_cursor = False # only pin the view while ↑/↓ are actually in use - #: The results window under the pinned actions (per-hop medians + trace - #: log); PgUp/PgDn slide it while the route and controls hold still. - self._tail_window = ListWindow() # --- state ----------------------------------------------------------------- @@ -670,15 +668,15 @@ class TraceScreen(Screen): def handle(self, action: str, data: str = "") -> None: """Move the action cursor, commit the selected action, scroll, or dismiss. - ↑/↓ belong to the action cursor; PgUp/PgDn/Home/End slide the results - window beneath the pinned controls, so a long trace log can be read while - the route and actions stay on screen. + ↑/↓ belong to the action cursor, and past the last action edge scroll carries + them on down the results; PgUp/PgDn/Home/End page the whole screen, the + cursor left where it was until an arrow brings it back. """ if action == "enter": self._commit_action() elif action == "up": # 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. + # a highlight that leaps end to end takes the page with it. self._index = max(0, self._index - 1) self._pin_cursor = True elif action == "down": @@ -686,16 +684,16 @@ class TraceScreen(Screen): self._pin_cursor = True elif action == "pageup": self._pin_cursor = False - self._tail_window.top -= self._tail_window.page + self.scroll_pages(-1) elif action in ("pagedown", "space"): self._pin_cursor = False - self._tail_window.top += self._tail_window.page + self.scroll_pages(1) elif action in ("home", "ctrl_home"): self._pin_cursor = False - self._tail_window.top = 0 + self.scroll_to_top() elif action in ("end", "ctrl_end"): self._pin_cursor = False - self._tail_window.to_end() + self.scroll_to_bottom() elif action == "escape": self.cancel() self.resolve(None) @@ -841,24 +839,16 @@ class TraceScreen(Screen): # trace-settings group. if key in ("explore", "reverse", "samples"): lines.append("") - tail = self._tail_lines(stats, current, width) - if tail: - # The results scroll in a window beneath the pinned controls (see - # ListWindow): the route and actions never leave the screen, however - # long a sampling session's log grows. - win = max(3, self._scroll_viewport - len(lines)) - top, count = self._tail_window.fit(len(tail), win) - if top > 0: - lines.append(render_to_ansi(ListWindow.marker(top, "above"), width)) - lines.extend(tail[top : top + count]) - below = len(tail) - top - count - if below > 0: - lines.append(render_to_ansi(ListWindow.marker(below, "below"), width)) + # The results are page, not a window of their own: nothing highlights them, so a + # private window would hide its rows from the arrows and leave the frame a page + # exactly as tall as the screen — edge scroll would have nothing to scroll (see + # ListWindow). The frame scrolls them, ↓ off the last action carries on into them. + lines.extend(self._tail_lines(stats, current, width)) self._scroll_total = max(1, len(lines)) return lines def _tail_lines(self, stats: TraceStats, current: TraceResult | None, width: int) -> list[str]: - """The windowed results block: per-hop medians, then the trace log. + """The results block under the actions: per-hop medians, then the trace log. Memoized per traces revision while idle — the block re-renders every stored trace, and between completions nothing in it moves. A *running* trace skips diff --git a/meshterm/ui/tui/screen.py b/meshterm/ui/tui/screen.py index 3c5596f..26d31e6 100644 --- a/meshterm/ui/tui/screen.py +++ b/meshterm/ui/tui/screen.py @@ -646,6 +646,16 @@ class ListWindow: Each screen owns its own cursor, so this is a rule its ``handle`` keeps, not something this class can enforce. + **A window is for a list the highlight walks**, which is why :meth:`fit` and + :meth:`fit_blocks` take the highlight with no default. Every row a window hides must be + one the arrows can reach by walking onto it, since the window follows the highlight. + Rows nothing ever highlights (a log, a results table) belong to the page instead, + where the frame scrolls them and edge scroll (:meth:`Screen.edge_scroll`) reaches them. + Windowed privately, they made the page exactly as tall as the screen, so the frame + saw nothing to scroll: ↓ on the last row did nothing while a ``↓ n more`` sat under it + (the trace screen's results, JP 2026-10-04). ``None`` is still a highlight argument, + for a list whose rows the highlight has just left for another part of the same screen. + Attributes: top: First list row the window shows (clamped by :meth:`fit` each paint). page: Rows the window carried on the last :meth:`fit` — the paging stride. @@ -656,7 +666,7 @@ class ListWindow: self.top = 0 self.page = 6 - def fit(self, n: int, win: int, index: int | None = None) -> tuple[int, int]: + def fit(self, n: int, win: int, index: int | None) -> tuple[int, int]: """Settle the window over ``n`` rows into ``win`` lines: ``(top, count)``. The edge markers eat the window's boundary rows exactly when rows hide @@ -666,8 +676,10 @@ class ListWindow: Args: n: Total list rows. win: Lines the window may spend — on content and markers alike. - index: A highlighted row that must stay visible, or ``None`` when the - window scrolls free (a cursor-less log; ``top`` is just clamped). + index: The highlighted row, which must stay visible, or ``None`` while the + highlight is elsewhere on the screen (``top`` is then just clamped). + Required: a window over rows no highlight walks hides them from the + arrows (see the class docstring). Returns: The first visible row and how many rows to draw. Rows hidden above @@ -694,7 +706,7 @@ class ListWindow: self.page = count return top, count - def fit_blocks(self, heights: list[int], win: int, index: int | None = None) -> tuple[int, int]: + def fit_blocks(self, heights: list[int], win: int, index: int | None) -> tuple[int, int]: """Settle the window over variable-height rows: ``(top, count)`` blocks to draw. The hanging-wrap sibling of :meth:`fit`, for a list whose rows are *blocks* of @@ -706,8 +718,9 @@ class ListWindow: Args: heights: Rendered line count per list row. win: Lines the window may spend — on content and markers alike. - index: A highlighted row that must stay visible, or ``None`` when the window - scrolls free (``top`` is then just clamped). + index: The highlighted row, which must stay visible, or ``None`` while the + highlight is elsewhere on the screen (``top`` is then just clamped). + Required, as for :meth:`fit`. Returns: The first visible row and how many rows to draw, as :meth:`fit` returns them. diff --git a/tests/test_live_screens.py b/tests/test_live_screens.py index 2b5c4b6..35c2f47 100644 --- a/tests/test_live_screens.py +++ b/tests/test_live_screens.py @@ -322,6 +322,44 @@ async def test_trace_screen_multi_trace_reports_progress_and_abort_keeps_landed( assert session.stack == [] +async def test_trace_results_are_page_that_edge_scroll_reaches() -> None: + """Once traced, ↓ on the last action scrolls on down the results to the oldest trace. + + The results used to sit in a window of their own, sized to whatever the controls + left: the page was then exactly the screen's height, so the frame had nothing to + scroll and ↓ on Trace did nothing while ``↓ n more`` sat under it. + """ + from meshterm.ui.tui import frame + + screen, _ = _trace_screen() + for _ in range(12): # a log long enough to carry the actions off the top + screen.start_trace() + await screen._worker + + def view() -> list[str]: + lines = screen.render_body(72) + visible, _above, _below = frame._visible_slice(screen, lines, 16) + return [_plain([line]).strip() for line in visible] + + def press(action: str) -> None: + if not screen.edge_scroll(action): + screen.handle(action) + + body = _plain(screen.render_body(72)) + assert "more" not in body # every result is on the page; nothing is windowed off + view() + press("down") # Trace is the last action: the cursor pins on it… + view() + for _ in range(30): + press("down") # …and each further ↓ scrolls the page a line + view() + page = view() + assert page[-1].startswith("#1") # the oldest trace closes the page + assert not any("❯" in line for line in page) # the actions scrolled off the top + press("up") # the snap-back: Trace comes back before anything moves + assert any("❯" in line and "Trace" in line for line in view()) + + async def test_trace_screen_seeds_route_from_previous_trace() -> None: """Before any fresh reply, the stored route shows, marked as previous.""" old = _trace(4.0)