Path lines: chrome pays its own way, and every route says its length

Three things the path rows owed their readers.

The opens-further `…` was being reserved out of the lane, so a route that
fitted exactly cracked on its own last chip — the row claiming the walk ran
on when it had arrived, the crack being the closing cap with half of it taken
away. It now rides outside the budget (`with_action_mark`, and `cut_to(...,
action=True)`): the path is fitted to the whole lane and the mark takes the
leftovers, or goes unshown. That is the widget's answer everywhere a path row
carries it, not the node page's local trade.

Every stats line hanging under a path now leads with the hop count
(`hops_atom`) — the figure the picture above encodes but never states, and
the first thing two routes are compared on. `direct` where there are none,
which is the app's own word for it; the Explore list's direct-shot provenance
tag was that same word for the same reason, so the atom absorbs it.

And Explore paths cuts its unselected candidates instead of middle-eliding
them, so walking the cursor no longer rewrites the row under it. The `⋯`
rescue saves a route's two endpoints; here they are the same two on every row
by construction, so it spent cells on what the reader knows and took them off
the candidates' front. The probe-results rows pin their ranking lanes out of
the ←→ scroll while they are at it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-10 01:30:02 -04:00
1 parent 771a865e8a
commit c2640d9660
8 files changed
+315 -58

No files matched your search

+8 -1
View File
@@ -50,6 +50,7 @@ from .pathline import (
PathLine,
cut_mark,
cut_to,
hops_atom,
path_line,
)
from .theme import snr_style
@@ -281,8 +282,14 @@ class MessagePathsScreen(Screen):
The row's second line, hanging muted under the route it describes: the path is
what distinguishes one arrival from another (and what the graph above draws), so
it takes the lane, and the frame's own particulars step in beneath it.
The hop count leads (:func:`~meshterm.ui.pathline.hops_atom`): it is the one fact
about the route the line above encodes without stating, and the number two
arrivals of the same message are compared on before anything else.
"""
text = Text(arrival.when.astimezone().strftime("%H:%M:%S"), style="muted")
text = hops_atom(len(arrival.hops))
text.append(" ")
text.append(arrival.when.astimezone().strftime("%H:%M:%S"), style="muted")
if arrival.snr is not None:
text.append(" ")
text.append(f"{arrival.snr:+.1f} dB", style=snr_style(arrival.snr))
+26 -18
View File
@@ -103,6 +103,8 @@ from .pathline import (
PathLine,
cut_mark,
cut_to,
hops_atom,
with_action_mark,
)
from .tui.screen import CANCEL, ListWindow, Screen
from .widgets import (
@@ -217,11 +219,6 @@ _CLUSTER_NODE = "\x00clu"
#: ``" "`` pointer's own width, so the context lines up under the path it belongs to.
_ROUTE_INDENT = 2
#: The app-wide opens-further-prompts mark, trailing every route row's pathline (Enter on
#: it arms a trace). Applied at render time rather than baked into :attr:`_Route.path`, so
#: measuring/cropping the raw hash chain for horizontal scroll never has to account for it.
_OPENS_MARKER = " …"
#: Cells one ←/→ press horizontally scrolls the highlighted route's pathline, or the Info
#: tab's key lane (see :meth:`NodeDetailScreen.handle`) — the same step the app-wide select
#: list's ``hscroll`` uses. On a key it happens to be exactly four bytes, so every window the
@@ -518,8 +515,10 @@ class NodeDetailScreen(Screen):
if not routes or not (0 <= self._row_index < len(routes)):
return False
avail = max(1, self._last_width - _ROUTE_INDENT)
total = cell_len(routes[self._row_index].path.plain) + cell_len(_OPENS_MARKER)
return total > avail
# The trailing `…` is chrome riding outside the lane (pathline.with_action_mark), so
# it is no part of what has to fit: a route exactly as wide as its lane scrolls
# nowhere, and the mark is simply the thing that goes unshown.
return cell_len(routes[self._row_index].path.plain) > avail
def _on_info_tab(self) -> bool:
"""Whether the Info tab is the one filling the stage (so its key lane is on screen)."""
@@ -976,7 +975,11 @@ class NodeDetailScreen(Screen):
The route keeps its per-node colours even when selected (the pointer, and the white
line in the graph above, carry the selection) — unlike the plain action rows, which
go fully brand, since here the colour *is* the content. The trailing ``…`` is the
app-wide opens-further-prompts mark: Enter on the row arms a trace on it. The
app-wide opens-further-prompts mark: Enter on the row arms a trace on it. It rides
*outside* the lane (:func:`~meshterm.ui.pathline.with_action_mark`) — chrome buys no
cells off the route, so a chain that fits stays whole and closes on its rounded cap
instead of cracking to make room for two cells of hint, and the mark is what goes
unshown where the lane is full. The
pathline never hop-wraps — it is one line, cropped: the highlighted row rides
:attr:`_hshift` (``←→``, see :meth:`handle`) so a named chain wider than the lane can
still be read to its end, under a :func:`~meshterm.ui.pathline.cut_mark` at whichever
@@ -989,15 +992,14 @@ class NodeDetailScreen(Screen):
other row is simply cut to the lane (:func:`~meshterm.ui.pathline.cut_to`, cracked or
ellipsized by the same rule), and the context line under any row — plain prose, never
a path — ellipsizes: only the row you are on can scroll, and it is the only one whose
end you are asking to see. The context —
bottleneck SNR, sample count, the ``★ best`` / ``device route`` tag — is dropped
entirely when a route earns none of it.
end you are asking to see. The context — hop count, bottleneck SNR, sample count, the
``★ best`` / ``device route`` tag — always leads with the count, so every row is two
lines tall and the list stops changing height as the cursor walks it.
"""
indent = _ROUTE_INDENT
avail = max(1, width - indent)
pointer = Text("❯ " if selected else " ", style="brand" if selected else "")
marked = route.path.copy()
marked.append(_OPENS_MARKER, style="muted")
marked = route.path
if selected and self._hshift:
total = cell_len(marked.plain)
# A scrolled row has given up a cell to its left mark, so its last window spans
@@ -1022,7 +1024,8 @@ class NodeDetailScreen(Screen):
path.append_text(cut_mark(marked, shift + window - 1, ELIDE_TAIL))
else:
path = cut_to(marked, avail)
path.no_wrap = True
path = with_action_mark(path, avail)
path.no_wrap = True
line1 = Text()
line1.append_text(pointer)
line1.append_text(path)
@@ -1452,9 +1455,14 @@ def _route_line(
Names cost cells that hashes don't, which is what the row's horizontal scroll is for (see
:meth:`NodeDetailScreen._route_row_lines`) — the same trade the Message paths rows make,
and the reason a name is worth it: a route reads as places, and the reader pays only for
the one row they are on. ``context`` is the bottleneck SNR, sample count, and a ``★ best``
/ ``device route`` tag marking the winner and the firmware's learned route — kept off the
pathline itself so a long chain never crowds it out, and empty when a route earns none.
the one row they are on. ``context`` leads with the route's hop count
(:func:`~meshterm.ui.pathline.hops_atom` — the figure the line above encodes but never
states, and the one two routes are compared on first), then the bottleneck SNR, sample
count, and a ``★ best`` / ``device route`` tag marking the winner and the firmware's
learned route — all kept off the pathline itself so a long chain never crowds it out.
The count means the row always earns a context line, which is right: every route has a
length, and a row whose second line came and went with the evidence made the list jump
a row taller as the cursor moved.
"""
hash_bytes = max(hash_bytes, 1) # an unknown mode still needs a real width to slice
@@ -1471,7 +1479,7 @@ def _route_line(
PathHop(SELF_GLYPH, you=True),
]).text()
atoms: list[Text] = []
atoms: list[Text] = [hops_atom(len(hops_out))]
if weakest is not None:
snr = Text("weakest ", style="muted")
snr.append(f"{weakest:+.1f} dB", style=snr_style(weakest))
+71 -9
View File
@@ -22,7 +22,9 @@ drawn*, so every surface the survey found can eventually route through it:
that name. A chip caught by a *cut* — a lane that ran out, a line scrolled past its
edge — breaks off on a half block in its own fill
(:func:`cut_mark`), and that crack is what says the segment continues; only chips
crack, an arrow line still ellipsizes. ``auto`` (the default) picks powerline exactly
crack, an arrow line still ellipsizes. A row that also carries the app-wide
opens-further-prompts ``…`` hangs it *outside* the budget
(:func:`with_action_mark`) — chrome may not cost the route cells. ``auto`` (the default) picks powerline exactly
when the terminal can draw it (:func:`~meshterm.ui.termfont.powerline_enabled` —
a recommended font, a glyph-capable renderer, or the user's override) and falls
back to arrows everywhere else, so no terminal ever sees tofu.
@@ -131,6 +133,11 @@ _ELISION = "⋯"
#: standing where words were. An arrow hop is text, so shortening it is what happened.
_ELLIPSIS = "…"
#: The app-wide "this row opens further prompts" mark (see the UX standards), as a *path*
#: row wears it — see :func:`with_action_mark` for why it is spelled here rather than
#: appended by each surface.
ACTION_MARK = " …"
#: What a *chip* line cuts with instead (JP, 2026-08-09) — the half block, drawn in the
#: cut chip's own fill with no background, so the cell is half segment and half bare
#: page: the chip breaks off mid-body and the crack says it is incomplete. An ellipsis
@@ -292,7 +299,37 @@ def cut_mark(line: Text, at: int, side: str) -> Text:
return Text(CRACK_HEAD if side == ELIDE_HEAD else CRACK_TAIL, style=fill)
def cut_to(line: Text, width: int) -> Text:
def with_action_mark(line: Text, width: int) -> Text:
"""``line`` plus the opens-further-prompts ``…`` — riding *past* the width budget.
The mark says what Enter on the row does. It is not part of the path, so it must not
cost the path a cell: reserving room for it up front made a route that fitted its lane
exactly crack on its last chip (JP, 2026-08-10), so the row claimed the walk ran on
when the walk had in fact finished — the crack only replaces the closing cap, and the
two cells the mark wanted were the two the reader lost.
So the path is fitted to the *whole* lane first and the mark lands in whatever is left
over; where nothing is left, it simply isn't drawn. Losing it costs the reader a hint
the row's own behaviour gives them the moment they press Enter; losing the tail of a
hop costs them the route. That is the widget's default answer wherever a path row
carries the mark, not one surface's local trade — pass the *fitted* line here (after
:func:`cut_to` or after a scroll window) and let the leftovers decide.
Args:
line: The path line, already fitted to ``width``.
width: The lane's cell budget.
Returns:
The line with the mark appended, or unchanged when the lane has no room for it.
"""
if line.cell_len + cell_len(ACTION_MARK) > width:
return line
out = line.copy()
out.append(ACTION_MARK, style="muted")
return out
def cut_to(line: Text, width: int, *, action: bool = False) -> Text:
"""Fit a rendered path line to ``width`` by cutting its tail — cracked, not elided.
The drop-in for ``Text.truncate(width, overflow="ellipsis")`` wherever the line being
@@ -303,19 +340,44 @@ def cut_to(line: Text, width: int) -> Text:
Args:
line: The rendered line to fit.
width: The cell budget.
action: Append the opens-further-prompts mark afterwards, free of the budget
(:func:`with_action_mark`) — for a row Enter opens something from.
Returns:
A line no wider than ``width``.
"""
if line.cell_len <= width:
return line
if width <= 0:
return Text()
mark = cut_mark(line, width - 2, ELIDE_TAIL)
body = line.copy()
body.truncate(max(0, width - mark.cell_len), overflow="crop")
body.append_text(mark)
return body
if line.cell_len <= width:
fitted = line
else:
mark = cut_mark(line, width - 2, ELIDE_TAIL)
fitted = line.copy()
fitted.truncate(max(0, width - mark.cell_len), overflow="crop")
fitted.append_text(mark)
return with_action_mark(fitted, width) if action else fitted
def hops_atom(count: int) -> Text:
"""The hop count, as the stats line hanging under a path line spells it.
Wherever a surface hangs stats under a path, the number of hops is one of them (JP,
2026-08-10): it is the figure the picture above encodes but never states, the one two
routes are most often compared on, and the one a reader would otherwise have to count
chips to get. ``direct`` where there are none — a path with no relays isn't "0 hops",
it is the app's own word for a frame that went straight there (:class:`PathLine`'s
own ``empty`` note says exactly that).
Args:
count: How many *relay* hops the route took (endpoints excluded — us and the far
node are on every route here, so counting them would say nothing).
Returns:
The muted atom, ready to join a ``·`` chain.
"""
if count <= 0:
return Text("direct", style="muted")
return Text(f"{count} hop" if count == 1 else f"{count} hops", style="muted")
class PathLine:
+53 -20
View File
@@ -101,7 +101,7 @@ from .theme import snr_style
from .tui.render import render_lines, render_to_ansi
from .tui.screen import ListWindow, Screen
from .tui.spinner import Spinner, spinner_interval
from .pathline import PathHop, PathLine, path_line
from .pathline import PathHop, PathLine, cut_to, hops_atom, path_line
from .widgets import NodeResolver, _link_text, _route_path, highlighted_hash
if TYPE_CHECKING:
@@ -1257,8 +1257,16 @@ def _scenario_path(
unnamed hop its prefix-lit hash) instead of the old single-colour smear — and, as
in the route lane above it, our own end goes bare: every candidate starts from us,
so the word would be the same on every row and the cells are the candidates'.
With a ``width`` budget the line middle-elides (``PathLine.ellipsized``) so both
endpoints survive a narrow terminal; ``None`` returns the full line.
A ``width`` budget *cuts* the line rather than middle-eliding it
(:func:`~meshterm.ui.pathline.cut_to`): the ``⋯`` rescue exists to save a route's two
endpoints, and here both endpoints are the same two on every row by construction — our
own ``★`` and the one target the whole screen is about — so it would spend cells on
what the reader already knows and take them from the candidates' *front*, the only part
that differs. Cutting also makes every row read the way the highlighted one does at
shift zero, so walking the cursor down the list no longer rewrites the row under it
(JP, 2026-08-10). ``None`` returns the full line, which is what the highlighted row
slides under ``←→``.
"""
route = path_line(
[None, *scenario.hops, target_id],
@@ -1267,21 +1275,24 @@ def _scenario_path(
self_name=device_label,
bare_self=True,
)
return route.text() if width is None else route.ellipsized(width)
return route.text() if width is None else cut_to(route.text(), width)
def _scenario_detail(scenario: Any) -> Text:
"""The line hanging under a scenario's pathline: its provenance and evidence.
"""The line hanging under a scenario's pathline: its length, provenance and evidence.
The device route and the direct shot keep their short provenance tag (observed
candidates *are* their hop sequence, so they carry none); then the bottleneck
SNR and sample count a trace would expect to measure, or ``unobserved`` when
the evidence graph has nothing to say about it yet.
The hop count leads (:func:`~meshterm.ui.pathline.hops_atom`) — the figure the line
above encodes but never states, and the first thing one candidate route is weighed
against another on. It also absorbs the *direct* shot's provenance tag, which was
that same word for the same reason (no repeaters at all); the device route keeps its
own, since a firmware-learned route is a claim about where the hops came from rather
than about how many there are. Observed candidates *are* their hop sequence and carry
no tag. Then the bottleneck SNR and sample count a trace would expect to measure, or
``unobserved`` when the evidence graph has nothing to say about it yet.
"""
atoms: list[Text] = []
if scenario.source in ("device", "direct"):
style = "accent" if scenario.source == "device" else "muted"
atoms.append(Text(scenario.label, style=style))
atoms: list[Text] = [hops_atom(len(scenario.hops))]
if scenario.source == "device":
atoms.append(Text(scenario.label, style="accent"))
if scenario.weakest_snr is not None:
snr = Text("weakest ", style="muted")
snr.append(f"{scenario.weakest_snr:+.1f} dB", style=snr_style(scenario.weakest_snr))
@@ -1772,8 +1783,15 @@ async def _open_session(
sample_count = int(picked)
return None
def outcome_title(rank: int, outcome: ProbeOutcome) -> Text:
"""One probed candidate as a ranked select row: one measured trace, not a guess."""
def outcome_lanes(rank: int, outcome: ProbeOutcome) -> Text:
"""A probed candidate's fixed head: rank, verdict, bottleneck SNR, round trip.
Split out from :func:`outcome_title` so the row can *measure* the block it pins
out of the ←→ scroll (:attr:`~meshterm.ui.tui.select.Choice.hscroll_from`) rather
than guess at it. These lanes are the whole reason the list is ranked — sliding
them off to read the tail of a ten-hop spec would cost the row its identity and
gain nothing, since the columns are the part that already fits.
"""
stats = outcome.stats
text = Text(f"#{rank} ", style="muted")
if stats.successes:
@@ -1787,6 +1805,11 @@ async def _open_session(
if stats.median_rtt_ms is not None:
text.append(f" {stats.median_rtt_ms:.0f} ms", style="muted")
text.append(" via ", style="muted")
return text
def outcome_title(lanes: Text, outcome: ProbeOutcome) -> Text:
"""One probed candidate as a ranked select row: one measured trace, not a guess."""
text = lanes.copy()
text.append(outcome.candidate.spec, style="brand")
text.append(f" ({outcome.candidate.label})", style="faint")
return text
@@ -1914,9 +1937,10 @@ async def _open_session(
for scenario in scenarios:
items.append(
Choice(
# Width-aware (see Choice.title): a long candidate middle-elides to
# the terminal so both endpoints survive; the highlighted row keeps
# its natural length and slides under ←→ instead.
# Width-aware (see Choice.title): a long candidate is cut to the
# terminal, cracking on its own chip exactly as the highlighted row
# does at shift zero — the highlight then keeps its natural length
# and slides under ←→ instead of the row being redrawn as it lands.
title=(
lambda width, scenario=scenario: _scenario_path(
scenario, topo, target_id,
@@ -1965,7 +1989,14 @@ async def _open_session(
section_heading("Ranked · reliability, then bottleneck SNR")
]
for rank, outcome in enumerate(outcomes, start=1):
result_items.append(Choice(title=outcome_title(rank, outcome), value=outcome))
lanes = outcome_lanes(rank, outcome)
result_items.append(
Choice(
title=outcome_title(lanes, outcome),
value=outcome,
hscroll_from=lanes.cell_len,
)
)
result_items.append(Separator(" "))
result_items.append(Choice(title="Keep current path", value=None)) # the exit: no adoption
adopted = await session.run_screen(
@@ -1974,7 +2005,9 @@ async def _open_session(
result_items,
footer_hint="↑↓ move · Enter adopt path · Esc keep",
wrap=False,
hscroll=True, # ranked rows carry whole specs — let ←→ read the tail
# ←→ read the tail of a long spec; the ranking lanes in front of it stay
# pinned (each row declares their width — see outcome_lanes).
hscroll=True,
)
)
if adopted is CANCEL or adopted is None:
+38
View File
@@ -1167,6 +1167,44 @@ def test_scenario_path_direct_scenario_still_names_both_endpoints() -> None:
assert text.plain == "★ → Far"
def test_scenario_path_cuts_a_long_candidate_rather_than_eliding_its_middle() -> None:
"""Every row is cut the way the highlighted one is at shift zero — no ``⋯`` rescue.
The middle-elide exists to save a route's two endpoints, and here both endpoints are
the same two on every row by construction (our own ``★``, the one target the screen is
about), so it would spend cells on what the reader knows and take them off the
candidates' *front* — the only part that differs. Cutting also stops the row being
redrawn the moment the cursor lands on it (JP, 2026-08-10).
"""
topo = _scenario_topo()
scenario = PathScenario(
label="observed path", hops=("3d63c6429436",), source="observed", score=1.0,
)
full = _scenario_path(
scenario, topo, "f2c24f54551e", device_label="YUL-Me", width_bytes=1
)
narrow = _scenario_path(
scenario, topo, "f2c24f54551e", device_label="YUL-Me", width_bytes=1,
width=full.cell_len - 3,
)
assert narrow.cell_len <= full.cell_len - 3
assert "⋯" not in narrow.plain # nothing elided out of the middle…
assert narrow.plain.startswith("★ → Hub") # …the head is intact, the tail is what went
def test_scenario_detail_leads_with_the_hop_count() -> None:
"""The stats line under a candidate opens with how long the route is."""
scenario = PathScenario(
label="observed path", hops=("3d63c6429436", "f2c24f54551e"), source="observed",
score=1.0, weakest_snr=-4.0, samples=2,
)
assert _scenario_detail(scenario).plain.startswith("2 hops · ")
# The direct shot's provenance tag *was* this same word, so the atom absorbs it rather
# than the row reading "direct · direct".
direct = PathScenario(label="direct", hops=(), source="direct", score=0.0, samples=1)
assert direct.label == "direct" and _scenario_detail(direct).plain.count("direct") == 1
def test_scenario_detail_carries_provenance_snr_and_samples() -> None:
"""The device/direct provenance tag, weakest SNR, and sample count all show, in order."""
scenario = PathScenario(
+10 -4
View File
@@ -52,8 +52,10 @@ def test_paths_screen_renders_graph_rows_and_cursor() -> None:
rows = body.split("sensor\n\n")[1].split("\n")
assert len(rows) == 2 * len(_arrivals())
assert rows[0].startswith("❯ ") and "YUL-Cartierville" in rows[0] # the picked route
assert rows[1].strip().startswith(_arrivals()[0].when.astimezone().strftime("%H:%M"))
assert "+4.0 dB" in rows[1] # …with its time and SNR tucked beneath it
# …with its length, time and SNR tucked beneath it, the hop count leading
assert rows[1].strip().startswith("1 hop ")
assert _arrivals()[0].when.astimezone().strftime("%H:%M") in rows[1]
assert "+4.0 dB" in rows[1]
assert "❯" in body
assert "white = selected path" in body # the graph caption
assert "★ you" in body and "▲ repeater" in body # the node-type legend
@@ -256,13 +258,17 @@ def test_paths_screen_direct_arrival_and_empty_state() -> None:
The route no longer collapses to the word *direct*: with both ends on the line,
``Alice → ★`` **is** what a direct delivery looks like, and it reads on the same rails
as every relayed row instead of swapping the picture for a caption.
as every relayed row instead of swapping the picture for a caption. The word survives
one row down, where it belongs — as the hop-count stat under the line, saying how far
the frame came rather than standing in for the picture of it.
"""
now = utcnow()
screen = _screen([Arrival(when=now, hops=(), snr=2.5)])
body = _plain(screen.render_body(76))
assert "❯ Alice → ★" in body
assert "direct" not in body
route = next(l for l in body.splitlines() if l.startswith("❯"))
assert "direct" not in route
assert body.splitlines()[body.splitlines().index(route) + 1].strip().startswith("direct")
empty = _screen([], matched=False)
body = _plain(empty.render_body(76))
assert "No direct-message frames logged in the window." in body
+50 -5
View File
@@ -205,7 +205,9 @@ def test_route_line_names_its_hops() -> None:
assert "3d" not in line and "f2" not in line # no hop repeats its hash after its name
assert line.rstrip().endswith(SELF_GLYPH) # our own node anchors the right, as the ★
assert "Us" not in line # …in one cell, not a name every row would repeat
assert context.plain == "device route" # the firmware-route tag, off the pathline itself
# The context leads with the route's length, then the firmware-route tag — both off the
# pathline itself.
assert context.plain == "1 hop · device route"
def test_route_line_greys_hops_nobody_can_name() -> None:
@@ -733,10 +735,11 @@ def test_node_detail_screen_hscrolls_the_selected_pathline() -> None:
for _ in range(20): # run the scroll to its stop
screen.handle("right")
row = next(l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯"))
# The clamp lands where the tail is actually readable: the line's own end — the last hop
# and the opens-marker — is on screen rather than cropped behind a right-hand edge mark
# promising a remainder the keys can no longer reach. Only the left mark is left drawn.
assert row.rstrip().endswith("aa …") and row.count("…") == 2
# The clamp lands where the tail is actually readable: the line's own end — its last hop
# — is on screen rather than cropped behind a right-hand edge mark promising a remainder
# the keys can no longer reach. Only the left mark is left drawn; the opens-further `…`
# rides outside the lane, so a window filled to its edge is exactly where it goes unshown.
assert row.rstrip().endswith("aa") and row.count("…") == 1
screen.handle("right") # …and the stop holds: nothing moves past it
assert next(
l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯")
@@ -786,6 +789,48 @@ def test_node_detail_route_row_cracks_a_chip_path_at_both_edges() -> None:
assert row.rstrip().endswith(CRACK_TAIL) and "…" not in row
def test_node_detail_route_row_spends_no_lane_cells_on_the_opens_marker() -> None:
"""A route that fills its lane exactly stays whole — the trailing ``…`` is not its cost.
The mark says what Enter does; it is chrome, not route. Reserving two cells for it made
a chain that fitted crack on its own last chip (JP, 2026-08-10) — the row claiming the
walk ran on when it had in fact arrived, the crack being nothing but the closing cap
with half of it taken away. Now the path is fitted to the whole lane and the mark takes
whatever is left, which on a full lane is nothing at all.
"""
avail = 72 - 2 # the row's lane: the width less the pointer column
exact = Text("x" * avail)
routes = _RoutesView(
routes=[_Route(draw=("3d",), spec="s0", path=exact.copy(), context=Text(""))],
glyph_of=lambda n: ("●", "#ffffff"),
label_of=lambda n: n[:2],
label_rgb_of=lambda n: (200, 200, 200),
)
screen = _screen(routes=routes, tabs=[_Tab("Routes", "routes")])
screen.note_viewport(30)
row = next(
l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯")
)
assert row == "❯ " + "x" * avail # whole, uncut, and no mark squeezed in
# …and with nothing to scroll, ←→ stay inert and unadvertised.
assert "←→ scroll" not in screen.footer_hint
# Two cells of slack is exactly what the mark costs, so there it is drawn.
roomy = _RoutesView(
routes=[_Route(draw=("3d",), spec="s0", path=Text("x" * (avail - 2)),
context=Text(""))],
glyph_of=lambda n: ("●", "#ffffff"),
label_of=lambda n: n[:2],
label_rgb_of=lambda n: (200, 200, 200),
)
screen = _screen(routes=roomy, tabs=[_Tab("Routes", "routes")])
screen.note_viewport(30)
row = next(
l for l in _plain(screen.render_body(72)).splitlines() if l.startswith("❯")
)
assert row == "❯ " + "x" * (avail - 2) + " …"
#: A 64-digit key whose every byte is distinct (``000102…1e1f``), so a window's first digits
#: say exactly where the lane was cut — an off-by-one shift reads ``0001…`` as ``00102…``.
_LONG_KEY = "".join(f"{i:02x}" for i in range(32))
+59 -1
View File
@@ -16,7 +16,8 @@ import meshterm.ui.pathline as pathline
from meshterm.ui.pathline import (
CRACK_HEAD, CRACK_TAIL, CURSOR_GLYPH, ELIDE_HEAD, ELIDE_TAIL, 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, path_line,
_SELF_INK, _YOU_BG, _style_hex, cut_mark, cut_to, elision_hop, hops_atom,
path_line, with_action_mark,
)
from meshterm.ui.theme import node_style
from meshterm.ui.widgets import path_text
@@ -553,3 +554,60 @@ def test_bare_self_keeps_us_in_the_you_white_where_nothing_is_composed() -> None
dim_self=False, dim_from=3, mode="plain").text()
tail = [s for s in faded.spans if faded.plain[s.start : s.end] == SELF_GLYPH]
assert [str(s.style) for s in tail] == ["you", "faint"]
def test_action_mark_rides_outside_the_width_budget() -> None:
"""The opens-further ``…`` costs the path no cells — it takes what is left, or nothing.
Reserving room for it made a route that filled its lane exactly crack on its last chip
(JP, 2026-08-10): the row claimed the walk ran on when the walk had finished, and the
two cells the hint wanted were two the reader lost. So the path is fitted first and the
mark lands in the leftovers.
"""
hops = [None, "3d63", "f2a1", None]
line = path_line(hops, prefix_bytes=2, self_name="Me", bare_self=True,
dim_self=False, mode="plain").text()
exact = line.cell_len
# A lane the route fills exactly: the route survives whole, and the mark is what goes.
fitted = cut_to(line, exact, action=True)
assert fitted.plain == line.plain
assert fitted.cell_len == exact
# One cell of slack still isn't enough for " …" — the mark is two cells, all or nothing.
assert cut_to(line, exact + 1, action=True).plain == line.plain
# Room for both: the mark appears, and the whole thing still fits the lane.
roomy = cut_to(line, exact + 2, action=True)
assert roomy.plain == line.plain + " …"
assert roomy.cell_len <= exact + 2
# A route that genuinely overflows is cut as always, and then has no room left over.
cut = cut_to(line, exact - 4, action=True)
assert cut.cell_len == exact - 4 and not cut.plain.endswith(" …")
# The mark never widens a line past its lane, whatever it is handed.
assert with_action_mark(line, exact - 1).plain == line.plain
def test_action_mark_leaves_a_chip_path_closed_rather_than_cracked() -> None:
"""In chips, the whole point: a route that fits keeps its closing cap, not a crack."""
hops = [None, "3d63", "f2a1", None]
line = path_line(hops, prefix_bytes=2, self_name="Me", bare_self=True,
dim_self=False, mode="powerline").text()
fitted = cut_to(line, line.cell_len, action=True)
assert CRACK_TAIL not in fitted.plain
assert fitted.plain == line.plain
def test_hops_atom_counts_relays_and_says_direct_for_none() -> None:
"""The stats-line atom: ``direct`` for a hopless route, else ``n hop(s)``.
A path with no relays isn't "0 hops" — ``direct`` is the app's own word for a frame
that went straight there, and it is what :class:`PathLine` says for an empty path too.
"""
assert hops_atom(0).plain == "direct"
assert hops_atom(1).plain == "1 hop"
assert hops_atom(4).plain == "4 hops"
assert hops_atom(-1).plain == "direct" # a caller that subtracted its endpoints twice
assert all(str(atom.style) == "muted" for atom in (hops_atom(0), hops_atom(3)))