diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index 5f2c567..e91922b 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -8,7 +8,7 @@ the node itself, in full: hue, its type label), the only chrome pinned above the stage — so the stage keeps nearly the whole screen; * **a tabbed stage** below it — one full-height view at a time, switched with ``←→`` (or - ``Tab``/``Shift+Tab``) across a one-line tab strip (see + ``Tab``/``Shift+Tab``) across a boxed tab strip (see :func:`~meshterm.ui.widgets.tab_strip`). Rather than stack the vitals, the location preview, and the route graph down one long scroll, each view earns the whole stage: @@ -481,16 +481,18 @@ class NodeDetailScreen(Screen): self._cursor = None self._list_hidden = False - # -- pinned chrome: the identity header, then the tab strip. One line of air - # follows the strip inside each stage (the route graph's own top padding, the - # Info tab's leading blank) rather than here, so the strip never costs two. + # -- 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 self._tabs: lines.append("") lines.extend( render_lines( - tab_strip([t.name for t in self._tabs], self._tab_index), width, no_wrap=True + tab_strip([t.name for t in self._tabs], self._tab_index, width), + width, + no_wrap=True, ) ) diff --git a/meshterm/ui/widgets.py b/meshterm/ui/widgets.py index 6e31d2d..72902ca 100644 --- a/meshterm/ui/widgets.py +++ b/meshterm/ui/widgets.py @@ -909,35 +909,54 @@ def node_type_legend(indent: str = "") -> Text: return legend -def tab_strip(labels: Sequence[str], active: int) -> Text: - """A one-line tab strip: the active view lit like a section heading, the rest muted. +def tab_strip(labels: Sequence[str], active: int, width: int) -> Group: + """A boxed tab strip: the active view drawn as a notebook tab, the rest sat beside it muted. THE navigation header for a screen that pages one full-height view at a time between a - handful of named views (the node detail page's ``Map`` / ``Routes``) instead of stacking - them. The active tab is drawn in the same accent ``── Label ──`` form the grouped select - lists give their section headings (:func:`~meshterm.ui.menus.section_heading`), so "the - view you are in" reads exactly like a section you have scrolled into; the inactive tabs sit - beside it muted, so the alternatives are visible without competing. A lone tab therefore - renders as a plain accent heading — the strip collapses gracefully when only one view has - content. The owning screen switches the active index (``←→``, with ``Tab``/``Shift+Tab`` as - a backup); the strip itself is pure presentation. + handful of named views (the node detail page's ``Info`` / ``Routes``) instead of stacking + them. A blank line of air above the strip plus the strip's own line was already the going + rate, so the strip spends a third line on an actual tab shape instead of a plain heading: + the active label sits boxed in accent-coloured rounded corners, its bottom edge opening + into a full-width rule that reads as the seam between chrome and page. The inactive tabs + sit beside the box muted and unboxed, so the alternative view stays visible without + competing. A lone tab collapses to the plain accent heading + (:func:`~meshterm.ui.menus.section_heading`'s ``── Label ──`` form) since there is nothing + to switch between. The owning screen switches the active index (``←→``, with + ``Tab``/``Shift+Tab`` as a backup); the strip itself is pure presentation. Args: labels: The tab names in display order. active: Index of the lit tab. + width: The strip's render width — the closing rule fills out to it. Returns: - A single-line :class:`~rich.text.Text` (no wrapping intended). + A :class:`~rich.console.Group` of one line (a lone tab, or none) or three (the box's + top border, the boxed + muted labels, and the closing rule). """ - strip = Text(no_wrap=True) + if not labels: + return Group(Text("")) + if len(labels) == 1: + return Group(Text(f"── {labels[0]} ──", style="accent", no_wrap=True)) + + top = Text(no_wrap=True) + mid = Text(no_wrap=True) + bot = Text(no_wrap=True) for i, label in enumerate(labels): if i: - strip.append(" ") + top.append(" ") + mid.append(" ") + bot.append("──", style="muted") if i == active: - strip.append(f"── {label} ──", style="accent") + inner = f" {label} " + top.append("╭" + "─" * len(inner) + "╮", style="accent") + mid.append("│" + inner + "│", style="accent") + bot.append(("╰" if i == 0 else "┴") + "─" * len(inner) + "┴", style="accent") else: - strip.append(label, style="muted") - return strip + top.append(" " * len(label)) + mid.append(label, style="muted") + bot.append("─" * len(label), style="muted") + bot.append("─" * max(0, width - len(bot.plain)), style="muted") + return Group(top, mid, bot) def _contacts_legend() -> Text: diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index 5b258c6..d8aed1e 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -124,12 +124,27 @@ def test_signal_row_summarizes_snr_and_rssi() -> None: # --- the tab strip -------------------------------------------------------------- -def test_tab_strip_lights_the_active_tab_and_mutes_the_rest() -> None: - """The active view reads as an accent section heading; the others sit beside it plain.""" - strip = tab_strip(["Map", "Routes"], 1) - assert strip.plain == "Map ── Routes ──" # active tab bracketed, inactive bare - lone = tab_strip(["Routes"], 0) - assert lone.plain == "── Routes ──" # a single tab collapses to a plain heading +def test_tab_strip_boxes_the_active_tab_and_mutes_the_rest() -> None: + """The active view reads as a boxed notebook tab; the others sit beside it bare.""" + group = tab_strip(["Map", "Routes"], 1, width=17) + top, mid, bot = group.renderables + assert mid.plain == "Map │ Routes │" # active tab boxed, inactive bare + assert top.plain == " ╭──────────╮" # box top over "Routes" only + assert bot.plain == "─────┴──────────┴" # rule joins the box's open bottom + assert len(top.plain) == len(mid.plain) == len(bot.plain) == 17 # no fill needed yet + + +def test_tab_strip_rule_fills_out_to_the_render_width() -> None: + """The closing rule under the strip extends to the full render width.""" + _, _, bot = tab_strip(["Map", "Routes"], 1, width=20).renderables + assert bot.plain == "─────┴──────────┴───" # 17 chars of box/rule, then 3 chars filler + assert len(bot.plain) == 20 + + +def test_tab_strip_collapses_a_lone_tab_to_a_plain_heading() -> None: + """A single tab renders as the plain accent heading, no box needed.""" + (lone,) = tab_strip(["Routes"], 0, width=40).renderables + assert lone.plain == "── Routes ──" # --- the folded-in route line --------------------------------------------------- @@ -425,14 +440,14 @@ def test_node_detail_screen_renders_its_sections() -> None: screen.note_viewport(30) body = _plain(screen.render_body(72)) assert "Hub" in body and "repeater" in body # the pinned identity header - assert "── Info ──" in body and "42" in body # the vitals moved into the Info tab + assert "│ Info │" in body and "42" in body # the vitals moved into the boxed Info tab assert "Time machine" in body and "Back" in body # the Info actions + shared tail assert "────────" in body # the faint rule closing the stage assert "no route observed yet" not in body # the Routes stage waits on its own tab screen.handle("right") body = _plain(screen.render_body(72)) - assert "── Routes ──" in body and "no route observed yet" in body + assert "│ Routes │" in body and "no route observed yet" in body assert "Trace" in body and "Back" in body assert "packets" not in body # the vitals stay on the Info tab # Every rendered line fits the 72-column standard. @@ -570,12 +585,12 @@ def test_node_detail_screen_tabs_switch_the_stage() -> None: # Opens on the Info tab: the vitals, the located preview's caption, and its braille # edge scrub all belong to it. body = _plain(screen.render_body(72)) - assert "── Info ──" in body and "centred here" in body + assert "│ Info │" in body and "centred here" in body assert screen.consume_edge_scrub() == 2 screen.handle("right") # switch to the Routes tab body = _plain(screen.render_body(72)) - assert "── Routes ──" in body and "no route observed yet" in body + assert "│ Routes │" in body and "no route observed yet" in body assert screen.consume_edge_scrub() == 0 # the braille preview isn't showing now