The walk's start is cropped, not given up whole

The breadcrumb fitted itself with ellipsized(ELIDE_HEAD): the head hop went
behind a leading ⋯ and whatever fitted after it snapped right. That mark cost
three cells and, worse, the whole hop it was standing in for — a 46-cell lane
opened on "⋯ › Repeater-06" when it had room for the tail of Repeater-05 too.

The trophy case has always cut its rows the other way: composed at natural
length, handed over whole, cracked at the lane's edge in the sheared chip's own
fill. Same crop here, mirrored to the end the trail is anchored on — cut_from,
cut_to's head-side counterpart, added to the widget so no surface hand-rolls it.
The trail draws whole while whole fits and crops its beginning when it doesn't;
a crop lands exactly on the width, so the right snap comes free.

Each end now carries the mark that is true of it: the head opens on the crack,
which says this segment continues, and the scrolled tail keeps the ⋯, which
says whole hops are missing — because off that end they really are.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-05 14:02:59 -04:00
1 parent 5ca5ea7d56
commit 23e89633fb
4 files changed
+134 -47

No files matched your search

+43 -4
View File
@@ -29,12 +29,13 @@ drawn*, so every surface the survey found can eventually route through it:
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.
* **Three overflow answers**, matching the three patterns the surfaces already use:
:meth:`PathLine.text` is the full one-liner (for callers that ellipsize or
h-scroll it themselves), :meth:`PathLine.ellipsized` fits a width by eliding
:meth:`PathLine.text` is the full one-liner (for callers that crop or
h-scroll it themselves — :func:`cut_to` anchored on the first hop, :func:`cut_from`
on the last), :meth:`PathLine.ellipsized` fits a width by eliding
hops behind a ``⋯`` mark, on whichever side it is told to eat into
(:data:`ELIDE_TAIL` by default — both endpoints survive, unlike a plain tail
truncation that amputates the destination; :data:`ELIDE_HEAD` for a breadcrumb
trail, which anchors on where the walk *is*) — and :meth:`PathLine.wrapped` breaks
truncation that amputates the destination; :data:`ELIDE_HEAD` where a surface
wants the head given up whole) — and :meth:`PathLine.wrapped` breaks
at hop boundaries under a hanging indent (never mid-name, never mid-chip),
folding where the route *means* something: the fewest lines it can take, evened
out across them rather than greedily crammed, and preferring the seam where the
@@ -365,6 +366,44 @@ def cut_to(line: Text, width: int, *, action: bool = False) -> Text:
return with_action_mark(fitted, width) if action else fitted
def cut_from(line: Text, width: int) -> Text:
"""Fit a rendered path line to ``width`` by cutting its *head* — cracked, not elided.
:func:`cut_to`'s mirror, for a line anchored on its **last** hop rather than its
first: a breadcrumb whose news is where the walk got to, a lane whose right edge is
the thing being read. The body keeps the tail cells and the freed cell at the left
carries :func:`cut_mark`, so the chip the crop landed in opens on
:data:`CRACK_HEAD` — half segment, half page, the picture of a path that began off
to the left — while an arrow line opens on the same ``…`` it always did. A line that
already fits comes back untouched, which is what makes "draw it whole until it can't
be" the caller's default rather than a special case it has to write.
This is a *crop*, deliberately not :meth:`PathLine.ellipsized`: nothing is dropped
behind a ``⋯``, so the reader loses exactly the cells the lane ran out of and not the
whole hop those cells were part of. The two marks stay honest about which happened —
the crack says a segment continues, the ellipsis says whole hops are missing.
Args:
line: The rendered line to fit.
width: The cell budget.
Returns:
A line no wider than ``width``, flush against its right edge by construction.
"""
if width <= 0:
return Text()
if line.cell_len <= width:
return line
from .tui.render import crop_cells # deferred: render reads PATH_INK from here
mark = cut_mark(line, line.cell_len - width + 1, ELIDE_HEAD)
kept = max(0, width - mark.cell_len)
out = Text(style=line.style, no_wrap=True)
out.append_text(mark)
out.append_text(crop_cells(line, line.cell_len - kept, kept))
return out
def hops_atom(count: int) -> Text:
"""The hop count, as the stats line hanging under a path line spells it.
+32 -32
View File
@@ -66,7 +66,7 @@ from ..services.topology import Link, MeshTopology
from .map_render import _SELF, _UNKNOWN
from .mapcanvas import RGB, MapCanvas, parse_hex
from .menus import fit_cells
from .pathline import ELIDE_HEAD, SELF_GLYPH, PathHop, PathLine, elision_hop
from .pathline import SELF_GLYPH, PathHop, PathLine, cut_from, elision_hop
from .theme import mark_rgb, name_style, snr_style
from .trace_screen import snr_bar
from .tui.render import query_line, render_to_ansi
@@ -136,10 +136,10 @@ _FAN_MIN_SLOTS = 7
#: never collide with a canonical id (those are hex).
_MORE = "\x00more"
#: The breadcrumb trail's own hop joiner (``›``, not the app-wide ``→``). The mark it shows
#: on whichever side holds walk that is out of view is
#: :func:`~meshterm.ui.pathline.elision_hop` itself (see :meth:`WalkScreen._trail_text`), so
#: a head the widget hid and a tail the scroll hid read as the same thing.
#: The breadcrumb trail's own hop joiner (``›``, not the app-wide ``→``). Each end that
#: holds walk out of view says so in the mark that is *true* of it (see
#: :meth:`WalkScreen._trail_text`): the head is cropped mid-hop, so it opens on the
#: cut's crack; the tail loses whole hops to the scroll, so it closes on the elision.
_TRAIL_SEP = " › "
#: How many find matches the list shows at most (the filter narrows it fast).
@@ -609,28 +609,33 @@ class WalkScreen(Screen):
reserved for keyed identities), so the trail and the rows below it agree on who is
who.
The line never wraps. At rest, a walk that outgrows the width eats into its
*head* (:data:`~meshterm.ui.pathline.ELIDE_HEAD`) rather than a route's usual
tail: the oldest steps go behind a leading ``⋯`` and what survives snaps flush
against the **right** edge, so the focus and the steps that just led to it are
what a glance lands on.
The line never wraps, and it is drawn **whole** for as long as whole fits: the
walk hangs flush left, opening on its rounded head chip, exactly as it would in
a lane with cells to spare. Only when it outgrows the width does it give
anything up, and what it gives up is its **beginning** — the trophy case's crop,
mirrored (:func:`~meshterm.ui.pathline.cut_from`, JP, 2026-09-05). The line is
composed at its natural length and *cropped* at the left edge, so the chip the
crop lands in opens on the half-block crack in its own fill and the cells the
reader loses are the cells the lane ran out of — no whole hop is dropped to buy
room for a mark. The focus and the steps that just led to it are what a glance
lands on, and the cropped line fills the width by construction, which is what
puts it flush right without a pad.
Which edge the line hangs off follows one thing only: **whether the walk's start
is on it.** A line that shows its first hop — the rounded head chip, us — sits
flush **left**, where a path that begins at its beginning belongs; the right snap
is what a *cut* head looks like, holding the ``⋯`` against the far edge so the
elision reads as "the line continues off this side" rather than as a gap. So it
is not the resting state that decides, but the fit: a scrolled line whose head
has come back into view is left-aligned like any other complete one.
Which edge the line hangs off therefore follows one thing: **whether the walk's
start is on it.** A line showing its first hop sits left, where a path that
begins at its beginning belongs; a cropped one sits right, holding the crack
against the edge it continues past. It is not the resting state that decides but
the fit, so a scrolled line whose head has come back into view is left-aligned
like any other complete one.
← and → then **scroll it** (JP, 2026-08-09), a hop at a time, off the tail end:
the elided head is a real part of the walk and a long one had no way to be read
at all. A scrolled line grows its own trailing ``⋯`` — the focus is now the part
out of view — so the mark on each side always means the same thing, more walk
that way. Scrolling stops where the head comes into view rather than running the
line off the edge, and any change to the trail itself resets it: a walk, a step
back, a teleport and ^U all end with the focus in view, which is where the next
move is read from.
the cropped head is a real part of the walk and a long one had no way to be read
at all. A scrolled line grows a trailing ``⋯`` — whole hops really are dropped
off that end, which is what that mark means, against the crack's "this segment
continues". Scrolling stops where the head comes into view rather than running
the line off the edge, and any change to the trail itself resets it: a walk, a
step back, a teleport and ^U all end with the focus in view, which is where the
next move is read from.
"""
hops = [self._trail_hop(node) for node in self._trail]
self._trail_width = width
@@ -639,14 +644,9 @@ class WalkScreen(Screen):
kept = hops[: len(hops) - self._trail_scroll]
if self._trail_scroll:
kept.append(elision_hop()) # the focus is off to the right
line = PathLine(kept, separator=_TRAIL_SEP)
full = line.text()
if full.cell_len <= width:
return full # the start is in view: the walk reads from where it set out
fitted = line.ellipsized(width, elide=ELIDE_HEAD)
snapped = Text(" " * max(0, width - fitted.cell_len)) # snap the tail to the edge
snapped.append_text(fitted)
return snapped
# Whole while it fits (flush left, from the start), cropped at the head when it
# doesn't — and a crop lands exactly on the width, so the right snap is free.
return cut_from(PathLine(kept, separator=_TRAIL_SEP).text(), width)
def _trail_max_scroll(self, width: int) -> int:
"""How far ← may scroll the trail: the step that first brings its head into view.
+35 -1
View File
@@ -17,7 +17,7 @@ from meshterm.ui.pathline import (
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,
_SELF_INK, _YOU_BG, _style_hex, cut_from, cut_mark, cut_to, elision_hop, hops_atom,
path_line, with_action_mark,
)
from meshterm.ui.theme import node_style
@@ -206,6 +206,40 @@ def test_cut_to_leaves_arrow_lines_on_the_ellipsis() -> None:
assert CRACK_TAIL not in fitted.plain
def test_cut_from_crops_the_head_and_keeps_the_line_flush_right() -> None:
"""``cut_to``'s mirror, for a line anchored on its last hop: the crop eats the start,
the crack opens the line in the fill of the very chip it sheared, and the result
lands exactly on the width — which is what makes it flush right without a pad."""
full = _chips().text()
fitted = cut_from(full, 14)
assert fitted.cell_len == 14
assert fitted.plain.startswith(CRACK_HEAD)
assert fitted.plain.endswith(full.plain[-1]) # the tail is what it is anchored on
assert "…" not in fitted.plain and CRACK_TAIL not in fitted.plain
assert str(fitted.spans[0].style) == _style_hex(node_style("22bb")) # inside BBBB
assert cut_from(full, 200) is full # fits → untouched, no copy, no mark
assert cut_from(full, 0).plain == ""
def test_cut_from_leaves_arrow_lines_on_the_ellipsis() -> None:
"""Same mode test as the tail cut: no fill to shear, so the classic mark opens it."""
fitted = cut_from(PathLine(_chips().hops, mode="plain").text(), 10)
assert fitted.cell_len == 10
assert fitted.plain.startswith("…")
assert CRACK_HEAD not in fitted.plain
def test_cut_from_drops_no_whole_hop_the_way_an_elision_does() -> None:
"""The crop is not :meth:`PathLine.ellipsized`: what the reader loses is the cells
the lane ran out of, never the whole hop those cells were part of."""
line = PathLine([PathHop(label) for label in ("AAAA", "BBBB", "CCCC")], mode="plain")
full = line.text()
cropped, elided = cut_from(full, 14), line.ellipsized(14, elide=ELIDE_HEAD)
assert cropped.plain == "…→ BBBB → CCCC" # BBBB survives, minus the cells that ran out
assert elided.plain == "⋯ → CCCC" # where the elision gave up the whole hop
assert cropped.cell_len == 14 and elided.cell_len < 14 # and left cells on the floor
def test_cut_mark_mirrors_itself_and_reads_the_visible_side() -> None:
"""The head mark is the tail's mirror, and each takes the fill of the nearest cell
still *drawn* — scanning back for a tail cut, forward for a head cut."""
+24 -10
View File
@@ -11,7 +11,7 @@ from datetime import timedelta
from meshterm.core.models import Contact, utcnow
from meshterm.services.topology import MeshTopology
from meshterm.ui.pathline import SELF_GLYPH
from meshterm.ui.pathline import CRACK_HEAD, ELIDE_HEAD, SELF_GLYPH, PathLine
from meshterm.ui.tui.render import render_to_ansi
from meshterm.ui.walk_screen import WalkScreen
@@ -287,8 +287,8 @@ def test_walk_walking_to_an_earlier_node_drops_the_loop() -> None:
assert screen._trail == [topo.self_id]
def test_walk_trail_drops_the_head_not_the_tail_when_narrow() -> None:
"""A trail too long for the line loses its head behind a leading ⋯, snapped right."""
def test_walk_trail_crops_its_head_not_its_tail_when_narrow() -> None:
"""A trail too long for the line is cropped at its *start*, the trophy case's crop."""
screen = _screen(_topo())
us = screen._topo.self_id
yul = screen._topo.canonical(YUL.public_key)
@@ -296,10 +296,24 @@ def test_walk_trail_drops_the_head_not_the_tail_when_narrow() -> None:
screen._trail = [us, yul, alice]
width = 20 # too narrow for the whole "Homestead › YUL-Cartierville › Alice"
text = screen._trail_text(width).plain
assert text.lstrip().startswith("⋯")
assert text[0] in ("…", CRACK_HEAD) # cut, not elided: no whole hop bought the mark
assert "⋯" not in text
assert text.endswith("Alice") # the focus is always kept
assert "Homestead" not in text # the head was dropped, not the tail
assert len(text) == width # the surviving tail snaps flush to the right edge
assert "Homestead" not in text # the start was cropped, not the tail
assert len(text) == width # a crop lands on the width, so it is flush right already
def test_walk_trail_crop_keeps_the_cells_an_elision_would_have_spent() -> None:
"""The crop's whole point: cells the lane has go to the walk, not to a dropped hop."""
screen, width = _walked_chain(8)
cropped = screen._trail_text(width)
elided = PathLine(
[screen._trail_hop(node) for node in screen._trail], separator=" › "
).ellipsized(width, elide=ELIDE_HEAD)
assert cropped.cell_len == width # the crop fills the lane…
assert elided.cell_len < width # …where dropping a whole hop left cells on the floor
# The crop keeps the tail of the hop it landed in; the elision dropped it whole.
assert cropped.plain.startswith("…-05 ") and "-05" not in elided.plain
def test_walk_trail_sits_left_until_it_overflows() -> None:
@@ -313,10 +327,10 @@ def test_walk_trail_scrolled_back_to_its_head_sits_left_again() -> None:
"""Alignment follows the head, not the scroll: a visible start hangs the line left."""
screen, width = _walked_chain(8)
limit = screen._trail_max_scroll(width)
for step in range(1, limit): # every stop short of the head keeps the right snap
for step in range(1, limit): # every stop short of the head is still cropped
screen.handle("left")
cut = _plain([render_to_ansi(screen._trail_text(width), width, no_wrap=True)])
assert cut.startswith(" ") and cut.lstrip().startswith("⋯"), step
assert cut[0] in ("…", CRACK_HEAD) and len(cut) == width, step
screen.handle("left") # the step that brings the walk's start back into view
assert screen._trail_scroll == limit
@@ -661,9 +675,9 @@ def test_walk_trail_scrolls_a_hop_at_a_time_off_its_tail() -> None:
screen, width = _walked_chain(8)
trail = _plain([render_to_ansi(screen._trail_text(width), width, no_wrap=True)])
# At rest the walk is flush right: the focus shows, the head is behind a leading ⋯.
# At rest the walk fills the lane: the focus shows, the start is cropped off the left.
assert "Repeater-08" in trail and "Homestead" not in trail
assert trail.lstrip().startswith("⋯")
assert trail[0] in ("…", CRACK_HEAD) and len(trail) == width
assert screen._trail_scroll == 0
screen.handle("left")