diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index b54bf4e..5647eab 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -64,6 +64,7 @@ from __future__ import annotations import asyncio import math +import re from dataclasses import dataclass, field, replace from datetime import datetime from typing import TYPE_CHECKING, Optional @@ -122,6 +123,27 @@ def _bind_tab_air(platform: Platform) -> None: global _TAB_AIR _TAB_AIR = 1 if platform.frame_border else 0 + +#: Whether the route fan is captioned ("node → you, as heard · white = selected route") +#: and allowed to keep the empty canvas row its top air leaves. Both go on the PicoCalc +#: (JP, 2026-08-09) and both rows go to the graph instead: the caption explains a picture +#: the white line and the ``you`` star already make, and the renderer's end padding +#: (:data:`~meshterm.ui.pathgraph._GRAPH_END_DOTS`, two cells) reserves a whole cell of air +#: above the topmost lane's label that nothing ever draws into. Rides the same frugality +#: signal as :data:`_TAB_AIR`, bound at platform-switch time like every platform constant. +_GRAPH_CAPTION = True + + +@on_platform +def _bind_graph_caption(platform: Platform) -> None: + """Bind the fan's caption/air to the platform (runs now and on every switch).""" + global _GRAPH_CAPTION + _GRAPH_CAPTION = platform.frame_border + + +#: An SGR escape, so a rendered canvas row can be tested for holding nothing but air. +_SGR = re.compile(r"\x1b\[[0-9;]*m") + #: The inline location preview's row bounds: it grows into whatever the Info tab's #: viewport spares (the vitals and action rows are short), floored so a cramped terminal #: still shows a recognisable neighbourhood and capped so a tall one doesn't become all map. @@ -866,6 +888,12 @@ class NodeDetailScreen(Screen): before the list would lose its window, and a busy node's fan only spreads out on a terminal tall enough to afford it. The selected route draws white with its off-route labels faded, as ever. + + Where the caption is dropped (:data:`_GRAPH_CAPTION` — the PicoCalc), the fan is + drawn one row *over* its ceiling and its leading blank canvas row is peeled off + after: the renderer always centres the lane band inside two cells of end padding + while its topmost label wants only one, so that row is reliably empty and the peel + pays for the row it was granted. Both rows land back in the ceiling itself. """ rv = self._routes assert rv is not None @@ -876,7 +904,7 @@ 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 + (1 if rv.legend else 0) + caption_lines = (1 if _GRAPH_CAPTION else 0) + (1 if rv.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) @@ -915,11 +943,15 @@ class NodeDetailScreen(Screen): glyph_of=rv.glyph_of, label_of=rv.label_of, # type: ignore[arg-type] label_rgb_of=label_rgb_of, - max_rows=max_rows, + max_rows=max_rows if _GRAPH_CAPTION else max_rows + 1, ) ) - caption = Text("node → you, as heard · white = selected route", style="faint") - lines.extend(render_lines(caption, width, no_wrap=True)) + if _GRAPH_CAPTION: + caption = Text("node → you, as heard · white = selected route", style="faint") + lines.extend(render_lines(caption, width, no_wrap=True)) + else: + while lines and not _SGR.sub("", lines[0]).strip(): + lines.pop(0) if rv.legend: lines.extend(render_lines(node_type_legend(), width, no_wrap=True)) self._stage_memo = (stage_key, lines) diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index 0455815..5e321b9 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -602,6 +602,51 @@ def test_node_detail_screen_route_selection_arms_the_trace() -> None: assert "Trace" not in body # the auto-route stand-in only shows with no routes to list +def test_node_detail_routes_stage_spends_the_caption_and_top_air_on_the_fan() -> None: + """On the PicoCalc the fan opens directly under the tab strip and runs uncaptioned, and + both reclaimed rows go back into the graph — never into a taller gap (JP, 2026-08-09). + + The graph's own end padding leaves a whole empty canvas row above its topmost label; the + stage draws one row over its ceiling and peels that row off, so the peel pays for itself. + """ + from meshterm.platforms import PICOCALC, REGULAR, set_platform + + # A fan busy enough that the row ceiling — not its own ideal height — is what sizes it, + # so the reclaimed rows show up as lanes rather than as slack. + busy = _RoutesView( + routes=[ + _Route(draw=(h * 12,), spec=f"{h}{h},f2", path=Text(f"via {h}{h}"), context=Text("")) + for h in "123456" + ], + glyph_of=lambda n: ("●", "#ffffff"), + label_of=lambda n: n[:2], + label_rgb_of=lambda n: (200, 200, 200), + ) + + def _stage(viewport: int) -> list[str]: + screen = _screen(routes=busy, tabs=[_Tab("Info", "info"), _Tab("Routes", "routes")]) + screen.handle("tab") # onto Routes + screen.note_viewport(viewport) + lines = screen.render_body(49) + strip_idx = next(i for i, l in enumerate(lines) if "Routes" in _plain([l]) and "│" in _plain([l])) + rule_idx = next(i for i, l in enumerate(lines) if set(_plain([l])) == {"─"} and i > strip_idx) + return [_plain([l]) for l in lines[strip_idx + 2 : rule_idx]] # past the strip's own rule + + set_platform(PICOCALC) + pico = _stage(22) + assert pico[0].strip(), "no blank row between the tab strip and the fan" + assert not any("selected route" in line for line in pico), "the caption is dropped" + + set_platform(REGULAR) + desktop = _stage(22) + assert not desktop[0].strip() # the desktop keeps its air… + assert any("node → you, as heard" in line for line in desktop) # …and its caption + # Both rows land in the drawing, not in the chrome: from the same viewport the console + # grants this ceiling-bound fan two more canvas rows than the captioned desktop stage. + drawn = [l for l in desktop if "node → you" not in l] + assert len(pico) == len(drawn) + 2 + + def test_node_detail_screen_context_hangs_under_the_pathline() -> None: """The weakest/samples/tag context draws on its own line, indented under the pathline.""" routes = _RoutesView(