The pairing PIN waits to be asked for

Device info is the page you open to read your radio out to somebody, the one that
gets screenshotted into a forum thread and left up while a colleague leans over
your shoulder. Every value on it is yours to give away except one: the BLE
pairing PIN is what lets another phone onto the radio, and it was sitting in the
Identity section in plain digits alongside the node name and the coordinates.

It now draws as the field rather than the value — six mask bullets, the same
glyph a password prompt types in, promoted to marks.MASK_MARK so the two can
never drift apart. Six is the width of the *field* (the setting's own bound is
999999), not of what is in it: masking per character is right while someone is
typing and counting their own digits, and wrong for a stored secret, where it
would say how many to guess. A device that reports no PIN keeps its "?" — an
absence is not a secret, and a "?" behind bullets would promise something to
uncover.

`p` uncovers it, and `p` puts it back. A bare letter is a read-only page's idiom
for its own verb (the Time Machine's `w`) and this page has no find-as-you-type
to compete for it; the footer names what the press would do *now* — `p show PIN`,
then `p hide PIN` — and on the console the same toggle is F3, `Reveal` then
`Hide`, since the lane is the only place that platform can learn the key exists.
A device with no PIN advertises neither: the atom drops and the slot stays empty,
because the action isn't a thing on that page at all.

The page is therefore its own screen now (ui/device_info_screen.py) rather than a
generic result window, and ScrollScreen grows `replace_content` — replace_items
for a read-only body — so the toggle swaps the page under a reader who keeps
their scroll position; nothing reflows, six cells become six. The CLI has no key
to press, so `meshterm info` and `config show` print it masked and
`config get device_pin` is the way to name it deliberately: one rule, which is
that the whole-device dump never carries the PIN. The editor one menu over still
lists it plainly — you go there to change it, a row at a time, and its letters
already belong to find-as-you-type.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-05 15:13:45 -04:00
1 parent 1d951052bf
commit 42937ce411
8 files changed
+368 -10

No files matched your search

+113 -1
View File
@@ -27,11 +27,14 @@ from meshterm.ui.config_editor import (
_parse_coords,
_valid_coords,
config_table,
has_pin,
contact_share_url,
device_actions,
edit_config,
send_advert,
)
from meshterm.ui.device_info_screen import DeviceInfoScreen
from meshterm.ui.marks import MASK_MARK
from meshterm.ui.theme import active_theme
from meshterm.ui.tui.prompt import TypedConfirmDialog
from meshterm.ui.tui.screen import CANCEL
@@ -65,7 +68,7 @@ _SNAPSHOT = {
"name": "Homestead-Hub",
"adv_lat": 45.5017,
"adv_lon": -73.5673,
"pin_code": 123456,
"ble_pin": 123456,
"radio_freq": 869525,
"radio_bw": 250,
"radio_sf": 11,
@@ -146,6 +149,115 @@ def test_config_table_drops_the_description_lane_beside_a_staged_column() -> Non
assert "STAGED" in header and "DESCRIPTION" not in header
# -- the concealed pairing PIN --------------------------------------------------
class _StubSession:
"""A minimal session: the screen only ever asks it to repaint."""
def __init__(self) -> None:
self.repaints = 0
def invalidate(self) -> None:
self.repaints += 1
def _pin_row(rendered) -> str: # noqa: ANN001 - lines or an already-joined render
"""The Device PIN row out of a rendered table or screen body."""
return next(line for line in _plain(rendered).split("\n") if "Device PIN" in line)
def _info_screen(snapshot: dict) -> DeviceInfoScreen:
return DeviceInfoScreen(
_StubSession(),
lambda reveal: config_table(snapshot, {}, reveal_pin=reveal),
title="Device info",
conceals=has_pin(snapshot),
)
def test_the_pin_is_bullets_until_it_is_asked_for() -> None:
# One bullet per digit — the app's own mask glyph, the one a password prompt types in.
masked = _pin_row(_table_lines(72))
assert f"{MASK_MARK * 6}" in masked
assert "123456" not in masked
assert "123456" in _pin_row(_table_lines(72, reveal_pin=True))
def test_the_mask_shows_the_field_not_the_pins_length() -> None:
# A stored secret draws its field: a one-digit PIN behind one bullet would have told
# you how many digits to guess (and read as a stray dot besides).
short = {**_SNAPSHOT, "ble_pin": 0}
console = Console(
width=72, file=io.StringIO(), theme=active_theme(), legacy_windows=False
)
with console.capture() as capture:
console.print(config_table(short, {}))
assert MASK_MARK * 6 in _pin_row(capture.get())
def test_a_device_with_no_pin_has_nothing_to_conceal() -> None:
# "?" is an absence, not a secret: masking it would claim there is something behind it.
snapshot = {k: v for k, v in _SNAPSHOT.items() if k != "ble_pin"}
console = Console(
width=72, file=io.StringIO(), theme=active_theme(), legacy_windows=False
)
with console.capture() as capture:
console.print(config_table(snapshot, {}))
assert "?" in _pin_row(_plain(capture.get()).split("\n"))
assert not has_pin(snapshot)
def test_p_uncovers_the_pin_and_puts_it_back() -> None:
screen = _info_screen(_SNAPSHOT)
assert MASK_MARK in _pin_row(screen.render_body(72))
screen.handle("text", "p")
assert "123456" in _pin_row(screen.render_body(72))
screen.handle("text", "p") # the same key puts it away again
assert MASK_MARK in _pin_row(screen.render_body(72))
def test_the_lane_chip_and_the_key_are_one_behaviour() -> None:
# The PicoCalc's chip dispatches the action the letter does, not a second copy of it.
screen = _info_screen(_SNAPSHOT)
assert screen.fkey_lane[2].label == "Reveal"
screen.handle("reveal")
assert "123456" in _pin_row(screen.render_body(72))
assert screen.fkey_lane[2].label == "Hide"
def test_the_footer_names_what_the_press_would_do_now() -> None:
screen = _info_screen(_SNAPSHOT)
assert "p show PIN" in screen.footer_hint
screen.handle("text", "p")
assert "p hide PIN" in screen.footer_hint
def test_a_page_with_no_pin_advertises_no_key_for_it() -> None:
# The standing rule: a footer never names a key that would do nothing, and a lane slot
# for an action this screen doesn't have stays empty rather than dim.
screen = _info_screen({k: v for k, v in _SNAPSHOT.items() if k != "ble_pin"})
assert "PIN" not in screen.footer_hint
assert screen.fkey_lane[2] is None
screen.handle("text", "p")
assert screen.fkey_lane[2] is None
def test_uncovering_the_pin_keeps_the_reader_where_they_were() -> None:
# Nothing reflows — six cells become six cells — so the scroll must not jump.
screen = _info_screen(_SNAPSHOT)
screen.note_viewport(10)
screen.render_body(72)
screen.scroll_lines(8)
where = screen.scroll
screen.handle("text", "p")
assert screen.scroll == where
assert len(screen.render_body(72)) == len(_table_lines(72))
# -- contact share URL ----------------------------------------------------------
+47
View File
@@ -62,10 +62,12 @@ from meshterm.ui.about import (
support_project,
)
from meshterm.ui.chat import ChatScreen
from meshterm.ui.config_editor import config_table, has_pin
from meshterm.ui.contactlist import SORT_COLUMNS, SORT_OPENS_ASCENDING
from meshterm.ui.contacts_screen import ContactsScreen
from meshterm.ui.courier_screen import CourierOutboxScreen
from meshterm.ui.dashboard_screen import DashboardScreen
from meshterm.ui.device_info_screen import DeviceInfoScreen
from meshterm.ui.livefeed_screen import LiveFeedScreen
from meshterm.ui.map_render import MapMarker
from meshterm.ui.map_screen import MapScreen
@@ -486,6 +488,49 @@ def _tx_sweep(cols: int, rows: int) -> Screen:
return screen
#: A device snapshot shaped like a companion's, for the Device info page. Every field the
#: config table draws, including the pairing PIN it conceals.
_DEVICE_SNAPSHOT = {
"name": "Homestead-Hub",
"adv_lat": 45.5017,
"adv_lon": -73.5673,
"ble_pin": 123456,
"radio_freq": 869525,
"radio_bw": 250,
"radio_sf": 11,
"radio_cr": 5,
"tx_power": 22,
"max_tx_power": 30,
"airtime_factor": 1.0,
"rx_delay": 0.0,
"manual_add_contacts": 0,
"autoadd_config": 0,
"flood_scope": "",
"adv_loc_policy": 1,
"multi_acks": 0,
"telemetry_mode_base": 1,
"telemetry_mode_loc": 0,
"telemetry_mode_env": 0,
"path_hash_mode": 1,
}
def _device_info(cols: int, rows: int) -> Screen:
return DeviceInfoScreen(
_GallerySession(cols, rows),
lambda reveal: config_table(_DEVICE_SNAPSHOT, {}, reveal_pin=reveal),
title="Device info",
conceals=has_pin(_DEVICE_SNAPSHOT),
)
def _device_info_revealed(cols: int, rows: int) -> Screen:
# The same page after ``p``: the widest state of the row the other case masks.
screen = _device_info(cols, rows)
screen.handle("text", "p")
return screen
def _about_meshterm(cols: int, rows: int) -> Screen:
return AboutPage("About MeshTerm", about_meshterm())
@@ -522,6 +567,8 @@ _ENTRIES: list[_Entry] = [
_Entry("packet_viewer", _packet_viewer),
_Entry("trace", _trace),
_Entry("tx_sweep", _tx_sweep),
_Entry("device_info", _device_info),
_Entry("device_info_revealed", _device_info_revealed),
_Entry("about_meshterm", _about_meshterm),
_Entry("about_author", _about_author),
_Entry("join_discord", _join_discord),