diff --git a/meshterm/ui/pathline.py b/meshterm/ui/pathline.py index 643cdd1..2d4828f 100644 --- a/meshterm/ui/pathline.py +++ b/meshterm/ui/pathline.py @@ -95,6 +95,12 @@ _DIM_FG = "#94a3b8" #: rendered as a dim pseudo-hop so it recedes in both modes. _ELISION = "⋯" +#: Extra columns a wrapped line steps in past the hanging indent. The continuation +#: marks (a trailing ``→``, a notched chip edge) say the path goes on; the step says +#: it at a glance, from the shape of the block alone — a route that folds reads as one +#: value that ran long, not as a second value stacked under the first. +WRAP_OFFSET = 2 + @dataclass(frozen=True) class PathHop: @@ -232,8 +238,9 @@ class PathLine: The hanging-indent convention: the caller lays its label lane on the first line, so that line is returned *without* the indent prefix while every - continuation starts with ``indent`` spaces; all lines fit ``width`` and the - content column is uniformly ``width - indent`` wide. Plain-mode lines that + continuation starts with ``indent`` spaces — plus :data:`WRAP_OFFSET`, the + step that makes a fold legible as a fold. Every line fits ``width``. + 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, from the @@ -281,7 +288,8 @@ class PathLine: 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) + step = 0 if i == 0 else WRAP_OFFSET + line = Text() if i == 0 else Text(" " * (indent + step)) body = self._render( group, cursor_arrow=local, force_plain=plain, carry_in=bool(i), carry_on=i < len(groups) - 1, @@ -290,7 +298,7 @@ class PathLine: # 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. continues = i < len(groups) - 1 and 0 < cell_len(cue) < budget - room = budget - (cell_len(cue) if continues else 0) + room = budget - step - (cell_len(cue) if continues else 0) if body.cell_len > room: body.truncate(room, overflow="ellipsis") line.append_text(body) @@ -355,7 +363,8 @@ 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 reopened seam). + 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). Returns: @@ -408,6 +417,7 @@ class PathLine: The hops grouped per line. """ cells, join, tail, lead, head = 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)) diff --git a/tests/test_pathline.py b/tests/test_pathline.py index df2e732..0013a38 100644 --- a/tests/test_pathline.py +++ b/tests/test_pathline.py @@ -14,8 +14,8 @@ import pytest import meshterm.ui.pathline as pathline from meshterm.ui.pathline import ( - POWERLINE_ROUND_CLOSE, POWERLINE_ROUND_OPEN, POWERLINE_SEP, SELF_GLYPH, PathHop, - PathLine, _style_hex, path_line, + POWERLINE_ROUND_CLOSE, POWERLINE_ROUND_OPEN, POWERLINE_SEP, SELF_GLYPH, + WRAP_OFFSET, PathHop, PathLine, _style_hex, path_line, ) from meshterm.ui.theme import node_style from meshterm.ui.widgets import path_text @@ -155,10 +155,11 @@ def test_ellipsized_last_resort_truncates_a_single_giant_hop() -> None: def test_wrapped_breaks_at_hops_under_a_hanging_indent() -> None: """Plain lines that continue end with the ``→`` cue; continuations hang at the - indent; every line respects the full width.""" + indent, stepped in by :data:`WRAP_OFFSET`; every line respects the full width.""" hops = [PathHop(label) for label in ("AAAA", "BBBB", "CCCC", "DDDD")] lines = PathLine(hops, mode="plain").wrapped(16, indent=2) - assert [line.plain for line in lines] == ["AAAA → BBBB →", " CCCC → DDDD"] + assert [line.plain for line in lines] == ["AAAA → BBBB →", " CCCC → DDDD"] + assert lines[1].plain.startswith(" " * (2 + WRAP_OFFSET)) assert all(line.cell_len <= 16 for line in lines) @@ -170,7 +171,7 @@ def test_wrapped_evens_the_lines_instead_of_widowing_the_tail() -> None: """ hops = [PathHop(label) for label in ("us", "alpha", "bravo", "us")] lines = PathLine(hops, mode="plain").wrapped(20, indent=0) - assert [line.plain for line in lines] == ["us → alpha →", "bravo → us"] + assert [line.plain for line in lines] == ["us → alpha →", " bravo → us"] def test_wrapped_folds_a_faded_return_leg_at_its_turn() -> None: @@ -185,7 +186,7 @@ def test_wrapped_folds_a_faded_return_leg_at_its_turn() -> None: lines = PathLine(out + back, mode="plain").wrapped(40, indent=0) assert [line.plain for line in lines] == [ "me → north-relay → east-relay → dest →", # out, ending on the target - "east-relay → north-relay → me", # and the mirror it comes home by + " east-relay → north-relay → me", # and the mirror it comes home by ] @@ -200,7 +201,7 @@ def test_wrapped_folds_a_walked_boomerang_at_its_turn_too() -> None: lines = PathLine(walked, mode="plain").wrapped(46, indent=0) assert [line.plain for line in lines] == [ "me → north-relay → east-relay → dest →", - "east-relay → north-relay → me", + " east-relay → north-relay → me", ] @@ -289,7 +290,7 @@ def test_wrapped_carries_the_cursor_even_onto_a_line_break() -> None: hops = [PathHop(label) for label in ("AAAA", "BBBB", "CCCC", "DDDD")] line = PathLine(hops, mode="powerline") mid = line.wrapped(16, indent=2, cursor_arrow=0) - assert [text.plain for text in mid] == ["AAAA → BBBB →", " CCCC → DDDD"] + assert [text.plain for text in mid] == ["AAAA → BBBB →", " CCCC → DDDD"] assert any(str(s.style) == "selected" for s in mid[0].spans) assert all(POWERLINE_SEP not in text.plain for text in mid) on_break = line.wrapped(16, indent=2, cursor_arrow=1) # the seam that broke @@ -304,14 +305,15 @@ def test_wrapped_chip_lines_open_on_the_break_they_continue() -> None: line above bleeds down. 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) + lines = PathLine(hops, mode="powerline").wrapped(20, indent=2) assert len(lines) == 2 assert lines[0].plain.startswith(" AAAA") # the square edge: this is the start - 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) + step = 2 + WRAP_OFFSET + assert lines[1].plain[:step].isspace() and lines[1].plain[step] == POWERLINE_SEP + carried = next(s for s in lines[1].spans if s.start == step) assert str(carried.style) == f"{_style_hex(node_style('3d'))} reverse" assert all(line.plain.endswith(POWERLINE_SEP) for line in lines) - assert all(line.cell_len <= 18 for line in lines) + assert all(line.cell_len <= 20 for line in lines) def test_rounded_caps_finish_a_path_only_where_the_font_has_them(monkeypatch) -> None: # noqa: ANN001 @@ -333,7 +335,7 @@ def test_rounded_caps_finish_a_path_only_where_the_font_has_them(monkeypatch) -> assert len(wrapped) == 2 assert wrapped[0].plain.startswith(POWERLINE_ROUND_OPEN) # the path opens here… assert wrapped[0].plain.endswith(POWERLINE_SEP) # …but does not end here - assert wrapped[1].plain[2] == POWERLINE_SEP # picked up mid-path… + assert wrapped[1].plain[2 + WRAP_OFFSET] == POWERLINE_SEP # picked up mid-path… assert wrapped[1].plain.endswith(POWERLINE_ROUND_CLOSE) # …and closed off assert all(text.cell_len <= 20 for text in wrapped) @@ -374,5 +376,5 @@ def test_bare_self_stands_us_on_a_star_and_fades_the_way_home() -> 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[2] == POWERLINE_SEP for line in lines[1:]) + assert all(line.plain[2 + WRAP_OFFSET] == POWERLINE_SEP for line in lines[1:]) assert all(line.cell_len <= 28 for line in lines)