Tabbed pages draw their strip on one row when the frame is short
Below sixteen viewport rows the boxed strip's three rows become one, the active tab standing on the rule between tees and every label held where it was. On the Cardputer that puts the node page's actions and a record's whole Info list back on screen. The node page's location preview steps aside when it can't have its five-row floor, rather than scrolling the header and actions away. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
44b840dfff
commit
5675ba0e1f
4 files changed
+71
-11
No files matched your search
@@ -132,6 +132,7 @@ from .widgets import (
|
||||
highlighted_hash,
|
||||
node_type_legend,
|
||||
tab_air,
|
||||
tab_compact,
|
||||
tab_strip,
|
||||
)
|
||||
|
||||
@@ -762,7 +763,12 @@ class NodeDetailScreen(Screen):
|
||||
lines.extend([""] * tab_air())
|
||||
lines.extend(
|
||||
render_lines(
|
||||
tab_strip([t.name for t in self._tabs], self._tab_index, width),
|
||||
tab_strip(
|
||||
[t.name for t in self._tabs],
|
||||
self._tab_index,
|
||||
width,
|
||||
compact=tab_compact(viewport),
|
||||
),
|
||||
width,
|
||||
no_wrap=True,
|
||||
)
|
||||
@@ -831,7 +837,9 @@ class NodeDetailScreen(Screen):
|
||||
|
||||
``budget`` is the viewport lines left for the whole stage; the vitals rows never
|
||||
truncate — it is the preview that flexes, taking whatever they and its caption
|
||||
leave, clamped to ``[_MAP_MIN_ROWS, _MAP_MAX_ROWS]``. Every row but the key hangs
|
||||
leave up to ``_MAP_MAX_ROWS``, and left out altogether where that is less than
|
||||
``_MAP_MIN_ROWS`` (a short frame keeps its header and actions on screen instead).
|
||||
Every row but the key hangs
|
||||
under itself when it wraps; the key holds its one line and scrolls (see
|
||||
:meth:`_key_line`), so a row count the preview sizes against can't move as a reader
|
||||
walks a long key.
|
||||
@@ -850,12 +858,15 @@ class NodeDetailScreen(Screen):
|
||||
)
|
||||
)
|
||||
if self._minimap is not None:
|
||||
lines.append("")
|
||||
caption = 1 if self._map_caption is not None else 0
|
||||
rows = max(_MAP_MIN_ROWS, min(_MAP_MAX_ROWS, budget - len(lines) - caption))
|
||||
lines.extend(self._minimap.render(width, rows))
|
||||
if self._map_caption is not None:
|
||||
lines.extend(render_lines(self._map_caption, width, no_wrap=True))
|
||||
room = budget - len(lines) - 1 - caption # less the blank above it
|
||||
# Below its floor the preview steps aside rather than push the identity header
|
||||
# and the actions off a short frame (the Cardputer's 14 rows leave it two).
|
||||
if room >= _MAP_MIN_ROWS:
|
||||
lines.append("")
|
||||
lines.extend(self._minimap.render(width, min(_MAP_MAX_ROWS, room)))
|
||||
if self._map_caption is not None:
|
||||
lines.extend(render_lines(self._map_caption, width, no_wrap=True))
|
||||
return lines
|
||||
|
||||
def _key_line(self, label: str, value: Text, width: int) -> str:
|
||||
|
||||
@@ -63,6 +63,7 @@ from .widgets import (
|
||||
route_graph_style,
|
||||
self_marker,
|
||||
tab_air,
|
||||
tab_compact,
|
||||
tab_strip,
|
||||
)
|
||||
|
||||
@@ -647,7 +648,10 @@ class RecordScreen(Screen):
|
||||
# air (see widgets.tab_air) — the node page's identity header and strip.
|
||||
lines: list[str] = [render_to_ansi(self._header(), width, no_wrap=True)]
|
||||
lines.extend([""] * tab_air())
|
||||
lines.extend(render_lines(tab_strip(self._tabs, self._tab_index, width), width))
|
||||
strip = tab_strip(
|
||||
self._tabs, self._tab_index, width, compact=tab_compact(self._scroll_viewport)
|
||||
)
|
||||
lines.extend(render_lines(strip, width))
|
||||
lines.extend([""] * tab_air())
|
||||
if self._tab == _TAB_AREA:
|
||||
self._cursor = None
|
||||
|
||||
+34
-3
@@ -1247,7 +1247,20 @@ def tab_air() -> int:
|
||||
return _TAB_AIR
|
||||
|
||||
|
||||
def tab_strip(labels: Sequence[str], active: int, width: int) -> Group:
|
||||
#: The viewport, in rows, below which a tabbed page draws its strip on one row (see
|
||||
#: :func:`tab_strip`'s ``compact``). The boxed strip costs three rows and its air; on the
|
||||
#: Cardputer's 11-row viewport that was the difference between a page's actions on screen
|
||||
#: and below the fold. Read from the viewport rather than the platform, so a desktop
|
||||
#: terminal dragged short gets the same answer the handheld does.
|
||||
COMPACT_TABS_BELOW = 16
|
||||
|
||||
|
||||
def tab_compact(viewport: int) -> bool:
|
||||
"""Whether a page with ``viewport`` rows draws its tab strip compact (one row)."""
|
||||
return viewport < COMPACT_TABS_BELOW
|
||||
|
||||
|
||||
def tab_strip(labels: Sequence[str], active: int, width: int, *, compact: bool = False) -> Group:
|
||||
"""A boxed tab strip: every tab always boxed on top, the active one open into the page.
|
||||
|
||||
THE navigation header for a screen that pages one full-height view at a time between a
|
||||
@@ -1277,19 +1290,37 @@ def tab_strip(labels: Sequence[str], active: int, width: int) -> Group:
|
||||
owning screen switches the active index (``Tab``/``Shift+Tab``); the strip itself is
|
||||
pure presentation.
|
||||
|
||||
Where rows are scarcer than that (``compact``, see :func:`tab_compact`) the same strip is
|
||||
drawn on its own bottom rule, in one row: ``──┤ Info ├── Routes ──────``. The active tab
|
||||
stands on the rule between tees, lit; an inactive one is its label on the rule, faint.
|
||||
Every tab is the same width in either state, so switching still never moves a label.
|
||||
|
||||
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.
|
||||
compact: Draw the strip on one row instead of three.
|
||||
|
||||
Returns:
|
||||
A :class:`~rich.console.Group` of one line (a lone tab, or none) or three (the shared
|
||||
top border, the boxed labels, and the shared bottom rule).
|
||||
A :class:`~rich.console.Group` of one line (a lone tab, none, or a compact strip) or
|
||||
three (the shared top border, the boxed labels, and the shared bottom rule).
|
||||
"""
|
||||
if not labels:
|
||||
return Group(Text(""))
|
||||
if len(labels) == 1:
|
||||
return Group(Text(f"── {labels[0]} ──", style="accent", no_wrap=True))
|
||||
if compact:
|
||||
row = Text("──", style="accent", no_wrap=True)
|
||||
for i, label in enumerate(labels):
|
||||
if i == active:
|
||||
row.append(f"┤ {label} ├", style="accent")
|
||||
else:
|
||||
row.append("─", style="accent")
|
||||
row.append(f" {label} ", style="faint")
|
||||
row.append("─", style="accent")
|
||||
row.append("─", style="accent")
|
||||
row.append("─" * max(0, width - len(row.plain)), style="accent")
|
||||
return Group(row)
|
||||
|
||||
n = len(labels)
|
||||
inner = [f" {label} " for label in labels]
|
||||
|
||||
@@ -287,3 +287,17 @@ def test_every_advert_type_has_one_name() -> None:
|
||||
assert node_type_label(4) == "sensor"
|
||||
assert node_type_label(9) == "type 9" # an advert type MeshTerm does not know yet
|
||||
assert node_type_label(None) is None
|
||||
|
||||
|
||||
def test_a_compact_tab_strip_is_one_row_and_never_moves_a_label() -> None:
|
||||
"""Below COMPACT_TABS_BELOW rows the strip draws on its rule, every tab a fixed width."""
|
||||
from meshterm.ui.widgets import COMPACT_TABS_BELOW, tab_compact, tab_strip
|
||||
|
||||
assert tab_compact(COMPACT_TABS_BELOW - 1) and not tab_compact(COMPACT_TABS_BELOW)
|
||||
rows = [tab_strip(["Info", "Routes", "Area"], i, 40, compact=True) for i in range(3)]
|
||||
plains = [group.renderables[0].plain for group in rows]
|
||||
assert all(len(group.renderables) == 1 for group in rows)
|
||||
assert plains[0].startswith("──┤ Info ├") and plains[1].startswith("─── Info ──┤ Routes ├")
|
||||
for label in ("Info", "Routes", "Area"):
|
||||
assert len({plain.index(label) for plain in plains}) == 1, label
|
||||
assert all(len(plain) == 40 for plain in plains)
|
||||
Reference in new issue
Block a user