Pressing Enter on a contact now opens its whole story on one page instead of a bare row: identity (name in its hue, key with the routing hash lit, type, first/last heard, packet tally, reception SNR/RSSI), an inline location preview centred on the node (a small static basemap via the new MiniMap), the observed routes to it, and an action list (trace armed with the suggested best path, open full map, time machine). Contacts owns the show/open/reshow loop; topology.suggested answers "the best evidence-backed way to reach this node", wired ahead of the firmware route in the trace arming precedence. Timemachine and Trace grew the entry points the page opens. Four fixes fell out of driving it on real hardware: Slow open. Each located-node page built a fresh BasemapSource and resolved its TileJSON -- a blocking HTTPS round-trip (~100ms, up to the 12s timeout on a bad link) -- on every open. Hold one source for the session (ctx.basemap_source), shared by the map, the picker, and the preview, and warm it behind the menu at login, so the resolve is paid once, off the navigation path. Black map. A companion advertising nonsense coordinates (Homestead reports lat -97, lon -1042) flung the viewport off the world, leaving the map a screen of empty/water fill that reads as solid black -- both from "open full map" and from filtering to it and framing. The old guard only caught the 0/0 no-GPS null island; the new geo.usable_fix() rejects any out-of-range fix too, applied to the map markers and the location preview alike. Verified on-device: of 265 located contacts, only Homestead drops. Path to node. The route/suggest rows render through THE path widget with a 1-byte hash in parentheses (a "name (3d)" tag), so they cross-read hop for hop against the route graph's byte labels. Route graph. Draw us on the left and the target on the right (us to target, "how we reach it", left to right) via a local endpoint swap that leaves the shared route_graph_style untouched for its other callers, and give the fan a generous lane step and row budget so a well-connected node's candidate paths spread into separate, legible tracks instead of a cramped tangle -- the height stays adaptive, so a one- or two-route node still draws compact. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
126 lines
5.4 KiB
Python
126 lines
5.4 KiB
Python
"""The interactive Contacts screen: the device's contacts in the shared sortable contact list.
|
|
|
|
The Time Machine picker's presentation pointed at the companion's contact table: the same
|
|
aligned ``NAME · HEARD · PKTS · KEY`` lanes, our own node pinned first, the same Ctrl+arrow
|
|
sort (now including the key column) and type-to-filter — one contact list app-wide, whatever
|
|
the data source (see :mod:`~meshterm.ui.contactlist`). Enter opens the highlighted node's
|
|
full-screen Node detail page (:mod:`~meshterm.ui.node_detail_screen`) — its identity, a
|
|
location preview, the observed routes to it, and the ways in (trace, map, time machine) —
|
|
and backing out of that page returns to the list right where it stood. The one-shot CLI
|
|
(``meshterm contacts --sort …``) still renders the static
|
|
:func:`~meshterm.ui.widgets.contacts_table`; only the menu gets the live list.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .contactlist import ContactListScreen, ContactRow
|
|
from .tui.screen import CANCEL
|
|
from .widgets import ContactsSort, _contact_pkts
|
|
|
|
if TYPE_CHECKING:
|
|
from ..context import AppContext
|
|
from ..core.models import Contact
|
|
|
|
#: A stable identity for the own-node row (its lane data has no key to stand on when no
|
|
#: device answered) — Enter on it opens our own node's detail page.
|
|
YOU = ("you",)
|
|
|
|
|
|
class ContactsScreen(ContactListScreen):
|
|
"""A full-screen, Ctrl+arrow-sortable list of this node and its known contacts.
|
|
|
|
Enter resolves the highlighted row — our own node (:data:`YOU`) or a
|
|
:class:`~meshterm.core.models.Contact` — for :func:`open_contacts` to open in the
|
|
Node detail page; the shared list handles the sort, filter, and navigation.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
self_name: str,
|
|
self_key: str,
|
|
contacts: "list[Contact]",
|
|
prefix_bytes: int,
|
|
counts: dict[str, int],
|
|
sort: ContactsSort,
|
|
) -> None:
|
|
"""Create the contacts screen over already-fetched contact data.
|
|
|
|
Args:
|
|
self_name: This node's advertised name.
|
|
self_key: This node's full public key (hex); blank renders a muted ``?``.
|
|
contacts: Known contacts to list under our own node.
|
|
prefix_bytes: Path-hash width in bytes to highlight in every key.
|
|
counts: Overheard-packet counts keyed by lowercased 12-hex node id; a contact
|
|
with no entry shows a faint ``—``.
|
|
sort: The initial sort; mutated in place by the Ctrl+arrows. Its ring should
|
|
span :data:`~meshterm.ui.contactlist.SORT_COLUMNS` so the hash sort is
|
|
reachable.
|
|
"""
|
|
rows = [ContactRow(value=YOU, name=self_name, key=self_key, you=True)]
|
|
for c in contacts:
|
|
rows.append(
|
|
ContactRow(
|
|
# The contact itself is the row's identity, so Enter hands the whole
|
|
# record straight to the detail page — no re-lookup by name/key.
|
|
value=c,
|
|
name=c.name,
|
|
key=c.public_key,
|
|
node_type=c.node_type,
|
|
last_seen=c.last_seen,
|
|
count=_contact_pkts(c, counts),
|
|
)
|
|
)
|
|
super().__init__(
|
|
f"Contacts · {len(contacts)} known",
|
|
rows=rows,
|
|
prefix_bytes=prefix_bytes,
|
|
sort=sort,
|
|
)
|
|
|
|
|
|
async def open_contacts(
|
|
ctx: "AppContext",
|
|
self_name: str,
|
|
self_key: str,
|
|
contacts: "list[Contact]",
|
|
prefix_bytes: int,
|
|
counts: dict[str, int],
|
|
sort: ContactsSort,
|
|
) -> None:
|
|
"""Open the interactive contacts list; Enter opens Node detail, Esc leaves.
|
|
|
|
Runs the show/open/reshow loop: the sortable list, then whichever node's detail page
|
|
Enter commits, then the list again (same sort, the highlight kept on its row) — until
|
|
Esc backs out of the list itself.
|
|
|
|
Args:
|
|
ctx: Shared application context (must be in the interactive menu).
|
|
self_name: This node's advertised name.
|
|
self_key: This node's full public key (hex).
|
|
contacts: Known contacts to list under our own node.
|
|
prefix_bytes: Path-hash width in bytes to highlight in every key.
|
|
counts: Overheard-packet counts keyed by lowercased 12-hex node id.
|
|
sort: The initial sort (column + direction) over the shared list's ring — mutated
|
|
in place, so a re-sort survives visiting a detail page and coming back.
|
|
|
|
Raises:
|
|
RuntimeError: If called outside the interactive menu (no full-screen session).
|
|
"""
|
|
from .node_detail_screen import open_node_detail
|
|
from .surface import TuiUi
|
|
|
|
if not isinstance(ctx.ui, TuiUi): # pragma: no cover - guarded by the menu-only caller
|
|
raise RuntimeError("the interactive contacts list is only available in the menu")
|
|
session = ctx.ui.session
|
|
# One screen for the whole visit: re-running it keeps the highlight (and any sort or
|
|
# filter) on the row the user just opened a detail for, rather than snapping to the top.
|
|
screen = ContactsScreen(self_name, self_key, contacts, prefix_bytes, counts, sort)
|
|
while True:
|
|
chosen = await session.run_screen(screen)
|
|
if chosen is CANCEL or chosen is None:
|
|
return
|
|
# The own-node sentinel opens our own node's page; any other value is a Contact.
|
|
await open_node_detail(ctx, None if chosen == YOU else chosen)
|