diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index c905fbd..84423bb 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -936,10 +936,13 @@ class NodeDetailScreen(Screen): # a multi-pass graph layout — is a pure function of the width, the row budget, # and which route is emphasized. One slot suffices: the key only moves on a # selection change or a resize, and then the previous layout is dead anyway. - caption_lines = (1 if _GRAPH_CAPTION else 0) + (1 if rv.legend else 0) + # The node-type key steps aside on a short frame, as the message paths' does: the + # marks mean one thing app-wide, and the rows go to the graph and the list. + legend = rv.legend and not short_frame(self._scroll_viewport) + caption_lines = (1 if _GRAPH_CAPTION else 0) + (1 if legend else 0) list_need = min(sum(len(block) for block in route_blocks), _LIST_MIN_LINES) max_rows = max(_GRAPH_MIN_ROWS, min(_PATH_MAX_ROWS, budget - caption_lines - list_need)) - stage_key = (width, max_rows, sel) + stage_key = (width, max_rows, sel, legend) if self._stage_memo is not None and self._stage_memo[0] == stage_key: return self._stage_memo[1] # Priority is fixed by evidence order (route 0, the best-evidence route, is always the @@ -978,7 +981,7 @@ class NodeDetailScreen(Screen): else: while lines and not _SGR.sub("", lines[0]).strip(): lines.pop(0) - if rv.legend: + if legend: lines.extend(render_lines(node_type_legend(width=width), width, no_wrap=True)) self._stage_memo = (stage_key, lines) return lines diff --git a/meshterm/ui/packet_viewer.py b/meshterm/ui/packet_viewer.py index 85ac3ee..366031a 100644 --- a/meshterm/ui/packet_viewer.py +++ b/meshterm/ui/packet_viewer.py @@ -74,6 +74,7 @@ from .widgets import ( revisit_note, route_graph_style, scope_text, + short_frame, ) #: Reads a frame's scope from its raw payload — ``ctx.region_store.scope_of`` in the app: @@ -710,7 +711,9 @@ class PacketViewer(Screen): # while the card is open (a repeater's list arriving, a name typed) names a code # that read as unknown a moment ago. The store memoizes the lookup, so asking it # every paint costs a dict hit. - key = (id(entry), width, age_minute, self._entry_scope(entry)) + # …and of whether the frame is short, which sets the node-type key aside. + short = short_frame(self._scroll_viewport) + key = (id(entry), width, age_minute, self._entry_scope(entry), short) cached = self._body_cache.get(key) if cached is not None: self._body_cache.move_to_end(key) @@ -726,7 +729,8 @@ class PacketViewer(Screen): lines.extend(graph) caption = Text("origin → you · labels = hash byte", style="faint") lines.append(render_to_ansi(caption, width, no_wrap=True)) - lines.extend(render_lines(node_type_legend(width=width), width, no_wrap=True)) + if not short: # the key steps aside on a short frame (see widgets.short_frame) + lines.extend(render_lines(node_type_legend(width=width), width, no_wrap=True)) if tail: lines.append("") lines.extend(self._grid_lines(tail, width, label_w)) diff --git a/meshterm/ui/records_screen.py b/meshterm/ui/records_screen.py index d9784c0..0cfaff0 100644 --- a/meshterm/ui/records_screen.py +++ b/meshterm/ui/records_screen.py @@ -307,7 +307,7 @@ class RecordScreen(Screen): # Each tab's composed stage above its action rows, per width — and the Area tab's # drawing per (width, rows) — all pure functions of the frozen record. self._info_cache: tuple[int, list[str]] | None = None - self._route_cache: tuple[int, list[str]] | None = None + self._route_cache: tuple[tuple[int, bool], list[str]] | None = None self._area_cache: tuple[tuple[int, int], list[str]] | None = None # The page opens at the top, reading down; the arrows drive (and follow) the action # cursor, while PgUp/PgDn/Home/End scroll the body free of it (see cursor_line). @@ -666,8 +666,9 @@ class RecordScreen(Screen): self._info_cache = cached else: cached = self._route_cache - if cached is None or cached[0] != width: - cached = (width, self._route_lines(width)) + short = short_frame(self._scroll_viewport) + if cached is None or cached[0] != (width, short): + cached = ((width, short), self._route_lines(width, short=short)) self._route_cache = cached lines.extend(cached[1]) @@ -712,13 +713,18 @@ class RecordScreen(Screen): lines.extend(render_to_ansi(lane, width, no_wrap=True) for lane in self._stat_lanes()) return lines - def _route_lines(self, width: int) -> list[str]: - """The Route tab above its action row: THE route graph, its key, then the route line.""" + def _route_lines(self, width: int, *, short: bool = False) -> list[str]: + """The Route tab above its action row: THE route graph, its key, then the route line. + + On a short frame the node-type key steps aside (see :func:`~meshterm.ui.widgets. + short_frame`), as it does under every route graph: the rows go to the route. + """ record = self._record lines = self._graph_lines(width) caption = Text("you → … → you · labels = hash byte", style="faint") lines.append(render_to_ansi(caption, width, no_wrap=True)) - lines.extend(render_lines(node_type_legend(width=width), width, no_wrap=True)) + if not short: + lines.extend(render_lines(node_type_legend(width=width), width, no_wrap=True)) # The walk itself, on THE path widget, across the card's whole width. No ``route`` # label lane: the line under a route graph captioned "you → … → you" is the route, diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index 5115ed6..b2a12a0 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -1263,3 +1263,26 @@ def test_toggling_the_lock_rewrites_the_rows_and_keeps_the_cursor_on_it() -> Non screen.handle("enter") assert resolved == ["lock", "unlock"] assert [a.key for a in screen._info_actions] == ["timemachine", "unlock", "remove"] + + +def test_routes_legend_steps_aside_on_a_short_frame() -> None: + """The node-type key is drawn under the fan, except on a short frame like the Cardputer's. + + There the rows go to the graph and the route list, as under the message paths' fan. + """ + view = _RoutesView( + routes=[_Route(draw=("3d" * 6,), spec="3d,f2", path=Text("via 3d"), context=Text(""))], + glyph_of=lambda n: ("▲", "#ffffff"), + label_of=lambda n: n[:2], + label_rgb_of=lambda n: (200, 200, 200), + legend=True, + ) + + def stage(viewport: int) -> str: + screen = _screen(routes=view, tabs=[_Tab("Info", "info"), _Tab("Routes", "routes")]) + screen.handle("tab") # onto Routes + screen.note_viewport(viewport) + return _plain(screen.render_body(53)) + + assert "▲ repeater" in stage(22) # the PicoCalc's body + assert "▲ repeater" not in stage(11) # the Cardputer's diff --git a/tests/test_packet_viewer.py b/tests/test_packet_viewer.py index f920764..5b50b20 100644 --- a/tests/test_packet_viewer.py +++ b/tests/test_packet_viewer.py @@ -264,7 +264,9 @@ def test_packet_viewer_shows_full_raw_field_labels() -> None: def test_packet_viewer_draws_a_relayed_packets_route_graph() -> None: """A packet that crossed relays gets THE route graph — braille edges, caption, legend.""" entry = PacketEntry(when=utcnow(), kind="packet", path="3d63,a1b2") - body = _plain(_viewer(entry).render_body(80)) + viewer = _viewer(entry) + viewer.note_viewport(30) # the frame records this before every real paint + body = _plain(viewer.render_body(80)) assert "origin → you" in body # the graph caption assert "★ you" in body and "▲ repeater" in body # the node-type legend assert any("⠀" <= ch <= "⣿" for ch in body) # braille edges are drawn @@ -566,3 +568,12 @@ def test_packet_viewer_counts_one_walked_hop_in_the_singular() -> None: raw={"payload_typename": "TRACE", "trace_snrs": [13.25]}, ) assert "1 hop walked" in _plain(_viewer(entry).render_body(80)) + + +def test_packet_viewer_legend_steps_aside_on_a_short_frame() -> None: + """Under a short frame's route graph the caption stays and the node-type key goes.""" + entry = PacketEntry(when=utcnow(), kind="packet", path="3d63,a1b2") + viewer = _viewer(entry) + viewer.note_viewport(10) # the Cardputer's dialog budget + body = _plain(viewer.render_body(49)) + assert "origin → you" in body and "▲ repeater" not in body diff --git a/tests/test_records_screen.py b/tests/test_records_screen.py index 996af9c..22bcaf5 100644 --- a/tests/test_records_screen.py +++ b/tests/test_records_screen.py @@ -115,6 +115,7 @@ def test_record_dialog_shows_stats_route_and_the_trace_action() -> None: def test_record_dialog_draws_the_walk_as_a_route_graph() -> None: """The walk is drawn on THE route graph — us starred at both ends, over a caption.""" screen = _dialog(_record()) + screen.note_viewport(40) # the frame records this before every real paint screen.handle("tab") # the Route tab lines = _plain(screen.render_body(60)).splitlines() legend = next(i for i, line in enumerate(lines) if "▲ repeater" in line) @@ -145,6 +146,7 @@ def test_record_dialog_route_runs_unlabelled_across_the_whole_card() -> None: our own two ends stand on the ★ the graph above already marks us with. """ dialog = _dialog(_record(route=tuple([HUB_ID, FAR_ID] * 4))) + dialog.note_viewport(40) # the frame records this before every real paint dialog.handle("tab") # the Route tab body = _plain(dialog.render_body(60)).splitlines() # The route closes the Route tab's stage: it runs from under the graph's legend to @@ -164,6 +166,7 @@ def test_record_dialog_route_runs_unlabelled_across_the_whole_card() -> None: def test_record_dialog_shows_the_node_type_legend() -> None: """The standard node-type key sits under the graph, so its markers read.""" screen = _dialog(_record()) + screen.note_viewport(40) # the frame records this before every real paint screen.handle("tab") # the Route tab body = _plain(screen.render_body(60)) assert "★ you" in body and "▲ repeater" in body and "◉ sensor" in body @@ -177,6 +180,7 @@ def test_record_dialog_legend_is_one_line_on_a_handheld_and_breaks_between_entri one would leave a glyph at the end of a line and its name at the start of the next. """ screen = _dialog(_record()) + screen.note_viewport(40) # the frame records this before every real paint screen.handle("tab") # the Route tab entries = ("★ you", "▲ repeater", "● companion", "■ room", "◉ sensor") body = _plain(screen.render_body(53)).splitlines() @@ -189,6 +193,15 @@ def test_record_dialog_legend_is_one_line_on_a_handheld_and_breaks_between_entri assert all(cell_len(line) <= 40 for line in narrow.splitlines()) +def test_record_dialog_legend_steps_aside_on_a_short_frame() -> None: + """On the Cardputer's 11 rows the Route tab keeps its graph and route, not the key.""" + screen = _dialog(_record()) + screen.handle("tab") # the Route tab + screen.note_viewport(11) + body = _plain(screen.render_body(53)) + assert "you → … → you" in body and "▲ repeater" not in body + + def test_record_graph_marks_a_repeater_relay_with_its_triangle() -> None: """A relay whose type is a repeater draws ▲, not the generic ● dot.""" dialog = _dialog(_record(), type_of=lambda h: 2 if h == HUB_ID else None) @@ -407,6 +420,7 @@ def test_record_route_tab_draws_the_walk_and_enter_traces_it() -> None: so the tab carries that action alone; the page's Delete stays on Info. """ screen = _dialog(_record(), far_label="Far", shape=_loop_shape()) + screen.note_viewport(40) # the frame records this before every real paint screen.handle("tab") lines = _plain(screen.render_body(58)).splitlines() stage = [line for line in lines[_strip_end(lines) :] if line]