diff --git a/meshterm/ui/message_paths_screen.py b/meshterm/ui/message_paths_screen.py index 2197c2c..ca4d5f6 100644 --- a/meshterm/ui/message_paths_screen.py +++ b/meshterm/ui/message_paths_screen.py @@ -13,16 +13,19 @@ detail read together: name's own colour, so the byte reads as that node and never crowds the line running through it. A node-type key sits under the graph. The row list carries the full names, so the graph's labels stay two cells wide and a many-path graph stays readable. -* the **arrival list** beneath is one row per logged copy — time, reception SNR, and - the relay chain as a path line (:mod:`~meshterm.ui.pathline`): each relay a chip in - its own node hue, named where we know the node (``YUL-Poly``) and standing in its - own hash at the device's path-hash width where we don't (``e839f2``, keyless grey). - No hash is repeated after a name — the graph above is where the hash bytes live, and - a chip and its label share the node's colour, so the two halves cross-reference by - hue instead of by spelling the hex twice. - ↑↓ move the selection (the graph's highlight follows); a row longer than the - dialog **scrolls horizontally with ←→**, the whole line shifting under a ``…`` at - whichever edge continues, and snaps back the moment the selection moves on. +* the **arrival list** beneath is two lines per logged copy. On top, alone on its lane + and introduced by nothing, the **route** as a path line (:mod:`~meshterm.ui.pathline`): + each relay a chip in its own node hue, named where we know the node (``YUL-Poly``) and + standing in its own hash at the device's path-hash width where we don't (``e839f2``, + keyless grey). No hash is repeated after a name — the graph above is where the hash + bytes live, and a chip and its label share the node's colour, so the two halves + cross-reference by hue instead of by spelling the hex twice. Under it, hanging muted, + the frame's own facts: time heard, reception SNR, and which resend it was. + The route is the line you pick — it is what one arrival differs from another by, and + what the graph highlights. ↑↓ move the selection (the graph's highlight follows); a + route longer than the dialog **scrolls horizontally with ←→**, the whole line shifting + under a ``…`` at whichever edge continues, and snaps back the moment the selection + moves on. Nothing here transmits; like the service beneath it, this is a read-model over what the radio already heard. @@ -52,6 +55,10 @@ from .widgets import ( #: Cells one ←/→ press shifts the selected row by. _HSTEP = 4 +#: Columns the reception-facts line hangs in under the route it belongs to — past the +#: ``❯ `` pointer lane, so the pair reads as one arrival with its detail tucked under it. +_DETAIL_INDENT = 4 + #: Edge colours: the selected path draws white over the unused paths' gray. _EDGE_SELECTED = (255, 255, 255) _EDGE_UNUSED = (110, 110, 110) @@ -199,53 +206,59 @@ class MessagePathsScreen(Screen): lines.append(self._selected_line(arrival, width)) else: row = Text(" ") - row.append_text(self._row_text(arrival)) + row.append_text(self._path_text(arrival)) lines.append(render_to_ansi(row, width, no_wrap=True)) + detail = Text(" " * _DETAIL_INDENT) + detail.append_text(self._detail_text(arrival)) + lines.append(render_to_ansi(detail, width, no_wrap=True)) self._scroll_total = len(lines) return lines # -- the rows -- - def _row_text(self, arrival: Arrival) -> Text: - """One arrival, unabridged: time, reception SNR, and its relay path. + def _path_text(self, arrival: Arrival) -> Text: + """One arrival's relay chain — the row's first line, and the one you pick. - The relay chain is THE path line, so a route here is drawn exactly as a route - anywhere else — chips in each node's own hue where the terminal can draw them, - arrows where it can't. Hops read as names, nothing else: an unnamed hop, having - no name to show, stands in its own hash at the device's path-hash width (muted - grey — colour is the "this is a name" signal), and no hop repeats its hash after - its name. The hash bytes are the graph's job, one row up; what ties the two - together is the shared node hue, not a second spelling of the hex. + The route gets the row's full width to itself, so no ``via`` introduces it: on a + lane that holds nothing else there is nothing to tell it apart from. It is THE + path line, so a route here is drawn exactly as a route anywhere else — chips in + each node's own hue where the terminal can draw them, arrows where it can't. + Hops read as names, nothing else: an unnamed hop, having no name to show, stands + in its own hash at the device's path-hash width (muted grey — colour is the + "this is a name" signal), and no hop repeats its hash after its name. The hash + bytes are the graph's job, one row up; what ties the two together is the shared + node hue, not a second spelling of the hex. """ - row = Text() - row.append(arrival.when.astimezone().strftime("%H:%M:%S"), style="muted") - row.append(" ") + return path_line( + arrival.hops, self._resolve, + prefix_bytes=self._prefix_bytes, self_name=self._self_name, + empty="direct", hash_as_name=True, + ).text() + + def _detail_text(self, arrival: Arrival) -> Text: + """One arrival's reception facts — when it landed, how loudly, which copy. + + The row's second line, hanging muted under the route it describes: the path is + what distinguishes one arrival from another (and what the graph above draws), so + it takes the lane, and the frame's own particulars step in beneath it. + """ + text = Text(arrival.when.astimezone().strftime("%H:%M:%S"), style="muted") if arrival.snr is not None: - row.append(f"{arrival.snr:+5.1f} dB", style=snr_style(arrival.snr)) - else: - row.append(" " * 8) - row.append(" ") - if arrival.hops: - row.append("via ", style="muted") - row.append_text( - path_line( - arrival.hops, self._resolve, - prefix_bytes=self._prefix_bytes, self_name=self._self_name, - empty="direct", hash_as_name=True, - ).text() - ) + text.append(" ") + text.append(f"{arrival.snr:+.1f} dB", style=snr_style(arrival.snr)) if arrival.resend: - row.append(f" (resend #{arrival.resend})", style="muted") - return row + text.append(f" · resend #{arrival.resend}", style="muted") + return text def _selected_line(self, arrival: Arrival, width: int) -> str: - """The highlighted row: ``❯`` pointer, shifted by ``←→`` under edge ``…``. + """The highlighted path: ``❯`` pointer, shifted by ``←→`` under edge ``…``. - The whole line scrolls — timestamp and SNR included — and the shift bound - is measured here against the current width, so a resize can only ever leave - the row clamped back into range. + The picked line is the route — the one thing here long enough to need scrolling, + and the one the graph above highlights — and the shift bound is measured here + against the current width, so a resize can only ever leave the row clamped back + into range. """ - full = self._row_text(arrival) + full = self._path_text(arrival) avail = max(1, width - 2) self._hmax = max(0, full.cell_len - avail) self._hshift = min(self._hshift, self._hmax) diff --git a/tests/test_message_paths_screen.py b/tests/test_message_paths_screen.py index 64bf907..c5d6ab1 100644 --- a/tests/test_message_paths_screen.py +++ b/tests/test_message_paths_screen.py @@ -42,12 +42,18 @@ def _arrivals() -> list[Arrival]: def test_paths_screen_renders_graph_rows_and_cursor() -> None: - """The quoted text, the graph endpoints, and one selectable row per arrival.""" + """The quoted text, the graph endpoints, and two lines per arrival: the route you + pick, and the reception facts hanging under it.""" screen = _screen(_arrivals()) body = _plain(screen.render_body(76)) assert "“on my way”" in body assert "Alice" in body and "Homestead" in body # origin and us, on the graph - assert body.count("via") == 2 # one row per arrival + assert "via" not in body # the route lane holds nothing but the route + rows = body.split("sensor\n\n")[1].split("\n") + assert len(rows) == 2 * len(_arrivals()) + assert rows[0].startswith("❯ ") and "YUL-Cartierville" in rows[0] # the picked route + assert rows[1].strip().startswith(_arrivals()[0].when.astimezone().strftime("%H:%M")) + assert "+4.0 dB" in rows[1] # …with its time and SNR tucked beneath it assert "❯" in body assert "white = selected path" in body # the graph caption assert "★ you" in body and "▲ repeater" in body # the node-type legend @@ -127,15 +133,20 @@ def test_paths_screen_marks_a_repeater_relay_with_its_triangle() -> None: assert "38;2;255;255;255" in raw and "38;2;110;110;110" in raw -def test_paths_screen_scrolls_the_selected_line_sideways() -> None: - """→ shifts the whole selected row under a leading …; ↑↓ snap it back.""" +def test_paths_screen_scrolls_the_selected_route_sideways() -> None: + """→ shifts the selected *route* under a leading …; ↑↓ snap it back. + + The reception facts under it never move — they always fit, and a lane that slid + with the route would make a long path look like it had lost its timestamp. + """ now = utcnow() long = Arrival(when=now, hops=tuple(f"{i:02x}{i:02x}" for i in range(12)), snr=1.0) screen = _screen([long, Arrival(when=now, hops=(), snr=None)]) narrow = 40 before = _plain(screen.render_body(narrow)) selected_before = next(ln for ln in before.split("\n") if ln.startswith("❯")) - assert screen._hmax > 0 # the row genuinely overflows at this width + assert screen._hmax > 0 # the route genuinely overflows at this width + assert "00" in selected_before and "0b" not in selected_before # head shown, tail cut for _ in range(3): screen.handle("right") after = _plain(screen.render_body(narrow)) @@ -143,9 +154,9 @@ def test_paths_screen_scrolls_the_selected_line_sideways() -> None: assert selected_after != selected_before assert "…" in selected_after # the left edge marks the hidden head stamp = long.when.astimezone().strftime("%H:%M:%S") - assert stamp in selected_before and stamp not in selected_after # whole line shifts + assert stamp in after and stamp not in selected_after # the facts hold their lane screen.handle("down") - assert screen._hshift == 0 # only the selected line stays scrolled + assert screen._hshift == 0 # only the selected route stays scrolled def test_paths_screen_direct_arrival_and_empty_state() -> None: