In a channel, a DM, or a room, the chip of a sender that is a locked contact reads 🔒 Name (⚿ on the PicoCalc), in the place of the ★ on our own chip. The transcript cache now compares the locks, so a ^K or a lock from the node page redraws the chips on the next paint. The padlock is one constant, marks.LOCK_ICON, shared with the Contacts list. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
78 lines
3.9 KiB
Python
78 lines
3.9 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 = "🔒"
|
|
|
|
#: 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]
|