Live feed: file a packet under what it is, and say it once
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
8afa592e9a
commit
3de4f8d9f9
3 files changed
+69
-38
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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(
|
||||
|
||||
+14
-5
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user