Chat: a sender label is a name drawn as a path line's chip

A name standing alone above its messages was a coloured word with nothing
to say it was a label — at a glance it read like something someone typed.
It now sits in a chip, and not a chip of its own invention: ui/widgets.
name_chip builds a one-hop PathLine and asks it for its line, so the fill,
the ink, the padding, the rounded cap and the closing point are whatever a
route's segments are wearing today and cannot drift from them. A sender
wears exactly what that node wears as a hop — hue in the fill under dark
ink, the keyless grey where no key places them, and our own messages
headed by the ★ on its neutral grey rather than by the word "you".

Only the group header. An @mention inside a body is part of what was said,
and framing it would put a chip in the middle of a sentence.

Degrading comes free with the borrowing: where the terminal can't draw
separators — the PicoCalc console among them — a path line is arrow text
and one hop is just the name in its hue, which is what a sender label was
before it was framed. The specimen card grows a chips row, which doubles
as a one-hop sample of the route language.

And the unknown sender takes node.unknown rather than muted: one hex apart
here, a whole slot apart on the console, and an unidentified sender is
content you can still act on, not chrome.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-13 00:58:52 -04:00
1 parent e5c756995e
commit f22ffa5011
7 files changed
+137 -142

No files matched your search

+19 -1
View File
@@ -19,7 +19,7 @@ always see the colours the app really emits.
from __future__ import annotations
import re
from typing import Iterable, Iterator, Union
from typing import Callable, Iterable, Iterator, Union
import pytest
@@ -53,6 +53,24 @@ def _plain_path_rendering(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
powerline_support.cache_clear()
@pytest.fixture
def powerline(monkeypatch: pytest.MonkeyPatch) -> Callable[[bool], None]:
"""Pin the powerline verdict for a test that is *about* chips.
The suite runs with ``MESHTERM_POWERLINE=0`` so screen assertions don't change with
the developer's glass (see the module docstring); a test of the chip language itself
needs the other answer, and asks for it through the supported override rather than by
reaching into the widget. ``monkeypatch`` restores the env and the autouse fixture
above clears the memoized verdict either side, so nothing leaks.
"""
def _set(on: bool) -> None:
monkeypatch.setenv("MESHTERM_POWERLINE", "1" if on else "0")
powerline_support.cache_clear()
return _set
@pytest.fixture(autouse=True)
def _reset_platform() -> Iterator[None]:
"""Every test starts and ends on :data:`~meshterm.platforms.REGULAR`.
+12 -12
View File
@@ -976,7 +976,8 @@ def test_channel_transcript_groups_by_sender() -> None:
rendered = _strip_ansi("\n".join(screen._render_grouped(80)))
assert rendered.count("Alice") == 1 # the two Alice messages share one header
assert "Bob" in rendered and "you" in rendered
# Our own group is headed by the ★ a route draws our end with, never by our name.
assert "Bob" in rendered and "★" in rendered
assert "hi" in rendered and "again" in rendered # bodies present, prefix stripped
assert "Alice: hi" not in rendered # the raw name prefix is lifted into the header
# Each message keeps its own timestamp on its line, even when grouped under one sender.
@@ -986,10 +987,11 @@ def test_channel_transcript_groups_by_sender() -> None:
assert stamps[0] != stamps[1] # grouped Alice messages show distinct times
def test_transcript_inscribes_the_sender_label_but_never_a_mention() -> None:
"""The name that *opens* a group is a tag; the same name inside a body is prose."""
def test_transcript_inscribes_the_sender_label_but_never_a_mention(powerline) -> None:
"""The name that *opens* a group is a chip; the same name inside a body is prose."""
from meshterm.ui.widgets import name_chip
powerline(True) # this is a test *about* the chip, so ask for a glass that draws one
conv = Conversation(label="#public", is_channel=True, channel_idx=0)
messages = [
ChatMessage(text="Alice: @[Bob] you around?", is_channel=True, channel_idx=0),
@@ -997,14 +999,11 @@ def test_transcript_inscribes_the_sender_label_but_never_a_mention() -> None:
screen = ChatScreen(conv, messages, send=None, names={}, session=_StubSession())
rendered = _strip_ansi("\n".join(screen._render_grouped(80)))
# Built through the widget rather than spelled out: which caps it uses depends on the
# font the session found, and the point here is the framing, not the glyph.
def chipped(name: str) -> str:
return name_chip(name, "bold #ffffff").plain
assert chipped("Alice") in rendered # the header, inscribed
assert "@Bob" in rendered # the mention, as it was typed
assert chipped("Bob") not in rendered # …and not framed mid-sentence
# Built through the widget rather than spelled out: the caps are the path line's, and
# what is being asserted here is the framing, not the glyph.
assert name_chip("Alice").plain in rendered # the header, as a chip
assert "@Bob" in rendered # the mention, as it was typed
assert name_chip("Bob").plain not in rendered # …and never framed mid-sentence
def test_unidentified_sender_takes_the_node_grey_not_the_chrome_grey() -> None:
@@ -1230,7 +1229,8 @@ def test_channel_own_messages_do_not_merge_with_remote_namesake() -> None:
]
screen = _channel_screen(messages)
rendered = _strip_ansi("\n".join(screen._render_grouped(80)))
assert rendered.count("you") == 2 # two separate headers, not one merged group
# Two headers, and not merely un-merged: theirs is the name they sent, ours is the ★.
assert rendered.count("you") == 1 and rendered.count("★") == 1
def _channel_screen(messages, session=None, key_of=None) -> ChatScreen:
+54 -31
View File
@@ -7,7 +7,16 @@ and every caller inherits it.
from __future__ import annotations
from meshterm.platforms import PICOCALC, REGULAR, set_platform
from rich.style import Style
from rich.text import Text
from meshterm.ui.pathline import (
POWERLINE_ROUND_CLOSE,
POWERLINE_ROUND_OPEN,
PathHop,
PathLine,
)
from meshterm.ui.theme import node_style
from meshterm.ui.widgets import (
_format_age,
format_ago,
@@ -17,6 +26,11 @@ from meshterm.ui.widgets import (
)
def _span_style(text: Text, run: str) -> Style:
"""The style over ``run`` in ``text``, parsed — pathline spans carry style *strings*."""
return Style.parse(next(str(s.style) for s in text.spans if text.plain[s.start : s.end] == run))
def test_format_age_is_the_bare_column_form() -> None:
"""The lane form stays suffix-free at every magnitude, for aligned age columns."""
assert _format_age(None) == "never"
@@ -192,40 +206,49 @@ def test_revisit_note_is_absent_when_nothing_repeats() -> None:
assert revisit_note(()) is None
def test_name_chip_frames_the_name_without_recolouring_it() -> None:
"""The chip adds a field; the hue it fields is exactly the one it was handed."""
chip = name_chip("Alice", "bold #ff00aa")
def test_name_chip_is_a_path_line_of_one_hop() -> None:
"""The framing isn't imitated — it *is* the route language, so it can't drift from it."""
chip = name_chip("Alice", "a1b2")
hop = PathLine([PathHop("Alice", key="a1b2")]).text()
assert chip.plain[1:-1] == "Alice" # a cap either side, the name untouched between
styles = {chip.plain[s.start : s.end]: s.style for s in chip.spans}
assert styles["Alice"].color.name == "#ff00aa" # its own hue, still
assert styles["Alice"].bgcolor is not None # now with something under it
# The caps are the fill drawn over the page — foreground only, so the half-cell that
# isn't chip keeps whatever the row behind it is.
for cap in (chip.plain[0], chip.plain[-1]):
assert styles[cap].bgcolor is None
assert styles[cap].color == styles["Alice"].bgcolor
assert chip.plain == hop.plain
assert [(s.start, s.end, str(s.style)) for s in chip.spans] == [
(s.start, s.end, str(s.style)) for s in hop.spans
]
def test_name_chip_takes_a_theme_name_as_readily_as_a_hex() -> None:
"""``node.unknown``/``you`` arrive as theme names — the fill must not flatten them.
def test_name_chip_wears_the_hue_as_its_fill_padded_like_every_chip(powerline) -> None:
"""A route's colour scheme: the node's hue fills the chip, the ink on it is dark."""
powerline(True)
chip = name_chip("Alice", "a1b2")
Rich drops a style string that mixes a theme name with anything else, so a chip built
by concatenation renders the name unstyled. This is that regression, pinned.
"""
chip = name_chip("·", "node.unknown")
style = next(s.style for s in chip.spans if chip.plain[s.start : s.end] == "·")
assert style.color is not None and style.bgcolor is not None
assert style.color.name != style.bgcolor.name # not the invisible-on-itself case
assert chip.plain.strip(POWERLINE_ROUND_OPEN + POWERLINE_ROUND_CLOSE) == " Alice "
ink = _span_style(chip, "Alice")
assert ink.bgcolor.name == node_style("a1b2").removeprefix("bold ") # the hue
assert ink.color.name == "#0f172a" # the chip ink every hop is lettered in
def test_name_chip_draws_bare_where_the_console_has_no_field_for_it() -> None:
"""PicoCalc's greys stop at slot 7 as backgrounds — so the name goes unframed there."""
set_platform(PICOCALC)
try:
chip = name_chip("Alice", "bold #ff00aa")
finally:
set_platform(REGULAR)
def test_name_chip_draws_us_as_the_star_never_as_our_name(powerline) -> None:
"""Our end of a route is the map's own marker; a sender label is no different."""
powerline(True)
chip = name_chip("you", you=True)
assert chip.plain == "Alice" # no caps, no field — and no tofu on the console font
assert "★" in chip.plain and "you" not in chip.plain
assert _span_style(chip, "★").bgcolor.name == "#3f3f46" # neutral grey, not a hue
def test_name_chip_greys_a_node_it_cannot_place(powerline) -> None:
"""No key, no hue — colour is reserved for keyed identities, in a chip as in a route."""
powerline(True)
keyless = name_chip("·")
assert _span_style(keyless, "·").bgcolor.name == "#64748b" # the keyless grey
def test_name_chip_falls_back_to_the_bare_name_without_powerline(powerline) -> None:
"""No separator glyph to draw a chip with — the PicoCalc's console font among them."""
powerline(False)
chip = name_chip("Alice", "a1b2")
assert chip.plain == "Alice" # exactly what an arrow-mode path line makes of one hop
assert str(next(iter(chip.spans)).style) == node_style("a1b2") # still its own hue