A chat link is never cut where the screen can hold it, and ^U shows its code

A URL too long for a message's hanging lane steps out to the timestamp's
column on a line of its own, whole, since a terminal opens a link, and a
reader copies one, only while it sits on one line. Only a URL wider than
the screen still folds. ^U on a picked message opens its links on the
share screen, one code at a time, and with several, the arrows step
through them, the URL line flanked by a lit or dim arrow each way. On the
PicoCalc the lane carries it as QR, behind Day down.

CLAUDE.md also states the shortcut rule: a bare letter only on a screen
that takes no typing, a Ctrl chord everywhere letters are text.

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-01 23:07:51 -04:00
1 parent f847ebd637
commit c6c80b4c1f
8 files changed
+365 -27

No files matched your search

+15
View File
@@ -222,6 +222,12 @@ deliberately, one at a time, and say why in the code.
- Label + description command rows go through `menu_rows` (two cell-aligned lanes,
description muted). Editor rows (setting/value/description) go through `lane_row`.
- A row that opens further prompts ends with `…`; a row that acts immediately doesn't.
- **A bare-letter shortcut only where nothing is typed.** A screen that filters, finds or
composes as you type has no free letters, so its verbs are Ctrl chords — one table,
`session._CTRL_LETTER_CHORDS`, each letter the mnemonic of its action (`^P` paths,
`^U` URL, `^Y` you). A screen that takes no typing may spend a bare letter instead (the
Time Machine's `w`, the dashboard's `s`, the device splash's `h`). Either way the key
is named where it acts: in the hint, and on the PicoCalc's lane.
- Empty states are lowercase muted, optionally `— explanation`, never parenthesized.
- Body section headings inside screens: accent title, optional muted ` · note`.
- A find-as-you-type screen echoes its live query as `/query` in `warn`, on its own body
@@ -243,6 +249,11 @@ deliberately, one at a time, and say why in the code.
narrower quiet zone, before it would ever be cut (a contact card is 57 cells and 29
rows at the standard fit in half blocks; a regular terminal is 24 tall), and when code
and URL can't share the frame the code is whole at the top and the URL a page down.
A chat message's links open there too, on every platform: ^U on the picked message,
and with several, one code at a time that ←→ step through, clamped. That screen's URL
line is flanked `←`/`→`, lit toward another code and dim at an end — the one mark the
bare frame carries beyond the code and its URL, because nothing else could say the
others are there.
Two codes sit inline instead: a ` ```qr ` fence in a written page, where the code is an
illustration drawn in the prose where the fence is, and — on the PicoCalc alone
(`Platform.url_codes`) — a chat message's URLs, each drawn as a code under the message
@@ -441,6 +452,10 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow
### Layout
- Wrapped labelled rows hang under their value block (two-column grid), never column 0.
The one exception is a **URL, which is never cut where the screen can hold it**: one too
long for its hanging lane steps out to the gutter on a line of its own
(`render_hanging(whole=…, gutter=…)`), since a terminal opens a link, and a reader
copies one, only while it sits on one line. Only a URL wider than the screen folds.
- 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.
+79 -14
View File
@@ -30,7 +30,7 @@ from ..core.events import EventKind, MeshEvent
from ..core.models import ChatMessage, Contact, Conversation, Message, utcnow
from ..core.regions import WILDCARD
from ..platforms import Platform, on_platform
from .qr import qr_strip
from .qr import QrScreen, qr_strip
from .theme import name_style, snr_style
from .tui.prompt import (
CHANNEL_BYTE_LIMIT,
@@ -67,6 +67,14 @@ _TRAILING = ".,;:!?'\""
#: inside it, so ``(see https://example.com/a_(b))`` keeps the ``)`` that belongs to it.
_CLOSERS = {")": "(", "]": "[", "}": "{"}
#: A whitespace-delimited word — the unit the wrap moves whole, so the run a URL must not be
#: cut across is the word it sits in, any bracket or full stop beside it included.
_WORD = re.compile(r"\S+")
#: The column a URL too long to hang under its body starts at instead: the timestamp's,
#: clear of the ``❯`` the picked message's first line carries in front of it.
_URL_GUTTER = 2
#: Whether a message's URLs are drawn as QR codes under it (``Platform.url_codes``, the
#: PicoCalc's alone). Bound per platform, never asked per frame.
_URL_CODES = False
@@ -106,8 +114,8 @@ class ChatScreen(Screen):
Enter sends the current line, or acts on a picked message: in a channel it primes
a reply ``@mention``, in a direct chat it opens the message's delivery paths. ^P
opens the picked message's paths in either kind — a path belongs to one message, so
with nothing picked there is nothing to show. Esc leaves the chat once nothing is
picked.
with nothing picked there is nothing to show — and ^U its links as QR codes, on the
share screen. Esc leaves the chat once nothing is picked.
A channel with a send scope names its region in the title (``#ops · yul``), and ^R there
resends a message *unscoped* — the picked one, or with nothing picked the newest — the
@@ -149,6 +157,10 @@ class ChatScreen(Screen):
outside ``Day ↓``, matching both the pager on the right and the list it echoes.
Lit only with more than one day to step between: a conversation held in an
afternoon has sections the way a one-section list does — none.
``QR`` (^U) rides F2's Shift half, beside ``Retry`` on F3's, the two being things
to do *to* the picked message: its links' codes on a share screen, larger than
the ones hung under it in the transcript. Lit while the pick carries a URL.
"""
from .tui.fkeys import FPair, default_lane
@@ -161,7 +173,14 @@ class ChatScreen(Screen):
!= self._messages[-1].created_at.astimezone().date()
)
lane[0] = FPair("Day ↑", "ctrl_pageup", enabled=days)
lane[1] = FPair("Day ↓", "ctrl_pagedown", enabled=days)
lane[1] = FPair(
"Day ↓",
"ctrl_pagedown",
"QR",
"url_code",
enabled=days,
opp_enabled=bool(self._picked_urls()),
)
lane[3] = FPair("Page ↓", "pagedown", "Latest", "ctrl_end", enabled=live, opp_enabled=live)
lane[4] = FPair("Page ↑", "pageup", "Oldest", "ctrl_home", enabled=live, opp_enabled=live)
if not self._is_channel:
@@ -249,6 +268,7 @@ class ChatScreen(Screen):
self._status = ""
self._stick = True # keep the newest message in view until the user scrolls up
self._paths_open = False # one paths dialog at a time
self._codes_open = False # one links share screen at a time
self._paste_open = False # one paste-confirm dialog at a time
self._resend_open = False # one resend-unscoped confirm at a time
# The pick: index of the highlighted message (or None when the compose line is
@@ -280,18 +300,22 @@ class ChatScreen(Screen):
"""Key hint, reflecting whether a message is picked and what Enter does to it.
Only keys that would act appear: ``^P paths`` needs a picked message to show the
paths *of*, and ``^R retry failed`` needs something to retry (see
:meth:`_retry_target`) — the same rules the F-key lane dims its slots by.
paths *of*, ``^U QR`` a picked message with a URL in it (see :meth:`_picked_urls`),
and ``^R retry failed`` something to retry (see :meth:`_retry_target`) — the same
rules the F-key lane dims its slots by.
"""
if self._selected is not None:
code = " · ^U QR" if self._picked_urls() else ""
if self._is_channel and self._retry_target() is not None:
# A picked scoped message of ours can be resent unscoped, and that key has
# to be named; the reply's "(@mention)" and ^End give way to keep the line
# inside 72 (Esc still cancels the pick, and Enter still says what it does).
return "Enter reply · ^P paths · ^R resend unscoped · ↑↓ pick · Esc cancel"
# inside 72 (Esc still cancels the pick, and Enter still says what it does),
# and ↑↓ too when a link's code is also there to name.
pick = "" if code else " · ↑↓ pick"
return f"Enter reply · ^P paths{code} · ^R resend unscoped{pick} · Esc cancel"
if self._is_channel:
return "Enter reply (@mention) · ^P paths · ↑↓ pick · ^End/Esc cancel"
return "Enter paths · ↑↓ pick · ^End/Esc cancel"
return f"Enter reply (@mention) · ^P paths{code} · ↑↓ pick · ^End/Esc cancel"
return f"Enter paths{code} · ↑↓ pick · ^End/Esc cancel"
if self._retry_target() is not None:
if self._is_channel:
return "Enter send · ↑ pick a message · ^R resend unscoped · Esc back"
@@ -571,6 +595,11 @@ class ChatScreen(Screen):
rather than under the timestamp gutter. When ``selected``, the line is marked as the
reply target (matching the select screen's ``❯`` pointer and cursor highlight).
A URL is never cut where the screen can hold it: one too long for the body's lane
steps out to the timestamp's column on a line of its own (see
:func:`~meshterm.ui.tui.render.render_hanging`), since a terminal opens a link, and
a reader copies one, only while it sits on one line.
Where the platform draws them (:data:`_URL_CODES`, the PicoCalc), each URL in the
body gets a QR code under it, side by side and hanging at the body's indent, so a
link read on the handheld can be opened on a phone instead of typed out.
@@ -580,7 +609,10 @@ class ChatScreen(Screen):
prefix.append("❯ " if selected else " ", style="cursor" if selected else None)
prefix.append(f"{stamp:%H:%M} ", style="cursor" if selected else "muted")
body_text = self._body_text(body, message, selected=selected)
lines = render_hanging(prefix, body_text, width, indent=prefix.cell_len)
whole = [m.span() for m in _WORD.finditer(body_text.plain) if _URL.search(m.group())]
lines = render_hanging(
prefix, body_text, width, indent=prefix.cell_len, whole=whole, gutter=_URL_GUTTER
)
urls = _urls(body) if _URL_CODES else []
if urls:
lines += render_lines(qr_strip(urls, width, indent=prefix.cell_len), width)
@@ -722,9 +754,10 @@ class ChatScreen(Screen):
↑↓, PgUp/PgDn (a screenful), Ctrl+Home (the very first message), and
Ctrl+PgUp/PgDn (day dividers), carrying the view with it. Enter on a picked
message primes a reply ``@mention`` in a channel and opens the delivery paths
in a direct chat; ^P opens the picked message's paths in either kind, and does
nothing while nothing is picked. ^End (or moving past the newest) returns to the
compose line; Esc peels the pick first, the screen second.
in a direct chat; ^P opens the picked message's paths in either kind, and ^U its
links' QR codes, each doing nothing while nothing is picked. ^End (or moving past
the newest) returns to the compose line; Esc peels the pick first, the screen
second.
"""
if action == "enter":
if self._selected is not None:
@@ -738,6 +771,8 @@ class ChatScreen(Screen):
self._begin_paste(data)
elif action == "paths":
self._open_paths(self._selected)
elif action == "url_code":
self._open_codes()
elif action == "retry":
if self._is_channel:
self._begin_resend_unscoped()
@@ -796,6 +831,36 @@ class ChatScreen(Screen):
self._session.run_detached(run())
def _picked_urls(self) -> list[str]:
"""The URLs in the picked message's body, in reading order; none with nothing picked."""
if self._selected is None or not self._messages:
return []
message = self._messages[max(0, min(self._selected, len(self._messages) - 1))]
return _urls(self._sender_and_body(message)[1])
def _open_codes(self) -> None:
"""Show the picked message's links as QR codes on the share screen (^U).
The share screen a channel or a contact card gets (:class:`~meshterm.ui.qr.
QrScreen`), full-frame, so a phone can take a link read here and open it. Several
links are one screen that ←→ steps through, in the order the message gives them.
Like ^P it acts on the *pick*: a link belongs to one message, and with nothing
picked there is no telling which. One share screen at a time.
"""
urls = self._picked_urls()
if not urls or self._codes_open:
return
self._codes_open = True
async def run() -> None:
try:
await self._session.run_screen(QrScreen(*urls, title="Links"))
finally:
self._codes_open = False
self._session.invalidate()
self._session.run_detached(run())
def _begin_paste(self, data: str) -> None:
"""Confirm a clipboard paste on an amber dialog, then insert it into the compose line.
+45 -6
View File
@@ -19,7 +19,8 @@ URL it encodes, so the whole panel is contrast for the camera and the one line a
might type out instead. A code sits *inside* a page in two places: a ``qr`` fence in a
written page (:mod:`~meshterm.ui.markdown`), which draws :func:`qr_text` in the flow of
its prose, and — on the PicoCalc — a chat message carrying URLs, which hangs a code for
each under its text, side by side (:func:`qr_strip`).
each under its text, side by side (:func:`qr_strip`). The same message's links also open
on the share screen (^U), on every platform, one code at a time.
"""
from __future__ import annotations
@@ -300,20 +301,58 @@ class QrScreen(ScrollScreen):
nothing. The fit is asked to hold the code *and* the URL first; failing that, the
code alone, with the URL a page down; failing that, the smallest code there is, and
the frame windows it from the top so a larger terminal shows it whole.
Given **several** URLs (a chat message's links), it is still one screen, showing one
code at a time: ←→ step through them in order and stop at either end, and the URL
line is flanked by ``←``/``→`` — lit where there is another code that way, dim where
there isn't — the one mark the bare frame carries beyond the code and its URL,
because nothing else on it could say the others are there.
"""
bare = True
def __init__(self, url: str, *, title: str) -> None:
"""Set up the share screen for ``url``.
def __init__(self, *urls: str, title: str) -> None:
"""Set up the share screen for ``urls``, showing the first.
Args:
url: The ``meshcore://…`` share URL, encoded as the code and printed under it.
urls: The URLs to show, in order — one share URL (``meshcore://…``), or the
links a chat message carries. Each is encoded as the code and printed
under it.
title: ``Share {name}`` — never drawn on the bare frame; the screen's name
for the log and the stack.
"""
super().__init__(Text(""), title=title, floating=False)
self.url = url
self.urls = urls
self._index = 0
@property
def url(self) -> str:
"""The URL whose code is showing."""
return self.urls[self._index]
def _link(self) -> Text:
"""The URL line: the URL, and with several, the ←→ that step to the others."""
link = Text(justify="center")
several = len(self.urls) > 1
if several:
link.append("← ", style="accent" if self._index > 0 else "muted")
link.append(self.url, style="accent")
if several:
last = len(self.urls) - 1
link.append(" →", style="accent" if self._index < last else "muted")
return link
def handle(self, action: str, data: str = "") -> None:
"""Step to the previous or next URL's code on ←→, or behave as a result window."""
if action in ("left", "right"):
# Clamped like every cursor in the app: held arrows settle at an end.
step = -1 if action == "left" else 1
index = max(0, min(len(self.urls) - 1, self._index + step))
if index != self._index:
self._index = index
self.scroll_to_top()
return
super().handle(action, data)
def render_body(self, width: int) -> list[str]:
"""The code fitted to ``width`` and the frame's rows, then a blank row, then the URL."""
@@ -321,7 +360,7 @@ class QrScreen(ScrollScreen):
# this is the whole terminal's rows; before any paint it is the default 1, and
# the smallest code stands in until the first paint corrects it.
rows = self._scroll_viewport
link = Text(self.url, style="accent", justify="center")
link = self._link()
link_rows = len(render_lines(link, width))
code, border = (
_fit(self.url, width, rows - 1 - link_rows)
+62 -5
View File
@@ -13,6 +13,7 @@ automatically when the terminal is resized.
from __future__ import annotations
from collections import OrderedDict
from collections.abc import Sequence
from io import StringIO
from rich.cells import cell_len
@@ -362,7 +363,15 @@ def crop_cells(text: Text, start: int, width: int) -> Text:
return out
def render_hanging(prefix: Text, body: Text, width: int, *, indent: int) -> list[str]:
def render_hanging(
prefix: Text,
body: Text,
width: int,
*,
indent: int,
whole: Sequence[tuple[int, int]] = (),
gutter: int = 0,
) -> list[str]:
"""Render ``prefix + body`` at ``width``, wrapping the body with a hanging indent.
The first visual line carries ``prefix`` followed by the body; every wrapped
@@ -370,11 +379,22 @@ def render_hanging(prefix: Text, body: Text, width: int, *, indent: int) -> list
than falling back to column zero. Used by the chat transcript so a wrapped message
lines up with its own first line instead of with the timestamp gutter.
``whole`` names runs of the body that must not be cut where the screen can hold them —
a URL, which a terminal can only open, and a reader only copy, while it sits on one
line. A run that fits the hanging lane needs nothing: the wrap already moves a word
to the next line rather than splitting it. One that outruns the lane but not the
screen steps out of the block onto a line of its own, starting at ``gutter`` (or as
far right of it as still fits); the body resumes under its indent after it, unless
what follows is short enough to finish the run's own line. Only a run wider than the
whole screen is folded, as before, since no line could hold it.
Args:
prefix: The leading run (e.g. a pointer + timestamp) shown once, on the first line.
body: The wrappable message text; styling (mentions, glyphs) is preserved.
width: Total render width in columns.
indent: Columns to indent continuation lines by (typically ``prefix.cell_len``).
whole: ``(start, end)`` offsets into ``body.plain`` of runs to keep on one line.
gutter: The column a run too wide for the lane starts at, when it can.
Returns:
The rendered lines, newline-free.
@@ -382,12 +402,49 @@ def render_hanging(prefix: Text, body: Text, width: int, *, indent: int) -> list
width = max(1, width)
console = _console(width)
avail = max(1, width - indent)
wrapped = list(body.wrap(console, avail)) or [Text("")]
pad = " " * indent
plain = body.plain
# The runs that need the step out: wider than the lane, no wider than the screen.
out = [
(start, end) for start, end in sorted(whole) if avail < cell_len(plain[start:end]) <= width
]
rows: list[tuple[int, Text]] = [] # (left pad, line); the first row's pad is the prefix
def hang(start: int, end: int) -> None:
"""Wrap ``body[start:end]`` under the indent, trimming the seams beside a run."""
if out:
while start < end and plain[start].isspace() and start:
start += 1
while end > start and plain[end - 1].isspace():
end -= 1
lines = list(body[start:end].wrap(console, avail)) if end > start else []
if not rows and not lines:
lines = [Text("")] # the prefix's line, even when the body opens on a run
rows.extend((indent, line) for line in lines)
pos = 0
for i, (start, end) in enumerate(out):
if start < pos:
continue
hang(pos, start)
length = cell_len(plain[start:end])
pad = gutter if length + gutter <= width else width - length
line = body[start:end]
# What follows up to the next run joins this line when it fits whole: a delivery
# mark or an SNR left alone on a line of its own reads as a stray.
upto = out[i + 1][0] if i + 1 < len(out) else len(plain)
tail = plain[end:upto].rstrip()
if tail and "\n" not in tail and pad + length + cell_len(tail) <= width:
line.append_text(body[end : end + len(tail)])
end = upto
rows.append((pad, line))
pos = end
if pos < len(plain) or not rows:
hang(pos, len(plain))
combined = Text()
for i, line in enumerate(wrapped):
for i, (pad, line) in enumerate(rows):
if i:
combined.append("\n")
combined.append_text(prefix if i == 0 else Text(pad))
combined.append_text(prefix if i == 0 else Text(" " * pad))
combined.append_text(line)
return render_lines(combined, width)
+4 -2
View File
@@ -64,8 +64,9 @@ from .spinner import spinner_interval
#: ``m``/``i``/``h`` are not free: prompt_toolkit spells Enter, Tab and Backspace as
#: ``Keys.ControlM``/``ControlI``/``ControlH``, so claiming them here would rebind those keys.
#: A chord's letter is the mnemonic of the *action*, not of one screen's word for it —
#: ``locate`` is ^Y for **you** (JP, 2026-08-09; ^U until 2026-10-01), the same key on the
#: map and in the mesh walk, because what it names on both is our own node.
#: ``locate`` is ^Y for **you** (JP, 2026-08-09), the same key on the map and in the mesh
#: walk, because what it names on both is our own node; it was ^U until 2026-10-01, when U
#: went to ``url_code`` — a chat message's links as QR codes.
#:
#: Two of these are app-wide rather than a screen's: ``to_menu`` (^W) unwinds the whole
#: navigation stack back to the main menu, and ``quit`` (^Q, alongside the older ^C) asks
@@ -85,6 +86,7 @@ _CTRL_LETTER_CHORDS: dict[str, str] = {
# ^S is XOFF's key, and safe here for the same reason ^Q is not XON (see above): raw
# mode clears IXON/IXOFF, so the terminal never eats it to freeze the screen.
"s": "reveal",
"u": "url_code",
"v": "paste_clipboard",
"w": "to_menu",
"y": "locate",
+30
View File
@@ -275,6 +275,36 @@ def test_the_share_screen_refits_its_code_to_the_frame_every_paint() -> None:
assert len(code_rows(53, 26)) <= 26 # the PicoCalc: likewise
def test_several_links_are_one_share_screen_that_arrows_step_through() -> None:
"""←→ move between the codes and stop at the ends; the URL line says which way has more.
One link draws no arrows at all — there is nowhere to step — so a share card keeps
its bare frame exactly as it was.
"""
first, second = "https://meshterm.net", "https://github.com/jpmartineau/MeshTerm"
screen = QrScreen(first, second, title="Links")
screen.note_viewport(24)
def link_line() -> str:
lines = [_ANSI.sub("", line) for line in screen.render_body(72)]
return next(line for line in lines if "https://" in line).strip()
assert screen.url == first and link_line() == f"← {first} →"
screen.handle("left") # clamped: already at the first
assert screen.url == first
screen.handle("right")
assert screen.url == second and link_line() == f"← {second} →"
screen.handle("right") # clamped at the last, never back round to the first
assert screen.url == second
assert "→" in screen._link().plain and screen._link().spans[-1].style == "muted"
assert screen._link().spans[0].style == "accent" # ← lit: the first is that way
single = QrScreen(first, title="Share Lakeside")
single.note_viewport(24)
lines = [_ANSI.sub("", line) for line in single.render_body(72)]
assert next(line for line in lines if "https://" in line).strip() == first
def test_where_braille_is_solid_every_code_is_drawn_in_it() -> None:
"""On the PicoCalc a code is braille, one module a dot — eight to a cell.
+96
View File
@@ -2434,3 +2434,99 @@ def test_a_picked_message_keeps_its_codes_in_view() -> None:
whole = _code_rows(_strip_ansi(screen._render_grouped(53)).splitlines())
assert any("map at https://meshterm.net" in row for row in shown)
assert len(_code_rows(shown)) == len(whole) # every row of the code, none below the fold
# -- URLs kept whole, and their codes on ^U --------------------------------------------
#: A link longer than the regular body lane (72 - the 9-cell gutter) but not the screen.
_LONG_URL = "https://github.com/jpmartineau/MeshTerm/blob/main/meshterm/ui/chat.py"
def _url_chat(text: str, session=None) -> ChatScreen: # noqa: ANN001
conv = Conversation(label="#ops", is_channel=True, channel_idx=1)
message = ChatMessage(text=f"Alice: {text}", is_channel=True)
return ChatScreen(conv, [message], send=None, names={}, session=session or _StubSession())
def test_a_url_too_long_to_hang_steps_out_to_the_gutter_whole() -> None:
"""A link the body lane can't hold, but the screen can, is drawn on one line, uncut.
It starts under the timestamp — clear of the picked message's ``❯`` — and the body
resumes at its own indent after it, so only the link leaves the block.
"""
screen = _url_chat(f"look at {_LONG_URL} and tell me what you think of it all")
rows = _strip_ansi(screen._render_grouped(72)).splitlines()
link = next(row for row in rows if _LONG_URL[:20] in row)
assert link == " " + _LONG_URL # whole, at the gutter
after = rows[rows.index(link) + 1]
assert after.startswith(" " * 9 + "and tell me") # back under the body's indent
screen.handle("up") # picked: the ❯ is on the first line, never the link's
rows = _strip_ansi(screen._render_grouped(72)).splitlines()
assert " " + _LONG_URL in rows
def test_a_short_tail_finishes_the_links_line_and_a_too_wide_link_still_folds() -> None:
"""What fits after a stepped-out link stays on its line; a link no screen holds folds."""
url = "https://meshterm.net/" + "a" * 46 # 67 cells: wider than the 63-cell lane
rows = _strip_ansi(_url_chat(f"see {url} ok")._render_grouped(72)).splitlines()
assert " " + url + " ok" in rows # 2 + 67 + 3: exactly the screen
rows = _strip_ansi(_url_chat(f"see {url} ok!")._render_grouped(72)).splitlines()
assert " " + url in rows and " " * 9 + "ok!" in rows # a cell too many: below it
wide = "https://meshterm.net/" + "b" * 60 # 81 cells: wider than the screen
rows = _strip_ansi(_url_chat(f"see {wide}")._render_grouped(72)).splitlines()
assert not any(wide in row for row in rows) # cut, as before
assert all(row.startswith(" " * 9) for row in rows if "bbb" in row) # hanging, as before
def test_ctrl_u_opens_the_picked_messages_links_on_one_share_screen() -> None:
"""^U shows the pick's links as QR codes, all of them, in the order the message gives."""
from meshterm.ui.qr import QrScreen
opened: list = []
class Session(_StubSession):
async def run_screen(self, screen): # noqa: ANN001, ANN202
opened.append(screen)
async def scenario() -> None:
screen = _url_chat(f"map at https://meshterm.net, code at {_LONG_URL}!", Session())
screen.handle("url_code") # nothing picked: no telling which message's links
await asyncio.sleep(0)
assert opened == []
screen.handle("up")
screen.handle("url_code")
await asyncio.sleep(0)
assert len(opened) == 1 and isinstance(opened[0], QrScreen)
assert opened[0].urls == ("https://meshterm.net", _LONG_URL)
asyncio.run(scenario())
def test_ctrl_u_is_named_only_on_a_picked_message_with_a_link() -> None:
"""The hint names ^U where it acts and stays inside 72; the lane lights QR the same way."""
plain = _url_chat("no links here")
linked = _url_chat("map at https://meshterm.net")
assert "^U" not in linked.footer_hint # nothing picked yet
linked.handle("up")
plain.handle("up")
assert "^U QR" in linked.footer_hint and "^U" not in plain.footer_hint
assert fkeys.action_for(linked.fkey_lane, 7) == "url_code" # Shift+F2
assert linked.fkey_lane[1].opp_enabled and not plain.fkey_lane[1].opp_enabled
# Every pick state's hint, with a link in it, inside the 72-cell budget.
direct = _screen(
_StubSession(),
send=None,
messages=[ChatMessage(text="see https://meshterm.net", peer="d4e5f6a7")],
)
direct.handle("up")
scoped = _url_chat("x")
scoped._retry_target = lambda: 0 # a resendable pick, the longest hint there is
scoped._messages[0] = ChatMessage(text="see https://meshterm.net", is_channel=True)
scoped.handle("up")
for screen in (linked, direct, scoped):
assert "^U QR" in screen.footer_hint
assert len(screen.footer_hint) <= 72, screen.footer_hint
+34
View File
@@ -561,6 +561,29 @@ def _chat_urls(cols: int, rows: int) -> Screen:
return ChatScreen(conv, messages, send=None, names={}, session=_GallerySession(cols, rows))
def _chat_long_url(cols: int, rows: int) -> Screen:
"""A picked message whose link outruns the body lane: it steps out whole, and ^U is named.
Regular's 72-cell gate sees the link start at the gutter and the hint carrying
``^U QR``; on the PicoCalc the same link folds under the indent (it is wider than the
whole panel) with its code hung below, and the lane lights ``QR``.
"""
conv = Conversation(label="Lakeside emergency", is_channel=True, channel_idx=2)
messages = [
ChatMessage(
text=(
"Alice: the full road list is at "
"https://github.com/jpmartineau/MeshTerm/blob/main/meshterm/ui/chat.py "
"if anyone needs it"
),
is_channel=True,
),
]
screen = ChatScreen(conv, messages, send=None, names={}, session=_GallerySession(cols, rows))
screen.handle("up")
return screen
class _PickerChat:
"""The unread counter the picker rows read live."""
@@ -1410,6 +1433,15 @@ def _share_qr(cols: int, rows: int) -> Screen:
return QrScreen(url, title="Share Lakeside")
def _links_qr(cols: int, rows: int) -> Screen:
"""A chat message's two links on the share screen: one code, ←→ flanking its URL."""
from meshterm.ui.qr import QrScreen
return QrScreen(
"https://meshterm.net/map", "https://github.com/jpmartineau/MeshTerm", title="Links"
)
_ENTRIES: list[_Entry] = [
_Entry("dashboard", _dashboard),
_Entry("dashboard-scoped", _dashboard_scoped),
@@ -1426,6 +1458,7 @@ _ENTRIES: list[_Entry] = [
_Entry("chat", _chat),
_Entry("chat_channel_scoped", _chat_channel_scoped),
_Entry("chat_urls", _chat_urls),
_Entry("chat_long_url", _chat_long_url),
_Entry("chat_picker", _chat_picker),
_Entry("channels_manager", _channels_manager),
_Entry("channel_detail", _channel_detail),
@@ -1465,6 +1498,7 @@ _ENTRIES: list[_Entry] = [
_Entry("join_discord", _join_discord),
_Entry("support_project", _support_project),
_Entry("share_qr", _share_qr),
_Entry("links_qr", _links_qr),
_Entry("diagnostics", _diagnostics),
]