An activity chart that ends a row shortens to fit

The channel list's activity sparkline is the row's last column, and
where the row was too wide for the screen, the PicoCalc's above all,
the row's ellipsis cut it off mid-chart. The row now takes the render
width and draws the chart in whatever cells the lanes before it leave,
dropping its oldest buckets so now stays on the right; with no cell
left it is not drawn, and the ACTIVITY heading shortens and then goes
with it, so MSGS is never cut instead.

A row like that declares itself fitted, so the highlight draws it
fitted too rather than as a full line for the arrows to slide. And a
row exactly as wide as its list no longer claims to overflow by a cell.
CLAUDE.md states the rule for any chart that ends a row.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-03 20:17:33 -04:00
1 parent 149eb0cd90
commit a8bec6f4cc
6 files changed
+134 -43

No files matched your search

+6
View File
@@ -467,6 +467,12 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow
starting `www.`, or ending in a TLD IANA has delegated (`assets/tlds.txt`, the registry
verbatim; refreshing it is downloading it again). So `meshterm.net` is a link and
`file.txt` is not. A scheme-less link opens, and encodes, as `https://…`.
- **A chart that is a row's last column shortens to fit**, on every platform: drawn in
whatever cells the lanes before it leave, its oldest buckets dropped so now stays on the
right, never cut by the row's ellipsis — and left out when no cell is left. The row
title takes the render width to know it (`Choice.title` as a one-argument callable;
`channels._slot_text` is the reference), and the header's label gives way the same way
(`("ACTIVITY", "ACT", "")`, gone with the chart).
- Dialogs anchor slightly above true centre, sized for their populated state.
- Radio traffic: single transmissions or a user-chosen sample count with cooldown pacing
— never bursts.
+61 -35
View File
@@ -473,12 +473,13 @@ _NAME_WIDTH_MAX = 18
#: as wide as the longest scope (never narrower than its ``SCOPE`` label), taking what the
#: names leave of this budget: with a name at :data:`_NAME_WIDTH_MAX` it gets eight cells —
#: what the 72-column row had spare before the lane existed, less the last cell an
#: ellipsizing row keeps back — so the activity sparkline is never cut to make room; shorter
#: names give a long region name more of its own. A 30-byte region name is ellipsized rather
#: than let widen the row. On the PicoCalc's 53 the row was already cut inside the activity
#: lane, so a scope lane there costs the MSGS count behind it; the detail page states it.
#: The leading SLOT lane is paid for out of this budget too (see :func:`_menu_items`), for
#: the same reason: the sparkline keeps its cells.
#: ellipsizing row keeps back — so the activity sparkline keeps its full width on the
#: desktop; shorter names give a long region name more of its own. A 30-byte region name is
#: ellipsized rather than let widen the row. On the PicoCalc's 53 the sparkline is already
#: drawn shorter to fit (see :func:`_slot_text`), so a scope lane there shortens it further,
#: and costs the MSGS count behind it only once the chart has no cells left; the detail page
#: states it. The leading SLOT lane is paid for out of this budget too (see
#: :func:`_menu_items`), for the same reason: the sparkline keeps its cells.
_NAME_SCOPE_BUDGET = _NAME_WIDTH_MAX + 8
#: Narrowest the right-aligned slot-index lane is drawn (two digits: MeshCore's default
#: table holds more than ten slots); a wider table widens it to its highest index.
@@ -491,22 +492,31 @@ _COUNT_WIDTH = 5
_AGE_WIDTH = 5
@lru_cache(maxsize=32)
def _activity_sparkline(histogram: tuple[int, ...], peak: float) -> Text:
"""The channel's braille activity sparkline over the trailing two hours, now at the right.
#: Cells the activity sparkline takes when the row has room for all of it: two five-minute
#: buckets a braille cell, so the trailing two hours.
_ACTIVITY_CELLS = ACTIVITY_DRAWN_BUCKETS // 2
@lru_cache(maxsize=64)
def _activity_sparkline(
histogram: tuple[int, ...], peak: float, cells: int = _ACTIVITY_CELLS
) -> Text:
"""The channel's braille activity sparkline, ``cells`` wide, now at the right.
The shared :func:`~meshterm.ui.braillechart.activity_sparkline` over the newest
:data:`ACTIVITY_DRAWN_BUCKETS` five-minute buckets of the repository histogram,
scaled to ``peak`` — the shared ceiling across every channel (see
:meth:`_LiveStats.peak`) — so the whole activity column shares one scale and the
rows' bars are comparable at a glance. The histogram runs deeper than is drawn; the
tail past the drawn buckets shapes ``peak`` but isn't charted.
``2 × cells`` five-minute buckets of the repository histogram — the trailing two hours
at its full :data:`_ACTIVITY_CELLS`, less where the row has less room (see
:func:`_slot_text`), which drops the *oldest* buckets so now stays on the right edge.
Scaled to ``peak`` — the shared ceiling across every channel (see
:meth:`_LiveStats.peak`) — so the whole activity column shares one scale and the rows'
bars are comparable at a glance. The histogram runs deeper than is drawn; the tail
past the drawn buckets shapes ``peak`` but isn't charted.
Memoized on its (hashable) inputs: the row callables rebuild every repaint, but the
histogram snapshot only moves once per :class:`_LiveStats` TTL, so between refreshes
every slot's sparkline is a cache hit. Callers treat the returned Text as read-only.
"""
return activity_sparkline(histogram, ACTIVITY_DRAWN_BUCKETS, peak=peak)
return activity_sparkline(histogram, 2 * cells, peak=peak)
# --- menus -------------------------------------------------------------------
@@ -519,12 +529,10 @@ def _lanes_header(slot_w: int, name_w: int, scope_w: int, width: int) -> str:
not separators). ``SLOT`` leads — the index every ``channels`` command and the chat's
slot references take — and its lane also spans the unlabelled glyph lane after it,
*measured* rather than assumed: a channel's glyph is two cells on the desktop and one on
the console, so a hard-coded width put every later label a column off there. ``UNREAD``
borrows its lane's trailing gap — the badge lane
itself is one cell too narrow for the word — which still leaves a space before the
message count. (No TYPE or HASH lane: the glyph already carries the openness and the
hash lives in Show key, which buys the activity sparkline its room on a 72-column
terminal.) ``SCOPE`` sits between the name and the badge: it says where the channel's
the console, so a hard-coded width put every later label a column off there. ``NEW``
sits over the unread badge's lane. (No TYPE or HASH lane: the glyph already carries the
openness and the hash lives in Show key, which buys the activity sparkline its room on a
72-column terminal.) ``SCOPE`` sits between the name and the badge: it says where the channel's
messages go, which is the channel's own fact, before the lanes that count its traffic —
and only while some channel has one (``scope_w`` is 0 otherwise). ``LAST`` comes before
``MSGS``: how recently a channel spoke is the question a glance down the list asks, and
@@ -533,7 +541,7 @@ def _lanes_header(slot_w: int, name_w: int, scope_w: int, width: int) -> str:
Resolved against the render width, because the header row is pinned and must stay one
row: at 53 columns the full line ran to 54 and wrapped, costing a content row out of
twenty-six and leaving the landmark drawn twice over. ``ACTIVITY`` gives its cells back
first (see :func:`~meshterm.ui.menus.column_header`).
first (see :func:`~meshterm.ui.menus.column_header`), as the chart under it does.
"""
return column_header(
[
@@ -546,7 +554,7 @@ def _lanes_header(slot_w: int, name_w: int, scope_w: int, width: int) -> str:
# off the digits it names.
Lane(f"{'LAST':>{_AGE_WIDTH}}", _AGE_WIDTH + 2),
Lane(f"{'MSGS':>{_COUNT_WIDTH}}", _COUNT_WIDTH + 2),
Lane(("ACTIVITY", "ACT")),
Lane(("ACTIVITY", "ACT", "")), # gone with its chart (see _slot_text)
],
width,
)
@@ -554,20 +562,27 @@ def _lanes_header(slot_w: int, name_w: int, scope_w: int, width: int) -> str:
def _slot_row(
ctx: AppContext, slot: ChannelSlot, stats: _LiveStats, slot_w: int, name_w: int, scope_w: int
) -> Callable[[], Text]:
) -> Callable[[int], Text]:
"""Return a list-row title *callable* the select screen re-renders on each repaint.
The unread badge, counts, age, and activity sparkline are all read live (see
:class:`_LiveStats`), so a message arriving while the list sits open updates the row on
the next repaint — exactly the conversation picker's behavior.
the next repaint — exactly the conversation picker's behavior. It takes the render
width, so the sparkline can fit itself to the row (see :func:`_slot_text`).
"""
return lambda: _slot_text(ctx, slot, stats, slot_w, name_w, scope_w)
return lambda width: _slot_text(ctx, slot, stats, slot_w, name_w, scope_w, width)
def _slot_text(
ctx: AppContext, slot: ChannelSlot, stats: _LiveStats, slot_w: int, name_w: int, scope_w: int
ctx: AppContext,
slot: ChannelSlot,
stats: _LiveStats,
slot_w: int,
name_w: int,
scope_w: int,
width: int,
) -> Text:
"""Build one channel's list row as fixed-width, colour-coded lanes.
"""Build one channel's list row as fixed-width, colour-coded lanes, ``width`` cells at most.
Alignment carries the readability — slot index (right-aligned, muted), glyph, name,
send scope, unread badge, last-message age, total messages, and the activity
@@ -583,6 +598,12 @@ def _slot_text(
``scope_w`` 0 (no channel has one) the lane is not drawn at all. The row is always a
Rich :class:`~rich.text.Text` so those spans survive under the select screen's row
highlight.
**The sparkline is the last lane, and it shortens to fit** (JP, 2026-10-03): where the
row is narrower than every lane at full width (the PicoCalc and Cardputer's 53 columns,
a long name, a scope lane), the chart is drawn in whatever cells the lanes before it
leave, dropping its oldest buckets so now stays on the right — rather than the row's
ellipsis cutting it off mid-chart. With no cell left for it, it is not drawn at all.
"""
st = stats.get(slot.identity)
muted = _is_muted(ctx, slot)
@@ -619,9 +640,13 @@ def _slot_text(
# row — what the console folds ``🔕`` to, so a muted channel with no messages drew
# the same glyph twice meaning different things.
text.append(f"{'○':>{_COUNT_WIDTH}}", style="muted")
text.append(" ")
# The shared peak across all channels, so every row's sparkline uses one scale.
text.append_text(_activity_sparkline(st.histogram if st is not None else (), stats.peak()))
# Whatever the lanes leave after the gap, up to the chart's full width.
cells = min(_ACTIVITY_CELLS, width - text.cell_len - 2)
if cells > 0:
text.append(" ")
# The shared peak across all channels, so every row's sparkline uses one scale.
histogram = st.histogram if st is not None else ()
text.append_text(_activity_sparkline(histogram, stats.peak(), cells))
return text
@@ -643,7 +668,7 @@ def _menu_items(
# No lane at all while no channel has a scope (see :data:`_NAME_SCOPE_BUDGET`); the
# slot lane and its gap come out of the same budget, so the sparkline keeps its room.
# A drawn scope lane is never narrower than its label — a long name gives up cells
# before the lane would crowd ``SCOPE`` against ``UNREAD``.
# before the lane would crowd ``SCOPE`` against ``NEW``.
budget = _NAME_SCOPE_BUDGET - (slot_w + 2)
scope_w = max(len("SCOPE"), min(budget - name_w, max(*scopes))) if any(scopes) else 0
name_w = min(name_w, budget - scope_w)
@@ -651,9 +676,10 @@ def _menu_items(
# so they pin overhead while the slots scroll and give way to Organize/Add a channel.
items.append(Separator(lambda w: _lanes_header(slot_w, name_w, scope_w, w), heading=True))
for slot in slots:
items.append(
Choice(title=_slot_row(ctx, slot, stats, slot_w, name_w, scope_w), value=slot.idx)
)
# Fitted: the row is whole at any width (its chart shortens), so the highlight
# draws it fitted too rather than as a line for ←→ to slide (Choice.fitted).
row = _slot_row(ctx, slot, stats, slot_w, name_w, scope_w)
items.append(Choice(title=row, value=slot.idx, fitted=True))
else:
items.append(Separator(" no channels yet — add one below"))
+5 -2
View File
@@ -388,7 +388,10 @@ def column_header(lanes: Sequence[Lane], width: int, *, indent: int = 2) -> str:
A header is one row and stays one row. Where the line overruns ``width`` the lanes fall
back to their shorter labels — from the right, since the fixed lanes are padded to their
rows' content and only a trailing lane can actually give a cell back — and a line that
still won't fit is ellipsized. It never wraps: a pinned header (see
still won't fit is ellipsized. A trailing lane whose rows can vanish (a chart that
shortens to fit, then goes) ends its forms on ``""``, so its label goes with it rather
than the line being cut inside the lane before it; the padding after the last label drawn
is air, so it never counts against ``width``. It never wraps: a pinned header (see
:attr:`~meshterm.ui.tui.select.Separator.pinned`) is drawn outside the body slice, where
a second row would cost the content one.
@@ -408,7 +411,7 @@ def column_header(lanes: Sequence[Lane], width: int, *, indent: int = 2) -> str:
for lane, form in zip(lanes, picked, strict=True):
label = lane.forms[form]
out += label + " " * max(0, lane.width - cell_len(label))
return out
return out.rstrip()
at = len(lanes) - 1
while at >= 0 and cell_len(line()) > width:
+27 -6
View File
@@ -74,6 +74,13 @@ class Choice:
list's scrolling on* (see :class:`SelectScreen`): a head block is only meaningful
as the part that stays put, so a row that pins one is a row built to scroll,
wherever the builder's list ends up being shown.
fitted: The width-aware title *is* the row at any width, not a cut of a longer one:
its lanes are fixed and only a trailing chart gives cells back (the Channels
list's activity sparkline, which drops its oldest buckets to fit). The
highlighted row of an ``hscroll`` list then draws that fitted form too, instead
of keeping its natural one for ←→ to slide over — nothing past the edge of such a
row is worth sliding to, and a highlight that flipped the row back to a cut-off
chart would undo the fit on exactly the row being read.
"""
title: str | Text | Callable[[], str | Text] | Callable[[int], str | Text]
@@ -81,6 +88,7 @@ class Choice:
deletable: bool = False
detail: str | Text | Callable[[], str | Text] | None = None
hscroll_from: int = 0
fitted: bool = False
def __post_init__(self) -> None:
"""Read the title callable's arity once, so no paint has to ask again."""
@@ -98,6 +106,16 @@ class Choice:
"""The row's *natural* (unbounded) text — what filtering and measuring read."""
return self.text(_UNBOUNDED)
def scroll_text(self, width: int) -> str | Text:
"""What this row draws, and ←→ slide, as the highlighted row of an ``hscroll`` list.
Its natural form, so the whole line can be slid along — or, for a row whose fitted
form is complete (:attr:`fitted`), that form at ``width``, which by construction
leaves nothing to slide. The drawing, the slide's clamp, and the footer's ←→ atom
all read this one answer, so none of them can disagree about whether the row moves.
"""
return self.text(width) if self.fitted else self.label
@property
def detail_label(self) -> str | Text | None:
"""The row's current detail line, resolving a callable on each read."""
@@ -628,11 +646,10 @@ class SelectScreen(Screen):
current = self._current_choice()
if current is None:
return False
avail = max(1, self._last_width - 2)
return (
self._max_hshift(
cell_len(_plain(current.label)),
current.hscroll_from,
max(1, self._last_width - 2),
cell_len(_plain(current.scroll_text(avail))), current.hscroll_from, avail
)
> 0
)
@@ -702,7 +719,8 @@ class SelectScreen(Screen):
# width — against the row's content area (width less the 2-cell pointer).
self._last_width = width
if self._hscroll and self._hshift:
sel_len = cell_len(_plain(selected.label)) if selected is not None else 0
avail = max(1, width - 2)
sel_len = cell_len(_plain(selected.scroll_text(avail))) if selected is not None else 0
anchor = selected.hscroll_from if selected is not None else 0
self._hshift = max(
0, min(self._hshift, self._max_hshift(sel_len, anchor, max(1, width - 2)))
@@ -789,9 +807,10 @@ class SelectScreen(Screen):
# A width-aware title fits itself to the row's content area (the width less
# the 2-cell pointer). The exception is the highlighted row of an ``hscroll``
# list, which keeps its natural form: ←→ slide the full line, and a row that
# pre-elided itself would have nothing left to slide over.
# pre-elided itself would have nothing left to slide over — unless the row
# declares its fitted form complete (``Choice.fitted``).
if self._hscroll and is_sel:
label = item.label
label = item.scroll_text(max(1, width - 2))
else:
label = item.text(max(1, width - 2))
pointer = "❯ " if is_sel else " "
@@ -830,6 +849,8 @@ class SelectScreen(Screen):
"""
lane = max(1, avail - max(0, anchor))
run = max(0, label_cells - max(0, anchor))
if run <= lane:
return 0 # the whole run is in view unscrolled: nothing to slide to
steps = -(-max(0, run - (lane - 1)) // self._HSCROLL_STEP)
return steps * self._HSCROLL_STEP
+15
View File
@@ -691,6 +691,9 @@ def test_activity_sparkline_packs_24_buckets_into_braille() -> None:
# (fullest here) pair in the rightmost cell.
ramp = _activity_sparkline((16, 12, 8, 4) + (0,) * 20, 16).plain
assert ramp[-2:] == chr(0x2800 | 0x40 | 0xA0) + chr(0x2800 | 0x46 | 0xB8)
# Drawn shorter, it keeps the newest buckets: the same ramp, only less history.
short = _activity_sparkline((16, 12, 8, 4) + (0,) * 20, 16, 3).plain
assert len(short) == 3 and short[-2:] == ramp[-2:]
async def test_channel_rows_carry_stats_unread_and_lanes(ctx: AppContext) -> None:
@@ -726,6 +729,18 @@ async def test_channel_rows_carry_stats_unread_and_lanes(ctx: AppContext) -> Non
label = row.label
assert label.spans[-1].style == "ok" # …and its newest cell reads as live traffic
# Narrower than the whole row, the chart shortens to fit instead of being cut: the row
# ends exactly at the edge, on the same newest cell, with less history behind it.
natural = cell_len(plain)
now_cell = chr(0x2800 | 0x40 | 0xB8)
for width in (natural - 1, natural - 5, natural - 11):
fitted = row.text(width).plain
assert cell_len(fitted) == width and "…" not in fitted
assert fitted.endswith(now_cell)
# With no cell left for it, the chart is left out rather than drawn as a stub of gap.
lanes_only = row.text(natural - 13).plain
assert now_cell not in lanes_only and "⣀" not in lanes_only
async def test_standard_public_row_appears_only_while_it_is_absent(ctx: AppContext) -> None:
"""The 'Standard Public channel' add-action shows until a slot holds the fixed-key default."""
+20
View File
@@ -262,6 +262,26 @@ def test_select_hscroll_highlight_keeps_the_natural_row() -> None:
assert "start ⋯ end" in body # the unhighlighted row fitted itself
def test_select_hscroll_highlight_draws_a_fitted_row_fitted() -> None:
"""A row whose fitted form is complete (``Choice.fitted``) stays fitted under the highlight.
The Channels list's rows shorten their trailing chart to the width; drawn natural under
the highlight, the chart came back cut off on exactly the row being read. Nothing past
such a row's edge is worth sliding to, so it doesn't claim to overflow either: no ←→
atom, and → leaves it where it is.
"""
def chart_row(width: int) -> str:
return "lanes " + "⣀" * max(0, min(12, width - 6))
screen = SelectScreen("pick", [Choice(chart_row, 1, fitted=True)], hscroll=True)
lines = [Text.from_ansi(line).plain for line in screen.render_body(14)]
assert lines[0] == "❯ lanes " + "⣀" * 6 # fitted to the 12-cell content area
assert not screen._selected_overflows()
screen.handle("right")
assert [Text.from_ansi(line).plain for line in screen.render_body(14)] == lines
def test_select_filter_matches_callable_title() -> None:
"""Type-to-filter matches against a callable title's current text."""
screen = SelectScreen("pick", [Choice(lambda: "alpha", 1), Choice("beta", 2)])