From afe1424819b595c65e5a1d76b52440ff689ef4d2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Mon, 24 Aug 2026 03:56:35 -0400 Subject: [PATCH] Selection: white says "this one", and a chip is grey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Teal was still answering three questions it had no business answering. The wordmark's colour is the app's identity, and it is also a node hue — so a cyan-keyed node could vanish into the very highlight pointing at it. - A node's key-derived hue folds to the cursor white on the cursor row. A row is a column of identities right up until it is the row you are on, and then it is answering a different question; a hue on it argues with its own selection. Folded once at the render boundary for any Text whose *base* style is `cursor` (which is how every list and every screen drawing its own rows already marks it), so no screen has to remember the rule. `theme.is_identity_style` is node_style read backwards — every hue a key can mint, on both platforms — and only those fold: the heat of an age, an SNR reading, a red badge, a path line's chip fills all keep what they were given. So does the grey of a node no key could place: the highlight knows where you are, not who. - The reverse-video chip — a dialog's committing button, a running action's Abort, the arrow-mode composer slot, the editor cursor — is grey. A chip marks where a press lands. It is chrome, and chrome does not get a hue. Light grey slot 7 on the VT: the one grey a reverse can put behind text there, and the fill the F-key lane already uses. - The active sort column's heading and triangle take the same white as the cursor row, being the same claim one axis over. They were a bare `#22d3ee`, which put a selection cue back on the node spectrum and, on the console, straight onto the brand's own slot. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 29 +++- meshterm/ui/contactlist.py | 9 +- meshterm/ui/pathline.py | 5 +- meshterm/ui/theme.py | 81 +++++++-- meshterm/ui/tui/render.py | 46 +++++- meshterm/ui/widgets.py | 12 +- tests/test_selection_colour.py | 294 +++++++++++++++++++++++++++++++++ 7 files changed, 438 insertions(+), 38 deletions(-) create mode 100644 tests/test_selection_colour.py diff --git a/CLAUDE.md b/CLAUDE.md index a931dc0..839011d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -180,15 +180,26 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow characters. `node.unknown` is deliberately not `muted`: muted is chrome and may sit a step darker, while an unidentified node is content you can still act on. Our own node is the pure-white `you` style; a context colouring (chart quality) may still win. -- The cursor row — the row `❯` points at, in a select list or in a screen drawing its own - rows — wears `cursor` (white), never `brand`: the wordmark's teal is the app's identity, - not a selection, and teal/cyan is itself a node hue, so a cyan-keyed node used to vanish - into its own highlight. White is outside the node spectrum, so it can never collide with - an identity. It rides *under* the row's spans, so every lane keeps its own colour and - only the gaps take the tint; the path composer's insertion-slot chip takes the same white - so the row you pick and the slot it lands in read as one gesture. Reverse-video chips - (dialog buttons, the editor cursor) keep their own `selected` fill — on the VT a reversed - white lands on the light grey the F-key lane already owns. +- **White is what "you picked this" looks like**, and nothing else in the app is allowed + to say it. The cursor row — the row `❯` points at, in a select list or in a screen + drawing its own rows — wears `cursor` (white), never `brand`: the wordmark's teal is the + app's identity, not a selection, and teal/cyan is itself a node hue, so a cyan-keyed + node used to vanish into its own highlight. White is outside the node spectrum, so it + can never collide with an identity. The same white lights the **active sort column's** + heading and triangle (`contactlist._SORT_ACTIVE`, `widgets._sort_header`) — the same + claim one axis over — and the path composer's insertion-slot chip, so the row you pick + and the slot it lands in read as one gesture. It rides *under* the row's spans, so every + lane keeps the colour it set — an age's heat, an SNR reading, a red badge — with the one + exception the highlight exists for: **a node's key-derived hue folds to the cursor white + on the cursor row** (`theme.is_identity_style` → `render._whiten_identities`, applied + once at the render boundary for any Text whose *base* style is `cursor`), so the + highlighted row reads as one thing instead of as a name arguing with its own selection. + Only a keyed hue folds: `node.unknown`'s grey stays grey, because the highlight must not + claim to know a node we can't place. Reverse-video chips — a dialog's committing button, + a running action's Abort, the arrow-mode composer slot, the editor cursor — are the + `selected` fill, a **grey** block (`muted`'s slate; light grey slot 7 on the VT, the one + grey a reverse can put behind text there, and the same fill the F-key lane uses). A chip + marks where a press lands; it is chrome, and it does not get a hue. Recency heat colours heard/first-heard ages, never names — seven steps on plain human boundaries (`widgets._HEAT_STEPS`), each `heat.*` style named for how old the node it colours is: white under 5 minutes, then yellow, light red, brown, red, light grey, and diff --git a/meshterm/ui/contactlist.py b/meshterm/ui/contactlist.py index f7125c4..ad9c1e1 100644 --- a/meshterm/ui/contactlist.py +++ b/meshterm/ui/contactlist.py @@ -89,10 +89,13 @@ TRACE_SORT_OPENS_ASCENDING: dict[str, bool] = { "name": True, "traced": False, "heard": True, "packets": False, "hash": True, } -#: The cyan the active sort column and its triangle are lit in, matching the static Contacts +#: What the active sort column and its triangle are lit in, matching the static Contacts #: table's header (see :func:`~meshterm.ui.widgets._sort_header`) so sort cues read -#: identically everywhere. -_SORT_ACTIVE = "bold #22d3ee" +#: identically everywhere. The app's ``cursor`` white — the same ink the highlighted row +#: wears, because this is the same claim one lane over: *this* is the one you picked. It +#: used to be a bare cyan, which put a selection cue back on the node spectrum (and, on +#: the console, straight onto the wordmark's slot). +_SORT_ACTIVE = "cursor" #: The default footer: navigation, the Ctrl+arrow sort, filtering, then Esc last. _HINT = "↑↓ move · ^←→↑↓ sort · type to filter · Enter open · Esc back" diff --git a/meshterm/ui/pathline.py b/meshterm/ui/pathline.py index 641180f..831044d 100644 --- a/meshterm/ui/pathline.py +++ b/meshterm/ui/pathline.py @@ -770,8 +770,9 @@ class PathLine: note_style = "faint" if hop.dim else "muted" text = Text() if hop.cursor: - # No chip fill to carry the accent, so the slot takes the app's reverse-video - # `selected` — the same block the editor's cursor has always been. + # No chip fill to carry the slot's white, so it takes the app's reverse-video + # `selected` grey — the same block a dialog's committing button is drawn as, + # and the same block the editor's cursor has always been. text.append(hop.label, style="selected") elif hop.dim: text.append(hop.label, style="faint") diff --git a/meshterm/ui/theme.py b/meshterm/ui/theme.py index 06a0fd3..5c2932f 100644 --- a/meshterm/ui/theme.py +++ b/meshterm/ui/theme.py @@ -27,22 +27,33 @@ MESH_THEME = Theme( { "brand": "bold #5eead4", "accent": "bold #818cf8", - # The highlighted-button fill (cyan block, dark text) shared by every popup dialog. - # It must be a *single* theme name: Rich silently drops a style string that mixes a - # theme name with an attribute (e.g. "reverse brand" renders as plain text), so the - # reverse is baked into the definition here rather than tacked on at the call site. - "selected": "reverse bold #5eead4", - # THE cursor row — the one row the ❯ points at, in every select list and in every - # screen that draws its own rows (feed, routes, records, walk, composer). White, - # and deliberately *not* ``brand``: the highlight used to borrow the wordmark's - # teal, which put the app's identity ink and "the row you're on" on the same hue, - # and worse, teal/cyan is itself a node hue — a cyan-keyed node's name vanished - # into its own highlight. White is outside the per-node spectrum (see node_style) - # so it can never collide with an identity. It does share ink with ``you``, which - # is the accepted cost: spans that set their own colour keep it over the base, so - # only *unstyled* text goes white, and only on the row already under the reader's - # eye. Bold like ``brand`` was, so the dim-slot ``not bold`` pins that protect a - # span inside a highlighted row (see MESH_THEME_16) go on meaning what they meant. + # THE reverse-video chip — a dialog's committing button, a running action's Abort, + # the composer's insertion slot where there is no chip fill to carry it. A *grey* + # block with the page's own ink showing through, because the cyan it used to be + # was the wordmark's teal doing a third job (identity, and a node hue, and now a + # selection), and a chip is chrome: it marks where a press lands, it does not + # claim a colour. The slate is ``muted``'s, light enough that the reversed ink — + # whatever the terminal's background happens to be — reads on it. It must be a + # *single* theme name: Rich silently drops a style string that mixes a theme name + # with an attribute (e.g. "reverse muted" renders as plain text), so the reverse is + # baked into the definition here rather than tacked on at the call site. + "selected": "reverse bold #94a3b8", + # THE ink of "this is the one you picked" — the row the ❯ points at, in every + # select list and in every screen that draws its own rows (feed, routes, records, + # walk, composer), and the lit column heading one axis over where a list is + # sorted. White, and deliberately *not* ``brand``: the highlight used to borrow + # the wordmark's teal, which put the app's identity ink and "the row you're on" + # on the same hue, and worse, teal/cyan is itself a node hue — a cyan-keyed + # node's name vanished into its own highlight. White is outside the per-node + # spectrum (see node_style) so it can never collide with an identity. It does + # share ink with ``you``, which is the accepted cost. Spans that set their own + # colour keep it over the base — the heat of an age, an SNR reading, a red badge + # — with the one exception the highlight is *for*: a node's own key-derived hue + # folds to this white on the cursor row (see theme.is_identity_style and + # ui.tui.render._whiten_identities), so the row the reader is on reads as one + # thing rather than as a name competing with its own selection. Bold like + # ``brand`` was, so the dim-slot ``not bold`` pins that protect a span inside a + # highlighted row (see MESH_THEME_16) go on meaning what they meant. "cursor": "bold #ffffff", # Reversed error (the text-editor cursor sitting on an over-budget character). Baked # in for the same reason as ``selected`` — "reverse err" would render as plain text. @@ -257,7 +268,11 @@ MESH_THEME_16 = Theme( { "brand": "bold color(14)", "accent": "bold color(12)", - "selected": "reverse bold color(14)", + # Slot 7 is the only grey the VT can put *behind* a reverse: backgrounds stop at + # the dim bank, and slot 8's dark grey lands on black there. It is the same light + # grey the F-key lane already fills its chips with, which is the point — one chip + # look on the device. ``not bold`` because 7 is a dim slot (see the bold rule). + "selected": "reverse not bold color(7)", # Slot 15, the top of the bright bank — so the row's bold cannot promote it # further, and every dim-slot span inside it behaves exactly as it did under the # old bold slot-14 highlight. @@ -528,6 +543,38 @@ def _node_style_quantized(key: str) -> str: return f"bold {_NODE_SLOT_HEXES[sector]}" +#: Every style string a node's key can mint, on *either* platform: the 256-hue spectrum +#: and the console's six chromatic slots. A surface that has to *recognise* identity ink +#: rather than produce it matches against this — today that is the cursor row, where a +#: name gives way to the highlight's white. Both vocabularies live in the one set so the +#: answer never depends on which platform happens to be bound, and they cannot collide: +#: the spectrum's channels top out at ``0xf2`` (value 0.95) while every console slot +#: spells ``0xff``. +_IDENTITY_STYLES: frozenset[str] = frozenset( + [_node_style_spectrum(f"{byte:02x}") for byte in range(256)] + + [f"bold {hex_}" for hex_ in _NODE_SLOT_HEXES] +) + + +def is_identity_style(style: str) -> bool: + """Is ``style`` a hue some node's key minted — a *name's* ink rather than the page's? + + :func:`node_style` read backwards, for the one surface that needs the vocabulary as a + question: the cursor row, whose node names are drawn in its white instead of their own + hue (see :func:`~meshterm.ui.tui.render.render_to_ansi`). Deliberately narrow — only a + key-derived hue answers yes, so ``node.unknown``'s grey (a node we *cannot* identify, + which the highlight has no business claiming to know), the ``you`` white, and every + context colouring keep exactly what they were given. + + Args: + style: A style string as it appears on a span. + + Returns: + ``True`` if it is one of the hues :func:`node_style` mints. + """ + return style in _IDENTITY_STYLES + + def name_style(name: str, key: Optional[str] = None) -> str: """The stable colour a node or sender name is drawn in — keyed on the node's key. diff --git a/meshterm/ui/tui/render.py b/meshterm/ui/tui/render.py index 6f6f307..d18ca2a 100644 --- a/meshterm/ui/tui/render.py +++ b/meshterm/ui/tui/render.py @@ -17,10 +17,10 @@ from typing import Optional from rich.cells import cell_len from rich.console import Console, RenderableType -from rich.text import Text +from rich.text import Span, Text from ...platforms import Platform, on_platform -from ..theme import active_theme, fold_text +from ..theme import active_theme, fold_text, is_identity_style #: Cache one headless render console per width. Consoles are cheap but repaint happens on #: every keystroke and on the live-monitor timer, so caching avoids needless churn. Keyed @@ -124,6 +124,47 @@ def _console(width: int) -> Console: return console +def _whiten_identities(renderable: RenderableType) -> RenderableType: + """On the cursor row, a node's name is drawn in the highlight's white, not its hue. + + A node's name is always coloured by its key, so a column of them reads as a column of + identities — but the row the ``❯`` points at is answering a different question, and a + keyed hue on it competes with the very highlight that says "this one". So the row that + declares itself the cursor (its *base* style is ``cursor``, which is how every list and + every screen drawing its own rows marks it) has its identity spans folded to that same + white, and the row reads as one thing. + + Only :func:`~meshterm.ui.theme.is_identity_style` hues fold. Everything else on the row + is untouched — the heard-age heat, an SNR reading, a red badge, a path line's chip + fills, the grey of a node no key could place — because none of those are the identity + the highlight is standing in for. + + Done here because this is where a row *is* a row: one boundary every screen's rows + already leave through, rather than a rule each of them has to remember. Callers hand us + read-only :class:`Text` (the ANSI cache keys on their content), so the rewrite is on a + copy. + + Args: + renderable: Whatever is about to be rendered. + + Returns: + The renderable, or a cursor row's copy with its name hues turned white. + """ + if not isinstance(renderable, Text) or str(renderable.style) != "cursor": + return renderable + spans = renderable.spans + if not any(is_identity_style(str(span.style)) for span in spans): + return renderable + out = renderable.copy() + out.spans = [ + Span(span.start, span.end, "cursor") + if is_identity_style(str(span.style)) + else span + for span in spans + ] + return out + + def render_to_ansi(renderable: RenderableType, width: int, *, no_wrap: bool = False) -> str: """Render a Rich renderable to an ANSI string at ``width`` columns. @@ -143,6 +184,7 @@ def render_to_ansi(renderable: RenderableType, width: int, *, no_wrap: bool = Fa if cached is not None: _ANSI_CACHE.move_to_end(key) return cached + renderable = _whiten_identities(renderable) console = _console(width) with console.capture() as capture: if no_wrap: diff --git a/meshterm/ui/widgets.py b/meshterm/ui/widgets.py index 8ee4caf..cbf3ae2 100644 --- a/meshterm/ui/widgets.py +++ b/meshterm/ui/widgets.py @@ -1064,16 +1064,18 @@ def _ordered_contacts( def _sort_header(label: str, column: str, sort: ContactsSort) -> str: - """A column header: plain-muted, or cyan with a direction triangle when it's the sort key. + """A column header: plain-muted, or lit with a direction triangle when it's the sort key. - The active column's name and its triangle are lit cyan together (so the interactive - left/right selection is obvious) — ``▲`` for ascending, ``▼`` for descending. The column - reserves its width (see :func:`contacts_table`) so toggling the sort doesn't shift the row. + The active column's name and its triangle are lit together in the app's ``cursor`` white + (so the interactive left/right selection is obvious) — ``▲`` for ascending, ``▼`` for + descending. Same ink as the highlighted *row*, because it is the same claim one axis + over. The column reserves its width (see :func:`contacts_table`) so toggling the sort + doesn't shift the row. """ if column != sort.column: return label triangle = "▲" if sort.ascending else "▼" - return f"[bold #22d3ee]{label} {triangle}[/]" + return f"[cursor]{label} {triangle}[/]" def node_type_legend(indent: str = "") -> Text: diff --git a/tests/test_selection_colour.py b/tests/test_selection_colour.py new file mode 100644 index 0000000..25b7121 --- /dev/null +++ b/tests/test_selection_colour.py @@ -0,0 +1,294 @@ +"""White is what "you picked this" looks like — and nothing else says it. + +Three surfaces used to answer the question in the wordmark's teal: the cursor row (fixed +earlier), the chip a dialog's committing button is drawn as, and the heading of the column +a list is sorted by. Teal is a *node* hue as well as the app's identity ink, so every one +of them could collide with the very thing it was highlighting. + +What holds now: the cursor row and the active sort column are the ``cursor`` white; a +reverse-video chip is grey, because a chip is chrome and marks where a press lands rather +than claiming a colour; and on the cursor row a node's key-derived hue folds to that same +white, so the highlighted row reads as one thing instead of as a name arguing with its own +selection. Only a *keyed* hue folds — the grey of a node no key could place stays grey. +""" + +from __future__ import annotations + +import re + +import pytest +from rich.text import Text + +from meshterm.platforms import PICOCALC, REGULAR, set_platform +from meshterm.ui.contactlist import _SORT_ACTIVE +from meshterm.ui.theme import ( + MESH_THEME, + MESH_THEME_16, + is_identity_style, + name_style, + node_style, +) +from meshterm.ui.tui.render import render_to_ansi + +#: A key whose first byte lands well away from white in every direction, so "the hue is +#: gone" is a real observation rather than a coincidence of the palette. +_KEY = "a1b2c3d4e5f6" + + +@pytest.fixture(autouse=True) +def _regular_platform(): + """Every test states its own platform; default to the desktop and restore after.""" + set_platform(REGULAR) + yield + set_platform(REGULAR) + + +def _row(*, selected: bool) -> Text: + """A list row in the shape every screen builds: pointer, name, age, key lane.""" + row = Text() + row.append("❯ " if selected else " ", style="cursor" if selected else "") + row.append("YUL-Poly", style=name_style("YUL-Poly", _KEY)) + row.append(" ") + row.append("5m", style="heat.minutes") + row.append(" ") + row.append("a1", style=node_style(_KEY)) # the lit half of a key lane + row.append("b2c3d4e5", style="muted") + if selected: + row.style = "cursor" + return row + + +def _hues(ansi: str) -> set[str]: + """The truecolor foregrounds the rendered row actually emitted, as ``#rrggbb``.""" + return { + "#%02x%02x%02x" % tuple(int(part) for part in match.groups()) + for match in re.finditer(r"\x1b\[[\d;]*?38;2;(\d+);(\d+);(\d+)m", ansi) + } + + +# -- the cursor row's names --------------------------------------------------------- + + +def test_a_selected_row_draws_its_node_name_in_the_cursor_white() -> None: + """THE ask: the row you are on says "this one", not "this one is mauve".""" + hue = name_style("YUL-Poly", _KEY).removeprefix("bold ") + + hues = _hues(render_to_ansi(_row(selected=True), 60)) + + assert hue not in hues, f"the identity hue {hue} survived the highlight" + assert "#ffffff" in hues + + +def test_an_unselected_row_keeps_every_name_in_its_own_hue() -> None: + """The fold is the *highlight's* doing; the column below it still reads as identities.""" + hue = name_style("YUL-Poly", _KEY).removeprefix("bold ") + + assert hue in _hues(render_to_ansi(_row(selected=False), 60)) + + +def test_a_key_lane_s_lit_hash_folds_with_the_name_it_belongs_to() -> None: + """``highlighted_hash`` lights the hash in the same key-derived hue, so it folds too. + + Otherwise the highlighted row would go white everywhere except one two-character lane + still shouting its hue — the exact incoherence the fold exists to remove. + """ + row = Text(" ") + row.append("a1", style=node_style(_KEY)) + row.append("b2c3d4e5", style="muted") + row.style = "cursor" + + hues = _hues(render_to_ansi(row, 30)) + + assert node_style(_KEY).removeprefix("bold ") not in hues + assert "#94a3b8" in hues, "the unlit tail of the key is muted and stays muted" + + +def test_the_highlight_does_not_claim_to_know_an_unidentified_node() -> None: + """A node no key could place keeps its grey: the selection knows *where* you are, not who. + + ``node.unknown`` is not a hue — it is the absence of one — so folding it to white would + have the highlighted row assert an identity the app does not have. + """ + row = Text(" ") + row.append("3d", style="node.unknown") + row.style = "cursor" + + assert "#94a3b8" in _hues(render_to_ansi(row, 30)) + + +def test_the_highlight_leaves_every_other_lane_its_own_colour() -> None: + """Heat, SNR and badges are not identities — the row is highlighted, not repainted.""" + row = Text(" ") + row.append("5m", style="heat.minutes") + row.append(" ") + row.append("+7.5", style="snr.good") + row.append(" ") + row.append("stale", style="err") + row.style = "cursor" + + hues = _hues(render_to_ansi(row, 40)) + + assert {"#facc15", "#4ade80", "#f87171"} <= hues + + +def test_a_path_line_s_chips_keep_their_fills_on_the_cursor_row() -> None: + """A hue used as a chip's *fill* is the segment, not a name — it is not folded. + + The composed style (``ink on fill``) is deliberately not in the identity vocabulary, so + a route drawn in chips survives being highlighted intact. + """ + fill = node_style(_KEY).removeprefix("bold ") + row = Text(" ") + row.append(" YUL-Poly ", style=f"#0f172a on {fill}") + row.style = "cursor" + + assert f"48;2;{int(fill[1:3], 16)};" in render_to_ansi(row, 40) + + +def test_the_fold_never_touches_the_row_it_was_handed() -> None: + """Rendered Texts are cache keys, so the rewrite has to happen on a copy. + + A mutated input would poison the ANSI cache: the next lookup would hash the *folded* + row and miss, and any caller re-rendering the same object unselected would get white. + """ + row = _row(selected=True) + before = [(span.start, span.end, str(span.style)) for span in row.spans] + + render_to_ansi(row, 60) + + assert [(s.start, s.end, str(s.style)) for s in row.spans] == before + + +def test_the_ansi_cache_tells_a_highlighted_row_from_the_same_row_unhighlighted() -> None: + """Same words, same spans, different base style — and the cache keys on the base.""" + plain_ansi = render_to_ansi(_row(selected=False), 60) + lit_ansi = render_to_ansi(_row(selected=True), 60) + + assert plain_ansi != lit_ansi + assert render_to_ansi(_row(selected=False), 60) == plain_ansi # not clobbered + + +@pytest.mark.parametrize("platform", [REGULAR, PICOCALC]) +def test_the_fold_speaks_whichever_hue_vocabulary_is_bound(platform) -> None: # noqa: ANN001 + """PicoCalc quantizes the hue to a palette slot; the rule above it is the same rule.""" + set_platform(platform) + row = Text(" ") + row.append("YUL-Poly", style=name_style("YUL-Poly", _KEY)) + row.style = "cursor" + + lit = render_to_ansi(row, 30) + unlit = render_to_ansi(Text(" YUL-Poly"), 30) + + assert lit != unlit + assert "YUL-Poly" in re.sub(r"\x1b\[[\d;]*m", "", lit) + if platform is PICOCALC: + assert "\x1b[1;97mYUL-Poly" in lit, lit # slot 15, the console's white + else: + assert "38;2;255;255;255mYUL-Poly" in lit, lit + + +# -- the vocabulary itself ------------------------------------------------------------ + + +@pytest.mark.parametrize("platform", [REGULAR, PICOCALC]) +def test_every_hue_a_key_can_mint_is_recognised_as_one(platform) -> None: # noqa: ANN001 + """:func:`node_style` read backwards has to answer for all 256 first bytes. + + A hue the vocabulary missed would be a name that quietly refused to fold on exactly + the nodes whose keys start with that byte. + """ + set_platform(platform) + + assert all(is_identity_style(node_style(f"{byte:02x}")) for byte in range(256)) + + +@pytest.mark.parametrize( + "style", ["you", "cursor", "muted", "node.unknown", "brand", "heat.now", "err", + "bold #ffffff", "#94a3b8", "", "none"], +) +def test_nothing_but_a_key_derived_hue_counts_as_an_identity(style: str) -> None: + """Everything else on a row means something the highlight has no claim on.""" + assert not is_identity_style(style) + + +def test_the_two_platforms_hue_vocabularies_cannot_be_confused() -> None: + """Both are in the set at once, so they must not overlap or a switch would misfold. + + The spectrum tops out at ``0xf2`` (value 0.95) and every console slot spells ``0xff``, + which is what keeps the answer independent of the platform bound at the time. + """ + set_platform(REGULAR) + spectrum = {node_style(f"{byte:02x}") for byte in range(256)} + set_platform(PICOCALC) + slots = {node_style(f"{byte:02x}") for byte in range(256)} + + assert not (spectrum & slots) + + +# -- the reverse-video chip ----------------------------------------------------------- + + +def test_the_selection_chip_is_grey_on_both_platforms() -> None: + """A dialog button, an Abort, the arrow-mode composer slot: chrome, not a hue.""" + for theme in (MESH_THEME, MESH_THEME_16): + chip = theme.styles["selected"] + assert chip.reverse, "the chip is reverse video — the page's own ink shows through" + assert chip.color is not None + red, green, blue = chip.color.get_truecolor() + saturation = (max(red, green, blue) - min(red, green, blue)) / max(red, green, blue) + assert saturation <= 0.25, ( + f"the chip's fill {chip.color!r} carries a hue; it should be grey " + "(the palette's greys are slate, so a little blue cast is the family)" + ) + + +def test_the_chip_is_light_enough_for_the_page_s_ink_to_read_on_it() -> None: + """Reverse video puts the terminal's background *in* the chip, so the fill carries it.""" + red, green, blue = MESH_THEME.styles["selected"].color.get_truecolor() + + assert min(red, green, blue) >= 0x80 + + +def test_the_console_chip_uses_a_background_the_vt_can_actually_address() -> None: + """The VT has no bright backgrounds, and slot 8's dark grey reverses to black.""" + chip = MESH_THEME_16.styles["selected"] + + assert chip.color.number == 7, "slot 7 is the only grey a reverse can put behind text" + assert chip.bold is False, "a dim-slot style states its intent about bold" + + +def test_no_theme_style_still_paints_a_selection_in_the_wordmark_s_teal() -> None: + """The regression this whole file is named for, pinned as a property of the theme.""" + for theme in (MESH_THEME, MESH_THEME_16): + for name in ("selected", "cursor"): + assert theme.styles[name].color.get_truecolor() != ( + MESH_THEME.styles["brand"].color.get_truecolor() + ), name + + +# -- the active sort column ----------------------------------------------------------- + + +def test_the_active_sort_column_is_lit_in_the_cursor_white() -> None: + """The same claim as the cursor row, one axis over — so the same ink. + + It used to be a bare ``#22d3ee``, which put a *selection* cue back on the node + spectrum and, on the console, straight onto the wordmark's own slot. + """ + from meshterm.ui.contactlist import ContactsSort + from meshterm.ui.widgets import _sort_header + + lit = _sort_header("NAME", "name", ContactsSort("name", True)) + idle = _sort_header("HEARD", "heard", ContactsSort("name", True)) + + assert lit == "[cursor]NAME ▲[/]" + assert idle == "HEARD" + assert _SORT_ACTIVE == "cursor", "the live list and the static table light it the same" + + +def test_the_sort_cue_survives_the_console_s_sixteen_slots() -> None: + """A bare hex would have been quantized at the fold; a theme name is chosen deliberately.""" + set_platform(PICOCALC) + header = Text("NAME ▲", style=_SORT_ACTIVE) + + assert "\x1b[1;97m" in render_to_ansi(header, 20) # slot 15, not the brand's 14