From b73fcb254e9a056a3260ebd84d76097de5976092 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Fri, 2 Oct 2026 02:01:30 -0400 Subject: [PATCH 1/2] The splash fits its wordmark once, not on every paint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arrowing down the device list on the PicoCalc stalled on every keystroke. The time was not in the list: at 53 columns the full-size mark does not fit, so each paint sent load_logo back to the disk for every size until one did, parsed and measured each, and decoded every row again to centre it. None of that changes between paints, and the splash paints on every keystroke and every idle tick. compose_startup now asks _fitted_banner, a one-slot memo keyed by the banner and the width, dropped on a platform switch with the other composition memos since the fold bakes the theme in. Measured on the desktop under the picocalc platform, splash at 53x26, ↓/↑ alternating: 31.1 ms a paint before, 2.3 ms after. The logo was nine-tenths of the frame; the list itself is under 0.1 ms. 108 frames across 53x26, 53x40, 72x24, 100x30, 40x20 and 53x12, with and without a footnote, picocalc then regular then picocalc again, come out byte-identical before and after. Not yet timed on the device, which was unreachable; A/B it with profile-picocalc. The splash's live rescan (f9e9271) was the first suspect and is not the cost: a serial poll's device ids are stable, so it repaints only when a device comes or goes, and the enumeration itself runs in a thread. Co-Authored-By: Claude Opus 5.5 (1M context) --- meshterm/ui/tui/frame.py | 49 ++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/meshterm/ui/tui/frame.py b/meshterm/ui/tui/frame.py index 0a54197..9f2c5f5 100644 --- a/meshterm/ui/tui/frame.py +++ b/meshterm/ui/tui/frame.py @@ -449,6 +449,41 @@ def _banner_lines(banner: Sequence[str], cols: int) -> list[str]: return _center(padded, cols) +#: The wordmark as the splash last drew it: ``(banner, cols)`` and what that came to. One +#: slot, because there is one splash and one terminal size at a time. +_BANNER_CACHE: tuple[tuple, tuple[list[str], int]] | None = None + + +def _fitted_banner(banner: Sequence[str], cols: int) -> tuple[list[str], int]: + """The wordmark drawn at ``cols`` — fitted, folded and centred — and the art's width. + + Fitting the mark is the dearest thing the splash draws: a mark wider than the terminal + sends :func:`~meshterm.ui.logo.load_logo` back to the disk for every size until one + fits, each one parsed and measured, and then every row is decoded again to centre it. + None of that moves from one paint to the next, and the splash paints on every keystroke + and every idle tick. Done fresh each time it was nine-tenths of a splash frame at + 53×26, which on the PicoCalc put a visible wait behind every ↑↓ on the device list. + + Args: + banner: The wordmark rows the screen names (usually the full-size mark). + cols: Terminal width. + + Returns: + The centred rows to draw — shared with the memo, so never mutate them — and the + display width of the mark actually chosen, for hanging the footnote off its edge. + """ + global _BANNER_CACHE + key = (tuple(banner), cols) + if _BANNER_CACHE is not None and _BANNER_CACHE[0] == key: + return _BANNER_CACHE[1] + raw = list(banner) + if raw and logo_width(raw) > cols: + raw = load_logo(cols) + fitted = (_banner_lines(raw, cols), logo_width(raw)) + _BANNER_CACHE = (key, fitted) + return fitted + + def fit_hint(hint: str, width: int, *, shed_first: Sequence[str] = ()) -> str: """Drop ``·`` atoms from a footer hint, right to left, until it fits ``width``. @@ -508,16 +543,11 @@ def compose_startup(screen: Screen, cols: int, rows: int) -> str: """ # A screen names its wordmark; the width to draw it at is only known here, so this is # where the size is chosen — a narrow terminal gets a narrow mark rather than a torn one. - raw_banner = screen.banner or [] - if raw_banner and logo_width(raw_banner) > cols: - raw_banner = load_logo(cols) - banner = _banner_lines(raw_banner, cols) + # ``logo_w`` is the chosen mark's own width, so the footnote below can hang off its right + # edge (the wordmark is centered as one block, so every row shares one left margin). + banner, logo_w = _fitted_banner(screen.banner or (), cols) banner_h = len(banner) gap = 1 if banner else 0 # the blank line under the banner - - # The logo's own left margin and width, so the footnote below can hang off its right edge - # (the wordmark is centered as one block, so every row shares this margin). - logo_w = logo_width(raw_banner) logo_right = max(0, (cols - logo_w) // 2) + logo_w # Size the box to its widest real row (probe at a generous width, then measure), never @@ -848,7 +878,8 @@ def _bind(platform: Platform) -> None: Registered at module bottom so the immediate first run (see :func:`~meshterm.platforms.on_platform`) finds every cache already defined. """ - global _BASE_BOX_CACHE + global _BASE_BOX_CACHE, _BANNER_CACHE _BASE_BOX_CACHE = None + _BANNER_CACHE = None _DIALOG_CACHE.clear() _OVERLAY_CACHE.clear() From 5d56b45368532118df3a10eaaf416b107e69d88b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Fri, 2 Oct 2026 02:13:37 -0400 Subject: [PATCH 2/2] The node-type legend says room, not room server Beside its square the shorter word is unmistakable, and it brings the whole key to 52 cells, so the legend under a path graph or the contacts table is one line on the PicoCalc and the Cardputer instead of two. The type's name stays room server everywhere else, the CLI's answers included. Co-Authored-By: Claude Opus 5.5 (1M context) --- meshterm/ui/widgets.py | 19 +++++++++++++------ tests/test_records_screen.py | 23 ++++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/meshterm/ui/widgets.py b/meshterm/ui/widgets.py index d5ec8c8..c0fe8c5 100644 --- a/meshterm/ui/widgets.py +++ b/meshterm/ui/widgets.py @@ -1187,16 +1187,23 @@ def _sort_header(label: str, column: str, sort: ContactsSort) -> str: return f"[cursor]{label} {triangle}[/]" +#: The legend's word for each node type: the type's one name (:data:`NODE_TYPE_LABELS`), +#: except where a shorter word is unmistakable beside its glyph — ``room`` for a room +#: server (JP, 2026-10-02). The name everywhere else, the CLI's included, stays whole. +_LEGEND_WORDS = {**NODE_TYPE_LABELS, NODE_TYPE_ROOM: "room"} + + def node_type_legend(indent: str = "", width: int | None = None) -> Text: """The key to the node-type marks: ``★ you ▲ repeater ● companion …``. Every glyph in its shared map colour (see :data:`NODE_GLYPHS`), each named muted after - it. THE legend for any surface that draws typed node markers — the contacts list under its - table, the route graph under its lanes — so one glyph means one thing app-wide. + it (:data:`_LEGEND_WORDS`). THE legend for any surface that draws typed node markers — + the contacts list under its table, the route graph under its lanes — so one glyph means + one thing app-wide. - One line where it fits. Where it does not — the full names run to 59 cells, and the - PicoCalc has 53 — it breaks onto a second line between entries, never inside one, so - a mark is never parted from its name and no name is cropped. + One line where it fits: 52 cells, inside the handhelds' 53. Where it does not — an + indent, a narrower box — it breaks onto a second line between entries, never inside + one, so a mark is never parted from its name and no name is cropped. Args: indent: Leading spaces to sit the legend under a table or graph body. @@ -1205,7 +1212,7 @@ def node_type_legend(indent: str = "", width: int | None = None) -> Text: entries = [Text.assemble((SELF_MARK[0], SELF_MARK[1]), (" you", "muted"))] for node_type in (NODE_TYPE_REPEATER, NODE_TYPE_CHAT, NODE_TYPE_ROOM, NODE_TYPE_SENSOR): glyph, color = NODE_GLYPHS[node_type] - entries.append(Text.assemble((glyph, color), (f" {NODE_TYPE_LABELS[node_type]}", "muted"))) + entries.append(Text.assemble((glyph, color), (f" {_LEGEND_WORDS[node_type]}", "muted"))) gap = " " legend = Text(indent) diff --git a/tests/test_records_screen.py b/tests/test_records_screen.py index 86636c0..996af9c 100644 --- a/tests/test_records_screen.py +++ b/tests/test_records_screen.py @@ -169,19 +169,24 @@ def test_record_dialog_shows_the_node_type_legend() -> None: assert "★ you" in body and "▲ repeater" in body and "◉ sensor" in body -def test_record_dialog_legend_breaks_between_entries_on_a_picocalc_width() -> None: - """At 53 cells the legend takes two lines, and no mark is parted from its name. +def test_record_dialog_legend_is_one_line_on_a_handheld_and_breaks_between_entries() -> None: + """At 53 cells the whole key fits one line; narrower, no mark is parted from its name. - The full names run to 59 cells on one line, so cropping would cut "sensor" off the - PicoCalc; breaking inside an entry would leave a glyph at the end of one line and its - name at the start of the next. + ``room`` rather than ``room server`` brings the key to 52 cells, inside the PicoCalc's + and the Cardputer's 53. Where it still has to break, it breaks between entries: inside + one would leave a glyph at the end of a line and its name at the start of the next. """ screen = _dialog(_record()) screen.handle("tab") # the Route tab - body = _plain(screen.render_body(53)) - for entry in ("★ you", "▲ repeater", "● companion", "■ room server", "◉ sensor"): - assert entry in body - assert all(cell_len(line) <= 53 for line in body.splitlines()) + entries = ("★ you", "▲ repeater", "● companion", "■ room", "◉ sensor") + body = _plain(screen.render_body(53)).splitlines() + assert any(all(entry in line for entry in entries) for line in body) + assert not any("room server" in line for line in body) + + narrow = _plain(screen.render_body(40)) + for entry in entries: + assert entry in narrow + assert all(cell_len(line) <= 40 for line in narrow.splitlines()) def test_record_graph_marks_a_repeater_relay_with_its_triangle() -> None: