diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index 84423bb..c0e99cd 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -406,6 +406,28 @@ class NodeDetailScreen(Screen): lane[2] = FPair(nxt.name, "tab") return lane + @property + def title(self) -> str: # type: ignore[override] + """``Node — ``, or on a short frame the identity mark, ``▲ ``. + + On a short frame (the Cardputer's 14 rows, JP 2026-10-04) the title bar *is* the + identity: the type glyph stands in for the word ``Node`` and the name wears its own + hue (:meth:`bar_title`), so the identity line under the bar would only say it twice, + and its row goes to the stage instead (see :meth:`render_body`). Read after the paint + that decided it, as the frame draws the bar after the body. + """ + return self._mark.plain if self._compact and self._mark is not None else self._title + + @title.setter + def title(self, value: str) -> None: + self._title = value + + def bar_title(self, title: str, style: str) -> Text: + """The identity mark keeps its glyph's type colour and the name's hue in the bar.""" + if self._mark is not None and title == self._mark.plain: + return self._mark.copy() + return super().bar_title(title, style) + def __init__( self, *, @@ -418,12 +440,16 @@ class NodeDetailScreen(Screen): routes: _RoutesView | None = None, info_actions: list[_Action] | None = None, trace_action: _Action | None = None, + mark: Text | None = None, ) -> None: """Build the page over resolved display data. Args: title: The screen heading (``Node — ``). header: The identity line: type glyph, the coloured name, its type label. + mark: The identity as the title bar wears it on a short frame — the type glyph + in its type colour and the name in its own hue, ``▲ Hilltop-Repeater`` (see + :attr:`title`). ``None`` keeps the plain title and the identity line there. info_rows: ``(label, value)`` pairs for the Info tab's vitals block; each renders as a muted label lane with the value hanging under itself when it wraps. @@ -442,6 +468,9 @@ class NodeDetailScreen(Screen): """ super().__init__() self.title = title + self._mark = mark + #: Whether the last paint was on a short frame with a mark to wear (see :attr:`title`). + self._compact = False self._header = header self._info_rows = info_rows self._tabs = tabs @@ -753,12 +782,18 @@ class NodeDetailScreen(Screen): self._row_index %= len(focus) self._cursor = None self._list_hidden = False + short = short_frame(viewport) + # On a short frame the title bar wears the identity (see :attr:`title`), so the + # identity line under it is dropped, and so is the rule under the route graph: + # both rows go to the graph, whose ceiling is struck from what is left. + self._compact = short and self._mark is not None # -- pinned chrome: the identity header, then the tab strip (a lone tab collapses # to one line; a multi-tab strip boxes the active tab across three). The budget # below is struck from ``len(lines)`` after this, so either shape sizes correctly. lines: list[str] = [] - lines.extend(render_lines(self._header, width)) + if not self._compact: + lines.extend(render_lines(self._header, width)) if self._tabs: lines.extend([""] * tab_air()) lines.extend( @@ -767,7 +802,7 @@ class NodeDetailScreen(Screen): [t.name for t in self._tabs], self._tab_index, width, - compact=short_frame(viewport), + compact=short, ), width, no_wrap=True, @@ -795,11 +830,15 @@ class NodeDetailScreen(Screen): # The bare note pays for its own air under the strip — where the # platform affords the strip any air at all. lines.extend([""] * tab_air()) - budget = viewport - len(lines) - action_lines - 1 # the rule's line + rule = 0 if short else 1 # a short frame's graph keeps the rule's line + budget = viewport - len(lines) - action_lines - rule lines.extend(self._routes_stage(width, budget, route_blocks)) # The rule closes the stage, so the drawn view and the rows below it read as - # separate bands rather than one run-on column. - lines.append(render_to_ansi(Text("─" * width, style="faint"), width)) + # separate bands rather than one run-on column. A short frame's Routes tab goes + # without (JP, 2026-10-04): the selected route's white line and the list's own + # cursor already part the two, and the row is worth more to the graph. + if tab.kind == "info" or not short: + lines.append(render_to_ansi(Text("─" * width, style="faint"), width)) # -- the route list, windowed into whatever the stage left. if route_blocks: @@ -1257,9 +1296,11 @@ async def open_node_detail( else: glyph, glyph_style = NODE_GLYPHS.get(node_type, DEFAULT_GLYPH) name_hue = name_style(name, key) if name else "muted" - header = Text() - header.append(f"{glyph} ", style=glyph_style) - header.append(name or "unknown", style=name_hue) + # The mark is the identity a short frame's title bar wears; the header line adds the type. + mark = Text() + mark.append(f"{glyph} ", style=glyph_style) + mark.append(name or "unknown", style=name_hue) + header = mark.copy() type_label = NODE_TYPE_LABELS.get(node_type) if node_type is not None else None if you: header.append(" your node", style="muted") @@ -1472,6 +1513,7 @@ async def open_node_detail( routes=routes_view, info_actions=info_actions, trace_action=trace_action, + mark=mark, ) async with session.stay(screen) as visit: while True: diff --git a/tests/test_gallery.py b/tests/test_gallery.py index 99e39b8..0a9116b 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -327,12 +327,17 @@ def _archived(cols: int, rows: int) -> Screen: ) -def _node_detail_header() -> Text: +def _node_detail_mark() -> Text: # Through the app's own marker and name styles, not a hand-spelled hex: the gallery is # a specimen of what the platform draws, so a stub colour would hide a palette bug. glyph, glyph_style = NODE_GLYPHS[NODE_TYPE_REPEATER] - header = Text(f"{glyph} ", style=glyph_style) - header.append("Hilltop-Repeater", style=name_style("Hilltop-Repeater", _HUB_KEY)) + mark = Text(f"{glyph} ", style=glyph_style) + mark.append("Hilltop-Repeater", style=name_style("Hilltop-Repeater", _HUB_KEY)) + return mark + + +def _node_detail_header() -> Text: + header = _node_detail_mark() header.append(" repeater", style="muted") return header @@ -371,6 +376,7 @@ def _node_detail(cols: int, rows: int, *, with_minimap: bool = False) -> Screen: _Action("remove", "🗑", "err", "Remove contact…"), ], trace_action=_Action("trace", "\U0001f3af", "", "Trace — auto route …"), + mark=_node_detail_mark(), ) diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index b2a12a0..a365469 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -825,6 +825,90 @@ def test_node_detail_routes_stage_spends_the_caption_and_top_air_on_the_fan() -> assert len(pico) == len(drawn) + 2 +def _mark() -> Text: + mark = Text("▲ ", style="type.repeater") + mark.append("Hub", style="#ff8800") + return mark + + +def _busy_routes() -> _RoutesView: + """Four routes over a shared relay: a fan the row ceiling, not its own height, sizes.""" + return _RoutesView( + routes=[ + _Route( + draw=(h * 12, "f2" * 6), + spec=f"{h}{h},f2", + path=Text(f"via {h}{h}"), + context=Text(""), + ) + for h in "1234" + ], + glyph_of=lambda n: ("●", "#ffffff"), + label_of=lambda n: n[:2], + label_rgb_of=lambda n: (200, 200, 200), + ) + + +def test_a_short_frame_wears_the_identity_in_the_title_bar() -> None: + """On the Cardputer the bar reads ``▲ Hub`` in the node's colours; the identity line goes. + + The glyph stands in for the word ``Node`` and the name wears its own hue, so the line + under the bar that said the same would only say it twice (JP, 2026-10-04). A tall + frame keeps both as they were. + """ + from meshterm.platforms import CARDPUTER, set_platform + from meshterm.ui.tui import frame + + set_platform(CARDPUTER) + screen = _screen(mark=_mark()) + screen.note_viewport(12) # the Cardputer's body, under the bar and over the lane + body = _plain(screen.render_body(53)) + assert screen.title == "▲ Hub" + assert "repeater" not in body # the identity line is gone… + assert body.splitlines()[0].startswith("──┤ Info ├") # …the tab strip leads the page + bar = frame._title_bar(screen, 53, False, False) + start = bar.plain.index("▲") + styles = {str(s.style) for s in bar.spans if s.start <= start < s.end} + assert "type.repeater" in styles + hub = bar.plain.index("Hub") + assert "#ff8800" in {str(s.style) for s in bar.spans if s.start <= hub < s.end} + + tall = _screen(mark=_mark()) + tall.note_viewport(30) + body = _plain(tall.render_body(53)) + assert tall.title == "Node — Hub" and "repeater" in body + # Without a mark to wear, a short frame keeps its title and the identity line. + bare = _screen() + bare.note_viewport(12) + assert "repeater" in _plain(bare.render_body(53)) and bare.title == "Node — Hub" + + +def test_a_short_frame_gives_the_route_graph_the_rows_it_freed() -> None: + """No identity line and no rule under the graph: both rows go to the graph. + + Between the tab strip and the route list there is nothing but the fan, which takes + every row the list's guaranteed window leaves it. + """ + from meshterm.platforms import CARDPUTER, set_platform + + set_platform(CARDPUTER) + screen = _screen(mark=_mark(), routes=_busy_routes()) + screen.handle("tab") # onto Routes + screen.note_viewport(12) + lines = [_plain([line]) for line in screen.render_body(53)] + assert "Routes ├" in lines[0] + first_route = next(i for i, line in enumerate(lines) if "via 11" in line) + graph = lines[1:first_route] + assert not any(set(line.strip()) == {"─"} for line in graph) # no rule under the fan + assert len(graph) == 12 - 1 - 4 # all but the strip and the list's four rows + assert [line.strip() for line in lines[first_route:]] == [ + "❯ via 11 …", + "via 22 …", + "via 33 …", + "via 44 …", + ] + + 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(