diff --git a/CLAUDE.md b/CLAUDE.md index 11a29e6..4df5fe2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -462,14 +462,20 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow where the route began or ended (`PathLine(from_origin=…, to_destination=…)`, defaulting to a whole route). Arrow mode spells the same claim with the separator alone, a leading or trailing `→` with no hop on the far side of it. -- **A lone chip can stand at one end of a route it doesn't draw** (`name_chip(role=…)`). - A message goes from its author toward the nodes it names, so a chat's sender chip is an - `ORIGIN` — square (or round) on the left, the point on the right — and an `@mention` in - a body is a `DESTINATION` chip, `@` kept, opening on the notch and ending square. No - role is a node alone, square at both ends. Arrow mode ignores the role: a lone name - with a stray `→` reads as a cut route, so there the sender is its bare name and the - mention its bare `@Name`, as before. A chip in prose never breaks across lines - (`render_hanging` holds every `whole` run together, spaces and all). +- **A lone chip can stand at one end of a route it doesn't draw** (`widgets.hop_chip` / + `name_chip(role=…)`). A message goes from its author toward the nodes it names, so a + sender is an `ORIGIN` — square (or round) on the left, the point on the right — and an + `@mention` is a `DESTINATION` chip, `@` kept, opening on the notch and ending square. No + role is a node alone, square at both ends. Where it applies: the chat's sender chip and + mentions, the Messages list's preview (author chip, no colon; mentions), the packet + viewer's `from` (origin) and `to` (destination) rows around the `via` chain, the live + feed's addressed subject (`widgets.route_ends`: origin chip, one cell of page, + destination chip — never a seam, which would claim the two are neighbours), and the + courier's recipient. Arrow mode ignores the role: a lone name with a stray `→` reads as + a cut route, so there everything reads exactly as before (`Name: `, `you: `, `@Name`, + `sender → recipient`), and a lone hop carries no `PATH_INK`, so a cursor row whitens it + like any name. A chip in prose never breaks across lines (`render_hanging` holds every + `whole` run together, spaces and all). - Concept icons: 📡 advert · 🕒 clock/sync · 🔄 reboot · 💾 backup · 📂 restore · 🔑 channel/credential key · 🔐 identity/auth secret · 🔒 lock (a locked contact, a private channel) · 🔓 unlock · 🗑 clear/delete · ✎ compose/edit · diff --git a/meshterm/tools/chat.py b/meshterm/tools/chat.py index 0a3d611..8af12a3 100644 --- a/meshterm/tools/chat.py +++ b/meshterm/tools/chat.py @@ -58,9 +58,20 @@ 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.termfont import powerline_enabled from ..ui.theme import name_style from ..ui.tui import Choice, DeleteRequest, Separator -from ..ui.widgets import NODE_GLYPHS, age_seconds, channel_glyph, format_age +from ..ui.widgets import ( + DESTINATION, + NODE_GLYPHS, + ORIGIN, + age_seconds, + channel_glyph, + format_age, + hop_chip, + name_chip, +) from .base import Tool, ToolResult, register if TYPE_CHECKING: @@ -1020,14 +1031,16 @@ def _preview_text( It is the same as the live transcript: - - Our own messages get a ``you:`` prefix. - - In a received channel message, the inline ``Name:`` sender gets the hue that comes from - its key (muted when no known node has the name). + - Our own messages start with our author (refer to :func:`_append_author`). + - 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 names authors (:func:`~meshterm.ui.room.author_label`). - - Each ``@[Name]`` mention shows as a bare ``@Name``, in the same way. + - Each ``@[Name]`` mention shows as ``@Name``, in the same way (refer to + :func:`_append_body`). - Thus the list and the chat use the same colour language. + Thus the list and the chat use the same colour language, and where the terminal draws + chips, the same chips: the author closes on the point and a mention opens on the notch. The preview is made *in full*, however long the message is. Before, it was cut to a fixed 40 cells, and nothing could undo that cut. Now ←→ scroll the row. A preview that @@ -1037,13 +1050,13 @@ def _preview_text( body_raw = last.text.replace("\n", " ") text = Text() if last.outbound: - text.append("you: ", style="accent") + _append_author(text, PathHop(SELF_GLYPH, you=True), Text("you: ", style="accent")) _append_body(text, body_raw, key_of) elif last.is_channel: name, body = split_channel_sender(body_raw) if name is not None: - text.append(name, style=name_style(name, key_of(name))) - text.append(": ", style="muted") + key = key_of(name) + _append_author(text, PathHop(name, key=key), _byline(name, key)) _append_body(text, body, key_of) else: _append_body(text, body_raw, key_of) @@ -1051,26 +1064,48 @@ def _preview_text( from ..ui.room import author_label name, key = author_label(last.author, name_of) - text.append(name, style=name_style(name, key)) - text.append(": ", style="muted") + _append_author(text, PathHop(name, key=key), _byline(name, key)) _append_body(text, body_raw, key_of) else: _append_body(text, body_raw, key_of) 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``. + + 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 + the chip does not carry a colon. Where the terminal draws no chips, the author is the + ``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(" ") + else: + text.append_text(byline) + + +def _byline(name: str, key: str | None) -> Text: + """The author of a preview as text: the name in its hue, then a muted colon.""" + text = Text(name, style=name_style(name, key)) + text.append(": ", style="muted") + return text + + def _append_body(text: Text, body: str, key_of: NameKeyResolver) -> 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. It stays - muted when the name resolves to no node that we know. + 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. """ 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(f"@{name}", style=name_style(name, key_of(name))) + 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") diff --git a/meshterm/ui/courier_screen.py b/meshterm/ui/courier_screen.py index 4232875..3f3d669 100644 --- a/meshterm/ui/courier_screen.py +++ b/meshterm/ui/courier_screen.py @@ -38,9 +38,18 @@ from ..core.courier_store import DELIVERED, QUEUED, QueuedMessage from ..core.models import Contact, is_direct_messageable, utcnow from .contactlist import SORT_COLUMNS, SORT_OPENS_ASCENDING, ContactListScreen, ContactRow from .menus import icon_lane, marked_label, run_steps, section_heading +from .pathline import PathHop from .tui import CANCEL, DM_BYTE_LIMIT, Choice, SelectScreen, Separator from .watchtower_screen import contact_watch_key -from .widgets import ContactsSort, age_seconds, contact_packets, format_ago +from .widgets import ( + DESTINATION, + ContactsSort, + age_seconds, + contact_packets, + format_ago, + hop_chip, + name_chip, +) if TYPE_CHECKING: from ..context import AppContext @@ -302,9 +311,13 @@ def _entry_mark(mark: str, style: str, lane: int) -> Text: def _waiting_row(ctx: AppContext, message: QueuedMessage, lane: int = _MARK_LANE) -> Text: - """One waiting entry: the recipient, the body, and what the entry waits for.""" + """One waiting entry: the recipient, the body, and what the entry waits for. + + The recipient is the destination of the message, so it is a chip that opens on the + notch (refer to :func:`~meshterm.ui.widgets.hop_chip`), in the hue of its key. + """ row = _entry_mark("⏳", "warn", lane) - row.append(message.node_name) + row.append_text(name_chip(message.node_name, message.node_key, role=DESTINATION)) row.append(f" “{_shorten(message.text)}”", style="muted") row.append(" · ", style="muted") now = utcnow() @@ -327,12 +340,16 @@ def _waiting_row(ctx: AppContext, message: QueuedMessage, lane: int = _MARK_LANE def _done_row(message: QueuedMessage, lane: int = _MARK_LANE) -> Text: - """One finished entry: the outcome mark, the recipient, the body, and when it ended.""" + """One finished entry: the outcome mark, the recipient, the body, and when it ended. + + The recipient is a destination chip, the same as in the outbox. But a finished entry is + history, and all of its row is muted. Thus the chip is muted too. + """ if message.status == DELIVERED: row = _entry_mark("✓", "ok", lane) else: row = _entry_mark("✗", "err", lane) - row.append(message.node_name, style="muted") + row.append_text(hop_chip(PathHop(message.node_name, style="muted"), role=DESTINATION)) row.append(f" “{_shorten(message.text)}”", style="muted") when = message.finished or message.created verb = "delivered" if message.status == DELIVERED else "gave up" diff --git a/meshterm/ui/livefeed_screen.py b/meshterm/ui/livefeed_screen.py index e87d1cb..7135b78 100644 --- a/meshterm/ui/livefeed_screen.py +++ b/meshterm/ui/livefeed_screen.py @@ -95,11 +95,11 @@ from .packet_viewer import ( node_label, unnamed_scope, ) -from .pathline import SELF_GLYPH, PathHop, PathLine +from .pathline import SELF_GLYPH, PathHop, cut_to from .theme import name_style, snr_style from .tui.render import crop_cells, render_to_ansi from .tui.screen import ListWindow, Screen -from .widgets import NameKeyResolver, TypeOf, scope_text +from .widgets import NameKeyResolver, TypeOf, route_ends, scope_text if TYPE_CHECKING: from ..context import AppContext @@ -781,7 +781,8 @@ class LiveFeedScreen(Screen): (:func:`~meshterm.core.channels.identify_channel`). A channel for which we have no key shows the fingerprint that it advertises. * **direct message, request, response, returned path, anonymous request**: about - the two nodes between which it travels, drawn as ``sender → recipient`` + the two nodes between which it travels, drawn as an origin chip and a destination + chip, or as ``sender → recipient`` where the terminal draws no chips (:meth:`_endpoints`). * **ack**: about the message that it acknowledges, named by the checksum of that message. @@ -865,12 +866,14 @@ class LiveFeedScreen(Screen): def _endpoints(self, raw: dict) -> Text: """An addressed packet's subject: the two nodes between which it travels. - The subject is drawn as ``sender → recipient`` with the only hop-sequence widget - (:mod:`~meshterm.ui.pathline`). Thus the endpoints of a delivery show the same as - the hops of a route: resolved to contact names, each in the hue of its key, and - our node in white when a packet is addressed to us (or from us). The widget uses - plain arrows, not chips. This is a lane in a table row, and the padding of a chip - uses the cells that are necessary for the names. + The subject is drawn with the only hop-sequence widget (:mod:`~meshterm.ui.pathline`). + Thus the endpoints of a delivery show the same as the hops of a route: resolved to + contact names, each in the hue of its key, and our node as the ``★`` when a packet + is addressed to us (or from us). Where the terminal draws chips, the sender is an + origin chip and the recipient is a destination chip, and the relays between them + are not drawn (:func:`~meshterm.ui.widgets.route_ends`). Elsewhere the line is + ``sender → recipient``. The chips use more cells than the arrow, but the two ends of + a route read as two ends at a glance (JP, 2026-10-10). The packet names each endpoint by one byte of its key. This is the same one-byte identity that a relay hop has, with the same probability of a collision. Thus a @@ -882,18 +885,21 @@ class LiveFeedScreen(Screen): If the two names do not fit in the lane, the recipient keeps its name and the sender changes to its hash. The packet is addressed, so the recipient is the half - that gets the cells. + that gets the cells. A recipient that is still too wide is cut at the lane + (:func:`~meshterm.ui.pathline.cut_to`). A chip breaks off in its own colour, and an + arrow line ends on ``…``. """ dest = raw.get("dest_hash") or "" src = raw.get("src_key") or raw.get("src_hash") or "" if not src: return self._token("to", dest) - named = PathLine([self._hop(src), self._hop(dest)], mode="plain").text() + named = route_ends(self._hop(src), self._hop(dest)) if named.cell_len <= self._lanes.subject: return named # Too wide: the sender changes to its hash, so the recipient keeps all of its name # (or as much of it as the lane holds), and is not the half that gets cut. - return PathLine([self._hop(src, named=False), self._hop(dest)], mode="plain").text() + hashed = route_ends(self._hop(src, named=False), self._hop(dest)) + return cut_to(hashed, self._lanes.subject) def _hop(self, value: str, *, named: bool = True) -> PathHop: """One endpoint as a path hop: its contact name, or its one-byte hash in its hue. diff --git a/meshterm/ui/packet_viewer.py b/meshterm/ui/packet_viewer.py index dff916d..c1ed09b 100644 --- a/meshterm/ui/packet_viewer.py +++ b/meshterm/ui/packet_viewer.py @@ -65,19 +65,22 @@ from ..services.trace_runner import NodeResolver from .marks import SELF_MARK, UNKNOWN_MARK from .menus import SEP_COMPACT, SEP_ROOMY from .pathgraph import PathLayer, render_path_graph, revisited_hops -from .pathline import PathLine, hops_atom, path_line +from .pathline import PathHop, PathLine, hops_atom, path_line from .theme import glyph, name_style, snr_style from .trace_screen import snr_bar from .tui.render import render_lines, render_to_ansi from .tui.screen import Screen from .widgets import ( DEFAULT_GLYPH, + DESTINATION, NODE_GLYPHS, + ORIGIN, NameKeyResolver, TypeOf, age_seconds, format_ago, highlighted_hash, + hop_chip, node_type_legend, revisit_note, route_graph_style, @@ -843,7 +846,13 @@ class PacketViewer(Screen): glyph, glyph_style = self._node_marker(entry, style) who.append(glyph, style=glyph_style) who.append(" ") - who.append(label, style=style) + if style == "muted": # a bare hash: no name to put in a chip + who.append(label, style=style) + else: + # The node that sent the packet is the origin of its route. Thus it is a chip + # that closes on the point, and the ``via`` row continues that route. + hop = PathHop(label, you=True) if style == "you" else PathHop(label, key=entry.node) + who.append_text(hop_chip(hop, role=ORIGIN)) if entry.node and label != entry.node: who.append(" ") who.append_text(highlighted_hash(entry.node, self._prefix_bytes)) @@ -1146,10 +1155,10 @@ class PacketViewer(Screen): rows: list[tuple[str, RenderableType]] = [] dest = raw.get("dest_hash") if dest: - rows.append(("to", self._endpoint(dest))) + rows.append(("to", self._endpoint(dest, DESTINATION))) src = raw.get("src_key") or raw.get("src_hash") if src: - rows.append(("from", self._endpoint(src))) + rows.append(("from", self._endpoint(src, ORIGIN))) if raw.get("trace_tag"): rows.append(("tag", Text(raw["trace_tag"], style="muted"))) readings = raw.get("trace_snrs") @@ -1184,22 +1193,26 @@ class PacketViewer(Screen): line.append(f"{value:+.2f} dB", style=snr_style(value)) return line - def _endpoint(self, value: str) -> Text: + def _endpoint(self, value: str, role: str) -> Text: """One end of an addressed packet: its resolved name, then the key that named it. This is the presentation of the ``from`` row, without the node-type glyph: a one-byte hash is too weak an identity for a type mark. A node that we cannot name shows only the hash, all grey (``known=False``), as each unknown-node hash in the app does. + + A name is a chip at its end of the route (``role``). The sender closes on the point + and the recipient opens on the notch. The ``via`` row opens and closes on both, + because it is the middle (refer to :meth:`_via_path`). Thus the shape of each chip + shows which part of the one route its row names. """ text = Text() named = self._resolve(value) known = bool(named and named != value) if known: - style = ( - "you" if self._self_name and named == self._self_name else name_style(named, value) - ) - text.append(named, style=style) + ours = bool(self._self_name and named == self._self_name) + hop = PathHop(named, you=True) if ours else PathHop(named, key=value) + text.append_text(hop_chip(hop, role=role)) text.append(" ") text.append_text(highlighted_hash(value, self._prefix_bytes or 1, known=known)) return text diff --git a/meshterm/ui/widgets.py b/meshterm/ui/widgets.py index ccf01f8..bb2fb27 100644 --- a/meshterm/ui/widgets.py +++ b/meshterm/ui/widgets.py @@ -582,13 +582,73 @@ def highlighted_hash( #: The roles of a lone chip in a route that it does not draw (the ``role`` of -#: :func:`name_chip`). The chip of an *origin* closes on the point, because the route goes -#: on from it: the author of a message. The chip of a *destination* opens on the notch, -#: because the route came to it: the node that a mention names. +#: :func:`hop_chip`). The chip of an *origin* closes on the point, because the route goes +#: on from it: the author of a message, the sender of a packet. The chip of a +#: *destination* opens on the notch, because the route came to it: the node that a +#: mention names, the recipient of a packet or of a queued message. ORIGIN = "origin" DESTINATION = "destination" +def hop_chip(hop: PathHop, *, role: str | None = None) -> Text: + """One hop drawn alone, as the single chip of a path line. + + The ends of the chip say the same thing as the ends of a route. With no ``role``, the + node is the whole route, and the two ends are square (or rounded where the font has + the caps). A ``role`` puts the chip at one end of a route that is not drawn, and the + other end of the chip shows that the route continues there (refer to + :data:`ORIGIN` and :data:`DESTINATION`). A message goes from its author toward the + nodes that it names. Thus the author closes on the point and a mention opens on the + notch, as the first and the last hop of a route do (JP, 2026-10-10). + + Where the terminal cannot draw powerline separators, a path line is text in arrow mode, + and a single hop is only its label in its own style. There the ``role`` does nothing. + A lone name with a stray ``→`` before or after it reads as a broken route, and not as a + sender or as a mention (JP, 2026-10-10). The text there also has no + :data:`~meshterm.ui.pathline.PATH_INK` stamp. A lone name in arrow mode is a name, and + not a route whose hues tell one hop from the next. Thus the highlight of a list row + changes it to white, as it changes each other name on the row + (refer to :func:`~meshterm.ui.tui.render._whiten_identities`). + + Args: + hop: The hop to draw. + role: :data:`ORIGIN`, :data:`DESTINATION`, or ``None`` for a node alone. + + Returns: + The chip as a one-line :class:`Text`. + """ + if not powerline_enabled(): + line = PathLine([hop]).text() + line.style = "" + return line + return PathLine([hop], from_origin=role != DESTINATION, to_destination=role != ORIGIN).text() + + +def route_ends(origin: PathHop, destination: PathHop) -> Text: + """The two ends of a route whose middle is not drawn: an origin chip and a destination chip. + + The point of the origin and the notch of the destination face each other across one + cell of page. Thus the line reads as a route from the one to the other, and it does not + claim that the two are neighbours. A seam between two chips makes that claim. Where the + terminal draws no chips, the two ends are joined by the arrow of the app + (``sender → recipient``), which says the same thing in text. + + Args: + origin: The node where the route starts (the sender). + destination: The node where the route ends (the recipient). + + Returns: + The line, not fitted. A caller that must fit it to a lane cuts it with + :func:`~meshterm.ui.pathline.cut_to`, so that a chip cracks and is not elided. + """ + if not powerline_enabled(): + return PathLine([origin, destination]).text() + line = hop_chip(origin, role=ORIGIN) + line.append(" ") + line.append_text(hop_chip(destination, role=DESTINATION)) + return line + + def name_chip( label: str, key: str | None = None, *, you: bool = False, role: str | None = None ) -> Text: @@ -601,21 +661,9 @@ def name_chip( them (JP, 2026-08-12). The colour reads the same as in a route. The name has the hue of the node, on a darker fill of that hue. A node that no key can place has the keyless grey. Our own end is the ``★`` of the map on its neutral dark grey, and not a - name. - - The ends of the chip say the same thing as the ends of a route. With no ``role``, the - node is the whole route, and the two ends are square (or rounded where the font has - the caps). A ``role`` puts the chip at one end of a route that is not drawn, and the - other end of the chip shows that the route continues there (refer to - :data:`ORIGIN` and :data:`DESTINATION`). A message goes from its author toward the - nodes that it names. Thus the author closes on the point and a mention opens on the - notch, as the first and the last hop of a route do (JP, 2026-10-10). - - The degradation is also inherited. Where the terminal cannot draw powerline - separators, a path line is text in arrow mode, and a single hop is only the name in its - own hue. This is what a sender label was before it had a frame. There the ``role`` does - nothing. A lone name with a stray ``→`` before or after it reads as a broken route, and - not as a sender or as a mention (JP, 2026-10-10). + name. The ``role`` and the arrow mode are those of :func:`hop_chip`. In arrow mode, a + name is only the name in its own hue. This is what a sender label was before it had a + frame. Args: label: The name as it must read (it is already resolved, and this function never @@ -632,9 +680,7 @@ def name_chip( The chip as a one-line :class:`Text`. """ hop = PathHop(SELF_GLYPH, you=True) if you else PathHop(label, key=key or None) - if not powerline_enabled(): - role = None - return PathLine([hop], from_origin=role != DESTINATION, to_destination=role != ORIGIN).text() + return hop_chip(hop, role=role) def _shorten_hash(value: str, hash_bytes: int | None) -> str: diff --git a/tests/test_chat.py b/tests/test_chat.py index dd1f2e2..87ea1fb 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -459,6 +459,23 @@ def test_preview_colours_channel_sender_and_mentions() -> None: assert any(s.style == "node.unknown" and s.start <= zed < s.end for s in preview.spans) +def test_preview_draws_the_author_and_the_mentions_as_the_transcript_does(powerline) -> None: + """With chips, the author closes on the point and a mention opens on the notch. + + The point says what the colon said, so the chip has no colon. Our own author is the + ``★``, as the sender chip of our messages in the transcript. + """ + from meshterm.ui.pathline import POWERLINE_ROUND_CLOSE, POWERLINE_ROUND_OPEN, POWERLINE_SEP + + powerline(True) + theirs = ChatMessage(text="Bob: hi @[Alice]", is_channel=True, channel_idx=0) + author = POWERLINE_ROUND_OPEN + " Bob " + POWERLINE_SEP + mention = POWERLINE_SEP + " @Alice " + POWERLINE_ROUND_CLOSE + assert _preview_text(theirs, _NO_KEYS).plain == f"{author} hi {mention}" + mine = ChatMessage(text="yo", outbound=True, is_channel=True, channel_idx=0) + assert _preview_text(mine, _NO_KEYS).plain == f"{POWERLINE_ROUND_OPEN} ★ {POWERLINE_SEP} yo" + + def test_preview_keeps_the_whole_message() -> None: """The preview is built whole. The cut of the row is the part that the ←→ scroll passes.""" long = ChatMessage(text="x" * 300, is_channel=True, channel_idx=0) diff --git a/tests/test_courier.py b/tests/test_courier.py index 3e16b8c..d4c0417 100644 --- a/tests/test_courier.py +++ b/tests/test_courier.py @@ -543,6 +543,21 @@ def test_outbox_rows_recompute_live_state_per_repaint(tmp_path: Path) -> None: assert "try 1" in _outbox_plain(screen) +def test_outbox_draws_each_recipient_as_a_destination_chip(tmp_path: Path, powerline) -> None: + """A queued message goes to its recipient, so the recipient opens on the notch. + + A waiting recipient has the hue of its key. A finished one is muted with the rest of its + row, because the finished section is history. + """ + from meshterm.ui.pathline import POWERLINE_ROUND_CLOSE, POWERLINE_SEP + + powerline(True) + titles = _outbox_titles(tmp_path) + for name in ("Waiting", "Landed", "Lost"): + row = next(title for title in titles if name in title) + assert f"{POWERLINE_SEP} {name} {POWERLINE_ROUND_CLOSE}" in row + + def _title_plain(choice) -> str: """The label of a row as plain text. diff --git a/tests/test_livefeed.py b/tests/test_livefeed.py index 3ddd16f..95e6797 100644 --- a/tests/test_livefeed.py +++ b/tests/test_livefeed.py @@ -243,6 +243,36 @@ def test_livefeed_addressed_frame_is_about_its_two_ends() -> None: assert "a1 → Hilltop-Repe" in _rows(wide, 100)[0] +def test_livefeed_addressed_frame_draws_its_two_ends_as_chips(powerline) -> None: + """With chips, the sender's point and the recipient's notch face each other across a cell. + + A seam would claim that the two are neighbours, and the relays between them are not + drawn. A pair that is too wide for the lane cracks at the lane, and is not elided. + """ + from meshterm.ui.pathline import CRACK_TAIL, POWERLINE_SEP + + powerline(True) + screen = _screen(self_name="Us") + raw = {"payload_typename": "TEXT_MSG", "dest_hash": "c0", "src_hash": "a1"} + screen.on_event(MeshEvent.observation_event(_obs(node="", kind="packet", raw=raw))) + assert f" Alice {POWERLINE_SEP} {POWERLINE_SEP} ★ " in _rows(screen, 100)[0] + + wide = _screen() + wide._resolve = lambda h: {"a1": "Alice-With-A-Long-Name", "3d": "Hilltop-Repeater"}.get(h, "") + wide.on_event( + MeshEvent.observation_event( + _obs( + node="", + kind="packet", + raw={"payload_typename": "REQ", "dest_hash": "3d", "src_hash": "a1"}, + ) + ) + ) + row = _rows(wide, 100)[0] + assert f" a1 {POWERLINE_SEP} {POWERLINE_SEP} Hilltop" in row + assert CRACK_TAIL in row and "…" not in row + + def test_livefeed_tokened_classes_are_about_their_token() -> None: """An ack names the message that it answers. A trace names its tag. Neither says "packet".""" screen = _screen() diff --git a/tests/test_packet_viewer.py b/tests/test_packet_viewer.py index b28eca4..ecbd6b6 100644 --- a/tests/test_packet_viewer.py +++ b/tests/test_packet_viewer.py @@ -435,6 +435,37 @@ def test_packet_viewer_lays_out_what_a_frame_addressed() -> None: assert _plain(lines).count("dest_hash") == 0 +def test_packet_viewer_draws_each_end_of_the_route_as_the_chip_of_that_end(powerline) -> None: + """The sender closes on the point and the recipient opens on the notch, around ``via``.""" + from meshterm.ui.pathline import POWERLINE_ROUND_CLOSE, POWERLINE_ROUND_OPEN, POWERLINE_SEP + + powerline(True) + entry = PacketEntry( + when=utcnow(), + kind="packet", + path="3d", + raw={ + "payload_typename": "TEXT_MSG", + "route_typename": "FLOOD", + "dest_hash": "c0", + "src_hash": "a1", + }, + ) + viewer = PacketViewer( + [entry], + 0, + resolve=lambda h: {"c0": "Waymarker", "a1": "Alice"}.get(h, ""), + prefix_bytes=1, + self_name="Waymarker", + ) + lines = _stripped(viewer.render_body(80)) + to_row = next(ln for ln in lines if ln.startswith("to")) + from_row = next(ln for ln in lines if ln.startswith("from")) + + assert f"{POWERLINE_SEP} Waymarker {POWERLINE_ROUND_CLOSE} c0" in to_row # us, reached + assert f"{POWERLINE_ROUND_OPEN} Alice {POWERLINE_SEP} a1" in from_row # the route goes on + + def test_packet_viewer_names_a_tokened_frame_by_its_token() -> None: """An ack points to the message that it answers. A trace points to its own tag.""" ack = PacketEntry( diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 09de75b..225873d 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -13,6 +13,7 @@ from rich.text import Text from meshterm.core.models import node_type_label from meshterm.ui.pathline import ( + PATH_INK, POWERLINE_ROUND_CLOSE, POWERLINE_ROUND_OPEN, POWERLINE_SEP, @@ -26,9 +27,11 @@ from meshterm.ui.widgets import ( ORIGIN, format_age, format_ago, + hop_chip, name_chip, path_text, revisit_note, + route_ends, ) @@ -304,6 +307,31 @@ def test_name_chip_role_changes_nothing_without_powerline(powerline) -> None: assert name_chip("Alice", "a1b2", role=role).plain == "Alice" +def test_a_lone_hop_in_arrow_mode_is_a_name_and_not_a_route(powerline) -> None: + """Only a route keeps its hues on a highlighted row. A lone name turns white like any name.""" + powerline(False) + chip = hop_chip(PathHop("Alice", key="a1b2"), role=ORIGIN) + + assert str(chip.style) != PATH_INK + assert all(str(s.style) != PATH_INK for s in chip.spans) + + +def test_route_ends_face_each_other_across_one_cell_of_page(powerline) -> None: + """The middle is not drawn, so no seam joins the two ends. A seam makes them neighbours.""" + powerline(True) + line = route_ends(PathHop("Alice", key="a1"), PathHop("Bob", key="c3")) + + opening = POWERLINE_ROUND_OPEN + " Alice " + POWERLINE_SEP + assert line.plain == opening + " " + POWERLINE_SEP + " Bob " + POWERLINE_ROUND_CLOSE + + +def test_route_ends_are_the_arrow_of_the_app_without_powerline(powerline) -> None: + """A terminal with no chips reads the two ends as it always did.""" + powerline(False) + + assert route_ends(PathHop("Alice", key="a1"), PathHop("Bob", key="c3")).plain == "Alice → Bob" + + def test_name_chip_falls_back_to_the_bare_name_without_powerline(powerline) -> None: """If there is no separator glyph to draw a chip, the chip is the bare name.