From db68a17e239fb880f9368b24f04a4ca6cb9bc78f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Tue, 28 Jul 2026 03:18:57 -0400 Subject: [PATCH] Live feed: the route is Enter's job, not a lane's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the via chain from the feed row. Whatever the fixed lanes left it was a handful of cells, so a route never actually arrived — it arrived elided to a stub that named one hop and hinted at the rest, which is the least useful form a route can take. A route is a shape rather than a lane, and the packet viewer already draws it properly one keypress away: a wrapped path line over the route graph, with the room to say the whole thing. So the feed says what arrived and how well it was heard; Enter says how it got here. What that buys is the whole row fitting a 72-column screen — 69 cells, class label included. The label was being dropped on exactly the screens where it mattered most, to make room for a route that never fitted either; now nothing competes for those cells and the class reads in words down to the width where it genuinely can't. ←→ stays: it just has less to do, firing only on a terminal too narrow for the lanes themselves, and its footer atom appears only there. Co-Authored-By: Claude Opus 5 (1M context) --- meshterm/ui/livefeed_screen.py | 80 +++++++++++++++------------------- tests/test_livefeed.py | 71 ++++++++++++++++-------------- 2 files changed, 74 insertions(+), 77 deletions(-) diff --git a/meshterm/ui/livefeed_screen.py b/meshterm/ui/livefeed_screen.py index a9b2f6d..2c4171e 100644 --- a/meshterm/ui/livefeed_screen.py +++ b/meshterm/ui/livefeed_screen.py @@ -3,12 +3,17 @@ The interactive face of the ``livefeed`` tool — the dashboard's old feed panel, promoted to a first-class screen. One always-repainting list streams the latest packets, newest first: time, class (icon + label, icon alone on a narrow terminal), -node, SNR/RSSI, and the trailing detail (a relayed frame's ``via`` chain, a message's -conversation). Seeded from stored history so the screen opens full, then streamed +node, SNR/RSSI, and a message's conversation. What a row deliberately does *not* carry +is the relay path a frame rode in on: a route is a shape, not a lane, and squeezing one +into the cells left at the right edge only ever produced a stub — so the route belongs +to the packet viewer, which has the room to draw it as a wrapped path line over its +graph. The feed's job is to say what arrived and how well it was heard; Enter says how +it got here. + +Seeded from stored history so the screen opens full, then streamed live off the event hub. ``↑``/``↓`` walk the rows, PgUp/PgDn/Home/End page and jump -them, ``←``/``→`` scroll the highlighted row sideways when it runs past the right edge -(a long relay path read to its end without opening anything), and Enter opens the -highlighted packet in the shared +them, ``←``/``→`` scroll the highlighted row sideways on a terminal too narrow to hold +it whole, and Enter opens the highlighted packet in the shared :class:`~meshterm.ui.packet_viewer.PacketViewer` — which then pages through the feed itself with the same ``↑``/``↓``, and, for an overheard channel-text packet naming a channel we hold the key for, decrypts it. @@ -42,7 +47,6 @@ from .packet_viewer import ( from .theme import name_style, snr_style from .tui.render import crop_cells, render_to_ansi from .tui.screen import ListWindow, Screen -from .pathline import path_line from .widgets import NameKeyResolver, TypeOf if TYPE_CHECKING: @@ -63,9 +67,11 @@ _FEED_NAME_WIDTH = 18 #: packet under (``direct message``), so every label reads whole and the lanes hold. _FEED_CLASS_WIDTH = 14 -#: Terminal width below which the feed drops the textual class label and keeps only -#: the two-cell icon, buying the name and reception lanes room (≤72-col care). -_FEED_LABEL_MIN_WIDTH = 80 +#: Terminal width below which the feed drops the textual class label and keeps only the +#: two-cell icon. It is exactly the width the full row occupies — with no route to make +#: room for, every lane fits a 72-column screen, so the label (the row's most informative +#: field now that it names the real class) is only ever dropped when it truly can't fit. +_FEED_LABEL_MIN_WIDTH = 69 #: Cells one ←/→ press shifts the highlighted row by — the app-wide select list's own #: step (:attr:`~meshterm.ui.tui.select.SelectScreen._HSCROLL_STEP`), so a row here @@ -344,16 +350,17 @@ class LiveFeedScreen(Screen): textual label beside it is dropped wholesale on a narrow terminal (``show_label``), keeping the lanes aligned either way. The node lane is then free to be about the node: its name in the app-wide palette hue (our own node - white, a bare hash muted), and a dash where nobody identified themselves. Never - wraps — the detail lane gets whatever width the fixed lanes leave (``width``). + white, a bare hash muted), and a dash where nobody identified themselves. No + relay path rides here — the whole row fits a 72-column screen precisely because + it doesn't try to, and the route is drawn properly one keypress away, in the + packet viewer. - A row that runs past the right edge is read by scrolling it, not by growing it. - An unhighlighted row simply elides its relay path's middle hops, keeping both - ends of the route in view; the *highlighted* row instead slides under ``←→`` - (:attr:`_hshift`), carrying its detail whole so it can be read to the end — the - app-wide h-scroll convention, with the ``▸`` pointer lane pinned so the cursor - never scrolls away from the row it marks. The shift bound is measured here, - against the current width, so a resize can only clamp it back into range. + A row that runs past the right edge — a terminal narrower than the lanes need — + is read by scrolling it, not by growing it: the *highlighted* row slides under + ``←→`` (:attr:`_hshift`), the app-wide h-scroll convention, with the ``▸`` + pointer lane pinned so the cursor never scrolls away from the row it marks. The + shift bound is measured here, against the current width, so a resize can only + clamp it back into range. """ row = Text(no_wrap=True, overflow="ellipsis") row.append("▸ " if selected else " ", style="accent") @@ -382,9 +389,7 @@ class LiveFeedScreen(Screen): f" {entry.rssi:5.0f} dBm" if entry.rssi is not None else " " * 10, style="muted", ) - note = self._feed_note( - entry, None if selected else max(1, avail - body.cell_len - 2) - ) + note = self._feed_note(entry) if note is not None: body.append(" ") body.append_text(note) @@ -406,8 +411,8 @@ class LiveFeedScreen(Screen): class lane two columns left already says that, straight from :func:`~meshterm.ui.packet_viewer.class_marks`, and a row that spelled it twice was reading ``packet`` beside ``channel text`` as though they were two facts. - A relayed flood names no origin, so its lane says so with a dash and lets the - eye travel on to the ``via`` chain, which does name nodes. + A relayed flood names no origin, so its lane says so with a dash — the route that + would name nodes is the packet viewer's to draw, not a stub for this row to carry. """ if entry.kind == "message": sender = _channel_sender(entry.text) @@ -421,35 +426,22 @@ class LiveFeedScreen(Screen): return entry.where, "muted" # an ack's code, or any other stray context return "—", "muted" - def _feed_note(self, entry: PacketEntry, budget: Optional[int]) -> Optional[Text]: - """The row's trailing detail: a packet's relay path, a message's conversation. + def _feed_note(self, entry: PacketEntry) -> Optional[Text]: + """The row's trailing detail — a message's conversation, and nothing else. - The path renders through THE path line. Given a ``budget`` — the cells the row's - fixed lanes leave — a chain too long for the lane elides its *middle* hops behind - ``⋯``, so the origin and the last relay (the ends a right-edge cut would amputate) - always survive. ``None`` asks for the chain whole instead: that is the highlighted - row, which scrolls sideways rather than eliding, so nothing may be dropped before - ``←→`` has had the chance to reveal it. + A relayed frame's route used to sit here, and it never fitted: whatever the fixed + lanes left it was a handful of cells, so the chain arrived elided to a stub that + named one hop and hinted at the rest. A route is a shape rather than a lane, and + it is one keypress away — the packet viewer draws it as a wrapped path line over + the route graph, with the room to say the whole thing. So the feed says what + arrived; Enter says how it got here. Args: entry: The packet the row describes. - budget: Cells the detail may occupy, or ``None`` for the full-length line. Returns: The detail to append, or ``None`` when the class carries none. """ - if entry.kind == "packet" and entry.path is not None: - note = Text("via ", style="muted") - line = path_line( - entry.path.split(","), - self._resolve, - prefix_bytes=self._prefix_bytes, - self_name=self._self_name, - ) - note.append_text( - line.text() if budget is None else line.ellipsized(max(1, budget - 4)) - ) - return note if entry.kind == "message" and entry.where: return Text(entry.where, style="muted") return None diff --git a/tests/test_livefeed.py b/tests/test_livefeed.py index 37d310b..4d4cec3 100644 --- a/tests/test_livefeed.py +++ b/tests/test_livefeed.py @@ -74,17 +74,22 @@ def test_livefeed_live_events_land_in_the_feed() -> None: assert body.index("ack") < body.index("message") < body.index("advert") -def test_livefeed_packet_rows_show_their_relay_path() -> None: - """An RX-log packet reads as its relay path, resolved to names where known. +def test_livefeed_rows_leave_the_relay_path_to_the_viewer() -> None: + """A row says what arrived and how well it was heard; the route is Enter's job. - The path renders through the shared compact path widget, so each name carries its - own hue — assert on the stripped text, not the raw ANSI. + Whatever the fixed lanes left a route was never enough to draw one in — it arrived + elided to a stub — so the feed carries none, and the whole row fits a 72-column + screen with its class label intact. """ screen = _screen() screen.on_event( MeshEvent.observation_event(_obs(kind="packet", path="3d63,a1b2", snr=1.0)) ) - assert "via YUL → Alice" in "\n".join(_stripped(screen.render_body(100))) + row = _stripped(screen.render_body(72))[1] + assert "via" not in row and "YUL" not in row # no route, not even a stub of one + assert "📦 packet" in row # the class still reads in words at 72 + assert "+1.0 dB" in row and "-90 dBm" in row # …as does the reception it was heard at + assert len(row.rstrip()) <= 72 def test_livefeed_class_lane_names_the_payload_class_once() -> None: @@ -150,60 +155,60 @@ def test_livefeed_windows_inside_the_fixed_screen() -> None: assert "↓" in body and "more" in body # hidden feed rows are counted below -def _long_packet(**extra) -> Observation: - """A relayed packet whose ``via`` chain is far wider than any sane terminal.""" - return _obs(kind="packet", path=",".join(f"{i:02d}aa" for i in range(12)), **extra) +#: A terminal too narrow to hold the feed's fixed lanes — the only thing that makes a +#: row overflow now that no route rides in it (see ``_FEED_LABEL_MIN_WIDTH``). +_CRAMPED = 44 + + +def test_livefeed_the_whole_row_fits_a_72_column_screen() -> None: + """No row overflows at 72 — which is why ←→ has nothing to advertise there.""" + screen = _screen(seed=[_obs(node="n0", kind="telemetry")]) + for line in _stripped(screen.render_body(72))[1:]: + assert len(line.rstrip()) <= 72 + assert screen._hmax == 0 + assert "←→" not in screen.footer_hint def test_livefeed_highlighted_row_scrolls_sideways_to_its_tail() -> None: - """←→ slide the highlighted row so a long relay path reads to its last hop.""" - screen = _screen(seed=[_long_packet()]) - opening = _stripped(screen.render_body(100))[1] + """On a terminal too narrow for the lanes, ←→ slide the highlighted row to its end.""" + screen = _screen(seed=[_obs()]) + opening = _stripped(screen.render_body(_CRAMPED))[1] assert screen._hmax > 0 # the row does run past the right edge - assert "00aa" in opening and "11aa" not in opening # …so its tail is off-screen + assert not opening.rstrip().endswith("dBm") # …so its reception tail is off-screen for _ in range(40): # → saturates at the row's own end, never past it screen.handle("right") - scrolled = _stripped(screen.render_body(100))[1] + scrolled = _stripped(screen.render_body(_CRAMPED))[1] assert screen._hshift == screen._hmax assert scrolled.startswith("▸ ") # the pointer lane stays pinned while the row slides - assert scrolled.rstrip().endswith("11aa") # the last hop is now readable - assert "Alice" not in scrolled # …at the cost of the lanes that slid off the left + assert scrolled.rstrip().endswith("-90 dBm") # the tail is now readable + assert opening[2:10] not in scrolled # …at the cost of the time lane, slid off left for _ in range(40): screen.handle("left") assert screen._hshift == 0 - assert _stripped(screen.render_body(100))[1] == opening # back where it started + assert _stripped(screen.render_body(_CRAMPED))[1] == opening # back where it started def test_livefeed_moving_the_selection_abandons_the_rows_scroll() -> None: """Each row scrolls on its own: landing on another packet starts it at its beginning.""" - screen = _screen(seed=[_long_packet(age_s=1), _long_packet(age_s=0)]) - screen.render_body(100) + screen = _screen(seed=[_obs(node="n0", age_s=1), _obs(node="n1", age_s=0)]) + screen.render_body(_CRAMPED) screen.handle("right") assert screen._hshift > 0 screen.handle("down") assert screen._hshift == 0 -def test_livefeed_only_the_highlighted_row_carries_its_path_whole() -> None: - """An unhighlighted row elides its middle hops; the one you can scroll keeps them.""" - screen = _screen(seed=[_long_packet(age_s=1), _long_packet(age_s=0)]) - rows = _stripped(screen.render_body(100))[1:3] - assert "⋯" not in rows[0] # the highlighted row: whole, cropped at the edge - assert "⋯" in rows[1] # the rest: middle elided so both ends survive - - def test_livefeed_advertises_line_scroll_only_where_it_acts() -> None: """←→ earns its footer atom exactly while the highlighted row overflows.""" - short = _screen(seed=[_obs()]) - short.render_body(100) - assert "←→" not in short.footer_hint + screen = _screen(seed=[_obs()]) + screen.render_body(100) + assert "←→" not in screen.footer_hint # a row with room to spare scrolls nowhere - long_row = _screen(seed=[_long_packet()]) - long_row.render_body(100) - assert "←→ scroll line" in long_row.footer_hint - assert len(long_row.footer_hint) <= 72 # the screens-at-72 rule, fullest state + screen.render_body(_CRAMPED) + assert "←→ scroll line" in screen.footer_hint + assert len(screen.footer_hint) <= 72 # the screens-at-72 rule, fullest state def test_livefeed_without_a_device_reads_as_waiting() -> None: