Channels goes through the shared row builders it was working around
It was never in the dual-platform gallery, which is why none of this was caught. Adding it first, then fixing what it showed. The column header was a hand-built f-string with a five-cell indent and no idea of the render width: at 53 columns it ran to 54 and wrapped, costing a content row out of twenty-six and drawing the pinned landmark twice, and its indent assumed a two-cell channel glyph where the console draws one. It goes through column_header now, which measures the glyph and sheds ACTIVITY before it wraps. The command rows hand-padded their icons, so the one-cell marks (↕ ✎ 🗑) started their labels a column left of the two-cell ones - the Organize row had a two-space hack and a four-line comment about exactly this. They share a measured icon lane now, and the clear row tints its mark rather than its words. The empty message count was ·, which in that same row is also the status-atom separator and what the console folds 🔕 to: a muted channel with no messages drew it twice, two cells apart, meaning different things. It is ○, the app's empty mark. Also: the detail title was a 42-cell parenthesised blob that filled the PicoCalc's whole title bar, leaving nowhere to say Esc leaves - it is "Channel — name", with the openness and hash now leading a vital-signs line that sheds atoms rather than wrapping. The manager says "Enter open", which is what its rows do. The slot count chains with · rather than an em dash. And the four Add rows are replaced by one empty state when there is no free slot to add into, instead of all four dead-ending in the same refusal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4c01e1da7e
commit
d19e2ec712
3 files changed
+262
-55
No files matched your search
+38
-3
@@ -13,6 +13,7 @@ from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from rich.cells import cell_len
|
||||
from rich.console import Console
|
||||
|
||||
from meshterm.context import AppContext
|
||||
@@ -580,7 +581,7 @@ async def test_channel_rows_carry_stats_unread_and_lanes(ctx: AppContext) -> Non
|
||||
ctx.chat._unread[slot.conversation.key] = 2 # as the service would after two arrivals
|
||||
|
||||
title, items = _menu_items(ctx, slots, 8, _LiveStats(ctx))
|
||||
assert title == "Channels — 1/8 slots"
|
||||
assert title == "Channels · 1/8 slots" # a status atom chains with ·, not an em dash
|
||||
row = next(it for it in items if isinstance(it, Choice) and it.value == 0)
|
||||
plain = row.label.plain # the title is a live callable; .label resolves it
|
||||
assert "Ops" in plain
|
||||
@@ -678,13 +679,47 @@ async def test_detail_summary_reads_slot_totals_and_unread(ctx: AppContext) -> N
|
||||
await device.set_channel(3, "Ops", bytes(range(16)))
|
||||
slot = next(s for s in await read_channel_slots(device) if s.idx == 3)
|
||||
|
||||
assert _detail_summary(ctx, slot, _LiveStats(ctx)) == "Slot 3 · no messages recorded yet"
|
||||
# What the channel *is* leads — the openness and hash moved here out of a title that
|
||||
# was 42 cells wide and left no room on the console for the bar that says Esc leaves.
|
||||
assert _detail_summary(ctx, slot, _LiveStats(ctx)) == (
|
||||
"private · hash be · slot 3 · no messages yet"
|
||||
)
|
||||
|
||||
ctx.repo.record_chat_message(ChatMessage(text="hi", is_channel=True, channel_id=slot.identity))
|
||||
ctx.chat._unread[slot.conversation.key] = 1
|
||||
summary = _detail_summary(ctx, slot, _LiveStats(ctx))
|
||||
# A fresh age reads as bare "now" (the app-wide format_ago grammar — never "now ago").
|
||||
assert summary == "Slot 3 · 1 message · 1 unread · last message now"
|
||||
assert summary == "private · hash be · slot 3 · 1 msg · 1 unread · last now"
|
||||
|
||||
|
||||
async def test_the_detail_summary_sheds_atoms_rather_than_wrapping(ctx: AppContext) -> None:
|
||||
"""One line, on both platforms: the traffic atoms go before the line does.
|
||||
|
||||
The identifying atoms are on the left and the describing ones on the right, so a line
|
||||
too long for the console loses what the reader could already see in the row they opened
|
||||
this screen from — never the channel's own identity.
|
||||
"""
|
||||
from meshterm.core.models import ChatMessage
|
||||
from meshterm.platforms import PICOCALC, REGULAR, set_platform
|
||||
from meshterm.ui.channels import _detail_summary, _LiveStats
|
||||
|
||||
device = await ctx.device()
|
||||
await device.set_channel(0, "Lakeside emergency net", bytes(range(16)))
|
||||
slot = next(s for s in await read_channel_slots(device) if s.idx == 0)
|
||||
for _ in range(3):
|
||||
ctx.repo.record_chat_message(
|
||||
ChatMessage(text="hi", is_channel=True, channel_id=slot.identity)
|
||||
)
|
||||
ctx.chat._unread[slot.conversation.key] = 2
|
||||
|
||||
try:
|
||||
for platform in (REGULAR, PICOCALC):
|
||||
set_platform(platform)
|
||||
line = _detail_summary(ctx, slot, _LiveStats(ctx))
|
||||
assert cell_len(line) <= platform.readable_cols, (platform.name, line)
|
||||
assert line.startswith("private · hash be · slot 0") # identity always survives
|
||||
finally:
|
||||
set_platform(REGULAR)
|
||||
|
||||
|
||||
# -- muting channel notifications ---------------------------------------------
|
||||
|
||||
@@ -29,12 +29,14 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from rich.cells import cell_len
|
||||
from rich.text import Text
|
||||
|
||||
from meshterm.core.advert_store import AdvertPolicy
|
||||
from meshterm.core.channels import DEFAULT_PUBLIC_SECRET, derive_secret
|
||||
from meshterm.core.courier_store import CourierStore
|
||||
from meshterm.core.models import (
|
||||
NODE_TYPE_REPEATER,
|
||||
@@ -417,6 +419,77 @@ def _chat_picker(cols: int, rows: int) -> Screen:
|
||||
)
|
||||
|
||||
|
||||
def _channels_manager(cols: int, rows: int) -> Screen:
|
||||
"""The channel manager at its widest: every lane populated, every action row drawn.
|
||||
|
||||
Built through the feature's own row funnel, so the header line, the glyph lane, the
|
||||
unread badge, the counts, the ages and the sparkline are laid out by the code the app
|
||||
runs. The cases that matter are here: a name at the lane's ceiling, a muted channel (its
|
||||
mark folds to a different glyph on the console), a channel with no messages at all, and
|
||||
a three-digit unread badge.
|
||||
"""
|
||||
from meshterm.ui.channels import _MANAGER_HINT, ChannelSlot, _LiveStats, _menu_items
|
||||
|
||||
slots = [
|
||||
ChannelSlot(idx=0, name="Public", secret=DEFAULT_PUBLIC_SECRET),
|
||||
ChannelSlot(idx=1, name="Lakeside emergency", secret=bytes(range(16))),
|
||||
ChannelSlot(idx=2, name="#montreal", secret=derive_secret("#montreal")),
|
||||
ChannelSlot(idx=3, name="Ops", secret=bytes(range(16, 32))),
|
||||
]
|
||||
ctx = _ChannelsCtx(muted={slots[3].identity})
|
||||
title, items = _menu_items(ctx, slots, 8, _LiveStats(ctx))
|
||||
return SelectScreen(title, items, footer_hint=_MANAGER_HINT)
|
||||
|
||||
|
||||
def _channel_detail(cols: int, rows: int) -> Screen:
|
||||
"""One channel's action page, its vital-signs line above the rows."""
|
||||
from meshterm.ui.channels import ChannelSlot, _detail_items, _detail_summary, _LiveStats
|
||||
|
||||
slot = ChannelSlot(idx=2, name="Lakeside emergency", secret=bytes(range(16)))
|
||||
ctx = _ChannelsCtx(muted=set())
|
||||
stats = _LiveStats(ctx)
|
||||
return SelectScreen(
|
||||
f"Channel — {slot.name}",
|
||||
_detail_items(ctx, slot),
|
||||
prompt=_detail_summary(ctx, slot, stats),
|
||||
footer_hint="↑↓ move · Enter select · Esc back",
|
||||
)
|
||||
|
||||
|
||||
class _ChannelsChat:
|
||||
"""The chat service surface the channel rows read: unread counts and mute state."""
|
||||
|
||||
def __init__(self, muted: set[str]) -> None:
|
||||
self._muted = muted
|
||||
|
||||
def unread(self, key: str) -> int:
|
||||
"""A three-digit badge on one channel, so the lane is drawn at its widest."""
|
||||
return 128 if key.endswith("slot:1") or "Lakeside" in key else 0
|
||||
|
||||
|
||||
class _ChannelsCtx:
|
||||
"""The minimal AppContext surface the channel rows and detail page read."""
|
||||
|
||||
def __init__(self, muted: set[str]) -> None:
|
||||
self.chat = _ChannelsChat(muted)
|
||||
self.repo = _ChannelsRepo()
|
||||
self.preferences = Preferences()
|
||||
self._muted = muted
|
||||
|
||||
@property
|
||||
def mute_store(self): # noqa: ANN201 - a stand-in for the real store
|
||||
"""A store answering only the one question a row asks it."""
|
||||
return SimpleNamespace(is_muted=lambda identity: identity in self._muted)
|
||||
|
||||
|
||||
class _ChannelsRepo:
|
||||
"""Channel statistics with one busy channel, one quiet one, and one never used."""
|
||||
|
||||
def channel_stats(self, *a, **k): # noqa: ANN002, ANN003, ANN201
|
||||
"""Return nothing: the rows then draw their empty marks, which is the tighter case."""
|
||||
return {}
|
||||
|
||||
|
||||
class _PickerCtx:
|
||||
"""The minimal AppContext surface :meth:`ChatTool._picker_items` reads."""
|
||||
|
||||
@@ -789,6 +862,8 @@ _ENTRIES: list[_Entry] = [
|
||||
_Entry("map", _map),
|
||||
_Entry("chat", _chat),
|
||||
_Entry("chat_picker", _chat_picker),
|
||||
_Entry("channels_manager", _channels_manager),
|
||||
_Entry("channel_detail", _channel_detail),
|
||||
_Entry("livefeed", _livefeed),
|
||||
_Entry("walk", _walk),
|
||||
_Entry("timemachine", _timemachine),
|
||||
|
||||
Reference in new issue
Block a user