Enliven the conversation list and keep section headings in view
Color-code the chat picker rows: a contact's dot takes that person's chat hue (filled once talked-to, hollow before), previews light their sender names and @mentions in-hue, and a relative age column sits between the unread badge and the message text. Pin a grouped list's section heading to the top row once it scrolls off (sticky header in the frame), add PageUp/PageDown to SelectScreen, and drop arrow wraparound in the conversation picker so it doesn't jump across the section dividers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa537d5503
commit
8906e4ed53
9 files changed
+338
-78
No files matched your search
+43
-16
@@ -33,7 +33,7 @@ from meshterm.core.models import (
|
||||
from meshterm.persistence.repository import Repository
|
||||
from meshterm.services.chat_service import ChatService
|
||||
from meshterm.services.event_hub import EventHub
|
||||
from meshterm.tools.chat import _LiveLasts, _preview, _title
|
||||
from meshterm.tools.chat import _PREVIEW_WIDTH, _LiveLasts, _preview_text, _title
|
||||
from meshterm.ui.chat import ChatScreen
|
||||
from meshterm.ui.tui.screen import CANCEL
|
||||
|
||||
@@ -239,18 +239,29 @@ def test_preview_prefixes_own_messages_only() -> None:
|
||||
synthesized (that would double it), and a direct message's author is the row label.
|
||||
"""
|
||||
chan_in = ChatMessage(text="Bob: hi", is_channel=True, channel_idx=0) # sender inline
|
||||
assert _preview(chan_in) == "Bob: hi"
|
||||
assert _preview_text(chan_in).plain == "Bob: hi"
|
||||
dm_in = ChatMessage(text="hey", peer="aa", peer_name="Bob")
|
||||
assert _preview(dm_in) == "hey"
|
||||
assert _preview_text(dm_in).plain == "hey"
|
||||
mine = ChatMessage(text="yo", outbound=True, is_channel=True, channel_idx=0)
|
||||
assert _preview(mine) == "you: yo"
|
||||
assert _preview_text(mine).plain == "you: yo"
|
||||
|
||||
|
||||
def test_preview_colours_channel_sender_and_mentions() -> None:
|
||||
"""A channel preview lights its inline sender name and any ``@[Name]`` mention in a hue."""
|
||||
from meshterm.ui.chat import _sender_hue
|
||||
|
||||
msg = ChatMessage(text="Bob: hi @[Alice]", is_channel=True, channel_idx=0)
|
||||
preview = _preview_text(msg)
|
||||
assert preview.plain == "Bob: hi @Alice" # the mention's brackets are dropped for display
|
||||
styles = {span.style for span in preview.spans}
|
||||
assert _sender_hue("Bob") in styles and _sender_hue("Alice") in styles
|
||||
|
||||
|
||||
def test_preview_ellipsizes_long_text() -> None:
|
||||
"""An over-long preview is clipped to the width budget with a trailing ellipsis."""
|
||||
long = ChatMessage(text="x" * 100, is_channel=True, channel_idx=0)
|
||||
out = _preview(long, width=10)
|
||||
assert len(out) == 10 and out.endswith("…")
|
||||
out = _preview_text(long).plain
|
||||
assert len(out) == _PREVIEW_WIDTH and out.endswith("…")
|
||||
|
||||
|
||||
def test_title_shows_badge_and_author_preview(repo: Repository) -> None:
|
||||
@@ -266,7 +277,7 @@ def test_title_shows_badge_and_author_preview(repo: Repository) -> None:
|
||||
|
||||
|
||||
def test_title_reddens_only_the_unread_dot(repo: Repository) -> None:
|
||||
"""With unread the row is a Text whose ``●`` glyph (only) is styled red; else a plain str."""
|
||||
"""With unread the row's ``●`` glyph (only) is styled red; with none there is no dot."""
|
||||
from rich.text import Text
|
||||
|
||||
conv = Conversation(label="General", is_channel=True, channel_idx=0, channel_id="c0")
|
||||
@@ -279,7 +290,9 @@ def test_title_reddens_only_the_unread_dot(repo: Repository) -> None:
|
||||
assert reddened and all(span.end - span.start == 1 for span in reddened) # just the glyph
|
||||
|
||||
read = _title(_RowCtx(repo, unread={}), conv, {})
|
||||
assert isinstance(read, str) # no badge -> plain string, no styling
|
||||
assert isinstance(read, Text) # always a Text now, so its spans can carry the row's colour
|
||||
assert "●" not in read.plain # nothing unread -> no badge dot
|
||||
assert not any(span.style == "err" for span in read.spans)
|
||||
|
||||
|
||||
def test_title_preview_column_aligns_regardless_of_label_length(repo: Repository) -> None:
|
||||
@@ -289,15 +302,15 @@ def test_title_preview_column_aligns_regardless_of_label_length(repo: Repository
|
||||
long = Conversation(label="A much longer channel name here", is_channel=True, channel_idx=1, channel_id="c1")
|
||||
m0 = ChatMessage(text="X: hello", is_channel=True, channel_id="c0")
|
||||
m1 = ChatMessage(text="Y: hello", is_channel=True, channel_id="c1")
|
||||
l0 = _title(ctx, short, {"chan:c0": m0})
|
||||
l1 = _title(ctx, long, {"chan:c1": m1})
|
||||
l0 = _title(ctx, short, {"chan:c0": m0}).plain
|
||||
l1 = _title(ctx, long, {"chan:c1": m1}).plain
|
||||
assert l0.index("X: hello") == l1.index("Y: hello")
|
||||
|
||||
|
||||
def test_title_leads_with_openness_glyph(repo: Repository) -> None:
|
||||
"""Channel rows lead with an openness glyph: # name-derived, 🌐 fixed-key public, 🔒 private."""
|
||||
ctx = _RowCtx(repo)
|
||||
head = lambda conv: _title(ctx, conv, {}).split(" ", 1)[0]
|
||||
head = lambda conv: _title(ctx, conv, {}).plain.split(" ", 1)[0]
|
||||
named = Conversation(
|
||||
label="#general", is_channel=True, channel_id="c0", secret=derive_secret("#general")
|
||||
)
|
||||
@@ -312,16 +325,30 @@ def test_title_leads_with_openness_glyph(repo: Repository) -> None:
|
||||
assert head(private) == "🔒"
|
||||
|
||||
|
||||
def test_title_contact_glyph_reflects_conversation_history(repo: Repository) -> None:
|
||||
"""A contact shows 💬 once we've exchanged messages, 👤 before any conversation exists."""
|
||||
def test_title_contact_dot_reflects_conversation_history(repo: Repository) -> None:
|
||||
"""A contact's dot is filled ● once we've talked, hollow ○ before — always in her hue."""
|
||||
from meshterm.ui.chat import _sender_hue
|
||||
|
||||
ctx = _RowCtx(repo)
|
||||
contact = Conversation(
|
||||
label="Alice", is_channel=False, contact=Contact(name="Alice", public_key="d4" + "0" * 62)
|
||||
)
|
||||
head = lambda lasts: _title(ctx, contact, lasts).split(" ", 1)[0]
|
||||
assert head({}) == "👤" # no history yet — a contact we haven't talked to
|
||||
head = lambda lasts: _title(ctx, contact, lasts).plain.split(" ", 1)[0]
|
||||
|
||||
def dot_is_hued(row) -> bool:
|
||||
return any(
|
||||
span.style == _sender_hue("Alice") and span.start == 0 and span.end == 1
|
||||
for span in row.spans
|
||||
)
|
||||
|
||||
# No history yet — a hollow ring, but still tinted in Alice's stable chat hue.
|
||||
fresh = _title(ctx, contact, {})
|
||||
assert fresh.plain.startswith("○") and dot_is_hued(fresh)
|
||||
|
||||
# Once we've exchanged messages the same-hued dot fills in.
|
||||
last = ChatMessage(text="hi", peer=contact.peer)
|
||||
assert head({contact.key: last}) == "💬" # we've exchanged messages
|
||||
talked = _title(ctx, contact, {contact.key: last})
|
||||
assert talked.plain.startswith("●") and dot_is_hued(talked)
|
||||
|
||||
|
||||
# -- chat service -------------------------------------------------------------
|
||||
|
||||
@@ -142,6 +142,75 @@ def test_select_filter_matches_callable_title() -> None:
|
||||
assert _run(screen, "enter") == 1
|
||||
|
||||
|
||||
def test_select_no_wrap_clamps_at_the_ends() -> None:
|
||||
"""With wrap off, Up on the first row and Down on the last stay put (no cycling)."""
|
||||
items = [Choice("alpha", 1), Choice("beta", 2), Choice("gamma", 3)]
|
||||
screen = SelectScreen("pick", items, wrap=False)
|
||||
screen.handle("up") # already on the first choice — must not jump to the last
|
||||
assert _run(screen, "enter") == 1
|
||||
screen = SelectScreen("pick", items, default=3, wrap=False) # last choice
|
||||
screen.handle("down") # already on the last — must not wrap to the first
|
||||
assert _run(screen, "enter") == 3
|
||||
|
||||
|
||||
def test_select_pageup_pagedown_jump_by_a_page() -> None:
|
||||
"""PageDown/PageUp move the highlight a page at a time, clamped to the choice range."""
|
||||
from meshterm.ui.tui.select import _PAGE
|
||||
|
||||
items = [Choice(f"c{i}", i) for i in range(30)]
|
||||
screen = SelectScreen("pick", items) # starts on the first choice
|
||||
screen.handle("pagedown")
|
||||
assert _run(screen, "enter") == _PAGE # advanced one page down
|
||||
screen = SelectScreen("pick", items, default=25)
|
||||
screen.handle("pageup")
|
||||
assert _run(screen, "enter") == 25 - _PAGE # and one page back up
|
||||
|
||||
|
||||
def _grouped_menu(default: object = None) -> SelectScreen:
|
||||
"""A two-section menu long enough that each section scrolls past a small viewport."""
|
||||
items: list = [Separator("── Channels ──")]
|
||||
items += [Choice(f"chan{i}", ("c", i)) for i in range(6)]
|
||||
items += [Separator("── Direct ──")]
|
||||
items += [Choice(f"peer{i}", ("d", i)) for i in range(8)]
|
||||
return SelectScreen("pick", items, default=default)
|
||||
|
||||
|
||||
def _top_plain(screen: SelectScreen, viewport: int) -> str:
|
||||
"""Slice the screen at its selection-driven scroll and return the top row's plain text."""
|
||||
lines = screen.render_body(40)
|
||||
visible, _above, _below = frame._visible_slice(screen, lines, viewport)
|
||||
return Text.from_ansi(visible[0]).plain.strip()
|
||||
|
||||
|
||||
def test_select_pins_section_heading_when_it_scrolls_off() -> None:
|
||||
"""Selecting deep in a section keeps that section's heading pinned to the top row."""
|
||||
# Highlighting a channel far enough down pushes the "Channels" heading off the top, so it
|
||||
# is re-pinned rather than vanishing.
|
||||
assert _top_plain(_grouped_menu(default=("c", 5)), viewport=6) == "── Channels ──"
|
||||
# Deep into the Direct group, the pinned heading switches to that section's.
|
||||
assert _top_plain(_grouped_menu(default=("d", 6)), viewport=6) == "── Direct ──"
|
||||
|
||||
|
||||
def test_select_does_not_pin_a_heading_that_is_still_visible() -> None:
|
||||
"""With the list scrolled to the top, the real heading shows — nothing is pinned over it."""
|
||||
screen = _grouped_menu() # default selection is the first choice, so scroll stays at 0
|
||||
lines = screen.render_body(40)
|
||||
visible, above, _below = frame._visible_slice(screen, lines, 6)
|
||||
assert Text.from_ansi(visible[0]).plain.strip() == "── Channels ──"
|
||||
assert above is False # top of the list; no pinned duplicate and no "more above"
|
||||
|
||||
|
||||
def test_select_pinned_heading_keeps_the_last_row_reachable() -> None:
|
||||
"""Even with a heading pinned, the bottom choice stays fully visible (not clipped)."""
|
||||
screen = _grouped_menu()
|
||||
screen.handle("end") # highlight the final choice
|
||||
lines = screen.render_body(40)
|
||||
visible, _above, below = frame._visible_slice(screen, lines, 6)
|
||||
assert Text.from_ansi(visible[0]).plain.strip() == "── Direct ──" # heading pinned
|
||||
assert any("peer7" in Text.from_ansi(row).plain for row in visible) # last row shown
|
||||
assert below is False # and we know we're at the bottom
|
||||
|
||||
|
||||
# --- scroll ------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user