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: