From 3d3506be4fd4221ae89e2da05bc8e5a652e85168 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Wed, 9 Sep 2026 01:36:03 -0400 Subject: [PATCH] A route that has finished does not end on the mark for "there is more" The chevron is the ribbon's continuation cue: it is what a wrapped line closes with to say the path runs on past the edge, and it is the same shape as every seam between two hops. So the last chip of a finished route wearing one read as a route cut off mid-walk. Where the font has the rounded caps nothing changed - they close the lozenge and always did. Where it hasn't, the widget already squared the *opening* off and documented that it squares both; only the close never followed. It now appends nothing at all and the last chip's own pad is the edge. The cell that frees up goes back to the route. `_measure` used to report one closing figure for every line, which was true while the close was always a point; it reports two now - what a line the path runs on past closes with, and what the line that *ends* it closes with - so a wrapped path measures its own last line honestly instead of holding a cell back for a glyph that is no longer drawn. The one caller that flows a leg of a route rather than a whole one says so, because its final line is a continuation and still pays the point. Co-Authored-By: Claude Opus 5 (1M context) --- CLAUDE.md | 6 +++ meshterm/ui/pathline.py | 85 +++++++++++++++++++++++++++-------------- tests/test_pathline.py | 40 +++++++++++-------- 3 files changed, 87 insertions(+), 44 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f4a5223..180acd9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -257,6 +257,12 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow same fill are the exception the interlock can't draw: the point drops its background so the page cuts the wedge. An elision breaks the ribbon rather than joining it — bare `⋯` on the page between a closing point and the next chip's notch, no fill, no padding. +- The ribbon's **outer ends**: the chevron means *the route continues*, so a path that has + finished never wears one. It ends **square** — nothing appended, the last chip's own pad + is the edge — and opens square the same way; a full Nerd Font rounds both ends into a + lozenge instead (`POWERLINE_ROUND_*`, drawn only where `termfont.powerline_full`). A + *wrapped* line the path outruns still closes on the point: there the route really does + go on, which is the cue arrow mode spells with a trailing `→`. - Concept icons: 📡 advert · 🕒 clock/sync · 🔄 reboot · 💾 backup · 📂 restore · 🔑 channel/credential key · 🔐 identity/auth secret · 🗑 clear/delete · ✎ compose/edit · ⚙ parameter · `#` count · ▶ run · ⚡ explore/probe · ★ best/winner · ⭐ watch · diff --git a/meshterm/ui/pathline.py b/meshterm/ui/pathline.py index 0feb539..f5f4711 100644 --- a/meshterm/ui/pathline.py +++ b/meshterm/ui/pathline.py @@ -527,7 +527,7 @@ class PathLine: if seam is not None and len(groups) > 1: # The outbound leg's own last line still continues into the return, so it # holds the cue back where the whole path's final line doesn't. - legs = self._flow(self._hops[:seam], budget, plain, len(cue), len(cue)) + legs = self._flow(self._hops[:seam], budget, plain, len(cue), len(cue), ends=False) legs += self._flow(self._hops[seam:], budget, plain, len(cue), 0, carry_in=True) if len(legs) <= len(groups): # the turn folds for free — take it groups = legs @@ -582,7 +582,7 @@ class PathLine: full = self.text().cell_len if not self._hops: return Measurement(full, full) - cells, _join, tail, lead, _head = self._measure( + cells, _join, tail, lead, _head, _foot = self._measure( self._hops, self._resolved_mode() != "powerline" ) least = max(cells) + tail + lead + WRAP_OFFSET @@ -590,7 +590,9 @@ class PathLine: # --- where the breaks fall -------------------------------------------------------- - def _measure(self, hops: list[PathHop], plain: bool) -> tuple[list[int], int, int, int, int]: + def _measure( + self, hops: list[PathHop], plain: bool + ) -> tuple[list[int], int, int, int, int, int]: """Each hop's own width, plus what joining, opening and closing a line costs. Fitting hops to a column is arithmetic once every hop has been measured once — @@ -602,24 +604,26 @@ class PathLine: plain: Measure as arrow text rather than as chips. Returns: - ``(cells, join, tail, lead, head)`` — each hop's cells, the cells one join - between two hops costs (chip mode's seam is the single interlocked chevron — - and so is either side of an elision gap, so the figure holds there too), the - cells a line always closes with (chip mode's edge; nothing in arrow mode), the - cells every line *after the first* opens with (chip mode's notch, the seam - redrawn), and the cells the *first* line opens with (chip mode's rounded cap, - nothing where the font has none). + ``(cells, join, tail, lead, head, foot)`` — each hop's cells, the cells one + join between two hops costs (chip mode's seam is the single interlocked + chevron — and so is either side of an elision gap, so the figure holds there + too), the cells a line the path *runs on past* closes with (chip mode's + point; nothing in arrow mode), the cells every line *after the first* opens + with (chip mode's notch, the seam redrawn), and the two outer caps: what the + *first* line opens with and what the line that *ends* the path closes with — + one cell each where the font has the rounded caps, nothing where it hasn't, + a squared end being drawn by appending nothing at all. """ if plain: plain_cells = [self._plain_hop(hop).cell_len for hop in hops] - return plain_cells, cell_len(self._separator), 0, 0, 0 + return plain_cells, cell_len(self._separator), 0, 0, 0, 0 widths = [ cell_len(hop.label) if hop.gap else self._chip(hop, self._chip_fill(hop)).cell_len for hop in hops ] sep = cell_len(POWERLINE_SEP) - head = cell_len(POWERLINE_ROUND_OPEN) if powerline_full() else 0 - return widths, sep, sep, sep, head + cap = cell_len(POWERLINE_ROUND_OPEN) if powerline_full() else 0 + return widths, sep, sep, sep, cap, cap @staticmethod def _fill( @@ -631,13 +635,15 @@ class PathLine: last: int, lead: int = 0, head: int = 0, + foot: int = 0, + ends: bool = True, ) -> list[int]: """Pack hop widths into lines of ``budget`` cells, greedily, never splitting one. Args: cells: Each hop's width, in order (see :meth:`_measure`). join: Cells one join between two hops costs. - tail: Cells every line closes with. + tail: Cells a line the path runs on past closes with. budget: The content column's width in cells. reserve: Cells held back on a line for the continuation cue it will carry. last: Cells held back on a line ending at the *final* hop — ``0`` when the @@ -646,6 +652,12 @@ class PathLine: lead: Cells every line but the first opens with — the reopened seam plus the :data:`WRAP_OFFSET` step it hangs past the indent. head: Cells the first line opens with (the rounded cap, when drawn). + foot: Cells the line that *ends the path* closes with (the rounded cap, when + drawn) — charged in place of ``tail``, a finished path closing on a cap + or, where the font has none, on nothing at all. + ends: These hops finish the path, so their last line pays ``foot``. ``False`` + where they are one leg of a route that goes on and every line, the last + included, still closes on the point. Returns: How many hops each line takes; a hop too wide for ``budget`` gets a line of @@ -655,9 +667,11 @@ class PathLine: count = 0 width = head for i, cell in enumerate(cells): + final = i == len(cells) - 1 grown = width + cell + (join if count else 0) - held = last if i == len(cells) - 1 else reserve - if count and grown + tail + held > budget: + held = last if final else reserve + close = foot if final and ends else tail + if count and grown + close + held > budget: sizes.append(count) width, count = lead + cell, 1 else: @@ -673,6 +687,7 @@ class PathLine: reserve: int, last: int, carry_in: bool = False, + ends: bool = True, ) -> list[list[PathHop]]: """Break ``hops`` into the fewest lines, then even those lines out. @@ -692,25 +707,31 @@ class PathLine: last: Cells held back on the line the hops end on (see :meth:`_fill`). carry_in: These hops are a *later* leg of a path already under way, so even their first line opens as a continuation, not as a beginning. + ends: These hops finish the path, so their last line closes on the outer cap + rather than on the continuation point (see :meth:`_fill`). Returns: The hops grouped per line. """ - cells, join, tail, lead, head = self._measure(hops, plain) + cells, join, tail, lead, head, foot = self._measure(hops, plain) lead += WRAP_OFFSET # every continuation steps in past the hanging indent if carry_in: head = lead - lines = len(self._fill(cells, join, tail, budget, reserve, last, lead, head)) + + def fill(column: int) -> list[int]: + return self._fill(cells, join, tail, column, reserve, last, lead, head, foot, ends) + + lines = len(fill(budget)) low, high = 1, budget while low < high: # the narrowest column still taking `lines` rows mid = (low + high) // 2 - if len(self._fill(cells, join, tail, mid, reserve, last, lead, head)) <= lines: + if len(fill(mid)) <= lines: high = mid else: low = mid + 1 groups: list[list[PathHop]] = [] at = 0 - for size in self._fill(cells, join, tail, low, reserve, last, lead, head): + for size in fill(low): groups.append(hops[at : at + size]) at += size return groups @@ -825,12 +846,18 @@ class PathLine: """Powerline chips: each hop filled with its hue, a two-cell gap at every seam. The two outer ends say whether this line *is* the path or only part of it. A - line that opens the path opens rounded (squared off where the font has no - rounded caps); one that continues a wrapped path opens on the break's other - half — which is exactly the seam's own second cell, so a fold looks like the - seam it interrupted. A line that ends the path closes rounded; one the path - outruns closes on the point, the same "goes on" cue arrow mode spells with a - trailing ``→``. + line that opens the path opens rounded; one that continues a wrapped path opens + on the break's other half — which is exactly the seam's own second cell, so a + fold looks like the seam it interrupted. A line that ends the path closes + rounded; one the path outruns closes on the point, the same "goes on" cue arrow + mode spells with a trailing ``→``. + + Where the font has no rounded caps both outer ends are drawn **square** — the + chip's own pad is the edge, and nothing is appended. Square is not a degraded + cap, it is the one shape left that says *stop*: the point is spoken for as the + continuation cue, so closing a finished path on one claimed a hop had been cut + off (JP, 2026-09-09). Only the *opening* used to square itself off, which left + every route on a core-only terminal ending on the mark for "there is more". An elision (:attr:`PathHop.gap`) interrupts the ribbon rather than joining it: the chip before it closes on the page, the mark sits on the page bare, and the chip @@ -863,8 +890,10 @@ class PathLine: text.append_text(self._chip(hop, fills[i])) if hops[-1].gap: return text # the line ended on the page; there is no chip left to close - close = POWERLINE_SEP if carry_on or not rounded else POWERLINE_ROUND_CLOSE - text.append(close, style=fills[-1]) # the edge into the page: pointed or round + if carry_on: + text.append(POWERLINE_SEP, style=fills[-1]) # the point: the path goes on + elif rounded: + text.append(POWERLINE_ROUND_CLOSE, style=fills[-1]) # the lozenge's far end return text @staticmethod diff --git a/tests/test_pathline.py b/tests/test_pathline.py index 3c4d768..415024a 100644 --- a/tests/test_pathline.py +++ b/tests/test_pathline.py @@ -112,18 +112,19 @@ def test_empty_path_reads_as_the_callers_word() -> None: def test_chips_are_joined_by_one_interlocked_chevron() -> None: - """A seam is one cell, not two. + """A seam is one cell, not two — and the path's own end is not a seam at all. The previous chip's point is laid *on* the next chip's fill, so the route reads as - a ribbon whose segments meet on a chevron. The closing edge keeps its lone taper — - nothing follows it to lay the point on. + a ribbon whose segments meet on a chevron. The point is spoken for: it is what says + the route continues, so a finished path never wears one. It ends square on the last + chip's own pad, and the only chevrons in the line are the joins. """ alice_fill = node_style("aa").split()[-1] line = PathLine([PathHop("Alice", key="aa"), PathHop("you", you=True)], mode="powerline") text = line.text() - assert text.plain == f" Alice {POWERLINE_SEP} you {POWERLINE_SEP}" + assert text.plain == f" Alice {POWERLINE_SEP} you " seam_styles = [str(s.style) for s in text.spans if text.plain[s.start : s.end] == POWERLINE_SEP] - assert seam_styles == [f"{alice_fill} on {_YOU_BG}", _YOU_BG] + assert seam_styles == [f"{alice_fill} on {_YOU_BG}"] def test_chips_keep_the_same_words_and_honour_style_overrides() -> None: @@ -136,9 +137,9 @@ def test_chips_keep_the_same_words_and_honour_style_overrides() -> None: chips = PathLine(hops, mode="powerline").text().plain assert plain.replace(" → ", " ") == chips.replace(POWERLINE_SEP, "").replace(" ", " ").strip() themed = PathLine([PathHop("X", style="brand")], mode="powerline").text() - assert str(themed.spans[-1].style) == "#5eead4" # the closing edge, brand-filled + assert pathline._fills(themed)[-1] == "#5eead4" # the chip runs to the very last cell hexed = PathLine([PathHop("X", style="bold #123456")], mode="powerline").text() - assert str(hexed.spans[-1].style) == "#123456" + assert pathline._fills(hexed)[-1] == "#123456" def test_auto_mode_follows_the_terminal_verdict(monkeypatch: pytest.MonkeyPatch) -> None: @@ -161,7 +162,7 @@ def test_the_cursor_is_a_hop_of_its_own_in_either_mode() -> None: assert _styles(plain)[CURSOR_GLYPH] == "selected" # the reverse-video block chips = PathLine(hops, mode="powerline").text() - assert chips.plain == f" a {POWERLINE_SEP} {CURSOR_GLYPH} {POWERLINE_SEP} b {POWERLINE_SEP}" + assert chips.plain == f" a {POWERLINE_SEP} {CURSOR_GLYPH} {POWERLINE_SEP} b " slot = next(s for s in chips.spans if chips.plain[s.start : s.end] == CURSOR_GLYPH) assert str(slot.style).endswith(f"on {_style_hex('cursor')}") # the cursor-white fill @@ -500,10 +501,11 @@ def test_wrapped_carries_the_cursor_like_any_other_hop() -> None: def test_wrapped_chip_lines_open_on_the_break_they_continue() -> None: """Chip wrapping never splits a chip; each line opens on the break it continues. - Every line ends on the pointed edge, and every line *but the first* opens on the - break's other half — the point notched out of its own fill in reverse video, so the - page shows through and not a trace of the line above bleeds down. The point always - faces the way the path flows. + Every line the path *outruns* ends on the pointed edge — the last one ends square, + the route having finished — and every line *but the first* opens on the break's + other half: the point notched out of its own fill in reverse video, so the page + shows through and not a trace of the line above bleeds down. The point always faces + the way the path flows. """ hops = [ PathHop(label, key=key) @@ -518,7 +520,8 @@ def test_wrapped_chip_lines_open_on_the_break_they_continue() -> None: # (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 lines[0].plain.endswith(POWERLINE_SEP) # …the path runs on past this line + assert lines[-1].plain.endswith(" ") # …and stops square on the last chip's pad assert all(line.cell_len <= 20 for line in lines) @@ -526,8 +529,10 @@ def test_rounded_caps_finish_a_path_only_where_the_font_has_them(monkeypatch) -> """Rounded caps finish a path only where the font actually has them. A full Nerd Font rounds the path's two *outer* ends into a lozenge; a core-only - terminal squares the opening and points the close, never drawing tofu. Interior - breaks stay angled either way — a rounded end would read as the path stopping. + terminal squares *both* of them off, appending nothing and letting the outer chips' + own pads be the edges, never drawing tofu. Interior breaks stay angled either way — + a rounded end would read as the path stopping, and a pointed one at the finish would + read as the opposite, a route cut off mid-walk. """ hops = [ PathHop(label, key=key) @@ -537,7 +542,10 @@ def test_rounded_caps_finish_a_path_only_where_the_font_has_them(monkeypatch) -> monkeypatch.setattr(pathline, "powerline_full", lambda: False) assert line.text().plain.startswith(" AAAA") - assert line.text().plain.endswith(POWERLINE_SEP) + assert line.text().plain.endswith("DDDD ") + # The point is still what a *wrapped* line ends on: there the route really does go on. + squared = line.wrapped(20, indent=2) + assert squared[0].plain.endswith(POWERLINE_SEP) and squared[-1].plain.endswith("DDDD ") monkeypatch.setattr(pathline, "powerline_full", lambda: True) assert line.text().plain.startswith(POWERLINE_ROUND_OPEN + " AAAA")