Hash widget: the addressed prefix lights in the node's own hue

highlighted_hash lit a key's path-hash prefix in the fixed brand cyan;
it now takes the node's hash-derived palette hue — the same colour the
node's name wears — so a hash carries its node's identity colour even
where no name is known, and a key's prefix, its name, and its map
labels all agree. The remainder (and a hash standing in as a name)
stays muted, and the truncation ellipsis keeps inheriting the colour
of the digit it replaces.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Fable 5 committed 2026-07-18 20:39:42 -04:00
1 parent 79d00defdd
commit f7dcda0575
5 files changed
+45 -18

No files matched your search

+3 -2
View File
@@ -109,8 +109,9 @@ Relative ages: `format_ago` for prose ("now", "5m ago", "never" — never "now a
node's key (its first byte — any known prefix agrees) so a rename keeps the colour;
the name's characters seed it only when no key exists (a channel sender). 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. Bare hashes stay muted —
colour is the "this is a name" signal.
Recency heat colours heard/first-heard ages, never names. A hash's addressed prefix
(via `highlighted_hash`) lights in the same key-derived hue; the rest of the hash, and
any hash standing in as a name, stays muted.
- SNR always through `snr_style`; timelines oldest→now left-to-right, grey baseline = 0,
drawn via `ui/braillechart` only.
+8 -5
View File
@@ -40,7 +40,7 @@ from ..core.models import (
from .map_render import _NODE, _REPEATER, _SELF, _UNKNOWN
from .mapcanvas import RGB, parse_hex
from .pathgraph import DST_NODE, GlyphOf, LabelOf, LabelRgbOf, SRC_NODE
from .theme import name_style, snr_style
from .theme import name_style, node_style, snr_style
if TYPE_CHECKING:
from ..core.discovery import DiscoveredDevice
@@ -378,8 +378,10 @@ def highlighted_hash(value: str, prefix_bytes: int, width: Optional[int] = None)
The one way MeshTerm displays a hash, wherever one appears: the first
``prefix_bytes`` bytes are the slice other nodes address in a forced trace path
(the path-hash), shown in the brand colour with the remainder muted, so the
addressable prefix stands out within the otherwise full key. A ``width`` budget
(the path-hash), lit in the node's hash-derived palette hue — the same hue its
name wears (see :func:`~meshterm.ui.theme.node_style`) — with the remainder muted,
so the addressable prefix stands out within the otherwise full key and carries the
node's identity colour even where no name is known. A ``width`` budget
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).
@@ -409,11 +411,12 @@ def highlighted_hash(value: str, prefix_bytes: int, width: Optional[int] = None)
pad = width - kept - 1
elif width is not None:
pad = width - len(raw)
hue = node_style(value) # from the untruncated key, though any prefix agrees
text = Text()
text.append(raw[:split], style="brand")
text.append(raw[:split], style=hue)
text.append(raw[split:], style="muted")
if ellipsis:
text.append("…", style="brand" if len(raw) < split else "muted")
text.append("…", style=hue if len(raw) < split else "muted")
text.append(" " * pad)
return text
+8 -3
View File
@@ -71,14 +71,16 @@ def test_path_hash_mode_is_strict_enum() -> None:
def test_highlighted_hash_highlights_path_hash_prefix() -> None:
"""The full key is shown with only its path-hash prefix bytes highlighted."""
"""The full key is shown with only its path-hash prefix bytes highlighted, lit in
the node's hash-derived palette hue (the same hue the node's name wears)."""
from meshterm.ui.theme import node_style
from meshterm.ui.widgets import highlighted_hash
pub = "aabbccddee" + "00" * 27
# mode 2 => 3-byte hashes => first 6 hex chars are the addressable prefix.
text = highlighted_hash(pub, prefix_bytes=3)
assert text.plain == pub # the full key is shown
highlighted = [s for s in text.spans if s.style == "brand"]
highlighted = [s for s in text.spans if s.style == node_style(pub)]
assert len(highlighted) == 1
assert text.plain[highlighted[0].start : highlighted[0].end] == "aabbcc"
@@ -134,9 +136,12 @@ def test_nodes_table_lists_us_first_with_full_keys() -> None:
# Keys (column 4) are the full key with the path-hash prefix highlighted (no truncation
# in the model; Rich ellipsizes only at render time when the terminal is too narrow).
from meshterm.ui.theme import node_style
keys = list(table.columns[4].cells)
assert keys[1].plain == "3d63c6" + "00" * 29
assert any(s.style == "brand" for s in keys[1].spans) # prefix highlighted
# The prefix is highlighted in the key's own hash-derived hue.
assert any(s.style == node_style("3d63c6") for s in keys[1].spans)
def test_nodes_table_sorts_by_heard_and_packets() -> None:
+13 -4
View File
@@ -552,7 +552,8 @@ def test_mesh_page_rhythm_left_edge_aligns_with_the_day_charts(tmp_path: Path) -
def test_picker_row_lanes_align_under_the_header() -> None:
"""Picker rows lane up under the header; unknown nodes read as heat-coloured names."""
"""Picker rows lane up under the header; the heard age glows hot, the hash prefix
lights in the key's own hue, and a nameless node's placeholder stays muted."""
from meshterm.core.models import HeardNode
from meshterm.ui.nodelist import NodeRow, _header, _lane
from meshterm.ui.widgets import NodesSort
@@ -570,12 +571,20 @@ def test_picker_row_lanes_align_under_the_header() -> None:
)
plain = row.plain
assert "unknown" in plain and "3d" * 6 in plain and "42" in plain
# A just-heard mystery node reads hot (white), not placeholder-grey.
# A just-heard node's HEARD age reads hot (white); the nameless placeholder is muted.
assert any(span.style == "#ffffff" for span in row.spans)
# The hash's routing prefix (2 bytes here) is lit brand, the tail muted.
unknown_at = plain.index("unknown")
assert any(
span.style == "muted" and span.start <= unknown_at < span.end
for span in row.spans
)
# The hash's routing prefix (2 bytes here) is lit in the key's hue, the tail muted.
from meshterm.ui.theme import node_style
hash_at = plain.index("3d" * 6)
assert any(
span.style == "brand" and span.start == hash_at and span.end == hash_at + 4
span.style == node_style("3d" * 6)
and span.start == hash_at and span.end == hash_at + 4
for span in row.spans
)
# Header labels land over their lanes (+2 covers the select pointer column); the lanes
+13 -4
View File
@@ -54,10 +54,17 @@ def test_path_text_empty_reads_as_direct() -> None:
def test_path_text_lights_the_hash_prefix() -> None:
"""An unnamed hop renders through the shared hash widget, its prefix lit."""
"""An unnamed hop renders through the shared hash widget, its prefix lit in the
node's hash-derived hue."""
from meshterm.ui.theme import node_style
text = path_text(["77bb"], _resolve, prefix_bytes=1)
brand = [text.plain[s.start : s.end] for s in text.spans if "brand" in str(s.style)]
assert "77" in brand # the addressed prefix stands out within the hash
lit = [
text.plain[s.start : s.end]
for s in text.spans
if str(s.style) == node_style("77bb")
]
assert "77" in lit # the addressed prefix stands out within the hash
def test_path_text_hash_as_name_shows_grey_identity_hash() -> None:
@@ -69,7 +76,9 @@ 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 not any(str(s.style) == "brand" for s in text.spans) # no prefix lit
from meshterm.ui.theme import node_style
assert not any(str(s.style) == node_style("e839f2ab") for s in text.spans) # no prefix lit
def test_path_text_hash_as_name_drops_the_byte_when_it_is_the_whole_hash() -> None: