Node detail: a tabbed stage with a switchable route list

The page stacked the location preview and the route graph down one long
scroll, and the graph was inert — no way to pick which route it lit. Give
it a tabbed stage instead: a one-line strip (new widgets.tab_strip) pages
Map and Routes one full-height view at a time, switched with ←→ (Tab /
Shift+Tab backup; BackTab now dispatches as "shift_tab"). Tabs are
adaptive — only views with content show, a lone tab collapses to a lit
heading, and our own fix-less node falls back to a bare action list.

The Routes tab folds the old route/suggest info rows into a selectable
route list (best marked ★ best, the firmware's device route, then the
good observed alternatives), each spelled contact→relays→us through the
path widget with a hanging wrap. ↑↓ over the rows drives the graph: the
picked route lights white while the rest go grey and every node off it
fades its label to grey (a per-render label_rgb_of closure — the pathgraph
widget stays generic). A dedicated 🎯 Trace this route row opens the trace
flow armed on whichever route is selected (nothing transmits here).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 4.8 committed 2026-07-22 19:01:10 -04:00
1 parent 57d413ba42
commit 8d8193b6b1
5 files changed
+642 -334

No files matched your search

+438 -208
View File
@@ -6,24 +6,39 @@ the node itself, in full:
* **who it is** — its name in the node's own hue, its key with the routing hash lit, its
type, when it was first and last heard, how many packets we've overheard, its reception
SNR (median and best) and last RSSI, and where it sits;
* **where it is** — a small static basemap preview (see :class:`~meshterm.ui.minimap.MiniMap`)
centred on the node with the rest of the mesh around it, when the node has advertised a
location;
* **how we hear it** — the routes we've actually heard it arrive over, drawn on the shared
route graph (:mod:`~meshterm.ui.pathgraph`) node→us (the inbound direction the packets
travelled, contact on the left, us on the right), the best-evidence one lit white over the
alternatives. Only *good* routes are drawn — stale evidence and far-weaker outliers are
dropped, so the graph shows the routes worth trusting rather than every chain ever heard;
* **the ways in** — an action list: *Trace target* (armed with the suggested best path, so
Enter walks straight to it), *Open full map*, and *Time machine* (only when the recorder
actually holds history for the node). ↑/↓ move the cursor, Enter commits, Esc backs to the
list.
SNR (median and best) and last RSSI, and where it sits — the fixed identity block pinned
at the top of the page;
* **a tabbed stage** below it — one full-height view at a time, switched with ``←→`` (or
``Tab``/``Shift+Tab``) across a one-line tab strip (see
:func:`~meshterm.ui.widgets.tab_strip`). Rather than stack the location preview and the
route graph down one long scroll, each earns the whole stage:
* **Map** — a static basemap preview (see :class:`~meshterm.ui.minimap.MiniMap`) centred
on the node with the rest of the mesh around it, shown when the node has advertised a
location. Its ``Open full map`` action sits right under it.
* **Routes** — the routes we've actually heard the node arrive over, drawn on the shared
route graph (:mod:`~meshterm.ui.pathgraph`) node→us (the inbound direction the packets
travelled, contact on the left, us on the right). Beneath the graph sits the *route
list*: one selectable row per distinct route (the firmware's learned route and the
observed alternatives, the strongest marked ``★ best``), each spelled out through THE
path widget with a hanging wrap. ``↑↓`` moves the selection; the picked route lights
white in the graph while the rest go grey and every node not on it fades its label to
grey, so the graph reads as *this* route through the fan. Only *good* routes are drawn —
stale evidence and far-weaker outliers are dropped, so the list is the routes worth
trusting rather than every chain ever heard. The ``🎯 Trace this route …`` action arms
a trace on whichever route is selected (nothing transmits here — it opens the trace
screen loaded with that path).
* **the ways in** — the tab's action rows: ``Open full map`` / ``Trace this route`` plus the
always-available ``Time machine`` (when the recorder holds history) and ``Back``. ``↑↓``
moves the cursor through them, Enter commits, Esc backs to the list; ``PgUp/PgDn`` scroll
the page when the identity block and stage together overflow a short terminal.
The screen is a pure read-and-route view: it renders already-resolved display data and
resolves an action token; :func:`open_node_detail` owns the data-gathering and runs the
sub-flows each action opens, then re-shows the page — the same loop the Time Machine and
Contacts list use. Nothing here transmits.
resolves an action token (the Trace token carrying the selected route's spec via
:meth:`NodeDetailScreen.selected_spec`); :func:`open_node_detail` owns the data-gathering
and runs the sub-flows each action opens, then re-shows the page — the same loop the Time
Machine and Contacts list use. Nothing here transmits.
"""
from __future__ import annotations
@@ -60,6 +75,7 @@ from .widgets import (
highlighted_hash,
node_type_legend,
path_text,
tab_strip,
)
if TYPE_CHECKING: # pragma: no cover - typing only
@@ -71,15 +87,15 @@ _SELF_GLYPH = ("★", "#facc15")
#: How many character rows the inline location preview draws.
_MAP_ROWS = 7
#: Route-graph tuning for this page. It draws the contact on the left and us on the right
#: (node → us, so the graph reads left to right as the inbound direction its packets
#: Route-graph tuning for the Routes tab. It draws the contact on the left and us on the
#: right (node → us, so the graph reads left to right as the inbound direction its packets
#: travelled to reach us). A well-connected node offers several candidate paths at once, and
#: cramming them into a short box compresses the lanes together — so this page keeps the shared
#: lane pitch but grants a generous row budget, letting a busy node spread each route into its
#: own clearly separated track instead of scaling the pitch down. The height is adaptive: it
#: grows only with the number of distinct lanes, so a node with one or two routes still draws
#: compact while a busy one earns the room it needs. The page scrolls (PgUp/PgDn), so a tall
#: graph never crowds the action rows off.
#: graph never crowds the route list off.
_PATH_MAX_ROWS = 22
#: A drawn route is dropped as *stale* when its freshest-limiting link — the stalest hop it
@@ -101,10 +117,16 @@ _PATH_OUTLIER_RATIO = 0.25
#: hanging-indent rule). Sized to the widest label the block uses ("packets").
_LABEL_LANE = 9
#: The selected route's edge colour (white, the spine) over the alternatives' grey, and the
#: grey a node's label fades to when it sits on no part of the selected route. One grey for
#: both, so an off-route relay's line and its name read as the same "not this route" dim.
_WHITE = (255, 255, 255)
_GREY = (120, 120, 120)
@dataclass(slots=True)
class _Action:
"""One action row at the foot of the page.
"""One action row at the foot of a tab.
Attributes:
key: The token the screen resolves with when this row is committed.
@@ -120,20 +142,47 @@ class _Action:
@dataclass(slots=True)
class _PathView:
"""The route-graph layers and their shared per-node draw callbacks, or a bare note.
class _Route:
"""One selectable route on the Routes tab: how it draws, how it traces, how it reads.
Attributes:
layers: The paths to draw (best-evidence one highest priority), or empty when
there is no route evidence at all — then ``note`` carries the muted stand-in.
draw: The relay hops in the graph's inbound draw order (contact → us), so a
:class:`~meshterm.ui.pathgraph.PathLayer` built from them lands the contact on
the left endpoint and our star on the right. Empty = a straight zero-hop shot.
spec: The forced-path spec a trace arms on when this route is selected (the symmetric
round trip through these hops); ``""`` lets the trace screen auto-resolve.
row: The pre-rendered route line — the whole path named through THE path widget,
contact → relays → us, with the bottleneck SNR / sample count and a ``★ best`` or
``device route`` tag trailing. Shown hanging-wrapped, so a long route lines up
under itself.
"""
draw: tuple[str, ...]
spec: str
row: Text
@dataclass(slots=True)
class _RoutesView:
"""The Routes tab's selectable routes and the shared per-node draw callbacks, or a note.
The routes are drawn as one fan (best-evidence spine plus alternatives); which one lights
white — and which nodes keep their name hue rather than fading to grey — follows the
screen's live selection, so the layers and label colours are composed per render rather
than baked in here.
Attributes:
routes: The selectable routes (strongest first), or empty when there is no route
evidence at all — then ``note`` carries the muted stand-in.
glyph_of: Per-node marker callback for the graph.
label_of: Per-node label callback for the graph.
label_rgb_of: Per-node label-colour callback for the graph.
label_rgb_of: Per-node label-colour callback (the un-muted base; the screen fades the
off-route nodes over it).
legend: Whether to draw the node-type key beneath the graph (a typed relay showed).
note: The muted line shown instead of a graph when there is no evidence.
"""
layers: list[PathLayer] = field(default_factory=list)
routes: list[_Route] = field(default_factory=list)
glyph_of: Optional[GlyphOf] = None
label_of: Optional[LabelOf] = None
label_rgb_of: Optional[LabelRgbOf] = None
@@ -141,15 +190,33 @@ class _PathView:
note: str = ""
@dataclass(slots=True)
class _Tab:
"""One tab in the stage's strip.
Attributes:
name: The strip label (``Map`` / ``Routes``).
kind: Which stage it draws (``map`` / ``routes``).
"""
name: str
kind: str
class NodeDetailScreen(Screen):
"""A full-screen page for one node: identity, location, routes, and the ways in.
"""A full-screen page for one node: identity, a tabbed stage, and the ways in.
A read-and-route view. It renders already-resolved display data (see
:func:`open_node_detail`, which assembles it) and, on Enter, resolves the highlighted
action's token for the opener to act on; Esc resolves :data:`CANCEL` to leave. ↑/↓ move
the action cursor (its row is kept in view while navigating); PgUp/PgDn/Home/End scroll
the whole page, so the location preview and route graph can be read on a short terminal
without losing the controls.
action's token for the opener to act on (a Trace token is paired with
:meth:`selected_spec`); Esc resolves :data:`CANCEL` to leave.
Two axes of navigation, matching the app's spatial feel: ``←→`` (or ``Tab`` /
``Shift+Tab``) switches which view fills the stage, and ``↑↓`` moves the cursor *within*
the active tab — through its route list (on the Routes tab, the selection drives the
graph highlight) and action rows. The cursor is kept in view while ``↑↓`` are in use;
``PgUp/PgDn/Home/End`` scroll the whole page, so the stage and its rows can be read on a
short terminal without losing the controls.
"""
floating = False
@@ -160,10 +227,13 @@ class NodeDetailScreen(Screen):
title: str,
header: Text,
info_rows: list[tuple[str, Text]],
actions: list[_Action],
tabs: list[_Tab],
minimap: Optional[MiniMap] = None,
map_caption: Optional[Text] = None,
path: Optional[_PathView] = None,
routes: Optional[_RoutesView] = None,
open_map_action: Optional[_Action] = None,
trace_action: Optional[_Action] = None,
tail_actions: Optional[list[_Action]] = None,
) -> None:
"""Build the page over resolved display data.
@@ -172,21 +242,33 @@ class NodeDetailScreen(Screen):
header: The identity line: type glyph, the coloured name, its type label.
info_rows: ``(label, value)`` pairs for the fixed info block; each renders as
a muted label lane with the value hanging under itself when it wraps.
actions: The action rows, in display order (a ``back`` row set apart at the end).
minimap: The inline location preview, or ``None`` when the node has no location.
tabs: The stage tabs to offer, in strip order (empty = no stage, just actions).
minimap: The inline location preview for the Map tab, or ``None``.
map_caption: A faint line under the preview (its centre/scale), when a map shows.
path: The route-graph view (layers + callbacks, or a muted note), or ``None`` to
omit the whole "Routes heard" section (we never overhear our own node).
routes: The Routes tab's route list + graph callbacks (or a muted note), or
``None`` when there is no Routes tab (we never overhear our own node).
open_map_action: The Map tab's ``Open full map`` action, or ``None``.
trace_action: The Routes tab's ``Trace this route`` action, or ``None``.
tail_actions: The always-available actions closing every tab (Time machine when
there is history, then Back).
"""
super().__init__()
self.title = title
self._header = header
self._info_rows = info_rows
self._actions = actions
self._tabs = tabs
self._minimap = minimap
self._map_caption = map_caption
self._path = path
self._index = 0
self._routes = routes
self._open_map_action = open_map_action
self._trace_action = trace_action
self._tail_actions = tail_actions or []
self._tab_index = 0
self._row_index = 0
#: The highlighted route on the Routes tab (drives the graph); tracks the cursor as
#: it moves onto a route row and holds while it rests on an action row, so the graph
#: keeps showing the pick the Trace row would arm on.
self._route_sel = 0
self._pin_cursor = False # open showing the top; only pin once ↑/↓ are used
self._cursor: Optional[int] = None
@@ -194,23 +276,60 @@ class NodeDetailScreen(Screen):
@property
def footer_hint(self) -> str: # type: ignore[override]
"""Navigation, commit, scroll, then Esc last."""
return "↑↓ actions · Enter open · PgUp/PgDn scroll · Esc back"
"""Tab switch (when there are tabs to switch), move, open, scroll, Esc last."""
parts: list[str] = []
if len(self._tabs) >= 2:
parts.append("←→ tab")
parts.extend(("↑↓ move", "Enter open"))
if self.content_overflows:
parts.append("PgUp/PgDn scroll")
parts.append("Esc back")
return " · ".join(parts)
def selected_spec(self) -> str:
"""The forced-path spec of the currently-highlighted route (``""`` = auto).
The opener reads this after a ``trace`` token resolves, so a trace arms on whichever
route the cursor had picked rather than always the best one.
"""
routes = self._routes.routes if self._routes is not None else []
if routes:
sel = self._route_sel if 0 <= self._route_sel < len(routes) else 0
return routes[sel].spec
return ""
def consume_edge_scrub(self) -> int:
"""Scrub the panel's right edge while a braille map shows (the same smear the map has)."""
return 2 if self._minimap is not None else 0
"""Scrub the panel's right edge only while the braille Map tab is the one showing."""
if self._minimap is None or not self._tabs:
return 0
return 2 if self._tabs[self._tab_index].kind == "map" else 0
def handle(self, action: str, data: str = "") -> None:
"""Move the action cursor, commit it, scroll the page, or leave."""
"""Switch tab, move the cursor within a tab, commit a row, scroll, or leave."""
focus = self._focusables()
n = len(focus)
if action == "enter":
self.resolve(self._actions[self._index].key)
if n:
kind, payload = focus[self._row_index % n]
if kind == "action":
assert isinstance(payload, _Action)
self.resolve(payload.key)
# A route row is inert on Enter: selecting it (the highlight + graph) is the
# whole interaction; the dedicated Trace row is what opens the trace flow.
elif action in ("right", "tab"):
self._switch_tab(1)
elif action in ("left", "shift_tab"):
self._switch_tab(-1)
elif action == "up":
self._index = (self._index - 1) % len(self._actions)
self._pin_cursor = True
if n:
self._row_index = (self._row_index - 1) % n
self._sync_route_sel(focus)
self._pin_cursor = True
elif action == "down":
self._index = (self._index + 1) % len(self._actions)
self._pin_cursor = True
if n:
self._row_index = (self._row_index + 1) % n
self._sync_route_sel(focus)
self._pin_cursor = True
elif action == "pageup":
self._pin_cursor = False
self.scroll_pages(-1)
@@ -227,13 +346,50 @@ class NodeDetailScreen(Screen):
self.resolve(CANCEL)
def cursor_line(self) -> Optional[int]:
"""Keep the highlighted action visible while ↑/↓ are in use; free scroll otherwise."""
"""Keep the highlighted row visible while ↑/↓ are in use; free scroll otherwise."""
return self._cursor if self._pin_cursor else None
def _switch_tab(self, delta: int) -> None:
"""Move the active tab, resetting the cursor to that tab's top (and its stage in view)."""
if len(self._tabs) < 2:
return
self._tab_index = (self._tab_index + delta) % len(self._tabs)
self._row_index = 0
self._route_sel = 0
self._pin_cursor = False
self.scroll_to_top()
self._sync_route_sel(self._focusables())
def _sync_route_sel(self, focus: list[tuple[str, object]]) -> None:
"""Point the graph highlight at the route under the cursor, when it rests on one."""
if focus:
kind, payload = focus[self._row_index % len(focus)]
if kind == "path":
assert isinstance(payload, int)
self._route_sel = payload
def _focusables(self) -> list[tuple[str, object]]:
"""The active tab's cursor stops: ``("path", route_idx)`` and ``("action", _Action)``.
The route rows come first (Routes tab only), then the tab's own committing action
(Open full map / Trace this route), then the shared tail (Time machine, Back). A tab
with no stage (our own fix-less node) is just the tail.
"""
tab = self._tabs[self._tab_index] if self._tabs else None
focus: list[tuple[str, object]] = []
if tab is not None and tab.kind == "routes" and self._routes is not None:
focus.extend(("path", i) for i in range(len(self._routes.routes)))
if self._trace_action is not None:
focus.append(("action", self._trace_action))
elif tab is not None and tab.kind == "map" and self._open_map_action is not None:
focus.append(("action", self._open_map_action))
focus.extend(("action", a) for a in self._tail_actions)
return focus
# --- rendering -------------------------------------------------------------
def render_body(self, width: int) -> list[str]:
"""Render the identity block, location preview, route graph, and action list."""
"""Render the identity block, the active tab's stage, and its cursor rows."""
lines: list[str] = []
lines.extend(render_lines(self._header, width))
for label, value in self._info_rows:
@@ -245,55 +401,112 @@ class NodeDetailScreen(Screen):
indent=_LABEL_LANE,
)
)
if self._minimap is not None:
lines.append("")
lines.extend(render_lines(Text("Location", style="accent"), width))
lines.extend(self._minimap.render(width, _MAP_ROWS))
if self._map_caption is not None:
lines.extend(render_lines(self._map_caption, width, no_wrap=True))
if self._path is not None:
lines.append("")
lines.extend(render_lines(Text("Routes heard", style="accent"), width))
lines.extend(self._path_lines(width))
lines.append("")
focus = self._focusables()
if focus:
self._row_index %= len(focus)
self._cursor = None
for i, action in enumerate(self._actions):
if action.key == "back":
lines.append("") # set the exit row apart, as the menus do
selected = i == self._index
text = Text("❯ " if selected else " ", style="brand" if selected else "")
if action.glyph:
text.append(f"{action.glyph} ", style=action.glyph_style)
text.append(action.label)
if selected:
text.style = "brand"
self._cursor = len(lines)
text.no_wrap = True
text.truncate(width, overflow="ellipsis")
lines.append(render_to_ansi(text, width))
if self._tabs:
lines.append("")
lines.extend(
render_lines(
tab_strip([t.name for t in self._tabs], self._tab_index), width, no_wrap=True
)
)
lines.append("")
if self._tabs[self._tab_index].kind == "map":
lines.extend(self._map_stage(width))
else:
lines.extend(self._routes_stage(width))
lines.append("")
for i, (kind, payload) in enumerate(focus):
selected = i == self._row_index
if kind == "path":
assert isinstance(payload, int)
if selected:
self._cursor = len(lines)
lines.extend(self._route_row_lines(self._routes.routes[payload], selected, width))
else:
assert isinstance(payload, _Action)
if payload.key == "back":
lines.append("") # set the exit row apart, as the menus do
if selected:
self._cursor = len(lines)
lines.append(self._action_line(payload, selected, width))
self._scroll_total = max(1, len(lines))
return lines
def _path_lines(self, width: int) -> list[str]:
"""The route graph (best-evidence path white over the rest), or the muted note."""
path = self._path
assert path is not None # only called when a path section exists
if not path.layers or path.glyph_of is None:
return render_lines(Text(path.note or "no route observed yet", style="muted"), width)
lines = render_path_graph(
path.layers,
width,
glyph_of=path.glyph_of,
label_of=path.label_of, # type: ignore[arg-type]
label_rgb_of=path.label_rgb_of, # type: ignore[arg-type]
max_rows=_PATH_MAX_ROWS,
def _map_stage(self, width: int) -> list[str]:
"""The location preview and its faint caption."""
assert self._minimap is not None
lines = list(self._minimap.render(width, _MAP_ROWS))
if self._map_caption is not None:
lines.extend(render_lines(self._map_caption, width, no_wrap=True))
return lines
def _routes_stage(self, width: int) -> list[str]:
"""The route-graph fan — the selected route white, its off-route nodes' labels faded —
or the muted note when there is no route evidence."""
rv = self._routes
assert rv is not None
if not rv.routes or rv.glyph_of is None:
return render_lines(Text(rv.note or "no route observed yet", style="muted"), width)
sel = self._route_sel if 0 <= self._route_sel < len(rv.routes) else 0
layers = [
PathLayer(hops=route.draw, color=_WHITE if i == sel else _GREY, priority=3 if i == sel else 2)
for i, route in enumerate(rv.routes)
]
# A node keeps its name hue only while it sits on the selected route (its endpoints
# always do); every other node in the fan fades its label to the same grey its line
# went, so the picture reads as *this* route rather than the whole tangle.
on_route = set(rv.routes[sel].draw) | {SRC_NODE, DST_NODE}
base_rgb = rv.label_rgb_of
assert base_rgb is not None
def label_rgb_of(node: str):
return base_rgb(node) if node in on_route else _GREY
lines = list(
render_path_graph(
layers,
width,
glyph_of=rv.glyph_of,
label_of=rv.label_of, # type: ignore[arg-type]
label_rgb_of=label_rgb_of,
max_rows=_PATH_MAX_ROWS,
)
)
caption = Text("node → you, as heard · white = best route", style="faint")
caption = Text("node → you, as heard · white = selected route", style="faint")
lines.extend(render_lines(caption, width, no_wrap=True))
if path.legend:
if rv.legend:
lines.extend(render_lines(node_type_legend(), width, no_wrap=True))
return lines
def _route_row_lines(self, route: _Route, selected: bool, width: int) -> list[str]:
"""One route row: a ``❯`` pointer when picked, the route hanging-wrapped under itself.
The route keeps its per-node colours even when selected (the pointer, and the white
line in the graph above, carry the selection) — unlike the plain action rows, which
go fully brand, since here the colour *is* the content.
"""
prefix = Text("❯ " if selected else " ", style="brand" if selected else "")
return render_hanging(prefix, route.row, width, indent=2)
def _action_line(self, action: _Action, selected: bool, width: int) -> str:
"""One action row: ``❯`` + icon + label, the whole row brand when it is the cursor's."""
text = Text("❯ " if selected else " ", style="brand" if selected else "")
if action.glyph:
text.append(f"{action.glyph} ", style=action.glyph_style)
text.append(action.label)
if selected:
text.style = "brand"
text.no_wrap = True
text.truncate(width, overflow="ellipsis")
return render_to_ansi(text, width)
# -- geographic helpers --------------------------------------------------------
@@ -374,7 +587,7 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
make_node_resolver,
make_node_type_resolver,
)
from ..services.topology import build_topology, render_forced_spec, _is_hex
from ..services.topology import build_topology, _is_hex
from ..tools.map import gather_markers
from .map_screen import basemap_source, open_map
from .surface import TuiUi
@@ -412,8 +625,8 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
prefix_bytes, width_bytes = 0, 1
stored_names = ctx.repo.node_names()
# One hash→name resolver for the whole page: the route/suggest rows and the route
# graph all name their hops through it (contacts first, recorder history behind).
# One hash→name resolver for the whole page: the route list and the route graph all name
# their hops through it (contacts first, recorder history behind).
resolve = make_node_resolver(contacts, stored_names)
if you:
@@ -483,16 +696,8 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
if canonical_target
else []
)
# The spec the Trace action arms on: the observed best path, else the firmware's
# learned route, else nothing (let the trace screen auto-resolve).
if target_hash and suggested is not None:
suggested_spec = render_forced_spec(suggested.hops, target_hash, width_bytes)
elif target_hash and device_route is not None:
suggested_spec = render_forced_spec(device_route, target_hash, width_bytes)
else:
suggested_spec = ""
# -- the info block.
# -- the info block (identity + how-heard + where; the routes fold into the Routes tab).
info_rows: list[tuple[str, Text]] = []
if key:
info_rows.append(("key", highlighted_hash(key, prefix_bytes)))
@@ -514,9 +719,6 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
info_rows.append(("signal", signal))
if lat is not None and lon is not None:
info_rows.append(("where", _range_text(lat, lon, self_lat, self_lon)))
if not you:
info_rows.append(("route", _route_row(device_route, resolve=resolve, self_name=self_name)))
info_rows.append(("suggest", _suggest_row(suggested, resolve=resolve, self_name=self_name)))
# -- the location preview (only when the node advertised a fix).
minimap: Optional[MiniMap] = None
@@ -538,32 +740,37 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
)
map_caption = Text(f"{label} · centred here", style="faint")
# -- the "routes heard" route graph (node → us), best-evidence path white.
path: Optional[_PathView] = None
# -- the "routes heard" route list + graph (node → us), best-evidence path white.
routes_view: Optional[_RoutesView] = None
if not you:
path = _path_view(
topo, scenarios, suggested, device_route, canonical_target,
routes_view = _routes_view(
topo, scenarios, suggested, device_route, canonical_target, target_hash, width_bytes,
resolve=resolve,
type_of=make_node_type_resolver(contacts),
key_of=make_name_key_resolver(contacts, stored_names),
style=route_graph_style,
self_name=self_name,
node_label=label,
name_key=key,
)
# -- the action rows.
def build_actions() -> list[_Action]:
rows: list[_Action] = []
if not you and node_id:
rows.append(_Action("trace", "🎯", "", _trace_label(suggested_spec)))
if minimap is not None:
rows.append(_Action("map", "🌍", "", "Open full map"))
if you:
rows.append(_Action("timemachine", "⏳", "", "Time machine — your activity"))
elif hn is not None:
rows.append(_Action("timemachine", "⏳", "", f"Time machine — {hn.count} receptions"))
rows.append(_Action("back", "", "", "Back"))
return rows
# -- the tabs (only the views that have content) and their action rows.
tabs: list[_Tab] = []
if minimap is not None:
tabs.append(_Tab(name="Map", kind="map"))
if routes_view is not None:
tabs.append(_Tab(name="Routes", kind="routes"))
open_map_action = _Action("map", "🌍", "", "Open full map") if minimap is not None else None
trace_action: Optional[_Action] = None
if not you and node_id:
trace_action = _Action("trace", "🎯", "", _trace_label(routes_view))
tail_actions: list[_Action] = []
if you:
tail_actions.append(_Action("timemachine", "⏳", "", "Time machine — your activity"))
elif hn is not None:
tail_actions.append(_Action("timemachine", "⏳", "", f"Time machine — {hn.count} receptions"))
tail_actions.append(_Action("back", "", "", "Back"))
title = f"Node — {label}" if not you else f"Node — {label} (you)"
while True:
@@ -571,16 +778,19 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> N
title=title,
header=header,
info_rows=info_rows,
actions=build_actions(),
tabs=tabs,
minimap=minimap,
map_caption=map_caption,
path=path,
routes=routes_view,
open_map_action=open_map_action,
trace_action=trace_action,
tail_actions=tail_actions,
)
action = await session.run_screen(screen)
if action is CANCEL or action is None:
break
if action == "trace":
await open_trace(ctx, name or key, initial_spec=suggested_spec)
await open_trace(ctx, name or key, initial_spec=screen.selected_spec())
elif action == "map":
if markers:
await open_map(ctx, markers)
@@ -614,66 +824,65 @@ def _signal_row(hn) -> Optional[Text]: # noqa: ANN001 - Optional[HeardNode]
return text if text.plain else None
def _route_row(
device_route: Optional[tuple[str, ...]], *, resolve, self_name: Optional[str]
def _route_line(
node_label: str,
name_key: str,
hops_out: tuple[str, ...],
tag: str,
weakest: Optional[float],
samples: int,
*,
resolve,
self_name: Optional[str],
) -> Text:
"""The firmware's learned route to the node, or a note that it floods.
"""One route rendered as a full line: contact → relays → us, then its context and tag.
The hops render through THE path widget (:func:`~meshterm.ui.widgets.path_text`) at a
1-byte hash width, so each reads ``name (3d)`` — the same name the route graph prints
beside its markers, plus the short hash it travels under, so row and graph cross-read.
The whole route reads left to right in the graph's own direction (contact on the left, us
on the right), so the row and the drawn line cross-read. The contact and our own node
anchor the two ends in their own hues (the contact's key-derived, us the white ``you``);
the relays in between render through THE path widget (:func:`~meshterm.ui.widgets.path_text`)
at a 1-byte hash width, each ``name (3d)`` — the trace presentation. The bottleneck SNR
and sample count trail as muted context, and a ``★ best`` / ``device route`` tag marks the
winner and the firmware's learned route.
"""
if device_route is None:
return Text("no learned route — floods", style="muted")
if not device_route:
return Text("direct neighbour (zero-hop route)", style="")
text = Text("device route", style="accent")
text.append(" via ", style="muted")
text.append_text(_hop_path(device_route, resolve, self_name))
return text
def _suggest_row(suggested, *, resolve, self_name: Optional[str]) -> Text: # noqa: ANN001
"""The observed best path (the "suggest best path" answer), or a muted stand-in.
Like :func:`_route_row`, the hops render through THE path widget named, with a 1-byte
hash in parentheses (the short id each hop travels under); the bottleneck SNR and sample
count trail behind as context.
"""
if suggested is None:
return Text("none observed yet — trace to learn one", style="muted")
text = (
_hop_path(suggested.hops, resolve, self_name)
if suggested.hops
else Text("direct", style="brand")
text = Text()
text.append(node_label, style=name_style(node_label, name_key))
relays = path_text(
list(reversed(hops_out)), resolve, prefix_bytes=1, self_name=self_name,
empty="", show_hash=True, hash_bytes=1,
)
if suggested.weakest_snr is not None:
if relays.plain:
text.append(" → ", style="muted")
text.append_text(relays)
text.append(" → ", style="muted")
text.append(self_name or "us", style="you")
if weakest is not None:
text.append(" · weakest ", style="muted")
text.append(f"{suggested.weakest_snr:+.1f} dB", style=snr_style(suggested.weakest_snr))
if suggested.samples:
text.append(f" · {suggested.samples}×", style="muted")
text.append(f"{weakest:+.1f} dB", style=snr_style(weakest))
if samples:
text.append(f" · {samples}×", style="muted")
if tag == "best":
text.append(" ★ best", style="brand")
elif tag == "device":
text.append(" device route", style="accent")
return text
def _hop_path(hops: tuple[str, ...], resolve, self_name: Optional[str]) -> Text:
"""A hop sequence rendered through THE path widget, each hop tagged with its first byte."""
return path_text(
list(hops), resolve, prefix_bytes=1, self_name=self_name,
show_hash=True, hash_bytes=1,
)
def _trace_label(routes: Optional["_RoutesView"]) -> str:
"""The Trace action's row label — armed on the selected route, or auto with none drawn."""
if routes is not None and routes.routes:
return "Trace this route …"
return "Trace — auto route …"
def _trace_label(suggested_spec: str) -> str:
"""The Trace action's row label — naming whether it arms on a suggested path or auto."""
return "Trace target — suggested path" if suggested_spec else "Trace target — auto route"
def _path_view(
def _routes_view(
topo,
scenarios,
suggested,
device_route,
canonical_target,
target_hash,
width_bytes,
*,
resolve,
type_of,
@@ -681,8 +890,9 @@ def _path_view(
style,
self_name,
node_label,
) -> _PathView:
"""Build the route-graph layers (node → us) and their draw callbacks, or a muted note.
name_key,
) -> _RoutesView:
"""Build the Routes tab's selectable routes (node → us) + graph callbacks, or a muted note.
The routes are drawn contact-on-the-left to us-on-the-right — the *inbound* direction the
packets travelled to reach us, since everything the graph knows was received, not sent.
@@ -690,29 +900,34 @@ def _path_view(
already draws (it was built for the Message paths view, where traffic arrives *at* us on
the right), so we hand it the target as its ``source`` — the left endpoint — and use its
callbacks as they come, only reversing each route's hop order so the drawn line runs from
the contact inward to us. The best-evidence route (the observed suggestion, else the
firmware's learned route) is lit white over the alternatives' grey.
the contact inward to us.
Only *good* alternatives are drawn: an observed route is kept as grey when its evidence is
both **fresh** (its stalest hop heard within :data:`_PATH_STALE_DAYS`) and **not an
outlier** (its score within :data:`_PATH_OUTLIER_RATIO` of the strongest observed one) —
so the graph shows the routes worth trusting rather than every chain ever heard. The
best-evidence route is always drawn, stale or not: it is the page's answer to how we'd
reach the node, not one of the alternatives being weighed. With no route evidence at all —
no learned route, no observed path, not even a direct link — there is nothing honest to
draw, so a muted note stands in.
The selectable list, strongest first, folds the old ``route`` / ``suggest`` info rows into
the tab: the best-evidence route (the observed suggestion, else the firmware's learned
route, else a bare direct shot), then the firmware's learned route when it is something
different, then the *good* observed alternatives. Only good alternatives are kept: an
observed route survives when its evidence is both **fresh** (its stalest hop heard within
:data:`_PATH_STALE_DAYS`) and **not an outlier** (its score within
:data:`_PATH_OUTLIER_RATIO` of the strongest observed one) — so the list is the routes
worth trusting rather than every chain ever heard. With no route evidence at all — no
learned route, no observed path, not even a direct link — there is nothing honest to draw,
so a muted note stands in and the tab still offers an auto trace.
Which route lights white (and which nodes keep their name hue) is the screen's live
selection, applied per render; this only assembles the routes and the base callbacks.
"""
from ..services.topology import render_forced_spec
if canonical_target is None:
return _PathView(note="no key to route to")
return _RoutesView(note="no key to route to")
has_evidence = (
device_route is not None
or any(s.source == "observed" for s in scenarios)
or topo.link(topo.self_id, canonical_target) is not None
)
if not has_evidence:
return _PathView(note="no route observed yet — trace to discover one")
return _RoutesView(note="no route observed yet — trace to discover one")
white, grey = (255, 255, 255), (120, 120, 120)
best_hops = (
suggested.hops if suggested is not None
else device_route if device_route is not None
@@ -722,32 +937,46 @@ def _path_view(
# the straight zero-hop shot — so the graph shows the direct link rather than a bare note.
if best_hops is None and topo.link(topo.self_id, canonical_target) is not None:
best_hops = ()
layers: list[PathLayer] = []
# The ordered, de-duplicated selectable routes (outbound hops us → target).
entries: list[tuple[tuple[str, ...], str, Optional[float], int]] = []
seen: set[tuple[str, ...]] = set()
def add(hops: tuple[str, ...], priority: int, color: tuple[int, int, int]) -> None:
# Reverse the outbound (us-outward) hop order into inbound (node→us) draw order, so
# the contact lands on the left endpoint and our star on the right.
drawn = tuple(reversed(hops))
if drawn in seen:
def add(hops_out: tuple[str, ...], tag: str, weakest: Optional[float], samples: int) -> None:
key = tuple(hops_out)
if key in seen:
return
seen.add(drawn)
layers.append(PathLayer(hops=drawn, color=color, priority=priority))
seen.add(key)
entries.append((key, tag, weakest, samples))
if best_hops is not None:
add(best_hops, 3, white)
if suggested is not None:
add(best_hops, "best", suggested.weakest_snr, suggested.samples)
else:
add(best_hops, "best", None, 0)
if device_route is not None:
add(device_route, "device", None, 0)
for scenario in _good_alternatives(topo, scenarios, canonical_target):
add(scenario.hops, 2, grey)
add(scenario.hops, "", scenario.weakest_snr, scenario.samples)
routes: list[_Route] = []
for hops_out, tag, weakest, samples in entries:
spec = render_forced_spec(hops_out, target_hash, width_bytes) if target_hash else ""
row = _route_line(
node_label, name_key, hops_out, tag, weakest, samples,
resolve=resolve, self_name=self_name,
)
routes.append(_Route(draw=tuple(reversed(hops_out)), spec=spec, row=row))
glyph_of, byte_label_of, label_rgb_of = style(
resolve=resolve, self_name=self_name, source=node_label, type_of=type_of, key_of=key_of
)
# This page names every node, not just the two ends. Where the Message paths graph tags
# a relay with only its first hash byte, here each relay wears its resolved contact name
# (its colour is already the name's hue), so the whole route reads as places rather than
# hex; an unidentified relay keeps the byte, the honest most it can be called. The two
# endpoints keep route_graph_style's names (target on the left, us on the right).
# This tab names every node in the graph, not just the two ends. Where the Message paths
# graph tags a relay with only its first hash byte, here each relay wears its resolved
# contact name (its colour is already the name's hue), so the whole route reads as places
# rather than hex; an unidentified relay keeps the byte, the honest most it can be called.
# The two endpoints keep route_graph_style's names (target on the left, us on the right).
def label_of(node: str) -> Optional[str]:
if node in (SRC_NODE, DST_NODE):
return byte_label_of(node)
@@ -761,9 +990,9 @@ def _path_view(
glyph_of = _with_target_glyph(
glyph_of, _NODE_GLYPHS.get(type_of(canonical_target), _DEFAULT_GLYPH)
)
legend = any(type_of(h) is not None for layer in layers for h in layer.hops)
return _PathView(
layers=layers,
legend = any(type_of(h) is not None for route in routes for h in route.draw)
return _RoutesView(
routes=routes,
glyph_of=glyph_of,
label_of=label_of,
label_rgb_of=label_rgb_of,
@@ -774,11 +1003,12 @@ def _path_view(
def _good_alternatives(topo, scenarios, target) -> list: # noqa: ANN001
"""The observed alternative routes worth drawing: fresh, evidence-backed, not outliers.
Trims the raw scenario list down to the alternatives the graph should show in grey:
Trims the raw scenario list down to the alternatives the graph should show as grey
alternatives:
* only the **observed** family (the device/direct scenarios are not routes the evidence
*observed* the node arrive over — the device route rides in white on its own when it is
the best, and a bare direct line the evidence never saw is not worth a lane);
*observed* the node arrive over — the device route rides on its own row, and a bare
direct line the evidence never saw is not worth a lane);
* only ones with real evidence behind them (a positive score — an unobserved link scores
zero, see :meth:`~meshterm.services.topology.MeshTopology._score_route`);
* only **fresh** ones — every hop heard within :data:`_PATH_STALE_DAYS`, so a route whose
+2 -1
View File
@@ -172,7 +172,8 @@ class Screen:
``right``, ``ctrl_left``, ``ctrl_right``, ``ctrl_up``, ``ctrl_down``,
``shift_up``, ``shift_down``,
``shift_left``, ``shift_right``, ``enter``, ``escape``, ``backspace``,
``delete``, ``space``, ``tab``, or ``text`` (with ``data`` set to the character).
``delete``, ``space``, ``tab``, ``shift_tab``, or ``text`` (with ``data``
set to the character).
data: The typed character when ``action`` is ``text``.
"""
if action == "escape":
+1
View File
@@ -71,6 +71,7 @@ _KEY_ACTIONS: dict[Any, str] = {
Keys.Backspace: "backspace",
Keys.Delete: "delete",
Keys.Tab: "tab",
Keys.BackTab: "shift_tab",
Keys.ControlR: "retry",
Keys.ControlP: "paths",
}
+31
View File
@@ -909,6 +909,37 @@ def node_type_legend(indent: str = "") -> Text:
return legend
def tab_strip(labels: Sequence[str], active: int) -> Text:
"""A one-line tab strip: the active view lit like a section heading, the rest muted.
THE navigation header for a screen that pages one full-height view at a time between a
handful of named views (the node detail page's ``Map`` / ``Routes``) instead of stacking
them. The active tab is drawn in the same accent ``── Label ──`` form the grouped select
lists give their section headings (:func:`~meshterm.ui.menus.section_heading`), so "the
view you are in" reads exactly like a section you have scrolled into; the inactive tabs sit
beside it muted, so the alternatives are visible without competing. A lone tab therefore
renders as a plain accent heading — the strip collapses gracefully when only one view has
content. The owning screen switches the active index (``←→``, with ``Tab``/``Shift+Tab`` as
a backup); the strip itself is pure presentation.
Args:
labels: The tab names in display order.
active: Index of the lit tab.
Returns:
A single-line :class:`~rich.text.Text` (no wrapping intended).
"""
strip = Text(no_wrap=True)
for i, label in enumerate(labels):
if i:
strip.append(" ")
if i == active:
strip.append(f"── {label} ──", style="accent")
else:
strip.append(label, style="muted")
return strip
def _contacts_legend() -> Text:
"""The node-type legend, indented to sit under the contacts table body."""
return node_type_legend(indent=" ")
+170 -125
View File
@@ -1,4 +1,4 @@
"""Node detail screen tests: the mini-map, the page render/navigation, and its helpers.
"""Node detail screen tests: the mini-map, the tabbed page, and its route/topology helpers.
The screen is a pure render-and-route view, so these drive it headless — display data is
built by hand (the way :func:`~meshterm.ui.node_detail_screen.open_node_detail` assembles
@@ -26,17 +26,19 @@ from meshterm.ui.minimap import MiniMap
from meshterm.ui.node_detail_screen import (
NodeDetailScreen,
_Action,
_PathView,
_Route,
_RoutesView,
_Tab,
_bearing,
_distance_km,
_path_view,
_range_text,
_route_row,
_route_line,
_routes_view,
_signal_row,
_suggest_row,
)
from meshterm.ui.pathgraph import DST_NODE, SRC_NODE
from meshterm.ui.tui.screen import CANCEL
from meshterm.ui.widgets import highlighted_hash, route_graph_style
from meshterm.ui.widgets import highlighted_hash, route_graph_style, tab_strip
US = "aaaaaaaaaaaa"
HUB = Contact(name="Hub", public_key="3d63c6429436" + "0" * 52, key_prefix="3d63c6429436",
@@ -119,7 +121,53 @@ def test_signal_row_summarizes_snr_and_rssi() -> None:
assert _signal_row(None) is None
# --- the topology-driven rows ---------------------------------------------------
# --- the tab strip --------------------------------------------------------------
def test_tab_strip_lights_the_active_tab_and_mutes_the_rest() -> None:
"""The active view reads as an accent section heading; the others sit beside it plain."""
strip = tab_strip(["Map", "Routes"], 1)
assert strip.plain == "Map ── Routes ──" # active tab bracketed, inactive bare
lone = tab_strip(["Routes"], 0)
assert lone.plain == "── Routes ──" # a single tab collapses to a plain heading
# --- the folded-in route line ---------------------------------------------------
def test_route_line_reads_contact_to_us_with_relays_named() -> None:
"""A route row runs contact → relays → us, each relay named and hash-tagged, tag trailing."""
resolve = make_node_resolver([HUB, FAR])
line = _route_line(
"Far", FAR.public_key, ("3d63c6429436",), "device", None, 0,
resolve=resolve, self_name="Us",
).plain
assert line.startswith("Far") # the contact anchors the left
assert "Hub" in line and "(3d)" in line # the relay named + its first-byte tag
assert line.rstrip().endswith("device route") # the firmware-route tag trails
assert "Us" in line # our own node anchors the right
def test_route_line_marks_the_best_route_and_its_context() -> None:
"""The winner wears ★ best and trails its bottleneck SNR and sample count."""
resolve = make_node_resolver([HUB, FAR])
line = _route_line(
"Far", FAR.public_key, ("3d63c6429436",), "best", 6.5, 4,
resolve=resolve, self_name="Us",
).plain
assert "★ best" in line and "weakest" in line and "6.5" in line and "4×" in line
def test_route_line_direct_route_has_no_relay() -> None:
"""A zero-hop route reads contact → us with nothing between them."""
line = _route_line(
"Far", FAR.public_key, (), "best", None, 0,
resolve=make_node_resolver([FAR]), self_name="Us",
).plain
assert "Far" in line and "Us" in line and "→" in line
# --- the routes view (list + graph callbacks) -----------------------------------
def _topo_with_route(): # noqa: ANN202
@@ -136,65 +184,43 @@ def _topo_with_route(): # noqa: ANN202
)
def test_route_and_suggest_rows_speak_the_evidence() -> None:
"""The route row names the learned route; the suggest row names the observed best path.
Both render their hops through THE path widget at a 1-byte hash width, so each hop reads
``name (3d)`` — the first-byte tag the route graph prints beside its markers.
"""
topo = _topo_with_route()
resolve = make_node_resolver([HUB, FAR])
learned = _plain([_route_row(("3d63c6429436",), resolve=resolve, self_name="Us").plain])
assert "device route" in learned and "Hub" in learned
assert "(3d)" in learned # the row tags each hop with its first hash byte
assert "floods" in _route_row(None, resolve=resolve, self_name="Us").plain # no route
best = topo.suggested("f2c24f54551e")
suggest = _suggest_row(best, resolve=resolve, self_name="Us")
assert "Hub" in suggest.plain and "(3d)" in suggest.plain and "×" in suggest.plain
assert "none observed" in _suggest_row(None, resolve=resolve, self_name="Us").plain
def test_path_view_draws_evidence_and_notes_its_absence() -> None:
"""With route evidence the graph draws node→us; without any, a muted note stands in."""
topo = _topo_with_route()
style_args = dict(
resolve=make_node_resolver([HUB, FAR]),
type_of=make_node_type_resolver([HUB, FAR]),
key_of=make_name_key_resolver([HUB, FAR]),
style=route_graph_style,
self_name="Us",
node_label="Far",
def _view(topo, suggested, device_route, target, node_label, contacts, name_key=None): # noqa: ANN001
"""Build a routes view the way :func:`open_node_detail` does, over the given evidence."""
return _routes_view(
topo, topo.scenarios(target, device_route=device_route), suggested, device_route,
target, target, 1,
resolve=make_node_resolver(contacts),
type_of=make_node_type_resolver(contacts),
key_of=make_name_key_resolver(contacts),
style=route_graph_style, self_name="Us", node_label=node_label,
name_key=name_key or (target + "0" * 52),
)
view = _path_view(
topo, topo.scenarios("f2c24f54551e", device_route=("3d63c6429436",)),
topo.suggested("f2c24f54551e"), ("3d63c6429436",), "f2c24f54551e", **style_args,
)
assert view.layers and view.glyph_of is not None # a graph, not a note
# The Hub is a repeater, so the graph earns its node-type legend.
assert view.legend is True
def test_routes_view_draws_evidence_and_notes_its_absence() -> None:
"""With route evidence the view carries selectable routes; without any, a muted note stands in."""
topo = _topo_with_route()
view = _view(topo, topo.suggested("f2c24f54551e"), ("3d63c6429436",),
"f2c24f54551e", "Far", [HUB, FAR])
assert view.routes and view.glyph_of is not None # a graph, not a note
assert view.legend is True # the Hub is a repeater, so the type legend is earned
empty = build_topology(self_id=US + "0" * 52, contacts=[FAR],
trace_paths=[], packet_paths=[], neighbour_links=[])
note = _path_view(
empty, empty.scenarios("f2c24f54551e"), None, None, "f2c24f54551e", **style_args
note = _routes_view(
empty, empty.scenarios("f2c24f54551e"), None, None, "f2c24f54551e", "f2c24f54551e", 1,
resolve=make_node_resolver([FAR]), type_of=make_node_type_resolver([FAR]),
key_of=make_name_key_resolver([FAR]), style=route_graph_style, self_name="Us",
node_label="Far", name_key=FAR.public_key,
)
assert not note.layers and "no route observed" in note.note
assert not note.routes and "no route observed" in note.note
def test_path_view_puts_the_contact_on_the_left_and_us_on_the_right() -> None:
def test_routes_view_puts_the_contact_on_the_left_and_us_on_the_right() -> None:
"""The graph reads node → us (the inbound direction): the contact on the left, our star right."""
from meshterm.ui.pathgraph import DST_NODE, SRC_NODE
topo = _topo_with_route()
view = _path_view(
topo, topo.scenarios("f2c24f54551e", device_route=("3d63c6429436",)),
topo.suggested("f2c24f54551e"), ("3d63c6429436",), "f2c24f54551e",
resolve=make_node_resolver([HUB, FAR]),
type_of=make_node_type_resolver([HUB, FAR]),
key_of=make_name_key_resolver([HUB, FAR]),
style=route_graph_style, self_name="Us", node_label="Far",
)
view = _view(topo, topo.suggested("f2c24f54551e"), ("3d63c6429436",),
"f2c24f54551e", "Far", [HUB, FAR])
assert view.label_of(SRC_NODE) == "Far" # the left endpoint is the target contact
assert view.glyph_of(DST_NODE)[0] == "★" # the right endpoint is our own star
assert view.label_of(DST_NODE) == "Us" # …labelled as us
@@ -202,24 +228,16 @@ def test_path_view_puts_the_contact_on_the_left_and_us_on_the_right() -> None:
assert view.label_of("3d63c6429436") == "Hub"
def test_path_view_relay_falls_back_to_the_hash_byte_when_unnamed() -> None:
def test_routes_view_relay_falls_back_to_the_hash_byte_when_unnamed() -> None:
"""A relay no contact can name keeps the honest first-byte tag rather than a blank."""
topo = _topo_with_route()
view = _path_view(
topo, topo.scenarios("f2c24f54551e", device_route=("abcd1234ef56",)),
None, ("abcd1234ef56",), "f2c24f54551e",
resolve=make_node_resolver([FAR]), # the relay abcd… is not among the contacts
type_of=make_node_type_resolver([FAR]),
key_of=make_name_key_resolver([FAR]),
style=route_graph_style, self_name="Us", node_label="Far",
)
view = _view(topo, None, ("abcd1234ef56",), "f2c24f54551e", "Far", [FAR])
assert view.label_of("abcd1234ef56") == "ab" # unnamed → its first hash byte
def test_path_view_target_wears_its_node_type_glyph() -> None:
def test_routes_view_target_wears_its_node_type_glyph() -> None:
"""The left endpoint draws the target's own map mark (a repeater ▲), not a plain dot."""
from meshterm.persistence.repository import TracedPath
from meshterm.ui.pathgraph import SRC_NODE
leaf = Contact(name="Leaf", public_key="27d4396a2967" + "0" * 52, key_prefix="27d4396a2967")
# Reach the Hub (a repeater) through the Leaf, so the Hub is the drawn left endpoint.
@@ -229,33 +247,36 @@ def test_path_view_target_wears_its_node_type_glyph() -> None:
]
topo = build_topology(self_id=US + "0" * 52, contacts=[HUB, leaf],
trace_paths=walks, packet_paths=[], neighbour_links=[])
view = _path_view(
topo, topo.scenarios("3d63c6429436"), topo.suggested("3d63c6429436"),
None, "3d63c6429436",
resolve=make_node_resolver([HUB, leaf]),
type_of=make_node_type_resolver([HUB, leaf]),
key_of=make_name_key_resolver([HUB, leaf]),
style=route_graph_style, self_name="Us", node_label="Hub",
)
view = _view(topo, topo.suggested("3d63c6429436"), None, "3d63c6429436", "Hub",
[HUB, leaf], name_key=HUB.public_key)
assert view.glyph_of(SRC_NODE)[0] == "▲" # the repeater target keeps its own glyph
def test_path_view_draws_routes_inbound_reversing_the_hop_order() -> None:
def test_routes_view_draws_routes_inbound_reversing_the_hop_order() -> None:
"""A drawn route runs node → us: the outbound (us-outward) hops reverse into inbound order."""
r1 = Contact(name="R1", public_key="111111111111" + "0" * 52, key_prefix="111111111111")
r2 = Contact(name="R2", public_key="222222222222" + "0" * 52, key_prefix="222222222222")
topo = build_topology(self_id=US + "0" * 52, contacts=[r1, r2, FAR],
trace_paths=[], packet_paths=[], neighbour_links=[])
route = ("111111111111", "222222222222") # us → r1 → r2 → target, outward order
view = _path_view(
topo, topo.scenarios("f2c24f54551e", device_route=route), None, route, "f2c24f54551e",
resolve=make_node_resolver([r1, r2, FAR]),
type_of=make_node_type_resolver([r1, r2, FAR]),
key_of=make_name_key_resolver([r1, r2, FAR]),
style=route_graph_style, self_name="Us", node_label="Far",
)
view = _view(topo, None, route, "f2c24f54551e", "Far", [r1, r2, FAR])
# Drawn contact→us, so the relay nearest the target leads and the one nearest us trails.
assert view.layers[0].hops == ("222222222222", "111111111111")
assert view.routes[0].draw == ("222222222222", "111111111111")
def test_routes_view_draws_a_direct_line_for_a_bare_neighbour() -> None:
"""A node only ever heard directly still draws its zero-hop line, not a muted note."""
from meshterm.persistence.repository import PacketPath
# A single overheard frame straight from Far to us — a direct link, no relays, no route.
topo = build_topology(
self_id=US + "0" * 52, contacts=[FAR],
trace_paths=[],
packet_paths=[PacketPath(when=utcnow(), origin="f2c24f54551e", hops=[], snr=6.0)],
neighbour_links=[],
)
view = _view(topo, topo.suggested("f2c24f54551e"), None, "f2c24f54551e", "Far", [FAR])
assert view.routes and view.routes[0].draw == () # a straight endpoint-to-endpoint line
def _topo_two_alternatives(): # noqa: ANN202
@@ -289,28 +310,6 @@ def test_good_alternatives_keeps_observed_routes_and_drops_outliers() -> None:
assert () not in kept # the bare direct family is never a grey lane
def test_path_view_draws_a_direct_line_for_a_bare_neighbour() -> None:
"""A node only ever heard directly still draws its zero-hop line, not a muted note."""
from meshterm.persistence.repository import PacketPath
# A single overheard frame straight from Far to us — a direct link, no relays, no route.
topo = build_topology(
self_id=US + "0" * 52, contacts=[FAR],
trace_paths=[],
packet_paths=[PacketPath(when=utcnow(), origin="f2c24f54551e", hops=[], snr=6.0)],
neighbour_links=[],
)
view = _path_view(
topo, topo.scenarios("f2c24f54551e"), topo.suggested("f2c24f54551e"),
None, "f2c24f54551e",
resolve=make_node_resolver([FAR]),
type_of=make_node_type_resolver([FAR]),
key_of=make_name_key_resolver([FAR]),
style=route_graph_style, self_name="Us", node_label="Far",
)
assert view.layers and view.layers[0].hops == () # a straight endpoint-to-endpoint line
def test_route_freshness_drops_a_route_with_a_long_quiet_hop() -> None:
"""A route counts as stale — and is dropped — once its stalest hop goes quiet past the horizon."""
from datetime import timedelta
@@ -347,40 +346,46 @@ def test_located_accepts_real_fixes_and_rejects_junk() -> None:
# --- the screen -----------------------------------------------------------------
def _screen(**over) -> NodeDetailScreen:
"""A node detail screen over hand-built display data (no map, a bare path note)."""
def _header() -> Text:
header = Text("▲ ", style="#a78bfa")
header.append("Hub", style="accent")
header.append(" repeater", style="muted")
return header
def _screen(**over) -> NodeDetailScreen:
"""A node detail screen over hand-built display data (a Routes tab with a bare note)."""
kwargs = dict(
title="Node — Hub",
header=header,
header=_header(),
info_rows=[
("key", highlighted_hash("3d63c6429436" + "0" * 52, 1)),
("heard", Text("5m ago")),
("packets", Text("42")),
],
actions=[
_Action("trace", "🎯", "", "Trace target — suggested path"),
tabs=[_Tab("Routes", "routes")],
minimap=None,
map_caption=None,
routes=_RoutesView(note="no route observed yet — trace to discover one"),
open_map_action=None,
trace_action=_Action("trace", "🎯", "", "Trace — auto route …"),
tail_actions=[
_Action("timemachine", "⏳", "", "Time machine — 42 receptions"),
_Action("back", "", "", "Back"),
],
minimap=None,
map_caption=None,
path=_PathView(note="no route observed yet — trace to discover one"),
)
kwargs.update(over)
return NodeDetailScreen(**kwargs)
def test_node_detail_screen_renders_its_sections() -> None:
"""The page shows identity, info, the path section, and the action rows."""
"""The page shows identity, info, the active tab, its stage, and the action rows."""
screen = _screen()
body = _plain(screen.render_body(72))
assert "Hub" in body and "repeater" in body # identity
assert "42" in body # a packet tally from the info block
assert "Routes heard" in body and "no route observed yet" in body
assert "Trace target" in body and "Time machine" in body and "Back" in body
assert "── Routes ──" in body and "no route observed yet" in body # the tab + its stage
assert "Trace" in body and "Time machine" in body and "Back" in body
# Every rendered line fits the 72-column standard.
for line in screen.render_body(72):
assert len(_plain([line])) <= 72
@@ -388,12 +393,12 @@ def test_node_detail_screen_renders_its_sections() -> None:
def test_node_detail_screen_cursor_and_commit() -> None:
"""↑/↓ move the action cursor (pinned in view); Enter resolves its key, Esc cancels."""
"""↑/↓ move the cursor (pinned in view); Enter resolves its key, Esc cancels."""
screen = _screen()
resolved: list = []
screen.resolve = lambda value: resolved.append(value) # type: ignore[method-assign]
# Opens un-pinned (top visible) with the cursor on the first action.
# Opens un-pinned (top visible) with the cursor on the first row (the Trace action).
assert screen.cursor_line() is None
screen.render_body(72)
screen.handle("down") # onto "Time machine"
@@ -406,14 +411,54 @@ def test_node_detail_screen_cursor_and_commit() -> None:
assert resolved == ["timemachine", CANCEL]
def test_node_detail_screen_includes_the_location_section_with_a_map() -> None:
"""A located node draws the Location heading and the inline preview under it."""
def test_node_detail_screen_route_selection_arms_the_trace() -> None:
"""↑/↓ over the route rows moves the graph highlight and the spec a Trace would arm on."""
routes = _RoutesView(
routes=[
_Route(draw=("3d63c6429436",), spec="3d,f2,3d", row=Text("via Hub")),
_Route(draw=("a1a1a1a1a1a1",), spec="a1,f2,a1", row=Text("via Alt")),
],
glyph_of=lambda n: ("●", "#ffffff"),
label_of=lambda n: n[:2],
label_rgb_of=lambda n: (200, 200, 200),
)
screen = _screen(routes=routes)
# Focusables: route 0, route 1, Trace, Time machine, Back. The best route arms by default.
assert screen.selected_spec() == "3d,f2,3d"
screen.handle("down") # onto route 1
assert screen._route_sel == 1 and screen.selected_spec() == "a1,f2,a1"
screen.handle("down") # onto the Trace action — the pick holds
assert screen.selected_spec() == "a1,f2,a1"
body = _plain(screen.render_body(72))
assert "via Hub" in body and "via Alt" in body # both route rows drew
def test_node_detail_screen_tabs_switch_the_stage() -> None:
"""←→ (and Tab) swap which view fills the stage; the footer offers the switch only then."""
mini = MiniMap(
_FakeSession(), _OfflineSource(), 14,
center_lat=45.5, center_lon=-73.6, zoom=13,
markers=[MapMarker(label="Hub", lat=45.5, lon=-73.6, key="3d63aa")],
)
screen = _screen(minimap=mini, map_caption=Text("Hub · centred here", style="faint"))
screen = _screen(
tabs=[_Tab("Map", "map"), _Tab("Routes", "routes")],
minimap=mini,
map_caption=Text("Hub · centred here", style="faint"),
)
assert "←→ tab" in screen.footer_hint # two tabs, so the switch is advertised
# Opens on the Map tab: its preview and caption show, and its braille edge gets scrubbed.
body = _plain(screen.render_body(72))
assert "Location" in body and "centred here" in body
assert screen.consume_edge_scrub() == 2 # the braille edge gets scrubbed
assert "── Map ──" in body and "centred here" in body
assert screen.consume_edge_scrub() == 2
screen.handle("right") # switch to the Routes tab
body = _plain(screen.render_body(72))
assert "── Routes ──" in body and "no route observed yet" in body
assert screen.consume_edge_scrub() == 0 # the map isn't the showing tab now
def test_node_detail_single_tab_hides_the_switch_hint() -> None:
"""A page with only one view drops the ←→ tab atom from its footer."""
screen = _screen() # a lone Routes tab
assert "←→ tab" not in screen.footer_hint
assert "↑↓ move" in screen.footer_hint and screen.footer_hint.endswith("Esc back")