An unknown node is light grey, and bold stops recolouring it
Two reports on the PicoCalc's message paths, one root cause each. The graph drew an unnamed hop's hash — and the sender's name — as white, the "you" colour. MapCanvas emits its own bold for markers and labels, and its colours arrive already quantized to a palette slot; the kernel VT then draws bold as *brightness*, so anything that landed in the dim bank was promoted to its bright partner. Light grey became white. A purple repeater would have become pink the same way. The canvas now drops emphasis where bold is brightness — the colour is the load-bearing part. The same trap reaches the theme through inheritance: Rich merges a row's base style into every span, so a dim-slot span left silent about bold changes colour inside a selected row. Every dim-slot style now says which it means — `not bold` to keep its colour, `bold` where the promotion is the point (only title.muted) — and a test forbids staying silent. The pathline drew the same hop dark grey, because `muted` collapses onto the console's dark grey while the desktop's is light. That conflated two things: `muted` is chrome and may recede a step, but a node we can't identify is content you can still act on. It gets its own name, `node.unknown` — light grey, identical to today's desktop muted, so nothing moves there — and it is what `name_style` returns keyless, what an unlit `highlighted_hash` wears, and what the `○` ring is. Also fixes a crash from the previous commit: the graph's label colour resolved a marker through `parse_hex`, which the type marks' theme names are not. A repeater relay we couldn't name would have raised. The gallery's node-detail header spelled a marker hex by hand; it goes through the app's own styles now, so a palette bug can't hide behind it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
935b4fb3b6
commit
d79d85b7ee
11 files changed
+210
-69
No files matched your search
@@ -133,9 +133,12 @@ Relative ages: `format_ago` for prose ("now", "5m ago", "never" — never "now a
|
||||
- Node names are always coloured: `name_style(name, key)` palette hue, derived from the
|
||||
node's key (its first byte — any known prefix agrees) so a rename keeps the colour.
|
||||
One rule on **every** platform; only the resolution changes (see **Platforms**).
|
||||
A surface holding only a name resolves it first (`make_name_key_resolver`); a name
|
||||
no known node carries stays muted — colour is reserved for keyed identities, never
|
||||
seeded from a name's characters. Our own node
|
||||
A surface holding only a name resolves it first (`make_name_key_resolver`); a node no
|
||||
key can place — an unresolved sender, a bare hash standing in as a name, an `○` ring —
|
||||
takes `node.unknown`, THE light grey for an unidentified node, everywhere and on both
|
||||
platforms. Colour is reserved for keyed identities, never seeded from a name's
|
||||
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.
|
||||
Recency heat colours heard/first-heard ages, never names. A key lane (via
|
||||
`highlighted_hash`) lights its hash in the same key-derived hue; the rest of the key,
|
||||
@@ -168,8 +171,14 @@ branch on the platform per frame, and never `from meshterm.platforms import PLAT
|
||||
found on-device. The font itself is built by `scripts/calculinux-console-font.sh`;
|
||||
the two files move in the same commit.
|
||||
- The 16-slot palette is `theme._VT_SLOTS` (programmed via `/etc/vtrgb`; same script).
|
||||
`MESH_THEME_16` speaks `color(0..15)` only; bold is brightness on the VT (never bold
|
||||
slots 5/6); backgrounds stop at slot 7. Both themes define identical style names.
|
||||
`MESH_THEME_16` speaks `color(0..15)` only; backgrounds stop at slot 7. Both themes
|
||||
define identical style names.
|
||||
- **Bold is brightness on the VT**: `bold` on a 0–7 foreground *is* slot N+8, so a
|
||||
dim-slot style must state its intent — `not bold` (keep the declared colour) or `bold`
|
||||
(the promotion is the point, only `title.muted`), never silent. Rich merges a row's
|
||||
base style into every span, so a silent one changes colour inside a selected row. Same
|
||||
trap outside the theme: `MapCanvas` drops emphasis entirely where bold is brightness,
|
||||
since its colours arrive quantized and it can't know which bank they landed in.
|
||||
- On picocalc, the node hue and the heat gradient **quantize** — same rule, coarser
|
||||
resolution: `node_style` snaps the key's hue to its sixth of the wheel
|
||||
(`theme._NODE_SLOT_HEXES`, the six chromatic bright slots) and heat to the `heat.*`
|
||||
|
||||
@@ -17,11 +17,24 @@ from __future__ import annotations
|
||||
import unicodedata
|
||||
from typing import Optional
|
||||
|
||||
from ..platforms import Platform, on_platform
|
||||
from .marks import RGB, parse_hex # noqa: F401 - canonical home; re-exported for importers
|
||||
|
||||
#: Unicode braille pattern base; add a dot bitmask to get the glyph.
|
||||
_BRAILLE_BASE = 0x2800
|
||||
|
||||
#: What an emboldened run emits — nothing on a 16-slot console, where the kernel VT draws
|
||||
#: bold as brightness and would recolour the run rather than weight it (see
|
||||
#: :meth:`MapCanvas.to_ansi_lines`). Bound at platform-switch time.
|
||||
_BOLD = "\x1b[1m"
|
||||
|
||||
|
||||
@on_platform
|
||||
def _bind(platform: Platform) -> None:
|
||||
"""Bind the canvas's emphasis to what the platform can express (now and on switches)."""
|
||||
global _BOLD
|
||||
_BOLD = "\x1b[1m" if platform.truecolor else ""
|
||||
|
||||
|
||||
def single_cell(text: str) -> str:
|
||||
"""Reduce ``text`` to characters that render in exactly one fixed-width cell.
|
||||
@@ -306,6 +319,12 @@ class MapCanvas:
|
||||
platform's render-boundary fold: on PicoCalc the truecolour SGR quantizes to
|
||||
the 16 palette slots (and any stray glyph folds to the console font) right
|
||||
here, wherever the lines end up embedded.
|
||||
|
||||
Emphasis is dropped on a platform that has no truecolour (see :data:`_BOLD`): the
|
||||
kernel VT draws ``bold`` as *brightness*, so a bold run whose colour just quantized
|
||||
into the dim bank would be promoted to that slot's bright partner — a light-grey
|
||||
unknown label arriving as white "you", a purple repeater as pink. The colour a
|
||||
marker was given is the load-bearing part; the emboldening is not.
|
||||
"""
|
||||
from .theme import fold_text
|
||||
|
||||
@@ -332,7 +351,7 @@ class MapCanvas:
|
||||
style = (color, bold)
|
||||
if style != cur:
|
||||
r, g, b = color
|
||||
parts.append(f"\x1b[0m\x1b[38;2;{r};{g};{b}m" + ("\x1b[1m" if bold else ""))
|
||||
parts.append(f"\x1b[0m\x1b[38;2;{r};{g};{b}m" + (_BOLD if bold else ""))
|
||||
cur = style
|
||||
parts.append(ch)
|
||||
if cur is not None:
|
||||
|
||||
@@ -28,11 +28,15 @@ def parse_hex(color: str) -> RGB:
|
||||
# and warm amber (roads), so markers use the hues a map never contains — pink/violet — to
|
||||
# stand out against it. Ordinary nodes are the loudest (bright pink); repeaters recede a
|
||||
# step (a calmer violet); our own node stays the fixed yellow star; a node heard of but
|
||||
# never identified is a muted grey ring. Every glyph is in the PicoCalc console font.
|
||||
# never identified is a light grey ring. Every glyph is in the PicoCalc console font.
|
||||
#
|
||||
# A mark's colour is whatever :func:`~meshterm.ui.theme.mark_rgb` takes — a literal hex, or
|
||||
# a theme style name where the platform must pick the shade itself. The unknown ring is
|
||||
# named (``node.unknown``) so the ring and the grey label beside it can never disagree.
|
||||
SELF_MARK = ("★", "#facc15")
|
||||
REPEATER_MARK = ("▲", "#a78bfa")
|
||||
NODE_MARK = ("●", "#f472b6")
|
||||
UNKNOWN_MARK = ("○", "#94a3b8")
|
||||
UNKNOWN_MARK = ("○", "node.unknown")
|
||||
|
||||
#: Sentinels naming a path's endpoints on the route graph. ``\x00`` never appears in a
|
||||
#: node hash, so they can share the node-id namespace without colliding with one.
|
||||
|
||||
@@ -578,7 +578,10 @@ class PathLine:
|
||||
elif hop.key:
|
||||
text.append(hop.label, style=node_style(hop.key))
|
||||
else:
|
||||
text.append(hop.label, style="muted")
|
||||
# No key to derive a hue from: the hop is a bare hash standing in for a node
|
||||
# we can't identify, so it takes the app-wide unknown-node grey — not `muted`,
|
||||
# which is chrome and sits a step darker on a console with only two greys.
|
||||
text.append(hop.label, style="node.unknown")
|
||||
if hop.annotation:
|
||||
text.append(f" ({hop.annotation})", style=note_style)
|
||||
return text
|
||||
|
||||
+35
-18
@@ -52,6 +52,13 @@ MESH_THEME = Theme(
|
||||
"warn": "bold #fbbf24",
|
||||
"err": "bold #f87171",
|
||||
"muted": "#94a3b8",
|
||||
# A node we can't identify — its ``○`` ring, and its label wherever a bare key or
|
||||
# hash stands in for a name (see name_style's keyless return). Its own name rather
|
||||
# than plain ``muted`` because the two must not track each other: ``muted`` is
|
||||
# chrome and may sit a step down from body text, while an unidentified node is
|
||||
# *content* you can still act on. On the console that difference is the whole
|
||||
# ladder — chrome takes the dark grey slot, this one the light grey.
|
||||
"node.unknown": "#94a3b8",
|
||||
# Panel/dialog titles: the same hue as the border they sit in, one shade brighter,
|
||||
# so the title reads as part of its frame while still standing out from it. One
|
||||
# entry per border style the frame compositor is given (see theme.title_style).
|
||||
@@ -120,10 +127,15 @@ MESH_THEME = Theme(
|
||||
#: bind:
|
||||
#:
|
||||
#: * The kernel VT renders **bold as brightness**: ``bold`` on a 0–7 foreground jumps it
|
||||
#: to slot N+8. A style may only combine ``bold`` with a dim slot when the bright
|
||||
#: partner keeps its meaning — and never with 5/6, whose partners are claimed by
|
||||
#: *different* semantics here (5 purple = the repeater mark, 13 pink = the node mark;
|
||||
#: 6 cyan = hint.brand, 14 bright cyan = brand).
|
||||
#: to slot N+8. So a dim-slot style must say what it means about bold — it cannot leave
|
||||
#: the question open, because Rich merges a *base* style into every span it wraps and a
|
||||
#: selected row's ``bold`` would then recolour the span outright (a light-grey unknown
|
||||
#: hash arriving as white "you", a purple repeater as pink). Every dim-slot style is
|
||||
#: therefore either explicitly ``not bold`` (the colour is load-bearing; keep it) or
|
||||
#: explicitly ``bold`` (the promotion *is* the intent — only ``title.muted``). Never
|
||||
#: silent, and never bold on 5/6, whose partners are claimed by *different* semantics
|
||||
#: here (5 purple = the repeater mark, 13 pink = the node mark; 6 cyan = hint.brand,
|
||||
#: 14 bright cyan = brand).
|
||||
#: * Backgrounds can only address slots 0–7 (SGR 40–47).
|
||||
#: * The six *chromatic bright* slots (9-14) are the node-name spectrum's landing zone —
|
||||
#: the console's rendering of the key-derived hue wheel (see :data:`_NODE_SLOT_HEXES`).
|
||||
@@ -205,40 +217,45 @@ MESH_THEME_16 = Theme(
|
||||
"you": "bold color(15)",
|
||||
"device.known": "bold color(15)",
|
||||
"bluetooth": "bold color(15) on color(4)",
|
||||
"bluetooth.edge": "color(4)",
|
||||
"bluetooth.edge": "not bold color(4)",
|
||||
"ok": "bold color(10)",
|
||||
"warn": "bold color(11)",
|
||||
"err": "bold color(9)",
|
||||
"muted": "color(8)",
|
||||
# Light grey, a step *above* muted's dark grey: the console has exactly two greys,
|
||||
# and an unidentified node's hash is content, not chrome.
|
||||
"node.unknown": "not bold color(7)",
|
||||
"title.accent": "bold color(12)",
|
||||
# The one deliberate promotion: bold takes slot 7 to 15, and near-white is exactly
|
||||
# what this title wants (the regular theme spells it #cbd5e1).
|
||||
"title.muted": "bold color(7)",
|
||||
"title.warn": "bold color(11)",
|
||||
"title.err": "bold color(9)",
|
||||
"title.ok": "bold color(10)",
|
||||
"title.brand": "bold color(14)",
|
||||
"hint.accent": "color(4)",
|
||||
"hint.accent": "not bold color(4)",
|
||||
"hint.muted": "color(8)",
|
||||
"hint.warn": "color(3)",
|
||||
"hint.err": "color(1)",
|
||||
"hint.ok": "color(2)",
|
||||
"hint.brand": "color(6)",
|
||||
"hint.warn": "not bold color(3)",
|
||||
"hint.err": "not bold color(1)",
|
||||
"hint.ok": "not bold color(2)",
|
||||
"hint.brand": "not bold color(6)",
|
||||
"faint": "color(8)",
|
||||
"track": "color(8)",
|
||||
"snr.good": "bold color(10)",
|
||||
"snr.ok": "bold color(11)",
|
||||
"snr.bad": "bold color(9)",
|
||||
"batt.high": "bold color(10)",
|
||||
"batt.mid": "color(3)",
|
||||
"batt.mid": "not bold color(3)",
|
||||
"batt.low": "bold color(9)",
|
||||
"batt.dim": "color(8)",
|
||||
"type.node": "color(13)",
|
||||
"type.repeater": "color(5)",
|
||||
"type.repeater": "not bold color(5)",
|
||||
"type.room": "color(15)",
|
||||
"type.sensor": "color(3)",
|
||||
"type.sensor": "not bold color(3)",
|
||||
"heat.hot": "bold color(15)",
|
||||
"heat.warm": "color(11)",
|
||||
"heat.cool": "color(3)",
|
||||
"heat.cold": "color(7)",
|
||||
"heat.cool": "not bold color(3)",
|
||||
"heat.cold": "not bold color(7)",
|
||||
"heat.never": "color(8)",
|
||||
# The F-key lane's chip fills: light-grey background (the palette's only "gray"
|
||||
# addressable as a background — see _VT_SLOTS) for the plain bank, green for the
|
||||
@@ -439,15 +456,15 @@ def name_style(name: str, key: Optional[str] = None) -> str:
|
||||
name: The display name (unused for the hue; kept so every call site reads
|
||||
``name_style(name, key)`` and the pair stays greppable).
|
||||
key: Any known prefix of the node's key/hash. ``None``/empty marks a sender whose
|
||||
key we couldn't resolve — drawn ``muted``, because colour is reserved for
|
||||
keyed identities (callers with only a name resolve it first via
|
||||
key we couldn't resolve — drawn ``node.unknown``, because colour is reserved
|
||||
for keyed identities (callers with only a name resolve it first via
|
||||
:func:`~meshterm.services.trace_runner.make_name_key_resolver`).
|
||||
|
||||
Returns:
|
||||
A style for the name; the same node always maps to the same style on a given
|
||||
platform, so it keeps its colour across screens and sessions.
|
||||
"""
|
||||
return node_style(key) if key else "muted"
|
||||
return node_style(key) if key else "node.unknown"
|
||||
|
||||
|
||||
# -- the compact icon language (PicoCalc) ---------------------------------------------
|
||||
|
||||
+14
-14
@@ -67,7 +67,7 @@ from .map_render import _NODE, _REPEATER, _SELF, _UNKNOWN
|
||||
from .mapcanvas import RGB, MapCanvas, parse_hex
|
||||
from .menus import fit_cells
|
||||
from .pathline import ELIDE_HEAD, PathHop, PathLine
|
||||
from .theme import name_style, node_style, snr_style
|
||||
from .theme import mark_rgb, name_style, node_style, snr_style
|
||||
from .trace_screen import snr_bar
|
||||
from .tui.render import render_to_ansi
|
||||
from .tui.screen import ListWindow, Screen
|
||||
@@ -523,7 +523,7 @@ class WalkScreen(Screen):
|
||||
style = self._list_name_style(node)
|
||||
return PathHop(
|
||||
self._label(node),
|
||||
key=None if style in ("you", "muted") else node,
|
||||
key=None if style in ("you", "node.unknown") else node,
|
||||
you=style == "you",
|
||||
)
|
||||
|
||||
@@ -681,7 +681,7 @@ class WalkScreen(Screen):
|
||||
white = (255, 255, 255)
|
||||
for other, (x, y) in placed.items():
|
||||
if other == _MORE:
|
||||
rgb = white if selected in hidden else parse_hex(_UNKNOWN[1])
|
||||
rgb = white if selected in hidden else mark_rgb(_UNKNOWN[1])
|
||||
canvas.marker(x, y, "…", rgb)
|
||||
continue
|
||||
glyph, _type_color = self._glyph(other)
|
||||
@@ -699,7 +699,7 @@ class WalkScreen(Screen):
|
||||
if selected in hidden:
|
||||
self._label_right(canvas, x, y, self._label(selected), white)
|
||||
else:
|
||||
self._label_right(canvas, x, y, f"+{len(hidden)} weaker", parse_hex(_UNKNOWN[1]))
|
||||
self._label_right(canvas, x, y, f"+{len(hidden)} weaker", mark_rgb(_UNKNOWN[1]))
|
||||
|
||||
return canvas.to_ansi_lines()
|
||||
|
||||
@@ -1028,7 +1028,7 @@ class WalkScreen(Screen):
|
||||
return "you"
|
||||
label = self._label(node)
|
||||
if label == node[:8]: # a bare hash is not a name — colour is the name signal
|
||||
return "muted"
|
||||
return "node.unknown"
|
||||
return name_style(label, node)
|
||||
|
||||
def _marker_rgb(self, node: str) -> RGB:
|
||||
@@ -1045,22 +1045,22 @@ class WalkScreen(Screen):
|
||||
return (255, 255, 255)
|
||||
raw = node.lower()
|
||||
if not raw or any(c not in "0123456789abcdef" for c in raw):
|
||||
return parse_hex(_UNKNOWN[1])
|
||||
return mark_rgb(_UNKNOWN[1])
|
||||
return parse_hex(node_style(node).rsplit("#", 1)[-1])
|
||||
|
||||
def _label_rgb(self, node: str) -> RGB:
|
||||
"""The label colour for a node on the canvas: its name hue, ours white, a bare hash muted.
|
||||
"""The label colour for a node on the canvas: its name hue, ours white, a bare hash grey.
|
||||
|
||||
The RGB counterpart of :meth:`_list_name_style`: a named node's key hue, our own
|
||||
node white, and a node known only by a bare hash muted (a key standing in as a name
|
||||
is never itself coloured, so the marker carries the identity and the hash-label
|
||||
stays grey).
|
||||
node white, and a node known only by a bare hash the unknown-node grey (a key
|
||||
standing in as a name is never itself coloured, so the marker carries the identity
|
||||
and the hash-label stays grey).
|
||||
"""
|
||||
style = self._list_name_style(node)
|
||||
if style == "you":
|
||||
return (255, 255, 255)
|
||||
if style == "muted":
|
||||
return parse_hex("#94a3b8")
|
||||
if "#" not in style: # a theme name (node.unknown) — the platform picks the shade
|
||||
return mark_rgb(style)
|
||||
return parse_hex(style.rsplit("#", 1)[-1])
|
||||
|
||||
def _glyph_style(self, node: str) -> str:
|
||||
@@ -1068,13 +1068,13 @@ class WalkScreen(Screen):
|
||||
|
||||
The text-side companion of :meth:`_marker_rgb`, so the focus line's leading glyph
|
||||
matches its canvas marker — key-hued for a real node, the white ``you`` for us, and
|
||||
muted for a keyless placeholder id.
|
||||
the unknown-node grey for a keyless placeholder id.
|
||||
"""
|
||||
if node == self._topo.self_id:
|
||||
return "you"
|
||||
raw = node.lower()
|
||||
if not raw or any(c not in "0123456789abcdef" for c in raw):
|
||||
return "muted"
|
||||
return "node.unknown"
|
||||
return node_style(node)
|
||||
|
||||
def _empty_state(self, width: int) -> list[str]:
|
||||
|
||||
+18
-13
@@ -442,6 +442,10 @@ def highlighted_hash(value: str, prefix_bytes: int, width: Optional[int] = None)
|
||||
shorter than the key ellipsizes it (the ``…`` takes the colour of the digit it
|
||||
replaces, so a highlight wider than the budget still reads as one).
|
||||
|
||||
With ``prefix_bytes=0`` nothing is lit and the key is standing in *as* a name — a node
|
||||
we can't identify — so the whole run takes ``node.unknown`` rather than ``muted``: it
|
||||
is the row's content, not the dim tail of a hash whose head already carries the hue.
|
||||
|
||||
Args:
|
||||
value: The key as hex, optionally ``0x``-prefixed and mixed-case.
|
||||
prefix_bytes: Number of leading bytes the current path-hash mode addresses; ``0``
|
||||
@@ -469,11 +473,12 @@ def highlighted_hash(value: str, prefix_bytes: int, width: Optional[int] = None)
|
||||
elif width is not None:
|
||||
pad = width - len(raw)
|
||||
hue = node_style(value) # from the untruncated key, though any prefix agrees
|
||||
rest = "muted" if split else "node.unknown"
|
||||
text = Text()
|
||||
text.append(raw[:split], style=hue)
|
||||
text.append(raw[split:], style="muted")
|
||||
text.append(raw[split:], style=rest)
|
||||
if ellipsis:
|
||||
text.append("…", style=hue if len(raw) < split else "muted")
|
||||
text.append("…", style=hue if len(raw) < split else rest)
|
||||
text.append(" " * pad)
|
||||
return text
|
||||
|
||||
@@ -497,19 +502,14 @@ def _shorten_hash(value: str, hash_bytes: Optional[int]) -> str:
|
||||
_SELF_RGB: RGB = (255, 255, 255)
|
||||
|
||||
|
||||
#: The truecolour of the ``muted`` grey — what a keyless name's hue collapses to on a
|
||||
#: raster (mirrors ``theme``'s muted ``#94a3b8``).
|
||||
_MUTED_RGB: RGB = (148, 163, 184)
|
||||
|
||||
|
||||
def _name_rgb(name: str, key: Optional[str] = None) -> RGB:
|
||||
"""The RGB of a node's stable palette hue (``theme.name_style`` minus its bold).
|
||||
|
||||
A name with no resolvable key styles ``muted`` (no hex to parse), so it lands on
|
||||
the muted grey here — the raster twin of the app-wide keyless-stays-muted rule.
|
||||
A name with no resolvable key styles ``node.unknown`` (a theme name, not a hex), so
|
||||
it lands on that grey here — the raster twin of the app-wide keyless-stays-grey rule.
|
||||
"""
|
||||
hexpart = name_style(name, key).split()[-1]
|
||||
return parse_hex(hexpart) if hexpart.startswith("#") else _MUTED_RGB
|
||||
return parse_hex(hexpart) if hexpart.startswith("#") else mark_rgb(hexpart)
|
||||
|
||||
|
||||
def name_rgb(name: str, key: Optional[str] = None) -> RGB:
|
||||
@@ -590,19 +590,24 @@ def route_graph_style(
|
||||
return node[:2]
|
||||
|
||||
def label_rgb_of(node: str) -> RGB:
|
||||
"""A label's colour: its node's name hue, us pure white, an unknown its ring."""
|
||||
"""A label's colour: its node's name hue, us pure white, an unknown its ring.
|
||||
|
||||
A relay we can't name keeps its *marker's* colour, so the hash under a repeater's
|
||||
``▲`` reads as that repeater rather than as a stray grey byte — which means this
|
||||
resolves whatever ``glyph_of`` hands back, style name or hex alike.
|
||||
"""
|
||||
if node == DST_NODE:
|
||||
return _SELF_RGB
|
||||
if node == SRC_NODE:
|
||||
if src_is_self:
|
||||
return _SELF_RGB
|
||||
if not source:
|
||||
return parse_hex(UNKNOWN_MARK[1])
|
||||
return mark_rgb(UNKNOWN_MARK[1])
|
||||
return _name_rgb(source, key_of(source) if key_of else None)
|
||||
named = resolve(node)
|
||||
if named and named != node:
|
||||
return _name_rgb(named, node)
|
||||
return parse_hex(glyph_of(node)[1])
|
||||
return mark_rgb(glyph_of(node)[1])
|
||||
|
||||
return glyph_of, label_of, label_rgb_of
|
||||
|
||||
|
||||
+7
-7
@@ -265,10 +265,10 @@ def test_preview_colours_channel_sender_and_mentions() -> None:
|
||||
assert preview.plain == "Bob: hi @Alice @Zed" # brackets dropped for display
|
||||
styles = {span.style for span in preview.spans}
|
||||
assert node_style("d4") in styles and node_style("60") in styles
|
||||
# The unresolvable @Zed stays muted like the body around it.
|
||||
# The unresolvable @Zed takes the unknown-node grey, like any name we can't place.
|
||||
zed = preview.plain.index("@Zed")
|
||||
assert any(
|
||||
s.style == "muted" and s.start <= zed < s.end for s in preview.spans
|
||||
s.style == "node.unknown" and s.start <= zed < s.end for s in preview.spans
|
||||
)
|
||||
|
||||
|
||||
@@ -802,8 +802,8 @@ def test_at_mention_renders_as_name_in_sender_hue() -> None:
|
||||
s for s in text.spans if s.style == hue and s.start <= at and at + len("@Alice") <= s.end
|
||||
]
|
||||
assert hue_spans
|
||||
# The unknown @Zed stays muted — no key, no colour.
|
||||
assert screen._sender_style("Zed") == "muted"
|
||||
# The unknown @Zed falls to the unknown-node grey — no key, no hue.
|
||||
assert screen._sender_style("Zed") == "node.unknown"
|
||||
|
||||
|
||||
def test_direct_chat_unknown_mention_stays_muted() -> None:
|
||||
@@ -828,8 +828,8 @@ def test_direct_chat_unknown_mention_stays_muted() -> None:
|
||||
|
||||
# A resolvable mention still lights in its own key-derived hue…
|
||||
assert screen._sender_style("Alice", mention=True) == node_style("60")
|
||||
# …but an unknown mention is muted, not painted with the peer's (d4…) hue.
|
||||
assert screen._sender_style("Zed", mention=True) == "muted"
|
||||
# …but an unknown mention is grey, not painted with the peer's (d4…) hue.
|
||||
assert screen._sender_style("Zed", mention=True) == "node.unknown"
|
||||
assert screen._sender_style("Zed", mention=True) != node_style("d4")
|
||||
# The sender label keeps the peer-key fallback (unchanged behaviour).
|
||||
assert screen._sender_style("Zed") == node_style("d4")
|
||||
@@ -1176,7 +1176,7 @@ def test_channel_self_style_keyed_on_concept_not_label() -> None:
|
||||
|
||||
screen = _channel_screen([])
|
||||
assert screen._sender_style("you", is_self=True) == "you" # us → white
|
||||
assert screen._sender_style("you", is_self=False) == "muted" # no key → muted
|
||||
assert screen._sender_style("you", is_self=False) == "node.unknown" # no key → grey
|
||||
keyed = _channel_screen([], key_of=_keys_of({"you": "d4" + "0" * 62}))
|
||||
remote = keyed._sender_style("you", is_self=False)
|
||||
assert remote == node_style("d4") # the key's spectrum hue
|
||||
|
||||
@@ -33,6 +33,7 @@ from rich.text import Text
|
||||
|
||||
from meshterm.core.courier_store import CourierStore
|
||||
from meshterm.core.models import (
|
||||
NODE_TYPE_REPEATER,
|
||||
ChatMessage,
|
||||
Contact,
|
||||
Conversation,
|
||||
@@ -72,7 +73,8 @@ from meshterm.ui.trace_screen import TraceScreen
|
||||
from meshterm.ui.tui import Screen, frame
|
||||
from meshterm.ui.tx_screen import TxSweepScreen
|
||||
from meshterm.ui.walk_screen import WalkScreen
|
||||
from meshterm.ui.widgets import ContactsSort, highlighted_hash
|
||||
from meshterm.ui.theme import name_style
|
||||
from meshterm.ui.widgets import _NODE_GLYPHS, ContactsSort, highlighted_hash
|
||||
|
||||
from tests.conftest import plain as _plain
|
||||
|
||||
@@ -150,8 +152,11 @@ def _contacts(cols: int, rows: int) -> Screen:
|
||||
|
||||
|
||||
def _node_detail_header() -> Text:
|
||||
header = Text("▲ ", style="#a78bfa")
|
||||
header.append("YUL-Cartierville", style="accent")
|
||||
# Through the app's own marker and name styles, not a hand-spelled hex: the gallery is
|
||||
# a specimen of what the platform draws, so a stub colour would hide a palette bug.
|
||||
glyph, glyph_style = _NODE_GLYPHS[NODE_TYPE_REPEATER]
|
||||
header = Text(f"{glyph} ", style=glyph_style)
|
||||
header.append("YUL-Cartierville", style=name_style("YUL-Cartierville", _HUB_KEY))
|
||||
header.append(" repeater", style="muted")
|
||||
return header
|
||||
|
||||
|
||||
+81
-2
@@ -67,6 +67,51 @@ def test_theme16_bold_never_jumps_a_dim_slot_to_an_unrelated_bright_one() -> Non
|
||||
)
|
||||
|
||||
|
||||
def test_theme16_dim_slot_styles_all_answer_the_bold_question() -> None:
|
||||
"""A dim-slot style must state its intent about bold — it cannot stay silent.
|
||||
|
||||
Rich merges a base style into every span it wraps, so a span left at ``bold=None``
|
||||
inside a selected (bold) row inherits it, and the VT then draws slot N as N+8: the
|
||||
style silently changes colour depending on what it lands in. Each one is therefore
|
||||
pinned ``not bold`` (keep the declared colour) or ``bold`` (the promotion is intended).
|
||||
"""
|
||||
silent = [
|
||||
name
|
||||
for name, style in _our_styles(MESH_THEME_16).items()
|
||||
if style.color is not None and style.color.number is not None
|
||||
and style.color.number <= 7 and style.bold is None
|
||||
]
|
||||
assert not silent, (
|
||||
f"dim-slot styles that would inherit a row's bold and change colour: {silent}"
|
||||
)
|
||||
|
||||
|
||||
def test_unknown_node_grey_survives_a_selected_row() -> None:
|
||||
"""THE reported bug: an unnamed hop's hash inside a selected row read as white "you".
|
||||
|
||||
``node.unknown`` is a dim slot, so an inherited bold would promote it to 15 — the
|
||||
``you`` white. It must render as plain light grey (37) either way, on both platforms.
|
||||
"""
|
||||
from io import StringIO
|
||||
|
||||
from rich.console import Console
|
||||
from rich.text import Text
|
||||
|
||||
set_platform(PICOCALC)
|
||||
console = Console(
|
||||
theme=MESH_THEME_16, width=20, file=StringIO(),
|
||||
force_terminal=True, color_system="standard", highlight=False,
|
||||
)
|
||||
for base in (None, "brand"): # unselected row, then the bold cursor row
|
||||
row = Text(" ")
|
||||
row.append("3d", style="node.unknown")
|
||||
if base:
|
||||
row.style = base
|
||||
with console.capture() as capture:
|
||||
console.print(row, end="")
|
||||
assert "\x1b[37m3d" in capture.get(), (base, capture.get())
|
||||
|
||||
|
||||
def test_theme16_backgrounds_stay_in_the_dim_bank() -> None:
|
||||
"""The VT has no bright backgrounds — SGR 40-47 only."""
|
||||
for name, style in _our_styles(MESH_THEME_16).items():
|
||||
@@ -179,10 +224,11 @@ def test_names_colour_by_key_on_both_platforms() -> None:
|
||||
hue = name_style("YUL-Cartierville", "3d63c6429436")
|
||||
assert hue.startswith("bold #"), platform.name
|
||||
# Any prefix of the key agrees, a rename does not move the colour, and a sender
|
||||
# we could not place stays muted — colour is reserved for keyed identities.
|
||||
# we could not place falls to the unknown-node grey — colour is reserved for
|
||||
# keyed identities.
|
||||
assert name_style("YUL-Cartierville", "3d") == hue
|
||||
assert name_style("renamed", "3d63c6429436") == hue
|
||||
assert name_style("nameless", None) == "muted"
|
||||
assert name_style("nameless", None) == "node.unknown"
|
||||
|
||||
|
||||
def test_picocalc_node_hues_land_on_their_own_palette_slots() -> None:
|
||||
@@ -199,6 +245,22 @@ def test_picocalc_node_hues_land_on_their_own_palette_slots() -> None:
|
||||
assert min(landed.count(h) for h in set(landed)) >= 256 // 8 # no starved sector
|
||||
|
||||
|
||||
def test_route_graph_resolves_a_named_marker_colour_to_rgb() -> None:
|
||||
"""A relay we can't name keeps its marker's colour — including a *typed* marker.
|
||||
|
||||
The type marks carry theme style names, so the graph's label colour has to resolve
|
||||
them rather than assume a literal hex (it raised ValueError when it did).
|
||||
"""
|
||||
from meshterm.ui.widgets import route_graph_style
|
||||
|
||||
for platform in (REGULAR, PICOCALC):
|
||||
set_platform(platform)
|
||||
_glyph_of, _label_of, label_rgb_of = route_graph_style(
|
||||
resolve=lambda hop: None, self_name="Me", source="Alice", type_of=lambda hop: 2,
|
||||
)
|
||||
assert label_rgb_of("3d63") == theme.mark_rgb("type.repeater"), platform.name
|
||||
|
||||
|
||||
def test_node_type_marks_stay_distinct_on_the_console() -> None:
|
||||
"""Each type mark owns a slot — a naive downsample would grey the repeater's violet."""
|
||||
set_platform(PICOCALC)
|
||||
@@ -208,6 +270,23 @@ def test_node_type_marks_stay_distinct_on_the_console() -> None:
|
||||
assert theme.mark_rgb("type.repeater") != theme.mark_rgb("muted")
|
||||
|
||||
|
||||
def test_canvas_drops_emphasis_where_bold_means_brightness() -> None:
|
||||
"""A braille canvas may not embolden on the console: the VT would recolour the run.
|
||||
|
||||
The canvas quantizes its own truecolour at the fold, so a bold run has no way to know
|
||||
which bank it landed in — an unknown label (slot 7) would arrive as white (15).
|
||||
"""
|
||||
from meshterm.ui.mapcanvas import MapCanvas
|
||||
|
||||
for platform, expect_bold in ((REGULAR, True), (PICOCALC, False)):
|
||||
set_platform(platform)
|
||||
canvas = MapCanvas(6, 1)
|
||||
canvas.marker(0, 0, "x", (148, 163, 184)) # markers always draw emboldened
|
||||
rendered = "".join(canvas.to_ansi_lines())
|
||||
assert ("\x1b[1m" in rendered) is expect_bold, (platform.name, repr(rendered))
|
||||
assert "\x1b[37m" in rendered # and the colour it was given survives intact
|
||||
|
||||
|
||||
# -- the font build script stays mirrored ---------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ def test_path_text_hash_as_name_shows_grey_identity_hash() -> None:
|
||||
)
|
||||
assert text.plain == "e839f2 (e8)" # mode width identity, then the addressed byte
|
||||
styles = {text.plain[s.start : s.end]: str(s.style) for s in text.spans}
|
||||
assert styles.get("e839f2") == "muted" # greyed — colour is the "this is a name" cue
|
||||
assert styles.get("e839f2") == "node.unknown" # grey — colour is the "this is a name" cue
|
||||
from meshterm.ui.theme import node_style
|
||||
|
||||
assert not any(str(s.style) == node_style("e839f2ab") for s in text.spans) # no prefix lit
|
||||
@@ -129,11 +129,11 @@ def test_make_name_key_resolver_contacts_win_over_stored_names() -> None:
|
||||
assert key_of("Zed") is None # nobody carries the name
|
||||
|
||||
|
||||
def test_name_style_without_a_key_is_muted() -> None:
|
||||
def test_name_style_without_a_key_is_the_unknown_grey() -> None:
|
||||
"""A keyless name has no hue — colour is reserved for keyed identities."""
|
||||
from meshterm.ui.theme import name_style, node_style
|
||||
|
||||
assert name_style("Stranger") == "muted"
|
||||
assert name_style("Stranger") == "node.unknown"
|
||||
keyed = name_style("Alice", "d4" + "0" * 62)
|
||||
assert keyed == node_style("d4" + "0" * 62) and keyed.startswith("bold #")
|
||||
|
||||
|
||||
Reference in new issue
Block a user