Trophy case: cut every walk the way the highlight is cut

Unselected rows middle-elided to the width while the highlighted one kept its
natural line and cracked at the lane, so moving the cursor rewrote the row
under it — two renderings of the same walk, differing in more than the shift.

The `⋯` rescue exists to save a route's two endpoints from a right truncation.
On this board both endpoints are the same `★` on every row, by construction, so
it spent three cells and a hop to arrive back at the one thing the reader
already knew, while the walk's *front* — the part that actually differs from
row to row — paid for it. Every row now carries the whole line and is cut by
the list, so selected and unselected differ in exactly one thing: the shift.

The title is a finished Text rather than a width-aware callable now (nothing
fits itself to the terminal any more), which retires the per-width memo — a
frozen record composes once per open instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-09 21:57:00 -04:00
1 parent 6e39537d73
commit 771a865e8a
2 files changed
+61 -28

No files matched your search

+24 -28
View File
@@ -715,22 +715,30 @@ async def open_records(ctx: "AppContext") -> dict:
row.append(" ")
return row
def browser_row(lanes: Text, record: DiscoveredPath, width: int) -> Text:
"""One record row: its fixed lanes (:func:`browser_lanes`), then the walk.
def browser_row(lanes: Text, record: DiscoveredPath) -> Text:
"""One record row: its fixed lanes (:func:`browser_lanes`), then the whole walk.
The walk draws on THE path widget with both ends bare
(:data:`~meshterm.ui.pathline.SELF_GLYPH`): a record is a boomerang by construction,
so naming ourselves twice per row would cost more cells than the whole score lane and
tell the reader what every other row already told them. Those stars keep the ``you``
white (``dim_self=False``) — the fade means "not yours to compose", and nothing on a
board of walks already made is being composed. A walk wider than ``width`` (the
row's render budget) middle-elides through ``PathLine.ellipsized`` so both endpoints
survive — a right truncation would amputate the return leg — while the *highlighted*
row keeps its natural length and h-scrolls under ←→, so the elided middle is read by
sliding it. That scroll starts at the lanes' own width (``Choice.hscroll_from``): the
walk is the only thing on the row that overflows, so it is the only thing that moves —
sliding rank and score off to the left would cost the reader their place in the board
and buy back cells the walk was already going to be given.
board of walks already made is being composed.
The line is composed at its **natural** length and handed over whole, so every row is
cut the same way the highlighted one is: anchored on its first hop and cracked at the
lane's edge (:func:`~meshterm.ui.pathline.cut_to`, applied by the list). It is
deliberately *not* middle-elided to the width. That rescue exists to save a route's
two endpoints from a right truncation — but on this board both endpoints are the
same ``★`` on every row, by construction, so the ``⋯`` would spend three cells and a
hop to arrive back at the one thing the reader already knows. What differs from row to
row is the walk's front, and every cell goes to it.
A row that outruns the lane is read by *sliding* it: the highlight keeps the same line
and h-scrolls under ←→ from the lanes' own width (``Choice.hscroll_from``), so the walk
is the only thing on the row that moves — sliding rank and score off to the left would
cost the reader their place in the board and buy back cells the walk was already going
to be given. Unselected and selected therefore differ in exactly one thing, the shift.
"""
row = lanes.copy()
walk = path_line(
@@ -742,7 +750,7 @@ async def open_records(ctx: "AppContext") -> dict:
bare_self=True,
dim_self=False,
)
row.append_text(walk.ellipsized(max(8, width - row.cell_len)))
row.append_text(walk.text())
return row
async def delete_category_flow() -> None:
@@ -780,20 +788,6 @@ async def open_records(ctx: "AppContext") -> dict:
):
ctx.repo.delete_discoveries(category.id)
def record_row_title(lanes: Text, record: DiscoveredPath):
"""A width-aware row title, memoized per width — the record is frozen, so the
path-widget assembly and middle-elide only ever run once per render width
instead of once per record per repaint."""
memo: dict[int, Text] = {}
def title(width: int) -> Text:
cached = memo.get(width)
if cached is None:
cached = memo[width] = browser_row(lanes, record, width)
return cached
return title
while True:
items: list = []
for category in CATEGORIES:
@@ -811,9 +805,11 @@ async def open_records(ctx: "AppContext") -> dict:
rank, category, record, show_width=show_width, score_w=score_w,
)
items.append(Choice(
# Width-aware (see Choice.title): the row re-fits its walk to each
# render width, middle-eliding rather than dying at the right edge.
title=record_row_title(lanes, record),
# A finished line, not a width-aware callable: the row fits itself to
# nothing, so the list cuts every row — highlighted or not — the one way
# (see browser_row). Records are frozen, so it is composed once per open
# rather than per repaint.
title=browser_row(lanes, record),
value=("open", category, rank, record),
# ←→ slide the walk alone; the lanes in front of it hold (browser_row).
hscroll_from=lanes.cell_len,
+37
View File
@@ -494,3 +494,40 @@ async def test_trace_this_path_unwinds_to_the_menu_not_the_browser(
assert walked == ["3d,f2"] # the record's spec went straight to Trace path
assert result == {"records": 1}
async def test_browser_cuts_every_row_the_way_it_cuts_the_highlighted_one(tui_ctx) -> None:
"""Unselected walks are cut, not middle-elided — the highlight only adds the shift.
Both ends of a record's walk are the same ``★`` on every row (a record is a boomerang),
so the ``⋯`` rescue that saves a route's two endpoints from a right truncation would buy
back nothing here while spending cells the walk's *front* — the part that differs from row
to row — was going to get. Every row therefore carries the whole line and is cut at the
lane, exactly as the highlighted row is at shift zero.
"""
ctx = tui_ctx
long_route = tuple(f"{byte:02x}c24f54551e" for byte in range(0x20, 0x2c))
for rank, route in enumerate((long_route, long_route[::-1]), start=1):
ctx.repo.record_discovery(
"grand_tour", 1, f"{route[0][:2]},f2", route,
score=float(20 - rank), stats={"hop_count": len(route), "distinct_nodes": len(route)},
app_version="0.1.0",
)
task = asyncio.ensure_future(open_records(ctx))
try:
browser = await _step_until(lambda: _trophy_case(ctx.ui.session))
assert browser is not None
rows = [_plain([line]) for line in browser.render_body(72)]
walks = [row for row in rows if "★" in row]
assert len(walks) == 2, rows # one highlighted, one not
assert not any("⋯" in row for row in walks) # nothing middle-elides any more
# Highlighted and not, every walk starts at our star right after the score lane…
assert all(re.search(r"#\d+ .*nodes ★ → ", row) for row in walks), walks
# …and runs on past the lane rather than closing on a rescued second endpoint.
assert all(row.rstrip().endswith("…") for row in walks), walks
browser.resolve(("back", None, 0, None))
await task
finally:
if not task.done():
task.cancel()