From 3de4f8d9f9806a81ad9bcf31056f55e287477fd1 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Tue, 28 Jul 2026 02:50:03 -0400 Subject: [PATCH] Live feed: file a packet under what it is, and say it once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The class lane and the node lane were saying the same thing. `packet` names only the event family a frame arrived in, so a relayed flood β€” which carries no origin, and so has no node to name β€” fell through to a stand-in that showed its parsed payload class. The row read `πŸ“¦ packet channel text`: a generic bucket beside the actual class, laid out as though they were two facts. The viewer had already settled this β€” `class_chrome()` headlines its card with `πŸ“» CHANNEL TEXT`, not `PACKET`. That decision now lives in `class_marks()`, which both surfaces read: the card shouts it, the feed's lane takes it in plain case. So a raw frame files under πŸ“» channel text / 🎯 trace / πŸ“© direct message, and even on a terminal too narrow for the label the icon alone finally says which class it is. With the class named once, the node lane goes back to being about the node β€” and an origin-less flood admits it with a dash instead of borrowing the class a second time. ANON_REQ's gloss becomes `anon request`, the spelling the standards already use, which also lets the lane hold every class whole at 14 cells. Co-Authored-By: Claude Opus 5 (1M context) --- meshterm/ui/livefeed_screen.py | 52 ++++++++++++++++++++-------------- meshterm/ui/packet_viewer.py | 36 +++++++++++++++-------- tests/test_livefeed.py | 19 +++++++++---- 3 files changed, 69 insertions(+), 38 deletions(-) diff --git a/meshterm/ui/livefeed_screen.py b/meshterm/ui/livefeed_screen.py index 6ab8bf4..a9b2f6d 100644 --- a/meshterm/ui/livefeed_screen.py +++ b/meshterm/ui/livefeed_screen.py @@ -36,9 +36,8 @@ from .packet_viewer import ( KIND_STYLES, PacketEntry, PacketViewer, - kind_icon, + class_marks, node_label, - payload_class, ) from .theme import name_style, snr_style from .tui.render import crop_cells, render_to_ansi @@ -60,9 +59,13 @@ _FEED_CAP = 100 #: The feed's fixed node-name lane width; longer names ellipsize so the columns hold. _FEED_NAME_WIDTH = 18 -#: Terminal width below which the feed drops the textual kind label and keeps only +#: The class lane's fixed width β€” wide enough for the longest class the app files a +#: 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 = 76 +_FEED_LABEL_MIN_WIDTH = 80 #: 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 @@ -334,11 +337,15 @@ class LiveFeedScreen(Screen): ) -> Text: """Lay one feed row out in fixed lanes: time, class, node, reception, detail. - The class lane leads with its two-cell icon; the textual label beside it is - dropped wholesale on a narrow terminal (``show_label``), keeping the lanes - aligned either way. The node name takes the app-wide palette hue (our own - node white, a bare hash muted). Never wraps β€” the detail lane gets whatever - width the fixed lanes leave (``width``). + The class lane says what the packet *is*, straight from + :func:`~meshterm.ui.packet_viewer.class_marks` β€” so a raw frame reads + ``πŸ“» channel text``, the class the viewer's card headlines, rather than the + ``πŸ“¦ packet`` event family it merely arrived in. Its icon always shows; the + 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``). 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 @@ -354,9 +361,14 @@ class LiveFeedScreen(Screen): body = Text(no_wrap=True, overflow="ellipsis") body.append(entry.when.astimezone().strftime("%H:%M:%S") + " ", style="muted") - body.append(kind_icon(entry.kind) + " ") + icon, class_label = class_marks(entry) + body.append(icon + " ") if show_label: - body.append(entry.kind.ljust(10), style=KIND_STYLES.get(entry.kind, "brand")) + body.append( + fit_cells(class_label, _FEED_CLASS_WIDTH), + style=KIND_STYLES.get(entry.kind, "brand"), + ) + body.append(" ") # the lane's own gutter β€” the longest class fills it exactly label, style = node_label(entry, self._resolve, self._self_name) if label == "?": label, style = self._feed_subject(entry) # no node identity: name what we can @@ -388,12 +400,14 @@ class LiveFeedScreen(Screen): def _feed_subject(self, entry: PacketEntry) -> tuple[str, str]: """Name the node lane when an entry carries no resolvable node identity. - The fallback the vast majority of rows hit β€” a relayed ``packet`` naming no - origin, or a channel message with no sender field. Rather than a useless ``?`` - (or the bare ``ch 3`` that only repeats the note), it reads the most identifying - thing the entry does carry: the sender a channel message named itself with, or - what *kind* of frame a relayed packet is (``channel text`` / ``trace`` / …). An - ack falls back to its code; nothing else, to a dash. + Rather than a useless ``?``, the lane reads the most identifying thing the entry + still carries: the sender a channel message named itself with, then an ack's + code. What it deliberately does *not* do is stand in the packet's class β€” the + 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. """ if entry.kind == "message": sender = _channel_sender(entry.text) @@ -403,10 +417,6 @@ class LiveFeedScreen(Screen): # muted β€” colour is reserved for keyed identities. return sender, ("you" if ours else name_style(sender, self._key_of(sender))) return "channel", "muted" - if entry.kind == "packet": - cls = payload_class(entry.raw) - if cls: - return cls, "muted" if entry.where: return entry.where, "muted" # an ack's code, or any other stray context return "β€”", "muted" diff --git a/meshterm/ui/packet_viewer.py b/meshterm/ui/packet_viewer.py index a261725..033c3c9 100644 --- a/meshterm/ui/packet_viewer.py +++ b/meshterm/ui/packet_viewer.py @@ -69,7 +69,7 @@ _PAYLOAD_GLOSS = { "ADVERT": "advert", "GRP_TXT": "channel text", "GRP_DATA": "channel data", - "ANON_REQ": "anonymous request", + "ANON_REQ": "anon request", "PATH": "path", "TRACE": "trace", "MULTIPART": "multipart", @@ -216,24 +216,36 @@ def payload_class(raw: Optional[dict]) -> Optional[str]: return _PAYLOAD_GLOSS.get(typename, typename.lower()) -def class_chrome(entry: PacketEntry) -> tuple[str, str]: - """The class headline every packet leads with: a two-cell icon and an UPPERCASE label. +def class_marks(entry: PacketEntry) -> tuple[str, str]: + """What a packet actually *is*: its two-cell icon and its plain-case class label. - A raw ``packet`` frame's class is its parsed payload class β€” ``CHANNEL TEXT``, - ``TRACE``, … β€” under its :data:`PAYLOAD_ICONS` glyph; a typename this table has - never heard of keeps the fallback mark and shouts the raw typename; a class-less - frame stays a plain ``PACKET``. Every other kind is its own class (``ADVERT``, - ``MESSAGE``, …) under the shared :data:`KIND_ICONS` glyph. + The one place the app decides which class a listed packet belongs to, so the viewer's + headline and the feed's class lane can never disagree. A raw ``packet`` frame's class + is its *parsed payload* class β€” ``channel text``, ``trace``, … β€” under its + :data:`PAYLOAD_ICONS` glyph, because ``packet`` alone names only the event family the + frame arrived in, not the thing it carries; a typename this table has never heard of + keeps the fallback mark and shows the raw typename; a class-less frame stays a plain + ``packet``. Every other kind is its own class (``advert``, ``message``, …) under the + shared :data:`KIND_ICONS` glyph. """ if entry.kind == "packet": raw = entry.raw if isinstance(entry.raw, dict) else {} typename = raw.get("payload_typename") if typename: icon = PAYLOAD_ICONS.get(typename, DEFAULT_ICON) - label = _PAYLOAD_GLOSS.get(typename, typename.lower()).upper() - return icon, label - return KIND_ICONS["packet"], "PACKET" - return kind_icon(entry.kind), entry.kind.upper() + return icon, _PAYLOAD_GLOSS.get(typename, typename.lower()) + return KIND_ICONS["packet"], "packet" + return kind_icon(entry.kind), entry.kind + + +def class_chrome(entry: PacketEntry) -> tuple[str, str]: + """The class headline the viewer's card leads with β€” :func:`class_marks`, shouted. + + The card's first row is a headline, so it takes the UPPERCASE treatment; a list lane + reads the same class in its own plain case straight from :func:`class_marks`. + """ + icon, label = class_marks(entry) + return icon, label.upper() def node_label( diff --git a/tests/test_livefeed.py b/tests/test_livefeed.py index a0d3f70..37d310b 100644 --- a/tests/test_livefeed.py +++ b/tests/test_livefeed.py @@ -87,8 +87,14 @@ def test_livefeed_packet_rows_show_their_relay_path() -> None: assert "via YUL β†’ Alice" in "\n".join(_stripped(screen.render_body(100))) -def test_livefeed_names_a_relayed_packet_by_its_payload_class() -> None: - """A relayed packet naming no origin reads as its payload class, never a bare '?'.""" +def test_livefeed_class_lane_names_the_payload_class_once() -> None: + """A raw frame is filed under what it *is*, and the node lane doesn't repeat it. + + ``packet`` names only the event family the frame arrived in, so the class lane + reads its parsed payload class β€” the very label the viewer's card headlines. The + node lane is then free to be about the node, and an origin-less flood says so with + a dash rather than standing the class in a second time. + """ screen = _screen() raw = {"payload_typename": "TRACE", "route_typename": "FLOOD"} screen.on_event( @@ -96,9 +102,12 @@ def test_livefeed_names_a_relayed_packet_by_its_payload_class() -> None: _obs(node="", kind="packet", snr=1.0, path="3d63,a1b2", raw=raw) ) ) - body = _plain(screen.render_body(100)) - assert "trace" in body # the payload-class gloss stands in for the missing identity - assert "?" not in body # …instead of the useless placeholder + row = _stripped(screen.render_body(100))[1] + assert "🎯 trace" in row # the class lane, under the payload class's own icon + assert row.count("trace") == 1 # said once, not once per lane + assert "packet" not in row # …and never as the generic event family + assert "β€”" in row # the node lane: nobody identified themselves + assert "?" not in row # …but never the useless placeholder def test_livefeed_names_a_channel_message_by_its_sender() -> None: