From 3fe4e5b4e1b5596b11cc1edcba153e072305da34 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Sun, 19 Jul 2026 01:17:32 -0400 Subject: [PATCH] Map: labels take the name hue, ours the you-white MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node labels were coloured by marker type (self yellow, repeater violet, leaf pink); they now carry the app-wide key-derived name hue — MapMarker grows a key field threaded from contacts, stored heard nodes, and self-info — with our own label the pure you-white while the ★ glyph keeps its yellow. Find-filter matches still force full white, non-matches still dim bare. The CLI legend follows suit (and its SEEN column header becomes HEARD, per the lexicon). Co-Authored-By: Claude Fable 5 --- meshterm/tools/map.py | 14 +++++++++++--- meshterm/ui/map_render.py | 18 +++++++++++++++--- tests/test_map.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/meshterm/tools/map.py b/meshterm/tools/map.py index 87c0b25..f365418 100644 --- a/meshterm/tools/map.py +++ b/meshterm/tools/map.py @@ -207,6 +207,7 @@ async def gather_markers(ctx: AppContext) -> list["MapMarker"]: lon=float(contact.lon), is_repeater=contact.is_repeater, detail=_signal_detail(observed.get(key)), + key=contact.public_key or contact.key_prefix or None, ) ) @@ -221,6 +222,7 @@ async def gather_markers(ctx: AppContext) -> list["MapMarker"]: lon=float(node.lon), is_repeater=node.is_repeater, detail=_signal_detail(node), + key=node.public_key or node.node or None, ) ) @@ -255,26 +257,32 @@ async def _self_marker(ctx: AppContext) -> Optional["MapMarker"]: lon=lon, is_repeater=info.get("adv_type") == NODE_TYPE_REPEATER, is_self=True, + key=str(info.get("public_key") or "") or None, ) def _legend(markers: list["MapMarker"]) -> Table: - """A compact legend: self → repeaters → leaf nodes, with coordinates and detail.""" + """A compact legend: self → repeaters → leaf nodes, with coordinates and detail. + + Names take their key-derived hue (our own the pure-white ``you``), matching the + interactive map's labels; the glyph keeps the marker's type colour. + """ from ..ui.map_render import _NODE, _REPEATER, _SELF + from ..ui.theme import name_style table = Table(box=None, padding=(0, 2, 0, 0), expand=False) table.add_column("") table.add_column("NODE") table.add_column("TYPE") table.add_column("COORDS", justify="right") - table.add_column("SEEN") + table.add_column("HEARD") ordered = sorted(markers, key=lambda m: -m._rank()) for m in ordered: glyph, color = _SELF if m.is_self else (_REPEATER if m.is_repeater else _NODE) kind = "you" if m.is_self else ("repeater" if m.is_repeater else "node") table.add_row( Text(glyph, style=color), - Text(m.label, style=color if m.is_self else ""), + Text(m.label, style="you" if m.is_self else name_style(m.label, m.key)), Text(kind, style="muted"), Text(f"{m.lat:.4f}, {m.lon:.4f}", style="muted"), Text(m.detail, style="muted"), diff --git a/meshterm/ui/map_render.py b/meshterm/ui/map_render.py index f8fd961..b3560c4 100644 --- a/meshterm/ui/map_render.py +++ b/meshterm/ui/map_render.py @@ -36,6 +36,8 @@ class MapMarker: is_repeater: Whether the node is a repeater (prioritised marker). is_self: Whether this is our own node (highlighted). detail: Extra text for the CLI legend (e.g. ``"18 pkts · +6.0 dB"``). + key: The node's key hex (as full as the caller holds), seeding the label's + key-derived hue; ``None`` leaves the label the muted no-key grey. """ label: str @@ -44,6 +46,7 @@ class MapMarker: is_repeater: bool = False is_self: bool = False detail: str = "" + key: Optional[str] = None def _rank(self) -> int: """Draw order: self on top of repeaters on top of leaf nodes.""" @@ -394,9 +397,18 @@ def _draw_nodes( rgb = _pile_color(rgb, pile[(ix >> 1, iy >> 2)]) canvas.marker(ix, iy, glyph, rgb) - # A filtered-out node is context: bare dim glyph, no label. + # A filtered-out node is context: bare dim glyph, no label. Labels take the + # node's key-derived name hue — the app-wide colour rule — with our own label the + # pure ``you`` white (the ★ glyph keeps its yellow); an active find filter still + # forces every match's label full white so the sought node pops. + from .widgets import name_rgb # widgets imports this module; late-bind to dodge the cycle + labelled = (p for p in placed if p[3]) for marker, ix, iy, _matched in sorted(labelled, key=lambda p: -p[0]._rank()): - _, color = _marker_style(marker) - label_color = _FIND_MATCH_LABEL if needle else parse_hex(color) + if needle: + label_color = _FIND_MATCH_LABEL + elif marker.is_self: + label_color = (255, 255, 255) # the `you` white + else: + label_color = name_rgb(marker.label, marker.key) canvas.marker_label(ix, iy, marker.label, label_color) diff --git a/tests/test_map.py b/tests/test_map.py index adc111e..286f366 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -614,3 +614,32 @@ def test_map_observation_round_trips_node_type(ctx) -> None: ) node = next(n for n in ctx.repo.heard_nodes() if n.node == "a1") assert node.is_repeater and node.node_type == NODE_TYPE_REPEATER + + +def test_render_map_labels_take_the_name_hue_ours_white() -> None: + """Node labels carry their key-derived hue; our own label is white while the + ★ glyph stays yellow; a keyless label lands on the muted grey.""" + from meshterm.ui.map_render import _SELF, MapMarker, render_map + from meshterm.ui.widgets import name_rgb + + vp = Viewport.fit([(45.5, -73.6), (45.4, -73.5)], 120, 80, max_zoom=14) + markers = [ + MapMarker("US", 45.5, -73.6, is_self=True, key="cc" * 32), + MapMarker("KEYED", 45.4, -73.5, key="d4" * 32), + MapMarker("BARE", 45.45, -73.55), + ] + lines = render_map(vp, {}, markers) + assert _glyph_color(lines, "★") == parse_hex(_SELF[1]) # the glyph keeps its yellow + assert _glyph_color(lines, "US") == (255, 255, 255) # ...the label goes you-white + assert _glyph_color(lines, "KEYED") == name_rgb("KEYED", "d4" * 32) + assert _glyph_color(lines, "BARE") == (148, 163, 184) # no key, the muted grey + + +def test_render_map_find_matches_still_label_white() -> None: + """An active find filter keeps forcing matching labels to full white.""" + from meshterm.ui.map_render import MapMarker, render_map + + vp = Viewport.fit([(45.5, -73.6), (45.4, -73.5)], 120, 80, max_zoom=14) + markers = [MapMarker("TARGET", 45.5, -73.6, key="d4" * 32)] + lines = render_map(vp, {}, markers, find="targ") + assert _glyph_color(lines, "TARGET") == (255, 255, 255)