In a chat, our messages go under our name
A channel, a direct chat, a room, and the Messages list show our messages under "★ Name" instead of the bare star. The chip has our key's hue turned over: dark ink on a light fill, where each other sender is light on dark. A mention of our name takes the same chip, as "★ @Name". The PicoCalc cannot draw a light background, so there the chip keeps the normal colours and the star marks it. Path lines keep the bare star. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
488db7f278
commit
a19eadd81b
11 files changed
+312
-57
No files matched your search
+57
-21
@@ -58,7 +58,7 @@ from ..services.trace_runner import (
|
||||
from ..ui import renderers
|
||||
from ..ui.fields import ChannelRef, NodeRef
|
||||
from ..ui.menus import Lane, column_header, fit_cells, section_heading
|
||||
from ..ui.pathline import SELF_GLYPH, PathHop
|
||||
from ..ui.pathline import PathHop
|
||||
from ..ui.termfont import powerline_enabled
|
||||
from ..ui.theme import name_style
|
||||
from ..ui.tui import Choice, DeleteRequest, Separator
|
||||
@@ -71,6 +71,7 @@ from ..ui.widgets import (
|
||||
format_age,
|
||||
hop_chip,
|
||||
name_chip,
|
||||
self_chip,
|
||||
)
|
||||
from .base import Tool, ToolResult, register
|
||||
|
||||
@@ -230,6 +231,10 @@ class ChatTool(Tool):
|
||||
stored_names, named_at = ctx.repo.node_names_with_times()
|
||||
key_of = make_name_key_resolver(contacts, stored_names, heard=named_at)
|
||||
name_of = make_node_resolver(contacts, stored_names)
|
||||
# Our name and key, for our own messages and the mentions of us in the previews.
|
||||
from ..ui.chat import our_node
|
||||
|
||||
us = await our_node(ctx)
|
||||
|
||||
# List the contacts by recency: first the contacts with messages, with the newest
|
||||
# exchange at the top. Then the contacts with no messages, in alphabetical order
|
||||
@@ -253,7 +258,7 @@ class ChatTool(Tool):
|
||||
for conversation in channels:
|
||||
items.append(
|
||||
Choice(
|
||||
title=_row_title(ctx, conversation, live, key_of, lanes),
|
||||
title=_row_title(ctx, conversation, live, key_of, lanes, us=us),
|
||||
value=conversation,
|
||||
# ←→ move only the message. The lanes before it stay (_Lanes.head).
|
||||
hscroll_from=lanes.head,
|
||||
@@ -264,7 +269,9 @@ class ChatTool(Tool):
|
||||
for conversation in rooms:
|
||||
items.append(
|
||||
Choice(
|
||||
title=_row_title(ctx, conversation, live, key_of, lanes, name_of=name_of),
|
||||
title=_row_title(
|
||||
ctx, conversation, live, key_of, lanes, name_of=name_of, us=us
|
||||
),
|
||||
value=conversation,
|
||||
deletable=lasts.get(conversation.key) is not None,
|
||||
hscroll_from=lanes.head,
|
||||
@@ -280,7 +287,7 @@ class ChatTool(Tool):
|
||||
for conversation in direct:
|
||||
items.append(
|
||||
Choice(
|
||||
title=_row_title(ctx, conversation, live, key_of, lanes),
|
||||
title=_row_title(ctx, conversation, live, key_of, lanes, us=us),
|
||||
value=conversation,
|
||||
# Del offers to delete the stored history of this thread, only
|
||||
# where there is history to delete.
|
||||
@@ -895,6 +902,7 @@ def _row_title(
|
||||
lanes: _Lanes,
|
||||
*,
|
||||
name_of: NodeResolver | None = None,
|
||||
us: tuple[str | None, str | None] = (None, None),
|
||||
) -> Callable[[], str | Text]:
|
||||
"""Return the row title as a *callable* that the select screen renders on each paint.
|
||||
|
||||
@@ -911,11 +919,13 @@ def _row_title(
|
||||
key_of: Maps a sender name back to the key of its node, for the hues of the preview.
|
||||
lanes: The measured lane widths of the list.
|
||||
name_of: Maps the author key of a room post to a name (only for rooms).
|
||||
us: The name and the key of our node (refer to
|
||||
:func:`~meshterm.ui.chat.our_node`), for our own chip in the preview.
|
||||
|
||||
Returns:
|
||||
A callable with no arguments, which makes the current row title.
|
||||
"""
|
||||
return lambda: _title(ctx, conversation, lasts, key_of, lanes, name_of=name_of)
|
||||
return lambda: _title(ctx, conversation, lasts, key_of, lanes, name_of=name_of, us=us)
|
||||
|
||||
|
||||
def _title(
|
||||
@@ -926,6 +936,7 @@ def _title(
|
||||
lanes: _Lanes,
|
||||
*,
|
||||
name_of: NodeResolver | None = None,
|
||||
us: tuple[str | None, str | None] = (None, None),
|
||||
) -> str | Text:
|
||||
"""Make a picker row from lanes of fixed width, with colour codes.
|
||||
|
||||
@@ -951,6 +962,7 @@ def _title(
|
||||
node.
|
||||
lanes: The measured lane widths of the list.
|
||||
name_of: Maps the author key of a room post to a name (only for rooms).
|
||||
us: The name and the key of our node, for our own chip in the preview.
|
||||
|
||||
Returns:
|
||||
The row title as a styled :class:`~rich.text.Text`.
|
||||
@@ -979,7 +991,7 @@ def _title(
|
||||
text.append(f"{age:>{_AGE_WIDTH}}", style="muted")
|
||||
text.append(" ")
|
||||
if last is not None:
|
||||
text.append_text(_preview_text(last, key_of, name_of))
|
||||
text.append_text(_preview_text(last, key_of, name_of, us=us))
|
||||
return text
|
||||
|
||||
|
||||
@@ -1025,13 +1037,18 @@ def _append_marker(
|
||||
|
||||
|
||||
def _preview_text(
|
||||
last: ChatMessage, key_of: NameKeyResolver, name_of: NodeResolver | None = None
|
||||
last: ChatMessage,
|
||||
key_of: NameKeyResolver,
|
||||
name_of: NodeResolver | None = None,
|
||||
*,
|
||||
us: tuple[str | None, str | None] = (None, None),
|
||||
) -> Text:
|
||||
"""A muted preview of the last message, with sender names and ``@mentions`` lit in their hue.
|
||||
|
||||
It is the same as the live transcript:
|
||||
|
||||
- Our own messages start with our author (refer to :func:`_append_author`).
|
||||
- Our own messages start with our chip, ``★ Name`` turned over, and a mention of our
|
||||
name takes the same chip (refer to :func:`~meshterm.ui.widgets.self_chip`).
|
||||
- In a received channel message, the inline ``Name:`` sender is the author, in the hue
|
||||
that comes from its key (the node grey when no known node has the name).
|
||||
- A room post starts with its author, named by key in the same way as the room screen
|
||||
@@ -1050,29 +1067,39 @@ def _preview_text(
|
||||
body_raw = last.text.replace("\n", " ")
|
||||
text = Text()
|
||||
if last.outbound:
|
||||
_append_author(text, PathHop(SELF_GLYPH, you=True), Text("you: ", style="accent"))
|
||||
_append_body(text, body_raw, key_of)
|
||||
name, key = us
|
||||
chip = self_chip(name, key, role=ORIGIN)
|
||||
# Where no chips are drawn, the chip is a block in reverse video. Our node with no
|
||||
# name keeps the old byline.
|
||||
byline = chip + Text(" ") if name and key else Text("you: ", style="accent")
|
||||
_append_author(text, chip, byline)
|
||||
_append_body(text, body_raw, key_of, us)
|
||||
elif last.is_channel:
|
||||
name, body = split_channel_sender(body_raw)
|
||||
if name is not None:
|
||||
key = key_of(name)
|
||||
_append_author(text, PathHop(name, key=key), _byline(name, key))
|
||||
_append_body(text, body, key_of)
|
||||
_append_author(text, _origin(name, key), _byline(name, key))
|
||||
_append_body(text, body, key_of, us)
|
||||
else:
|
||||
_append_body(text, body_raw, key_of)
|
||||
elif last.author and name_of is not None:
|
||||
from ..ui.room import author_label
|
||||
|
||||
name, key = author_label(last.author, name_of)
|
||||
_append_author(text, PathHop(name, key=key), _byline(name, key))
|
||||
_append_body(text, body_raw, key_of)
|
||||
_append_author(text, _origin(name, key), _byline(name, key))
|
||||
_append_body(text, body_raw, key_of, us)
|
||||
else:
|
||||
_append_body(text, body_raw, key_of)
|
||||
_append_body(text, body_raw, key_of, us)
|
||||
return text
|
||||
|
||||
|
||||
def _append_author(text: Text, hop: PathHop, byline: Text) -> None:
|
||||
"""Append the author of a preview: an origin chip where chips are drawn, else ``byline``.
|
||||
def _origin(name: str, key: str | None) -> Text:
|
||||
"""The chip of the author of a preview: it closes on the point, as in the transcript."""
|
||||
return hop_chip(PathHop(name, key=key), role=ORIGIN)
|
||||
|
||||
|
||||
def _append_author(text: Text, chip: Text, byline: Text) -> None:
|
||||
"""Append the author of a preview: its origin ``chip`` where chips are drawn, else ``byline``.
|
||||
|
||||
The chip closes on the point, the same as the sender chip of the transcript, and the
|
||||
body follows it after one space. The point says what the colon of ``Name:`` says, so
|
||||
@@ -1080,7 +1107,7 @@ def _append_author(text: Text, hop: PathHop, byline: Text) -> None:
|
||||
``byline`` (``Name: ``, or ``you: `` for us), as it always was (JP, 2026-10-10).
|
||||
"""
|
||||
if powerline_enabled():
|
||||
text.append_text(hop_chip(hop, role=ORIGIN))
|
||||
text.append_text(chip)
|
||||
text.append(" ")
|
||||
else:
|
||||
text.append_text(byline)
|
||||
@@ -1093,19 +1120,28 @@ def _byline(name: str, key: str | None) -> Text:
|
||||
return text
|
||||
|
||||
|
||||
def _append_body(text: Text, body: str, key_of: NameKeyResolver) -> None:
|
||||
def _append_body(
|
||||
text: Text,
|
||||
body: str,
|
||||
key_of: NameKeyResolver,
|
||||
us: tuple[str | None, str | None] = (None, None),
|
||||
) -> None:
|
||||
"""Append ``body`` to ``text``, muted, and light the names that it mentions.
|
||||
|
||||
Each ``@[Name]`` is drawn in the hue that comes from the key of that node, as a chip
|
||||
that opens on the notch where the terminal draws chips (the same as in the transcript).
|
||||
It takes the node grey when the name resolves to no node that we know.
|
||||
It takes the node grey when the name resolves to no node that we know. A mention of our
|
||||
own name (``us``) takes our chip, as in the transcript.
|
||||
"""
|
||||
pos = 0
|
||||
for match in MENTION.finditer(body):
|
||||
if match.start() > pos:
|
||||
text.append(body[pos : match.start()], style="muted")
|
||||
name = match.group(1)
|
||||
text.append_text(name_chip(f"@{name}", key_of(name), role=DESTINATION))
|
||||
if us[0] and name == us[0]:
|
||||
text.append_text(self_chip(name, us[1], mention=True, role=DESTINATION))
|
||||
else:
|
||||
text.append_text(name_chip(f"@{name}", key_of(name), role=DESTINATION))
|
||||
pos = match.end()
|
||||
if pos < len(body):
|
||||
text.append(body[pos:], style="muted")
|
||||
|
||||
+47
-18
@@ -44,7 +44,7 @@ from .tui.prompt import (
|
||||
from .tui.render import render_hanging, render_lines, right_aligned_tail
|
||||
from .tui.screen import CANCEL, Screen
|
||||
from .tui.spinner import Spinner, spinner_interval
|
||||
from .widgets import DESTINATION, ORIGIN, name_chip
|
||||
from .widgets import DESTINATION, ORIGIN, name_chip, self_chip
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..context import AppContext
|
||||
@@ -222,6 +222,8 @@ class ChatScreen(Screen):
|
||||
resend_unscoped: Callable[[ChatMessage], Awaitable[ChatMessage | None]] | None = None,
|
||||
locator: Locator | None = None,
|
||||
pages: ContactPages | None = None,
|
||||
self_name: str | None = None,
|
||||
self_key: str | None = None,
|
||||
) -> None:
|
||||
"""Build the chat screen.
|
||||
|
||||
@@ -259,8 +261,13 @@ class ChatScreen(Screen):
|
||||
pages: The contacts, for ^O: the node page of the author of the selected
|
||||
message (refer to :class:`~meshterm.ui.node_detail_screen.ContactPages`).
|
||||
With ``None``, ^O does nothing.
|
||||
self_name: The name of our node (refer to :func:`our_node`). Our messages and
|
||||
the mentions of our name show it (:func:`~meshterm.ui.widgets.self_chip`).
|
||||
self_key: Our public key, which gives the hue of that chip.
|
||||
"""
|
||||
super().__init__()
|
||||
self._self_name = self_name
|
||||
self._self_key = self_key
|
||||
self._scope = scope if conversation.is_channel else None
|
||||
self.title = f"{conversation.label} · {self._scope}" if self._scope else conversation.label
|
||||
self._is_channel = conversation.is_channel
|
||||
@@ -678,10 +685,12 @@ class ChatScreen(Screen):
|
||||
The chip makes a *label* different from the prose under it. A name alone above its
|
||||
messages then reads as a tag, not as a coloured word that a person typed. It is the
|
||||
chip of a path line (refer to :func:`~meshterm.ui.widgets.name_chip`). Thus a
|
||||
sender looks exactly like that node as a hop in a route, also for our messages:
|
||||
the ``★``, never our name.
|
||||
sender looks exactly like that node as a hop in a route.
|
||||
|
||||
Our star comes from the direction of the message (``outbound``), not from the
|
||||
Our messages are the exception. They go under our name, as ``★ Name`` on a chip
|
||||
that is turned over (refer to :func:`~meshterm.ui.widgets.self_chip`). A route
|
||||
shows our end as the bare ``★``, but a chat is a conversation between names.
|
||||
Our chip comes from the direction of the message (``outbound``), not from the
|
||||
``"you"`` label. Thus a remote sender with the name ``you`` still gets the hue of
|
||||
its key, and does not look like our node.
|
||||
|
||||
@@ -690,7 +699,7 @@ class ChatScreen(Screen):
|
||||
the other end, and it opens on the notch (refer to :meth:`_render_mentions`).
|
||||
"""
|
||||
if message.outbound:
|
||||
return name_chip("", you=True, role=ORIGIN)
|
||||
return self_chip(self._self_name, self._self_key, role=ORIGIN)
|
||||
# ``·`` is a channel line that arrived with no sender prefix: there is no key to use.
|
||||
key = None if sender == "·" else self._header_key(sender, message)
|
||||
return name_chip(sender, key, role=ORIGIN)
|
||||
@@ -783,7 +792,9 @@ class ChatScreen(Screen):
|
||||
:meth:`_begin_reply`). Here it shows as ``@Name`` in a chip of the hue of that
|
||||
node. Thus the user sees that a mention belongs to the node that it names. The text
|
||||
around the mentions keeps the base style of the line (``cursor`` when the message
|
||||
is the selected reply target, or else no style).
|
||||
is the selected reply target, or else no style). A mention of our own name takes
|
||||
our chip (:func:`~meshterm.ui.widgets.self_chip`), so that a message that names us
|
||||
is easy to see.
|
||||
|
||||
The chip opens on the notch, because the node that a mention names is the
|
||||
destination of a route that came from the sender (refer to :meth:`_group_header`,
|
||||
@@ -798,8 +809,11 @@ class ChatScreen(Screen):
|
||||
if match.start() > pos:
|
||||
text.append(body[pos : match.start()], style=base)
|
||||
name = match.group(1)
|
||||
key = self._sender_key(name, mention=True)
|
||||
text.append_text(name_chip(f"@{name}", key, role=DESTINATION))
|
||||
if self._self_name and name == self._self_name:
|
||||
chip = self_chip(name, self._self_key, mention=True, role=DESTINATION)
|
||||
else:
|
||||
chip = name_chip(f"@{name}", self._sender_key(name, mention=True), role=DESTINATION)
|
||||
text.append_text(chip)
|
||||
pos = match.end()
|
||||
if pos < len(body):
|
||||
text.append(body[pos:], style=base)
|
||||
@@ -1423,6 +1437,24 @@ class ChatScreen(Screen):
|
||||
pass
|
||||
|
||||
|
||||
async def our_node(ctx: AppContext) -> tuple[str | None, str | None]:
|
||||
"""The name and the public key of our node, from the cache of the session.
|
||||
|
||||
A chat shows them on our messages (refer to :func:`~meshterm.ui.widgets.self_chip`),
|
||||
and a direct chat names one end of each of its packets with the key. The read uses the
|
||||
cache, so it does not ask the device again.
|
||||
|
||||
Returns:
|
||||
``(name, key)``. An item is ``None`` when the device did not report it, or when the
|
||||
read failed. Our node with no name only keeps the bare ``★`` in a chat.
|
||||
"""
|
||||
try:
|
||||
info = await ctx.devstate.self_info()
|
||||
except Exception: # noqa: BLE001 - our node with no name keeps the bare star
|
||||
return None, None
|
||||
return str(info.get("name") or "") or None, str(info.get("public_key") or "") or None
|
||||
|
||||
|
||||
async def open_chat(ctx: AppContext, conversation: Conversation) -> int:
|
||||
"""Open the live chat screen for ``conversation`` and run it until the user closes it.
|
||||
|
||||
@@ -1504,6 +1536,7 @@ async def open_chat(ctx: AppContext, conversation: Conversation) -> int:
|
||||
from .node_detail_screen import ContactPages
|
||||
|
||||
paths = await _make_paths_presenter(ctx, conversation, device)
|
||||
self_name, self_key = await our_node(ctx)
|
||||
screen = ChatScreen(
|
||||
conversation,
|
||||
history,
|
||||
@@ -1517,6 +1550,8 @@ async def open_chat(ctx: AppContext, conversation: Conversation) -> int:
|
||||
resend_unscoped=resend_unscoped,
|
||||
locator=await Locator.gather(ctx),
|
||||
pages=await ContactPages.gather(ctx),
|
||||
self_name=self_name,
|
||||
self_key=self_key,
|
||||
)
|
||||
ctx.chat.set_active(conversation.key)
|
||||
|
||||
@@ -1733,16 +1768,10 @@ async def _make_paths_presenter(
|
||||
type_of = trace_runner.make_node_type_resolver(contacts)
|
||||
key_of = trace_runner.make_name_key_resolver(contacts, stored_names, heard=named_at)
|
||||
prefix_bytes = await ctx.devstate.routing_prefix_bytes()
|
||||
self_name: str | None = None
|
||||
self_key: str | None = None
|
||||
try:
|
||||
info = await ctx.devstate.self_info()
|
||||
self_name = str(info.get("name") or "") or None
|
||||
# Our key names one end of each direct packet in this conversation. The key of
|
||||
# the contact names the other end (refer to :func:`direct_arrivals`).
|
||||
self_key = str(info.get("public_key") or "") or None
|
||||
except Exception: # noqa: BLE001 - our node with no name only gets no white highlight
|
||||
self_name = None
|
||||
# Our key names one end of each direct packet in this conversation. The key of the
|
||||
# contact names the other end (refer to :func:`direct_arrivals`). Our node with no name
|
||||
# only gets no white highlight.
|
||||
self_name, self_key = await our_node(ctx)
|
||||
|
||||
secret = conversation.secret
|
||||
if conversation.is_channel and not secret and conversation.channel_idx is not None:
|
||||
|
||||
+19
-1
@@ -309,6 +309,11 @@ class PathHop:
|
||||
continues again". A chip says the opposite: that a node in the route has the
|
||||
name ``⋯``. Arrow mode does not need a special case, because a bare label
|
||||
between two arrows is already the same thing.
|
||||
inverse: Draw the chip turned over: the hue of ``key`` is the fill, and the darker
|
||||
fill of each other chip is the ink. It is our node in a chat (refer to
|
||||
:func:`~meshterm.ui.widgets.self_chip`). Arrow mode draws the label in reverse
|
||||
video, with the padding of a chip. The console of the PicoCalc has no light
|
||||
background, so there the chip keeps the colours of each other chip.
|
||||
"""
|
||||
|
||||
label: str
|
||||
@@ -320,6 +325,7 @@ class PathHop:
|
||||
style: str | None = None
|
||||
cursor: bool = False
|
||||
gap: bool = False
|
||||
inverse: bool = False
|
||||
|
||||
|
||||
def elision_hop() -> PathHop:
|
||||
@@ -1001,6 +1007,8 @@ class PathLine:
|
||||
text.append(hop.label, style="selected")
|
||||
elif hop.dim:
|
||||
text.append(hop.label, style="faint")
|
||||
elif hop.inverse and hop.key:
|
||||
text.append(f" {hop.label} ", style=f"{node_style(hop.key)} reverse")
|
||||
elif hop.style:
|
||||
text.append(hop.label, style=hop.style)
|
||||
elif hop.you:
|
||||
@@ -1201,6 +1209,10 @@ def _spectrum_colours(hop: PathHop) -> _ChipColours:
|
||||
automatic return home, a mirrored return leg). Our end must recede with the rest of
|
||||
that automatic half, and not keep its yellow among the greys. Plain mode says the same
|
||||
thing when it fades the name.
|
||||
|
||||
A chip that is turned over (``inverse``, our node in a chat) has the same two colours
|
||||
as the chip of its key, in the other order: the hue is the fill, and the dark fill is
|
||||
the ink. It is the one light chip in a chat, and the contrast of the pair stays the same.
|
||||
"""
|
||||
if hop.cursor:
|
||||
return _ChipColours(_style_hex("cursor") or _KEYLESS_BG, _CHIP_FG, _CHIP_FG)
|
||||
@@ -1209,9 +1221,11 @@ def _spectrum_colours(hop: PathHop) -> _ChipColours:
|
||||
return _ChipColours(_chip_fill(resolved), resolved, resolved)
|
||||
if hop.dim:
|
||||
return _ChipColours(_DIM_BG, _DIM_FG, _DIM_FG)
|
||||
hue = _style_hex(node_style(hop.key)) if hop.key else None
|
||||
if hop.inverse and hue:
|
||||
return _ChipColours(hue, _chip_fill(hue), _chip_fill(hue))
|
||||
if hop.you:
|
||||
return _ChipColours(_YOU_BG, _SELF_INK, _SELF_INK)
|
||||
hue = _style_hex(node_style(hop.key)) if hop.key else None
|
||||
if hue:
|
||||
return _ChipColours(_chip_fill(hue), hue, hue)
|
||||
return _ChipColours(_KEYLESS_BG, _KEYLESS_FG, _KEYLESS_FG)
|
||||
@@ -1233,6 +1247,10 @@ def _slot_colours(hop: PathHop) -> _ChipColours:
|
||||
yellow, a faded hop in the dark grey, and the slot as a white ``+`` in a break of the
|
||||
ribbon. The order of the rules is the same as on a truecolor terminal
|
||||
(:func:`_spectrum_colours`).
|
||||
|
||||
A chip that is turned over (``inverse``) keeps the colours of each other chip here. Its
|
||||
fill would be a bright slot, and the console cannot draw one as a background. In a chat,
|
||||
the ``★`` in its label still tells our node from the others.
|
||||
"""
|
||||
if hop.cursor:
|
||||
return _ChipColours(_SLOT_PAGE, _SLOT_WHITE, _SLOT_WHITE)
|
||||
|
||||
+17
-1
@@ -47,7 +47,14 @@ from ..core.models import (
|
||||
RoomAccess,
|
||||
RoomLogin,
|
||||
)
|
||||
from .chat import ChatScreen, _belongs, _contact_names, _make_paths_presenter, _with_restore
|
||||
from .chat import (
|
||||
ChatScreen,
|
||||
_belongs,
|
||||
_contact_names,
|
||||
_make_paths_presenter,
|
||||
_with_restore,
|
||||
our_node,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..context import AppContext
|
||||
@@ -141,6 +148,8 @@ class RoomScreen(ChatScreen):
|
||||
key_of: Callable[[str], str | None] | None = None,
|
||||
locator: Locator | None = None,
|
||||
pages: ContactPages | None = None,
|
||||
self_name: str | None = None,
|
||||
self_key: str | None = None,
|
||||
) -> None:
|
||||
"""Build the room screen.
|
||||
|
||||
@@ -169,6 +178,8 @@ class RoomScreen(ChatScreen):
|
||||
key_of: Gives the key of its node for a name, for the hues of ``@mention``.
|
||||
locator: The located nodes, for ^L: the map on the author of a post.
|
||||
pages: The contacts, for ^O: the node page of the author of a post.
|
||||
self_name: The name of our node, on our posts and on the mentions of us.
|
||||
self_key: Our public key, which gives the hue of that chip.
|
||||
"""
|
||||
super().__init__(
|
||||
conversation,
|
||||
@@ -181,6 +192,8 @@ class RoomScreen(ChatScreen):
|
||||
key_of=key_of,
|
||||
locator=locator,
|
||||
pages=pages,
|
||||
self_name=self_name,
|
||||
self_key=self_key,
|
||||
)
|
||||
self._label = conversation.label
|
||||
self._resolve = resolve
|
||||
@@ -425,6 +438,7 @@ async def open_room(ctx: AppContext, conversation: Conversation) -> int:
|
||||
async def join(ask: bool) -> RoomLogin | None:
|
||||
return await join_room(ctx, await fresh(), ask=ask)
|
||||
|
||||
self_name, self_key = await our_node(ctx)
|
||||
screen = RoomScreen(
|
||||
conversation,
|
||||
board,
|
||||
@@ -441,6 +455,8 @@ async def open_room(ctx: AppContext, conversation: Conversation) -> int:
|
||||
key_of=trace_runner.make_name_key_resolver(contacts, stored_names, heard=named_at),
|
||||
locator=await Locator.gather(ctx),
|
||||
pages=ContactPages(ctx, list(contacts)),
|
||||
self_name=self_name,
|
||||
self_key=self_key,
|
||||
)
|
||||
ctx.chat.set_active(conversation.key)
|
||||
|
||||
|
||||
+16
-4
@@ -20,7 +20,14 @@ from ..platforms import get_platform
|
||||
from .packet_viewer import KIND_ICONS, PAYLOAD_ICONS
|
||||
from .theme import _VT_SLOTS, fold_text, glyph, name_style, snr_style
|
||||
from .tui.fkeys import FPair, active_deck
|
||||
from .widgets import DESTINATION, ORIGIN, _recency_style, channel_glyph, name_chip
|
||||
from .widgets import (
|
||||
DESTINATION,
|
||||
ORIGIN,
|
||||
_recency_style,
|
||||
channel_glyph,
|
||||
name_chip,
|
||||
self_chip,
|
||||
)
|
||||
|
||||
#: Demonstration identities for the row of name colours: ``(name, key)``. The keys are
|
||||
#: synthetic. We chose them so that their first bytes are in three different sectors of
|
||||
@@ -28,6 +35,9 @@ from .widgets import DESTINATION, ORIGIN, _recency_style, channel_glyph, name_ch
|
||||
#: ``theme._NODE_SLOT_HEXES``).
|
||||
_DEMO_NAMES = (("Alice", "a1b2"), ("Lakeside", "3d63"), ("Lounge", "cc10"))
|
||||
|
||||
#: The key of our own node in the specimen, which gives the hue of its chat chip.
|
||||
_DEMO_SELF_KEY = "5e7f"
|
||||
|
||||
|
||||
def _palette_row() -> Text:
|
||||
"""The 16 slots as filled blocks: first the dim bank, then the bright bank.
|
||||
@@ -135,13 +145,15 @@ def specimen_lines() -> list[RenderableType]:
|
||||
# because a message goes on from its author. The mention at the end opens on the
|
||||
# notch, because the node that it names is where the message goes. The path line's
|
||||
# own segment draws them, so this row is also a one-hop sample of the route language:
|
||||
# the hue in the fill, the star for our end, and the keyless grey for a node that
|
||||
# nobody can identify.
|
||||
# the hue in the fill and the keyless grey for a node that nobody can identify. Our own
|
||||
# messages go under ``★ me``, on the one chip that is turned over (dark on a light fill
|
||||
# of our hue). The console of the PicoCalc has no light background, so there only the
|
||||
# star marks it.
|
||||
chips = Text("chips ")
|
||||
for name, key in _DEMO_NAMES[:2]:
|
||||
chips.append_text(name_chip(name, key, role=ORIGIN))
|
||||
chips.append(" ")
|
||||
chips.append_text(name_chip("", you=True, role=ORIGIN))
|
||||
chips.append_text(self_chip("me", _DEMO_SELF_KEY, role=ORIGIN))
|
||||
chips.append(" ")
|
||||
chips.append_text(name_chip("·", role=ORIGIN))
|
||||
chips.append(" ")
|
||||
|
||||
@@ -683,6 +683,40 @@ def name_chip(
|
||||
return hop_chip(hop, role=role)
|
||||
|
||||
|
||||
def self_chip(
|
||||
name: str | None, key: str | None, *, mention: bool = False, role: str | None = None
|
||||
) -> Text:
|
||||
"""Our node in a chat: ``★ Name``, in the hue of our key, on a chip that is turned over.
|
||||
|
||||
A chat (a channel, a direct chat, a room) names each sender, and our node too. A route
|
||||
shows our end as the bare ``★``, because the user never has to be told who that is. A
|
||||
chat is a conversation between names, so our messages go under our name (JP,
|
||||
2026-10-13). Two things make it different from the name of each other node. The ``★``
|
||||
of the app comes first. Also, the chip is turned over: the other senders are a light
|
||||
hue on a dark fill, and ours is dark on a light fill of our hue. The console of the
|
||||
PicoCalc cannot draw a light background, so there only the ``★`` marks us (refer to
|
||||
:attr:`~meshterm.ui.pathline.PathHop.inverse`). A mention of our name in a message
|
||||
takes the same chip, so that a message that names us is easy to see.
|
||||
|
||||
Our node with no name or no key (the device did not report them) keeps the bare ``★``
|
||||
chip of a route.
|
||||
|
||||
Args:
|
||||
name: The name of our node.
|
||||
key: Our public key, which gives the hue.
|
||||
mention: ``True`` for an ``@mention`` of our name. The label is ``★ @Name``:
|
||||
the star comes before the ``@`` (JP, 2026-10-13).
|
||||
role: :data:`ORIGIN`, :data:`DESTINATION`, or ``None``, as for :func:`name_chip`.
|
||||
|
||||
Returns:
|
||||
The chip as a one-line :class:`Text`.
|
||||
"""
|
||||
if not name or not key:
|
||||
return name_chip("", you=True, role=role)
|
||||
label = f"{SELF_GLYPH} @{name}" if mention else f"{SELF_GLYPH} {name}"
|
||||
return hop_chip(PathHop(label, key=key, inverse=True), role=role)
|
||||
|
||||
|
||||
def _shorten_hash(value: str, hash_bytes: int | None) -> str:
|
||||
"""Return ``value`` as bare hex truncated to ``hash_bytes`` bytes.
|
||||
|
||||
|
||||
Reference in new issue
Block a user