Path lines: the point always faces the way the path flows
A wrapped line was opening on U+E0B2, which points backwards — it read as an arrow going the wrong way, not as a carry-on. It now reopens the seam the break interrupted: the same right-facing point, arriving out of the previous line's last fill into this line's first chip. U+E0B0 is once again the only glyph the widget draws; what varies is whether the point lands on a field (a seam) or on the page (a closing edge), which is also the same-fill gap rule, now factored into _seam(). A bare hop keeps the one-cell padding every chip wears — it has no words between them, not no chip — so our end of a route reads as a stub of the you white rather than as nothing at all. Explore's candidate paths go bare too: every candidate starts from us, so the word was the same on every row and the cells are the candidates'. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c7ad0c4ad3
commit
c393aabc52
4 files changed
+84
-73
No files matched your search
+53
-50
@@ -34,9 +34,10 @@ drawn*, so every surface the survey found can eventually route through it:
|
||||
``highlighted_hash`` two-tone), the ``dim`` fade for resolved return legs, and an
|
||||
explicit style override for context colourings that outrank identity. Chips keep
|
||||
the exact same words as arrows — only colours and separators change — so a route
|
||||
reads identically whichever mode drew it. A hop with *no* label is drawn as pure
|
||||
seam — the arrow alone, no chip, no word — which is how a surface says "this end
|
||||
is us" without spending cells on saying so (see ``bare_self``).
|
||||
reads identically whichever mode drew it. A hop with *no* label draws as its seam
|
||||
and (in chip mode) the padding every chip wears — a bit of arrow and a stub of its
|
||||
own colour, no word — which is how a surface says "this end is us" without spending
|
||||
cells on saying so (see ``bare_self``).
|
||||
|
||||
Existing call sites still render through ``path_text``; migrating them here is a
|
||||
separate, per-surface pass. The composer's insertion cursor is the one deliberate
|
||||
@@ -56,16 +57,13 @@ from ..core.models import LOCAL_DEVICE_LABEL
|
||||
from .termfont import powerline_enabled
|
||||
from .theme import MESH_THEME, node_style
|
||||
|
||||
#: The powerline solid right-pointing triangle (U+E0B0) — the male point every chip
|
||||
#: seam is drawn with, deliberately from the *core* set so every recommended font
|
||||
#: qualifies (the rounded caps at U+E0B4+ exist only in full Nerd Font patches).
|
||||
#: The powerline solid right-pointing triangle (U+E0B0) — the only glyph the widget
|
||||
#: draws, seam and closing edge alike, deliberately from the *core* set so every
|
||||
#: recommended font qualifies (the rounded caps at U+E0B4+ exist only in full Nerd
|
||||
#: Font patches). A path only ever flows one way, so the point only ever faces right;
|
||||
#: what changes is whether it lands on a field (a seam) or on the page (an edge).
|
||||
POWERLINE_SEP = "\ue0b0"
|
||||
|
||||
#: Its mirror (U+E0B2, core too): the female point opening a *wrapped* line's first
|
||||
#: chip, so a continuation never reads as a fresh path. Only the very first chip of the
|
||||
#: whole line keeps the plain square left edge.
|
||||
POWERLINE_CAP = "\ue0b2"
|
||||
|
||||
#: The plain-mode joining arrow, exactly as ``path_text`` draws it today.
|
||||
_ARROW = " → "
|
||||
|
||||
@@ -94,9 +92,9 @@ class PathHop:
|
||||
Attributes:
|
||||
label: What is shown — a resolved name, or a hash standing as the node's
|
||||
identity (set ``lit_bytes`` for the two-tone prefix in that case). An
|
||||
empty label (with no annotation) makes the hop *bare*: it draws as its
|
||||
seam alone — a bit of arrow, no chip, no word — which is how a route
|
||||
whose ends are obviously us says so without spending cells on it.
|
||||
empty label (with no annotation) makes the hop *bare*: its seam and its
|
||||
padding are all that is drawn — a bit of arrow, no word — which is how a
|
||||
route whose ends are obviously us says so without spending cells on it.
|
||||
key: Any known prefix of the node's key/hash — picks the hash-derived hue
|
||||
(its first byte, so every prefix agrees). ``None`` renders muted/grey:
|
||||
colour is reserved for keyed identities.
|
||||
@@ -234,10 +232,11 @@ class PathLine:
|
||||
content column is uniformly ``width - indent`` wide. Plain-mode lines that
|
||||
continue end with the separator's own mark — a trailing ``→`` for an
|
||||
arrow-joined path, the bare ``,`` for a comma-joined wire spec — the "path
|
||||
goes on" cue; chip lines always close with their pointed edge and *open*, from
|
||||
the second line down, with the female one (:data:`POWERLINE_CAP`), so a
|
||||
continuation is never mistakable for a path starting over. A single hop wider
|
||||
than the content column stands alone, truncated with an ellipsis.
|
||||
goes on" cue; chip lines always close with their pointed edge and, from the
|
||||
second line down, open by redrawing the seam the break interrupted — the point
|
||||
arriving out of the previous line's last fill — so a continuation is never
|
||||
mistakable for a path starting over. A single hop wider than the content column
|
||||
stands alone, truncated with an ellipsis.
|
||||
|
||||
Where the breaks fall is chosen for how it *reads* (see :meth:`_flow` and
|
||||
:meth:`_turn_seam`), not by cramming each line full: the fold takes the
|
||||
@@ -274,12 +273,14 @@ class PathLine:
|
||||
|
||||
lines: list[Text] = []
|
||||
base = 0 # the global index of the group's first hop, for cursor mapping
|
||||
carried: Optional[str] = None # the fill a continuation reopens its seam from
|
||||
for i, group in enumerate(groups):
|
||||
local: Optional[int] = None
|
||||
if cursor_arrow is not None and 0 <= cursor_arrow - base < len(group) - 1:
|
||||
local = cursor_arrow - base
|
||||
line = Text() if i == 0 else Text(" " * indent)
|
||||
body = self._render(group, cursor_arrow=local, force_plain=plain, cap=bool(i))
|
||||
body = self._render(group, cursor_arrow=local, force_plain=plain, cap=carried)
|
||||
carried = None if plain else self._chip_fill(group[-1])
|
||||
# A lone hop too wide for the column is truncated — leaving room for the
|
||||
# cue it still has to carry, so even that line stays inside the width. A
|
||||
# column too narrow to hold both drops the cue: content wins the cells.
|
||||
@@ -315,18 +316,19 @@ class PathLine:
|
||||
``(cells, join, tail, lead)`` — each hop's cells, the cells one join between
|
||||
two hops costs, the cells a line always closes with (the chip mode's pointed
|
||||
edge; nothing in arrow mode), and the cells every line *after the first*
|
||||
opens with (chip mode's female cap).
|
||||
opens with (chip mode's reopened seam).
|
||||
|
||||
Note:
|
||||
Joins are measured at their full width even where a bare neighbour trims one
|
||||
(:meth:`_join`), and the closing edge is charged even to a line ending bare —
|
||||
an over-estimate of a cell, which packs a hair early and never overflows.
|
||||
(:meth:`_join`) — an over-estimate of a cell, which packs a hair early and
|
||||
never overflows.
|
||||
"""
|
||||
if plain:
|
||||
widths = [self._plain_hop(hop).cell_len for hop in hops]
|
||||
return widths, cell_len(self._separator), 0, 0
|
||||
widths = [self._chip(hop, self._chip_fill(hop)).cell_len for hop in hops]
|
||||
return widths, cell_len(POWERLINE_SEP), cell_len(POWERLINE_SEP), cell_len(POWERLINE_CAP)
|
||||
sep = cell_len(POWERLINE_SEP)
|
||||
return widths, sep, sep, sep
|
||||
|
||||
@staticmethod
|
||||
def _fill(
|
||||
@@ -349,7 +351,7 @@ class PathLine:
|
||||
last: Cells held back on a line ending at the *final* hop — ``0`` when the
|
||||
path really ends there (nothing follows to cue), ``reserve`` when this
|
||||
is only one leg of a path that goes on.
|
||||
lead: Cells every line but the first opens with (the female cap).
|
||||
lead: Cells every line but the first opens with (the reopened seam).
|
||||
|
||||
Returns:
|
||||
How many hops each line takes; a hop too wide for ``budget`` gets a line of
|
||||
@@ -442,7 +444,7 @@ class PathLine:
|
||||
*,
|
||||
cursor_arrow: Optional[int] = None,
|
||||
force_plain: bool = False,
|
||||
cap: bool = False,
|
||||
cap: Optional[str] = None,
|
||||
) -> Text:
|
||||
"""Join ``hops`` in the effective mode (plain whenever a cursor is asked).
|
||||
|
||||
@@ -505,38 +507,40 @@ class PathLine:
|
||||
text.append(f" ({hop.annotation})", style=note_style)
|
||||
return text
|
||||
|
||||
def _render_chips(self, hops: list[PathHop], *, cap: bool = False) -> Text:
|
||||
def _render_chips(self, hops: list[PathHop], *, cap: Optional[str] = None) -> Text:
|
||||
"""Powerline chips: each hop filled with its hue, seams interlocked.
|
||||
|
||||
Args:
|
||||
hops: The hops of this one line, in order.
|
||||
cap: Open the line with the female point (:data:`POWERLINE_CAP`) in the
|
||||
first chip's own fill — the mark of a wrapped continuation, where the
|
||||
whole line's very first chip instead keeps its square left edge.
|
||||
cap: The fill of the chip this line continues from — a wrapped line opens
|
||||
by redrawing the seam the break interrupted, so its first chip is
|
||||
landed *into* rather than started. ``None`` (the whole line's first
|
||||
chip) keeps the square left edge.
|
||||
"""
|
||||
fills = [self._chip_fill(hop) for hop in hops]
|
||||
text = Text()
|
||||
if cap:
|
||||
text.append(POWERLINE_CAP, style=fills[0])
|
||||
if cap is not None:
|
||||
text.append(POWERLINE_SEP, style=self._seam(cap, fills[0]))
|
||||
for i, hop in enumerate(hops):
|
||||
if i:
|
||||
# Two ways to draw a seam. Interlocked — the point in the previous
|
||||
# fill *on* the next one — is the tighter look and the default. But
|
||||
# two neighbours can land on the same fill (a hue collision, a run of
|
||||
# dimmed hops, two keyless greys), and then an interlocked seam is
|
||||
# invisible: one fused block where the route has two nodes. Those get
|
||||
# the open seam instead — the point over the page, leaving the sliver
|
||||
# of background that says where one chip ends and the next begins. A
|
||||
# bare hop takes it too: it has no field for the arrow to land in, so
|
||||
# that lone arrowhead *is* the endpoint.
|
||||
fused = _bare(hop) or fills[i - 1] == fills[i]
|
||||
style = fills[i - 1] if fused else f"{fills[i - 1]} on {fills[i]}"
|
||||
text.append(POWERLINE_SEP, style=style)
|
||||
text.append(POWERLINE_SEP, style=self._seam(fills[i - 1], fills[i]))
|
||||
text.append_text(self._chip(hop, fills[i]))
|
||||
if not _bare(hops[-1]):
|
||||
text.append(POWERLINE_SEP, style=fills[-1]) # the pointed edge into the page
|
||||
text.append(POWERLINE_SEP, style=fills[-1]) # the pointed edge into the page
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def _seam(before: str, after: str) -> str:
|
||||
"""One seam's style: interlocked into the next fill, or open onto the page.
|
||||
|
||||
Two ways to draw the point. Interlocked — the previous fill *on* the next
|
||||
one — is the tighter look and the default. But two neighbours can land on the
|
||||
same fill (a hue collision, a run of dimmed hops, two keyless greys), and then
|
||||
an interlock is invisible: one fused block where the route has two nodes.
|
||||
Those open onto the page instead, the taper leaving the sliver of background
|
||||
that says where one chip ends and the next begins.
|
||||
"""
|
||||
return before if before == after else f"{before} on {after}"
|
||||
|
||||
def _chip_fill(self, hop: PathHop) -> str:
|
||||
"""A chip's fill colour: override, white you, dim slate, hue, keyless grey."""
|
||||
if hop.style:
|
||||
@@ -554,10 +558,9 @@ class PathLine:
|
||||
def _chip(self, hop: PathHop, fill: str) -> Text:
|
||||
"""One chip: same words as arrow mode, dark ink on the identity fill.
|
||||
|
||||
A bare hop draws no chip at all — its seam alone carries it (see :meth:`_render_chips`).
|
||||
A bare hop keeps the padding every chip wears — it just has no words between
|
||||
them, so it reads as a stub of its own colour rather than as nothing at all.
|
||||
"""
|
||||
if _bare(hop):
|
||||
return Text()
|
||||
ink = _DIM_FG if hop.dim else _CHIP_FG
|
||||
soft = _DIM_FG if hop.dim else _CHIP_FG_SOFT
|
||||
text = Text()
|
||||
@@ -603,8 +606,8 @@ def path_line(
|
||||
so a call site swaps builders without changing what it says — a named hop reads
|
||||
``Name`` (annotated ``Name (3d)`` under ``show_hash``), an unnamed hop its
|
||||
prefix-lit hash (or its muted identity hash under ``hash_as_name``), ``None`` is
|
||||
our own device in white — or, under ``bare_self``, its bit of arrow and nothing
|
||||
else — and ``dim_from`` fades a resolved tail. The plain rendering
|
||||
our own device in white — or, under ``bare_self``, its bit of arrow and no words
|
||||
at all — and ``dim_from`` fades a resolved tail. The plain rendering
|
||||
is character- and style-identical to ``path_text``; what the swap buys is the
|
||||
:class:`PathLine` shapes (ellipsized / wrapped) and the powerline mode.
|
||||
|
||||
|
||||
@@ -1213,13 +1213,16 @@ def _scenario_path(
|
||||
:class:`~meshterm.services.topology.PathScenario` stores), so the row reads as
|
||||
the whole route rather than a fragment the reader has to mentally close.
|
||||
Renders through the shared path widget, so every hop wears its own key hue (an
|
||||
unnamed hop its prefix-lit hash) instead of the old single-colour smear.
|
||||
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'.
|
||||
"""
|
||||
route = path_line(
|
||||
[None, *scenario.hops, target_id],
|
||||
topo.display_name,
|
||||
prefix_bytes=width_bytes,
|
||||
self_name=device_label,
|
||||
bare_self=True,
|
||||
)
|
||||
return route.text()
|
||||
|
||||
|
||||
@@ -1147,7 +1147,8 @@ def _scenario_topo() -> object:
|
||||
|
||||
|
||||
def test_scenario_path_leads_and_ends_with_us_and_the_target() -> None:
|
||||
"""The pathline names the whole boomerang leg, not just the stored intermediate hops."""
|
||||
"""The pathline draws the whole boomerang leg, not just the stored intermediate
|
||||
hops — our own end bare, since every candidate starts from us."""
|
||||
topo = _scenario_topo()
|
||||
scenario = PathScenario(
|
||||
label="observed path", hops=("3d63c6429436",), source="observed", score=1.0,
|
||||
@@ -1155,17 +1156,17 @@ def test_scenario_path_leads_and_ends_with_us_and_the_target() -> None:
|
||||
text = _scenario_path(
|
||||
scenario, topo, "f2c24f54551e", device_label="YUL-Me", width_bytes=1
|
||||
)
|
||||
assert text.plain == "YUL-Me → Hub → Far"
|
||||
assert text.plain == "→ Hub → Far"
|
||||
|
||||
|
||||
def test_scenario_path_direct_scenario_still_names_both_endpoints() -> None:
|
||||
"""A direct (no-repeaters) scenario's pathline is just us and the target — no gap."""
|
||||
"""A direct (no-repeaters) scenario's pathline is just our arrow and the target."""
|
||||
topo = _scenario_topo()
|
||||
scenario = PathScenario(label="direct", hops=(), source="direct", score=0.0)
|
||||
text = _scenario_path(
|
||||
scenario, topo, "f2c24f54551e", device_label="YUL-Me", width_bytes=1
|
||||
)
|
||||
assert text.plain == "YUL-Me → Far"
|
||||
assert text.plain == "→ Far"
|
||||
|
||||
|
||||
def test_scenario_detail_carries_provenance_snr_and_samples() -> None:
|
||||
|
||||
+22
-18
@@ -13,9 +13,7 @@ import random
|
||||
import pytest
|
||||
|
||||
import meshterm.ui.pathline as pathline
|
||||
from meshterm.ui.pathline import (
|
||||
POWERLINE_CAP, POWERLINE_SEP, PathHop, PathLine, _style_hex, path_line,
|
||||
)
|
||||
from meshterm.ui.pathline import POWERLINE_SEP, PathHop, PathLine, _style_hex, path_line
|
||||
from meshterm.ui.theme import node_style
|
||||
from meshterm.ui.widgets import path_text
|
||||
|
||||
@@ -296,15 +294,20 @@ def test_wrapped_carries_the_cursor_even_onto_a_line_break() -> None:
|
||||
assert not any(str(s.style) == "selected" for s in on_break[1].spans)
|
||||
|
||||
|
||||
def test_wrapped_chip_lines_close_male_and_open_female() -> None:
|
||||
def test_wrapped_chip_lines_reopen_the_seam_the_break_interrupted() -> None:
|
||||
"""Chip wrapping never splits a chip; every line ends on the pointed edge, and
|
||||
every line *but the first* opens on its mirror — the continuation's own mark, so
|
||||
only the path's very first chip shows a square left edge."""
|
||||
hops = [PathHop(label) for label in ("AAAA", "BBBB", "CCCC", "DDDD")]
|
||||
every line *but the first* opens on the seam the break cut — the point arriving
|
||||
out of the previous line's last fill, so only the path's very first chip shows a
|
||||
square left edge. The point always faces the way the path flows."""
|
||||
hops = [PathHop(label, key=key) for label, key in
|
||||
(("AAAA", "aa"), ("BBBB", "77"), ("CCCC", "3d"), ("DDDD", "f2"))]
|
||||
lines = PathLine(hops, mode="powerline").wrapped(18, indent=2)
|
||||
assert len(lines) == 2
|
||||
assert lines[0].plain.startswith(" AAAA") # the square edge: this is the start
|
||||
assert lines[1].plain.startswith(" " + POWERLINE_CAP) # …and this is a carry-on
|
||||
assert lines[1].plain[2] == POWERLINE_SEP # …and this is a carry-on
|
||||
carried = next(s for s in lines[1].spans if s.start == 2)
|
||||
assert str(carried.style) == \
|
||||
f"{_style_hex(node_style('77'))} on {_style_hex(node_style('3d'))}"
|
||||
assert all(line.plain.endswith(POWERLINE_SEP) for line in lines)
|
||||
assert all(line.cell_len <= 18 for line in lines)
|
||||
|
||||
@@ -329,24 +332,25 @@ def test_same_fill_neighbours_get_the_open_seam() -> None:
|
||||
assert " on " not in gaps[0] # a dimmed return leg reads as hops, not one bar
|
||||
|
||||
|
||||
def test_bare_hops_draw_as_their_seam_alone() -> None:
|
||||
"""An empty label spends no cells: arrow mode drops the padding it would have sat
|
||||
in, chip mode gives it no chip at all — the arrow into the page *is* the hop."""
|
||||
def test_bare_hops_keep_their_padding_and_spend_no_words() -> None:
|
||||
"""An empty label costs no words: arrow mode drops the padding it would have sat
|
||||
in, chip mode keeps only the stub of colour every chip is padded with."""
|
||||
hops = [PathHop("", you=True), PathHop("Alice", key="aa"), PathHop("", you=True)]
|
||||
assert PathLine(hops, mode="plain").text().plain == "→ Alice →"
|
||||
|
||||
chips = PathLine(hops, mode="powerline").text()
|
||||
assert chips.plain == POWERLINE_SEP + " Alice " + POWERLINE_SEP
|
||||
hue = _style_hex(node_style("aa"))
|
||||
assert chips.plain == f" {POWERLINE_SEP} Alice {POWERLINE_SEP} {POWERLINE_SEP}"
|
||||
styles = [str(span.style) for span in chips.spans]
|
||||
# The leading seam is us pointing into Alice's field; the trailing one is Alice's
|
||||
# own point into the page — the closing edge a named tail would have added.
|
||||
assert styles[0] == f"#ffffff on {_style_hex(node_style('aa'))}"
|
||||
assert styles[-1] == _style_hex(node_style("aa"))
|
||||
assert styles[0] == "on #ffffff" # our stub: the you white, two cells of padding
|
||||
assert f"#ffffff on {hue}" in styles # the seam out of it, into Alice's field
|
||||
assert f"{hue} on #ffffff" in styles # and back out of Alice, into ours
|
||||
assert styles[-1] == "#ffffff" # the closing edge, pointing into the page
|
||||
|
||||
|
||||
def test_bare_self_endpoints_survive_wrapping() -> None:
|
||||
"""``bare_self`` strips our name and hash from a route's ends; a line that wraps
|
||||
still opens on the female point, and a widowed bare end still draws one."""
|
||||
still opens on the seam it broke, and every line still fits its column."""
|
||||
hops = [None, *(f"{i:02x}aa" for i in range(6)), None]
|
||||
line = path_line(hops, prefix_bytes=2, self_name="Me", show_hash=True,
|
||||
device_hash="a1b2", bare_self=True, mode="plain")
|
||||
@@ -357,5 +361,5 @@ def test_bare_self_endpoints_survive_wrapping() -> None:
|
||||
lines = path_line(hops, prefix_bytes=2, self_name="Me", bare_self=True,
|
||||
mode="powerline").wrapped(28, indent=2)
|
||||
assert len(lines) > 1
|
||||
assert all(line.plain.startswith(" " + POWERLINE_CAP) for line in lines[1:])
|
||||
assert all(line.plain[2] == POWERLINE_SEP for line in lines[1:])
|
||||
assert all(line.cell_len <= 28 for line in lines)
|
||||
Reference in new issue
Block a user