Files
MeshTerm/meshterm/ui/marks.py
T
Jean-Pierre MartineauandClaude Haiku 5.5 6e07b08c25 Managed nodes get a name, a 🔑 mark, and node page repairs
A node whose admin password MeshTerm stores is now a "managed node": a
🔑 beside the type mark in the Contacts list, the admin picker (its
first section, renamed from "Remembered admins"), and the node page
header. The menu's "Other nodes" section is now "Managed nodes".

Contacts carry adverts_refused_until: the device's stored advert time
when it is in the future, so the firmware's replay check drops every
new advert. The node page shows it and offers "Accept its adverts
again…", which rewrites the device's own record with only last_advert
lowered (Device.accept_adverts_again). A managed repeater or room gets
"Sync its clock…". The Clock drift page lists refused contacts.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-11-03 00:46:40 -05:00

86 lines
4.4 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""The shared mark constants: node-type glyphs, their colours, and path sentinels.
The spatial screens of the app (the map, the path graph, the braille rasters, and the
node rows) all mark nodes with the same marks in the same hues. Several of them need the
constants *without* the code around them. Before this module, ``ui.widgets`` put
``map_render``, ``mapcanvas``, and ``pathgraph`` on the boot path for a few tuples and
type aliases. This was approximately 60 ms of import time on the PicoCalc. Now the
constants are here, with no dependencies, and the large modules import *from* the
constants instead of holding them. ``map_render``, ``mapcanvas``, and ``pathgraph``
export their old names again, so the code that imports from those modules does not
change.
"""
from __future__ import annotations
from collections.abc import Callable
#: An ``(r, g, b)`` colour triple, 0 to 255 for each channel (the colour type of a raster
#: or a canvas).
RGB = tuple[int, int, int]
def parse_hex(color: str) -> RGB:
"""Convert ``"#rrggbb"`` (or ``"rrggbb"``) to an ``(r, g, b)`` tuple."""
c = color.lstrip("#")
return (int(c[0:2], 16), int(c[2:4], 16), int(c[4:6], 16))
# The palette of markers, shared in the whole app. Each marker is white, and its shape
# tells what it is (JP, 2026-10-14): a ``●`` for an ordinary node and a ``▲`` for a
# repeater, in the ``type.*`` white of the theme. They were pink and violet, the hues that
# a map never has. Our node is the star, in the white of ``you`` (JP, 2026-10-14). It was
# yellow, and then the hue of our key. A node that was heard but never identified is a
# light grey ring. Each glyph is in the PicoCalc console font.
#
# The colour of a mark is any value that :func:`~meshterm.ui.theme.mark_rgb` takes: a
# literal hex, or the name of a theme style when the platform must choose the shade. The
# unknown ring has a name (``node.unknown``), so that the ring and the grey label beside
# it can never be different. Our star has the name ``you``, the white of our node in each
# list, and the two type marks have their ``type.*`` names, so that the console chooses
# its own white.
SELF_MARK = ("★", "you")
REPEATER_MARK = ("▲", "type.repeater")
NODE_MARK = ("●", "type.node")
UNKNOWN_MARK = ("○", "node.unknown")
#: The only concealed character. One bullet replaces one character of a value that the
#: screen hides: a password that the user types (``ui/tui/prompt.py``), or the BLE pairing
#: PIN on the Device info page. The concept has one glyph, so a row of these glyphs has the
#: same meaning where it appears. It is *not* the ``●`` of an unread message or a node, on
#: purpose. Those marks have a meaning, and this one means "not shown".
MASK_MARK = "•"
#: The padlock of a locked contact: at the start of its row in the Contacts list, and before
#: its name on its sender chip in a chat. It is the private-channel ``🔒`` of the icon
#: lexicon, because it means the same thing (this item is closed to something). It goes
#: through :func:`~meshterm.ui.theme.glyph`, which gives the hand-drawn padlock ``⚿`` of the
#: font on the PicoCalc. An unlocked contact draws nothing. The mark is an exception that
#: the user must notice, and a lane of open padlocks makes the few closed padlocks hard to
#: see.
LOCK_ICON = "🔒"
#: The mark of a **managed node**: a node whose admin password MeshTerm stores (JP,
#: 2026-11-02). It is the ``🔑`` of a credential key in the icon lexicon, because the stored
#: password is what makes the node one that the user manages. It is in the same column as
#: the padlock in the Contacts list, before the type glyph, and on the node page next to
#: the type. :func:`~meshterm.ui.theme.glyph` gives the ``*`` of a masked secret on the
#: PicoCalc. A node that is not managed draws nothing, for the same reason as the padlock.
MANAGED_ICON = "🔑"
#: Sentinels that name the endpoints of a path on the route graph. ``\x00`` never occurs
#: in a node hash, so the sentinels can share the namespace of node ids and not collide
#: with an id.
SRC_NODE = "\x00src"
DST_NODE = "\x00dst"
#: Gives the graph marker of a node id: a ``(glyph, colour)`` pair.
GlyphOf = Callable[[str], tuple[str, str]]
#: The graph label of a node, or ``None`` or ``""`` to leave the marker bare.
LabelOf = Callable[[str], str | None]
#: The colour in which the label of a node is drawn (usually the hue of the node name).
LabelRgbOf = Callable[[str], RGB]