Cursor row: a route's hues are content, so the highlight spares them

A picked row folds its node hues to the cursor white so the row reads as one
thing rather than as a name arguing with its own selection. On a path line that
is wrong: there the hue is not decoration on a name, it is what tells one hop
from the next — and what a route graph above the row is cross-referenced by,
its labels being a marker and one byte of hash. Chips were never folded (their
fills are outside the fold's vocabulary), so the bug was the arrow form: every
path line on the PicoCalc, and on any terminal without the powerline glyphs.

PathLine now stamps every shape it mints with PATH_INK, a style that draws
nothing; Text.append_text carries the stamp into the row as a span over the
hops, and the fold skips identity spans lying inside one. So the Message paths
row keeps each hop in the colour its graph label wears, and so do the TX
screen's "Route — via", the trophy board's walk and the feed's sender → recipient
lane. The node detail's Routes tab, which bought this by hand (no cursor base at
all), is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-30 00:42:24 -04:00
1 parent 8e8a73fc36
commit c1db8e5a31
6 files changed
+142 -7

No files matched your search

+6 -1
View File
@@ -206,7 +206,12 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow
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,
claim to know a node we can't place. A **path line is spared** wherever it sits on the
row — there a hue is not decoration on a name, it is what tells one hop from the next and
what a route graph's one-byte labels are matched by — so `pathline` stamps its own extent
(`PATH_INK`, a style that draws nothing) and the fold skips what lies inside it. That is
what makes the arrow form say what the chip form always said, its fills having never been
in the fold's vocabulary. 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
+21 -3
View File
@@ -109,6 +109,13 @@ CURSOR_GLYPH = "+"
#: The plain-mode joining arrow, exactly as ``path_text`` draws it today.
_ARROW = " → "
#: The theme name a rendered path line wears as its base style: it draws *nothing* and
#: exists to be recognised. Every shape this widget mints is stamped with it (see
#: :meth:`PathLine._render`), so a row that appends a path carries a span saying where the
#: route lies — which is how the cursor row's identity fold knows to spare the hop hues
#: (:func:`~meshterm.ui.tui.render._whiten_identities`) instead of whitening a whole route.
PATH_INK = "pathline"
#: Chip ink: near-black slate for readable text on every spectrum hue and on white.
_CHIP_FG = "#0f172a"
#: Chip ink, softened — annotations and a hash label's unlit tail (the two-tone).
@@ -747,14 +754,25 @@ class PathLine:
carry_in: bool = False,
carry_on: bool = False,
) -> Text:
"""Join ``hops`` in the effective mode.
"""Join ``hops`` in the effective mode, marked as a path line.
The two carry flags mark a wrapped line's ends and only mean anything to
chips; arrow mode says the same thing with the trailing cue.
Every shape leaves through here, so this is where the line stamps its own extent:
the returned text's base style is :data:`PATH_INK`, which draws nothing and says
"these cells are a route". A row that appends it (``Text.append_text``) carries
that stamp along as a span over the hops, and the cursor row's identity fold reads
it there — see :func:`~meshterm.ui.tui.render._whiten_identities`. Inside a path
line the hue is not decoration on a name, it is what tells one hop from the next,
so the highlight lights the row without eating it.
"""
if not force_plain and self._resolved_mode() == "powerline":
return self._render_chips(hops, carry_in=carry_in, carry_on=carry_on)
return self._render_plain(hops)
line = self._render_chips(hops, carry_in=carry_in, carry_on=carry_on)
else:
line = self._render_plain(hops)
line.style = PATH_INK
return line
def _render_plain(self, hops: list[PathHop]) -> Text:
"""Arrow-joined hops — ``path_text``'s presentation, hop by hop."""
+15
View File
@@ -55,6 +55,18 @@ MESH_THEME = Theme(
# ``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",
# THE mark a path line puts around its own hops (PathLine._render), so the cursor
# row's identity fold can see where a route starts and stops
# (ui.tui.render._whiten_identities): inside a path line a node's hue is not
# decoration on a name, it is what tells one hop from the next — and what the
# graph drawn above the row cross-references, since a graph label is only a
# marker and one byte of hash. Folding those to white made a picked route read as
# one long white smear with no way back to the picture. Chips were never affected
# (their fills sit outside the fold's vocabulary); this is what makes the arrow
# form — every path line on the PicoCalc, and on any terminal without the
# powerline glyphs — say the same thing. Renders as nothing: it exists to be read
# at the render boundary, not seen.
"pathline": "none",
# 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.
"err.reverse": "reverse bold #f87171",
@@ -277,6 +289,9 @@ MESH_THEME_16 = Theme(
# further, and every dim-slot span inside it behaves exactly as it did under the
# old bold slot-14 highlight.
"cursor": "bold color(15)",
# The path line's extent mark — see the regular theme. Nothing to draw, but both
# themes name the same styles, and the fold that reads it runs on both.
"pathline": "none",
"err.reverse": "reverse bold color(9)",
"you": "bold color(15)",
"device.known": "bold color(15)",
+21 -1
View File
@@ -20,6 +20,7 @@ from rich.console import Console, RenderableType
from rich.text import Span, Text
from ...platforms import Platform, on_platform
from ..pathline import PATH_INK
from ..theme import active_theme, fold_text, is_identity_style
#: Cache one headless render console per width. Consoles are cheap but repaint happens on
@@ -139,6 +140,17 @@ def _whiten_identities(renderable: RenderableType) -> RenderableType:
fills, the grey of a node no key could place — because none of those are the identity
the highlight is standing in for.
**A path line is spared**, wherever it sits on the row. There the hue is not decoration
on a name: it is what tells one hop from the next, and what a route graph drawn above
the row is cross-referenced by — its labels are a marker and one byte of hash, and the
colour is what says *which node*. So a picked route kept its hops' colours in chip form
(the fills were never in this vocabulary) and lost them in arrow form, which is every
path line on the PicoCalc and on any terminal without the powerline glyphs (JP,
2026-08-30). The widget stamps its own extent with
:data:`~meshterm.ui.pathline.PATH_INK` and the stamp arrives here as a span over the
hops (``Text.append_text`` keeps a child's base style as one), so the route is spared
by name rather than by each screen remembering to ask.
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
@@ -155,16 +167,24 @@ def _whiten_identities(renderable: RenderableType) -> RenderableType:
spans = renderable.spans
if not any(is_identity_style(str(span.style)) for span in spans):
return renderable
routes = [
(span.start, span.end) for span in spans if str(span.style) == PATH_INK
]
out = renderable.copy()
out.spans = [
Span(span.start, span.end, "cursor")
if is_identity_style(str(span.style))
if is_identity_style(str(span.style)) and not _within(span, routes)
else span
for span in spans
]
return out
def _within(span: Span, runs: list[tuple[int, int]]) -> bool:
"""Does ``span`` lie inside one of ``runs`` — a hop inside a marked path line?"""
return any(start <= span.start and span.end <= end for start, end in runs)
def render_to_ansi(renderable: RenderableType, width: int, *, no_wrap: bool = False) -> str:
"""Render a Rich renderable to an ANSI string at ``width`` columns.
+7 -2
View File
@@ -14,7 +14,8 @@ import pytest
import meshterm.ui.pathline as pathline
from meshterm.ui.pathline import (
CRACK_HEAD, CRACK_TAIL, CURSOR_GLYPH, ELIDE_HEAD, ELIDE_TAIL, POWERLINE_ROUND_CLOSE,
CRACK_HEAD, CRACK_TAIL, CURSOR_GLYPH, ELIDE_HEAD, ELIDE_TAIL, PATH_INK,
POWERLINE_ROUND_CLOSE,
POWERLINE_ROUND_OPEN, POWERLINE_SEP, SELF_GLYPH, WRAP_OFFSET, PathHop, PathLine,
_SELF_INK, _YOU_BG, _style_hex, cut_mark, cut_to, elision_hop, hops_atom,
path_line, with_action_mark,
@@ -441,7 +442,11 @@ def test_wrapped_chip_lines_open_on_the_break_they_continue() -> None:
assert lines[0].plain.startswith(" AAAA") # the square edge: this is the start
step = 2 + WRAP_OFFSET
assert lines[1].plain[:step].isspace() and lines[1].plain[step] == POWERLINE_SEP
carried = next(s for s in lines[1].spans if s.start == step)
# …past the line's own PATH_INK stamp, which covers the whole body from the same cell
# (it marks the run as a path line for the cursor fold and draws nothing).
carried = next(
s for s in lines[1].spans if s.start == step and str(s.style) != PATH_INK
)
assert str(carried.style) == f"{_style_hex(node_style('3d'))} reverse"
assert all(line.plain.endswith(POWERLINE_SEP) for line in lines)
assert all(line.cell_len <= 20 for line in lines)
+72
View File
@@ -21,6 +21,7 @@ from rich.text import Text
from meshterm.platforms import PICOCALC, REGULAR, set_platform
from meshterm.ui.contactlist import _SORT_ACTIVE
from meshterm.ui.pathline import PathHop, PathLine
from meshterm.ui.theme import (
MESH_THEME,
MESH_THEME_16,
@@ -145,6 +146,77 @@ def test_a_path_line_s_chips_keep_their_fills_on_the_cursor_row() -> None:
assert f"48;2;{int(fill[1:3], 16)};" in render_to_ansi(row, 40)
def test_a_path_line_keeps_every_hop_s_hue_on_the_cursor_row() -> None:
"""A route's hues are content: they are how one hop is told from the next.
The chip form was never folded (its fills are outside the vocabulary), so an
arrow-drawn route — every path line on the PicoCalc, and on any terminal without the
powerline glyphs — has to survive the same way, or the same picked row says two
different things on the two platforms. The widget stamps its own extent and the fold
spares what lies inside it.
"""
hops = [PathHop("YUL-Poly", key=_KEY), PathHop("Waymarker", key="77" * 6)]
row = Text("❯ ", style="cursor")
row.append_text(PathLine(hops, mode="plain").text())
row.style = "cursor"
hues = _hues(render_to_ansi(row, 60))
assert node_style(_KEY).removeprefix("bold ") in hues
assert node_style("77").removeprefix("bold ") in hues
def test_a_name_beside_a_path_line_still_folds() -> None:
"""The exception is the route, not the row: a name lane next to one is still a name."""
row = Text(" ")
row.append("YUL-Poly", style=name_style("YUL-Poly", _KEY))
row.append(" ")
row.append_text(PathLine([PathHop("Waymarker", key="77" * 6)], mode="plain").text())
row.style = "cursor"
hues = _hues(render_to_ansi(row, 60))
assert name_style("YUL-Poly", _KEY).removeprefix("bold ") not in hues # the lane folded
assert node_style("77").removeprefix("bold ") in hues # …the route did not
@pytest.mark.parametrize("platform", [REGULAR, PICOCALC])
def test_the_message_paths_dialog_colours_its_picked_route_like_its_graph(platform) -> None: # noqa: ANN001
"""The end JP asked for: the picked row and the graph above it agree on each node.
The graph labels a relay with a marker and one byte of hash — the colour is what says
*which node* — so a row whitened hop by hop left the reader nothing to match them by.
"""
set_platform(platform)
from datetime import timedelta
from meshterm.core.models import ChatMessage, utcnow
from meshterm.services.message_paths import Arrival
from meshterm.ui.message_paths_screen import MessagePathsScreen
now = utcnow()
arrivals = [
Arrival(when=now, hops=("3d63", "a1b2"), snr=4.0),
Arrival(when=now + timedelta(seconds=2), hops=("a1b2",), snr=-2.0),
]
screen = MessagePathsScreen(
ChatMessage(text="on my way", is_channel=True, created_at=now),
arrivals,
matched=True,
resolve=lambda hop: {"3d63": "YUL-Cartierville", "a1b2": "Waymarker"}.get(hop, hop),
prefix_bytes=1, self_name="Homestead", summary="heard twice", source="Alice",
)
picked = next(line for line in screen.render_body(72) if "❯" in line)
for hop in ("3d63", "a1b2"):
assert _ink(node_style(hop)) in picked, f"the picked route lost {hop}'s hue"
def _ink(style: str) -> str:
"""The escape a style emits before its text, as it appears on the bound platform."""
return render_to_ansi(Text("x", style=style), 3).split("x")[0]
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.