Packet card: two columns back from the gutter, and rssi holds its line

On the PicoCalc the viewer's reception row folded the bare word "rssi"
onto a line of its own. Two things were spending the cells it needed.

The dialog gutter: every floating box left six columns to the backdrop it
sits over. Three a side reads as floating at 72; at 53 the same gutter is
a twelfth of the whole display, and it costs content. How wide the gutter
is worth being is now the platform's call (Platform.dialog_margin), and
the console's is four — still floating, two columns back.

The separator: the row chained its two atoms on the roomy "  ·  " no
matter the lane. That is the header's problem too, and the header already
solved it — roomy by default, compact when the cells run out — so the row
now takes the same trade, sizing itself at render time like the via path
beside it. Two cells alone would have left a two-digit SNR beside a
three-digit RSSI still folding; together they fit with a cell to spare.
The roomy/compact pair moves to ui/menus.py, one definition for both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-10 17:01:51 -04:00
1 parent ab63a83bbc
commit ce86e86693
6 files changed
+95 -21

No files matched your search

+11
View File
@@ -43,6 +43,14 @@ class Platform:
frame_border: Whether the base screen draws inside a bordered ``Panel``. ``False``
swaps it for a title-bar row instead (+4 cols, +1 row reclaimed) — a PicoCalc
chrome saving, wired in P4.
dialog_margin: Total columns a floating dialog leaves to the backdrop it sits over
— half of it on each side (see
:func:`~meshterm.ui.tui.frame._dialog_layout`). The gutter is what makes a
dialog read as floating rather than as a new screen, and three columns a side
do that comfortably at 72. On the 53-column console the *same* gutter is a
twelfth of the whole display, and it costs content: a packet card's reception
row folds ``rssi`` onto a line of its own for want of two cells (JP, on-device,
2026-08-10). Two columns a side still reads as floating and buys them back.
header_atoms: Which segments compose the persistent header, in the vocabulary
``"version"``, ``"device"``, ``"badges"``, ``"pulse"``, ``"battery"``. Wired
into :func:`~meshterm.ui.menu._header` in P4; unconsumed until then.
@@ -98,6 +106,7 @@ class Platform:
readable_cols: int
readable_rows: int
frame_border: bool
dialog_margin: int
header_atoms: tuple[str, ...]
footer_fkeys: bool
width_reclaim: bool
@@ -117,6 +126,7 @@ REGULAR = Platform(
readable_cols=72,
readable_rows=24,
frame_border=True,
dialog_margin=6,
header_atoms=("version", "device", "badges", "pulse", "battery"),
footer_fkeys=False,
width_reclaim=True,
@@ -139,6 +149,7 @@ PICOCALC = Platform(
readable_cols=53,
readable_rows=26,
frame_border=False,
dialog_margin=4,
# JP's call (2026-08-01, post-P7 review): the handheld's header brands the app —
# "MeshTerm vX" — rather than naming the device/port (on a soldered radio the port
# never changes), and the activity pulse takes whatever room remains.
+3 -9
View File
@@ -29,7 +29,7 @@ from ..platforms import get_platform
from ..tools import all_tools
from .surface import TuiUi
from .braillechart import activity_peak, activity_sparkline
from .menus import section_heading
from .menus import SEP_COMPACT, SEP_ROOMY, section_heading
from .theme import make_console
from .widgets import battery_cell
from .tui import (
@@ -124,12 +124,6 @@ _SPARK_MIN_CELLS = 24
#: many packets-per-minute, so a single stray reads as a small nub, not a full column.
_HEADER_ACTIVITY_FLOOR = 3.0
#: The header's default segment separator, and the tighter one it falls back to when the
#: roomy form would squeeze the pulse below :data:`_SPARK_MIN_CELLS` (see :func:`_header`).
_SEP_ROOMY = " · "
_SEP_COMPACT = " · "
def _header(ctx: AppContext, cache: dict, width: int) -> Text:
"""Build the persistent one-line header: who's connected, unread mail, mesh pulse.
@@ -176,10 +170,10 @@ def _header(ctx: AppContext, cache: dict, width: int) -> Text:
joined = content + len(pieces) * cell_len(sep)
return joined, (cell_len(sep) + battery.cell_len) if battery.cell_len else 0
sep = _SEP_ROOMY
sep = SEP_ROOMY
header_w, reserve = _measure(sep)
if width - header_w - reserve < _SPARK_MIN_CELLS:
sep = _SEP_COMPACT
sep = SEP_COMPACT
header_w, reserve = _measure(sep)
header = Text()
for piece in pieces:
+10
View File
@@ -40,6 +40,16 @@ if TYPE_CHECKING:
from ..context import AppContext
#: The app's status-atom separator, in its two widths. ``·`` chains atoms (the standards'
#: rule — ``Map · z12 · 34 nodes``); the roomy form is the default, and a surface running
#: out of cells falls back to the compact one rather than folding an atom onto a line of
#: its own. The header lays its segments out this way (see :func:`~meshterm.ui.menu._header`)
#: and so does the packet card's reception row — the same trade, wherever the cells are the
#: scarce thing.
SEP_ROOMY = " · "
SEP_COMPACT = " · "
def back_rows(value: Any = None) -> list:
"""The standard exit group closing a select list: a blank line, then ``Back``.
+43 -11
View File
@@ -43,6 +43,7 @@ from ..core.channels import decrypt_channel_text, identify_channel
from ..core.models import NODE_TYPE_LABELS, Observation, utcnow
from ..services.trace_runner import NodeResolver
from .map_render import _SELF, _UNKNOWN
from .menus import SEP_COMPACT, SEP_ROOMY
#: Composed packet cards the viewer memoizes (a few pages either side of the view).
_BODY_CACHE_MAX = 8
@@ -297,6 +298,44 @@ def node_label(
return (name, name_style(name, entry.node))
@dataclass(frozen=True, slots=True)
class _Reception:
"""The card's reception row — SNR with its quality bar, then RSSI — sized to its lane.
Handed to the grid *unsized*, like the via path beside it: the value column's width is
only settled once the label lane is (see :meth:`PacketViewer._label_width`), so the row
lays itself out at render time. The two atoms chain on the app's roomy separator and
fall back to the compact one (:data:`~meshterm.ui.menus.SEP_ROOMY`) when the roomy form
would not fit — the header's own trade, made wherever the cells are the scarce thing.
On the 53-column console they are: a two-digit SNR beside a three-digit RSSI misses the
lane by exactly that padding, and folding put the bare word ``rssi`` on a line of its
own (JP, on-device, 2026-08-10).
Attributes:
snr: Signal-to-noise ratio in dB, if measured.
rssi: Reception strength in dBm, if measured.
"""
snr: Optional[float]
rssi: Optional[float]
def _line(self, separator: str) -> Text:
"""The row drawn with ``separator`` between the two atoms."""
line = Text()
if self.snr is not None:
line.append(f"{self.snr:+.1f} dB ", style=snr_style(self.snr))
line.append_text(snr_bar(self.snr))
if self.rssi is not None:
if self.snr is not None:
line.append(separator, style="muted")
line.append(f"{self.rssi:.0f} dBm rssi", style="muted")
return line
def __rich_console__(self, console, options):
roomy = self._line(SEP_ROOMY)
yield roomy if roomy.cell_len <= options.max_width else self._line(SEP_COMPACT)
class PacketViewer(Screen):
"""The floating packet dialog: one entry laid out in full, pageable over its list.
@@ -679,17 +718,10 @@ class PacketViewer(Screen):
return resolved
return entry.name or None
def _reception(self, entry: PacketEntry) -> Text:
"""SNR (with the shared quality bar) and RSSI on one line."""
line = Text()
if entry.snr is not None:
line.append(f"{entry.snr:+.1f} dB ", style=snr_style(entry.snr))
line.append_text(snr_bar(entry.snr))
if entry.rssi is not None:
if entry.snr is not None:
line.append(" · ", style="muted")
line.append(f"{entry.rssi:.0f} dBm rssi", style="muted")
return line
@staticmethod
def _reception(entry: PacketEntry) -> _Reception:
"""SNR (with the shared quality bar) and RSSI on one line — see :class:`_Reception`."""
return _Reception(entry.snr, entry.rssi)
def _via_path(self, entry: PacketEntry) -> PathLine:
"""A ``packet`` entry's relay chain as THE path line (:mod:`~meshterm.ui.pathline`).
+3 -1
View File
@@ -444,7 +444,9 @@ def _dialog_layout(screen: Screen, cols: int, rows: int) -> tuple[int, int, int,
# Most dialogs stretch to a generous cap; a screen may instead request a natural width
# (a short confirm sized to its content), still bounded to the terminal. A grow-only
# screen's natural width ratchets like its height, so the box never narrows either.
cap = min(cols - 6, 100)
# What the cap leaves behind is the backdrop gutter the box floats over, and how many
# columns that is worth is the platform's call (see Platform.dialog_margin).
cap = min(cols - get_platform().dialog_margin, 100)
natural = getattr(screen, "dialog_width", None)
max_w = cap if natural is None else max(24, min(cap, screen.ratchet_width(natural)))
# Rows the box may spend between its borders — on body lines and breathing room alike.
+25
View File
@@ -13,6 +13,7 @@ from Crypto.Hash import HMAC, SHA256
from meshterm.core.channels import channel_hash, derive_secret
from meshterm.core.models import utcnow
from meshterm.platforms import set_platform
from meshterm.ui.packet_viewer import PacketEntry, PacketViewer
@@ -344,3 +345,27 @@ def test_packet_viewer_names_a_channel_datagram_by_its_confirmed_channel() -> No
unknown = _plain(_viewer(entry).render_body(80)) # no keys held: named by fingerprint only
assert "unknown" in unknown and "Public" not in unknown
def test_packet_viewer_reception_row_keeps_rssi_on_one_line() -> None:
"""SNR and RSSI never fold: the separator tightens before the row does.
The card's narrowest lane is the PicoCalc dialog's (53 columns less the backdrop
gutter and the box's own chrome), where a two-digit SNR beside a three-digit RSSI
misses the roomy `` · `` by exactly its padding — and folding puts the bare word
``rssi`` on a line of its own.
"""
from meshterm.platforms import PICOCALC, REGULAR
from meshterm.ui.tui.frame import _dialog_layout
entry = PacketEntry(when=utcnow(), kind="advert", node="3d63", snr=-13.5, rssi=-101.0)
for platform, cols in ((REGULAR, 72), (PICOCALC, PICOCALC.readable_cols)):
set_platform(platform)
viewer = _viewer(entry)
_, _, _, body = _dialog_layout(viewer, cols, 26)
rows = [row for row in _stripped(body) if "rssi" in row]
assert len(rows) == 1, (platform.name, _stripped(body))
assert "-13.5 dB" in rows[0] and "-101 dBm rssi" in rows[0], platform.name
# Where the cells are there, the roomy separator stays.
set_platform(REGULAR)
assert " · " in _plain(_viewer(entry).render_body(80))