Screens: Esc is the way out, so no row spends two lines saying so
The app-wide Back row existed because it duplicated Esc — two of its call sites said as much in a comment. On both platforms Esc is a labelled key and every footer hint names it, so the row bought nothing for the blank separator and line it took out of every screen; on the PicoCalc's 26 rows that is a row in thirteen. back_rows() is gone, and with it the four hand-drawn copies: ReorderScreen's clean-state row, the live feed's pinned foot stop (the cursor now clamps on the oldest packet), node detail's tail action, and the action-list rows on the trace and TX-sweep screens. Kept, because there leaving is a choice rather than an exit — the same rule that keeps a dialog's Cancel button: exit_rows()' staged pair, where Apply has no key of its own and ✗ Back names what the other way out costs; ReorderScreen's dirty-state pair; the two Quit rows, which initiate the app's terminal action behind a confirm; and the new-record dialog's Close, which is its default, so dropping it would let a reflex Enter navigate. With no Back row there is no Back value: the six spellings callers used to test three at a time (_BACK, "__back__", _CANCEL, two tuple shapes, bare None) collapse to `is CANCEL` / `is None`. The gallery now asserts the absence of an exit row on every screen, on both platforms. Resolves findings E and §10 of docs/survey-navigation.md. Finding D — Esc peeling a filter on three screens and leaving on two — still stands, and is now the only thing left telling a user what Esc does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9d524a27a2
commit
972c0b6f03
27 files changed
+292
-342
No files matched your search
@@ -22,7 +22,7 @@ These are binding. Every new screen, dialog, row, or hint follows them; when you
|
||||
old one that doesn't, bring it along. The enforcement points live in code — build through
|
||||
them instead of hand-rolling:
|
||||
|
||||
- `ui/menus.py` — `back_rows`, `exit_rows`, `menu_rows`, `lane_row`, `section_heading`,
|
||||
- `ui/menus.py` — `exit_rows`, `menu_rows`, `lane_row`, `section_heading`,
|
||||
`confirm_discard`, `fit_cells`.
|
||||
- `ui/markdown.py` — `render_markdown` (THE prose renderer: a page of writing, drawn in
|
||||
the language below).
|
||||
@@ -44,7 +44,7 @@ them instead of hand-rolling:
|
||||
| path | an ordered hop spec you compose or force (`a1,3d,…`) |
|
||||
| route | the concrete node sequence a trace walked or will walk |
|
||||
| via | prefix for a packet/message's relay chain |
|
||||
| Back | leave the current screen/list (the only exit word on rows) |
|
||||
| Back | leave the current screen/list — Esc's word, and a row's only where leaving is a *choice* (see below) |
|
||||
| Quit | leave the app (main menu, device splash) — nowhere else |
|
||||
|
||||
Node vs contact — the boundary: **node** is the hardware/participant sense — the map,
|
||||
@@ -60,10 +60,21 @@ Relative ages: `format_ago` for prose ("now", "5m ago", "never" — never "now a
|
||||
|
||||
### Screens and lists
|
||||
|
||||
- Every select list ends with the exit group from `back_rows()` / `exit_rows()`: exactly
|
||||
one blank `Separator(" ")` line, then the bare word **Back** (no arrow, no icon).
|
||||
Editors with staged changes show `✓ Apply n staged changes` over
|
||||
`✗ Back — discard staged changes`.
|
||||
- **No screen carries an exit row.** Esc leaves — it is on both platforms' keyboards and
|
||||
every footer hint says so — so a row that only repeated it was two lines out of every
|
||||
screen (a row in thirteen on the PicoCalc's 26) buying nothing. Lists end on their last
|
||||
content row; a hand-drawn action list ends on its last verb. The gallery enforces it:
|
||||
no rendered line may be the bare word **Back**.
|
||||
- The exception is where leaving is a **choice** rather than an exit, which is the same
|
||||
rule that keeps a dialog's Cancel button. `exit_rows(staged, …)` draws nothing while
|
||||
clean and, once changes are staged, one blank `Separator(" ")` line then
|
||||
`✓ Apply n staged changes` over `✗ Back — discard staged changes` — Apply has no key of
|
||||
its own, so it needs a visible counterpart naming what the other way out costs. Same
|
||||
shape in `ReorderScreen`. A **Quit** row is likewise kept (main menu, device splash):
|
||||
it *initiates* the app's terminal action behind a confirm, and on the splash it is the
|
||||
only statement that the app can be left at all.
|
||||
- A caller therefore tests one thing for "the user left": `CANCEL` (or the `None` that
|
||||
`ui.select` folds it to) — never a `_BACK`/`"__back__"` sentinel of its own.
|
||||
- Grouped-list section headings use `section_heading("Label")` → `── Label ──` accent.
|
||||
That is also what makes a heading *sticky* (it pins to the top row while its section
|
||||
scrolls, and the ^PgUp/^PgDn jumps step by it), so build them through it — a hand-rolled
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
# Navigation survey — every exception to "Esc pops the stack"
|
||||
|
||||
Written 2026-08-22 against `main` @ `4b29248`. A catalogue, not a change: nothing here has
|
||||
been fixed. Each finding says where it is, what it does, and what makes it a question.
|
||||
Written 2026-08-22 against `main` @ `4b29248`. A catalogue, not a change: nothing here had
|
||||
been fixed at the time of writing. Each finding says where it is, what it does, and what
|
||||
makes it a question.
|
||||
|
||||
**Resolved since:** findings **E** and **§10** — 2026-08-29. Exit rows were retired
|
||||
app-wide: `back_rows()` is gone, `exit_rows()` draws nothing while clean, and every
|
||||
caller's three-way Back test collapsed to `is CANCEL` / `is None`. What is kept is stated
|
||||
in CLAUDE.md. Everything else below still stands, **D included** — Esc's peel/leave split
|
||||
is now the only thing left telling a user what Esc does.
|
||||
|
||||
The point of the survey is that MeshTerm's navigation is *almost* uniform. The exceptions
|
||||
are few enough to list exhaustively, which means they can be decided one at a time rather
|
||||
@@ -255,7 +262,11 @@ dialogs, used here for a row that says "Back".
|
||||
> tuple-shaped ones exist only because their screens type their values as tuples; those could
|
||||
> take `CANCEL` too.
|
||||
|
||||
This ties directly into the exit-row question — see §10.
|
||||
**Resolved 2026-08-29** — by removal rather than by defaulting: with no Back row there is
|
||||
no Back value, and every caller now tests `is CANCEL` / `is None` alone. All six spellings
|
||||
are gone, `channels._BACK` and `contacts_screen._BACK` with them.
|
||||
|
||||
This tied directly into the exit-row question — see §10.
|
||||
|
||||
---
|
||||
|
||||
@@ -295,6 +306,15 @@ per tool and one measured from the content.
|
||||
|
||||
## 10. Where the exit-row question actually lands
|
||||
|
||||
> **Resolved 2026-08-29.** Acted on in full, along the middle position this section
|
||||
> proposed — wider, in the end, than the 19 `back_rows()` sites: the four hand-drawn Back
|
||||
> rows went too (`ReorderScreen`'s clean-state row, the live feed's pinned foot row, node
|
||||
> detail's tail action, and the `trace`/`tx` screens' action-list rows). Kept: the
|
||||
> `exit_rows` discard pair, `ReorderScreen`'s dirty-state pair, the two **Quit** rows, and
|
||||
> the new-record dialog's `Close` button — each for the reason named below. The gallery
|
||||
> now asserts the *absence* of an exit row on every screen, on both platforms. What
|
||||
> follows is the survey as written.
|
||||
|
||||
JP's note — *"remove the cancel and close actions at the bottom of pages; Esc is quicker and
|
||||
available on all platforms; keep it where there is a confirm or cancel situation"* — was
|
||||
acted on for the one unambiguous case (the path composer's `Cancel` row, which literally ran
|
||||
|
||||
@@ -37,7 +37,7 @@ from ..core.models import (
|
||||
)
|
||||
from ..services.trace_runner import NameKeyResolver, make_name_key_resolver
|
||||
from ..ui.chat import _MENTION, _split_channel_sender
|
||||
from ..ui.menus import Lane, back_rows, column_header, fit_cells, section_heading
|
||||
from ..ui.menus import Lane, column_header, fit_cells, section_heading
|
||||
from ..ui.theme import name_style
|
||||
from ..ui.tui import Choice, DeleteRequest, Separator
|
||||
from ..ui.widgets import _NODE_GLYPHS, _age_seconds, _format_age, channel_glyph
|
||||
@@ -184,8 +184,6 @@ class ChatTool(Tool):
|
||||
else:
|
||||
items.append(Separator(" no contacts yet — receive an advert first"))
|
||||
|
||||
items.extend(back_rows("__back__"))
|
||||
|
||||
default = next(
|
||||
(
|
||||
it.value
|
||||
@@ -210,7 +208,7 @@ class ChatTool(Tool):
|
||||
# demotes to the uncontacted (alphabetical) tail; keep the cursor on it.
|
||||
default_key = conversation.key
|
||||
continue
|
||||
if choice in (None, "__back__"):
|
||||
if choice is None: # Esc
|
||||
return None
|
||||
return choice
|
||||
|
||||
|
||||
@@ -416,7 +416,6 @@ async def _pick_target(
|
||||
The chosen contact name, or ``None`` if cancelled. With no other contacts,
|
||||
falls back to a free-text prompt so a hex key prefix can be typed.
|
||||
"""
|
||||
from ..ui.menus import back_rows
|
||||
from ..ui.theme import name_style
|
||||
from ..ui.tui import Choice
|
||||
from ..ui.widgets import _DEFAULT_GLYPH, _NODE_GLYPHS
|
||||
@@ -451,7 +450,6 @@ async def _pick_target(
|
||||
key=lambda c: -(c.last_seen.timestamp() if c.last_seen else 0.0),
|
||||
)
|
||||
]
|
||||
items.extend(back_rows(None))
|
||||
choice = await ctx.ui.select(
|
||||
"TX optimize — measure at",
|
||||
items,
|
||||
|
||||
@@ -36,18 +36,18 @@ def admin_picker_rows(
|
||||
contacts: The device's known contacts.
|
||||
|
||||
Returns:
|
||||
``(rows, candidates)`` — the select rows (grouped, with the exit group) and the
|
||||
offerable contacts (those holding a key). ``candidates`` is empty when nothing is
|
||||
offerable; ``rows`` is then just the exit group.
|
||||
``(rows, candidates)`` — the grouped select rows and the offerable contacts
|
||||
(those holding a key). Both are empty when nothing is offerable; the caller
|
||||
notes that and never opens a list at all.
|
||||
"""
|
||||
from .menus import back_rows, section_heading
|
||||
from .menus import section_heading
|
||||
from .theme import name_style
|
||||
from .tui import Choice
|
||||
from .widgets import _DEFAULT_GLYPH, _NODE_GLYPHS
|
||||
|
||||
candidates = [c for c in contacts if (c.public_key or c.key_prefix).strip()]
|
||||
if not candidates:
|
||||
return list(back_rows()), candidates
|
||||
return [], candidates
|
||||
|
||||
def row(contact: Contact) -> Choice:
|
||||
# The type mark keeps its own fixed hue; the *name* takes the node's key-derived
|
||||
@@ -82,7 +82,6 @@ def admin_picker_rows(
|
||||
if others:
|
||||
items.append(section_heading("Other contacts"))
|
||||
items.extend(row(c) for c in sorted(others, key=recency))
|
||||
items.extend(back_rows())
|
||||
return items, candidates
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ from ..core.connection import Device
|
||||
from ..core.models import Conversation
|
||||
from ..persistence.repository import ACTIVITY_DRAWN_BUCKETS
|
||||
from .braillechart import activity_peak, activity_sparkline
|
||||
from .menus import back_rows, command_label, fit_cells, menu_rows, section_heading
|
||||
from .menus import command_label, fit_cells, menu_rows, section_heading
|
||||
from .qr import share_popup
|
||||
from .tui import CANCEL, Choice, SelectScreen, Separator
|
||||
from .widgets import _age_seconds, _format_age, channel_glyph, format_ago
|
||||
@@ -79,7 +79,6 @@ _DEFAULT_PUBLIC = "__default_public__"
|
||||
_JOIN = "__join__"
|
||||
_IMPORT = "__import__"
|
||||
_REORDER = "__reorder__"
|
||||
_BACK = "__back__"
|
||||
|
||||
# Channel-detail action sentinels.
|
||||
_QR = "qr"
|
||||
@@ -178,7 +177,7 @@ async def manage_channels(ctx: "AppContext") -> int:
|
||||
async def handle(choice: object) -> bool:
|
||||
"""Dispatch one menu choice (over the still-pushed list); ``False`` exits."""
|
||||
nonlocal changes, highlight
|
||||
if choice in (None, _BACK):
|
||||
if choice is None: # Esc
|
||||
return False
|
||||
highlight = choice
|
||||
before = changes
|
||||
@@ -616,7 +615,6 @@ def _menu_items(
|
||||
]
|
||||
)
|
||||
items.extend(menu_rows(rows))
|
||||
items.extend(back_rows(_BACK))
|
||||
|
||||
return f"Channels — {len(slots)}/{capacity} slots", items
|
||||
|
||||
@@ -680,7 +678,6 @@ def _detail_items(ctx: "AppContext", slot: ChannelSlot) -> list:
|
||||
),
|
||||
]
|
||||
)
|
||||
items.extend(back_rows(_BACK))
|
||||
return items
|
||||
|
||||
|
||||
@@ -701,7 +698,7 @@ async def _channel_detail(
|
||||
async def handle(choice: object) -> Optional[int]:
|
||||
"""Run one action; an int closes the detail with that many changes, ``None`` stays."""
|
||||
nonlocal cursor
|
||||
if choice in (None, _BACK):
|
||||
if choice is None: # Esc
|
||||
return 0
|
||||
cursor = choice
|
||||
if choice == _QR:
|
||||
|
||||
@@ -55,7 +55,6 @@ from ..core.device_config import (
|
||||
settings_by_category,
|
||||
)
|
||||
from .menus import (
|
||||
back_rows,
|
||||
confirm_discard,
|
||||
exit_rows,
|
||||
lane_header,
|
||||
@@ -378,9 +377,9 @@ def _menu_items(
|
||||
Choice(title=lane_row(label, value, help_text, label_w, value_w), value=key)
|
||||
)
|
||||
|
||||
# The backtracking rows sit together below one blank line, like every other screen's
|
||||
# Back (the main menu's Quit included); with changes staged, Apply joins the group and
|
||||
# Back spells out the consequence of leaving (see menus.exit_rows).
|
||||
# Nothing at all while the editor is clean — Esc leaves, and a row saying so was
|
||||
# retired app-wide. With changes staged the pair appears below one blank line: Apply
|
||||
# has no key of its own, and Back spells out what leaving costs (see menus.exit_rows).
|
||||
items.extend(exit_rows(staged, apply_value=_APPLY, back_value=_CANCEL))
|
||||
|
||||
title = "Device config" + (f" — {staged} staged" if staged else "")
|
||||
@@ -614,7 +613,6 @@ async def _stage_preset(ctx: "AppContext", pending: dict[str, Any]) -> None:
|
||||
)
|
||||
for i, p in enumerate(RADIO_PRESETS)
|
||||
]
|
||||
items.extend(back_rows())
|
||||
idx = await ctx.ui.select(
|
||||
"Radio presets",
|
||||
items,
|
||||
@@ -690,7 +688,7 @@ async def device_actions(ctx: "AppContext") -> None:
|
||||
session.push(menu)
|
||||
try:
|
||||
choice = await menu.future
|
||||
if choice is CANCEL or choice in (None, _CANCEL):
|
||||
if choice is CANCEL or choice is None: # Esc
|
||||
return
|
||||
cursor = choice
|
||||
if choice == _SYNC_CLOCK:
|
||||
@@ -733,7 +731,6 @@ def _action_items() -> list:
|
||||
),
|
||||
]
|
||||
)
|
||||
items.extend(back_rows(_CANCEL))
|
||||
return items
|
||||
|
||||
|
||||
@@ -787,7 +784,6 @@ async def send_advert(ctx: "AppContext") -> None:
|
||||
("Share QR / URI", "Show this node's contact card", "share"),
|
||||
]
|
||||
),
|
||||
*back_rows(),
|
||||
],
|
||||
prompt="Announce this node to the mesh:",
|
||||
filterable=False,
|
||||
@@ -1022,7 +1018,6 @@ async def _identity_key_menu(ctx: "AppContext", device: "Device", snapshot: dict
|
||||
("Import a key…", "Replace this device's identity", "import"),
|
||||
]
|
||||
),
|
||||
*back_rows(),
|
||||
],
|
||||
prompt="Manage this node's private identity key:",
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ from typing import TYPE_CHECKING
|
||||
from rich.text import Text
|
||||
|
||||
from .contactlist import ContactListScreen, ContactRow
|
||||
from .menus import back_rows, marked_label, menu_rows
|
||||
from .menus import marked_label, menu_rows
|
||||
from .tui import Choice, Separator
|
||||
from .tui.screen import CANCEL
|
||||
from .widgets import ContactsSort, _age_seconds, _contact_pkts
|
||||
@@ -49,7 +49,6 @@ YOU = ("you",)
|
||||
#: The contact-list tail sentinels (distinct from any :class:`~meshterm.core.models.Contact`
|
||||
#: and from :data:`YOU`): the purge action row and the bare ``Back`` exit row.
|
||||
_PURGE = ("purge",)
|
||||
_BACK = ("back",)
|
||||
|
||||
#: A day in seconds, for the purge age ladder.
|
||||
_DAY = 86400
|
||||
@@ -144,8 +143,8 @@ class ContactsScreen(ContactListScreen):
|
||||
)
|
||||
)
|
||||
# The maintenance action closes the list, past every contact whatever the sort: a
|
||||
# blank spacer, the err-tinted purge row (a `…` — it opens further prompts), then the
|
||||
# standard exit group. Offered only when there are contacts to purge.
|
||||
# blank spacer, then the err-tinted purge row (a `…` — it opens further prompts).
|
||||
# Offered only when there are contacts to purge.
|
||||
tail: list = []
|
||||
if contacts:
|
||||
tail = [
|
||||
@@ -154,7 +153,6 @@ class ContactsScreen(ContactListScreen):
|
||||
title=marked_label("🗑", "Purge stale contacts…", "err"),
|
||||
value=_PURGE,
|
||||
),
|
||||
*back_rows(_BACK),
|
||||
]
|
||||
super().__init__(
|
||||
f"Contacts · {len(contacts)} known",
|
||||
@@ -207,7 +205,7 @@ async def open_contacts(
|
||||
screen = ContactsScreen(self_name, self_key, contacts, prefix_bytes, counts, sort)
|
||||
while True:
|
||||
chosen = await session.run_screen(screen)
|
||||
if chosen is CANCEL or chosen is None or chosen == _BACK:
|
||||
if chosen is CANCEL or chosen is None: # Esc
|
||||
return
|
||||
if chosen == _PURGE:
|
||||
# The purge picker and its confirm float over the list, so re-push it as the
|
||||
@@ -271,7 +269,6 @@ async def _purge_stale(ctx: "AppContext", self_key: str) -> int:
|
||||
from .tui import SelectScreen
|
||||
|
||||
items = menu_rows(rows)
|
||||
items.extend(back_rows(None))
|
||||
picked = await session.run_screen(
|
||||
SelectScreen(
|
||||
f"Purge stale contacts — {len(contacts)} known",
|
||||
|
||||
@@ -29,7 +29,7 @@ from rich.text import Text
|
||||
|
||||
from ..core.courier_store import DELIVERED, QUEUED, QueuedMessage
|
||||
from ..core.models import Contact, is_direct_messageable, utcnow
|
||||
from .menus import back_rows, command_label, marked_label, section_heading
|
||||
from .menus import command_label, marked_label, section_heading
|
||||
from .contactlist import SORT_COLUMNS, SORT_OPENS_ASCENDING, ContactListScreen, ContactRow
|
||||
from .theme import glyph
|
||||
from .tui import CANCEL, DM_BYTE_LIMIT, Choice, SelectScreen, Separator
|
||||
@@ -239,7 +239,6 @@ def _menu_items(ctx: "AppContext", entries: list[QueuedMessage]) -> list:
|
||||
items.append(Choice(lambda m=message: _done_row(m), ("msg", message.ident)))
|
||||
items.append(Choice(f"{glyph('🗑')} Clear finished", _CLEAR))
|
||||
|
||||
items.extend(back_rows()) # a visible exit beside Esc
|
||||
return items
|
||||
|
||||
|
||||
|
||||
@@ -37,11 +37,6 @@ Enter opens the highlighted packet in the shared
|
||||
itself with the same ``↑``/``↓``, and, for an overheard channel-text packet naming a
|
||||
channel we hold the key for, decrypts it.
|
||||
|
||||
The cursor's last stop, past the oldest packet, is the app's own exit group — a blank
|
||||
line and the bare word ``Back``, pinned to the foot of the screen so it is there to be
|
||||
seen and pressed however far the feed has scrolled. Enter on it leaves exactly as Esc
|
||||
does.
|
||||
|
||||
The screen holds no subscriptions of its own — the opener (:func:`open_livefeed`)
|
||||
wires the hub subscription and the once-a-second repaint, and tears them down when
|
||||
the screen resolves. The newest packet is highlighted from the moment the screen
|
||||
@@ -123,12 +118,6 @@ _FEED_LABEL_MIN_WIDTH = (
|
||||
+ _FEED_SUBJECT_WIDTH + _LANE_GAP + _SNR_LANE + _RSSI_LANE
|
||||
)
|
||||
|
||||
#: Body lines the pinned exit group costs: the blank separator, then the ``Back`` row —
|
||||
#: the exact shape :func:`~meshterm.ui.menus.back_rows` gives a select list, struck from
|
||||
#: the feed's window so the group stays at the foot of the screen instead of scrolling
|
||||
#: with the packets.
|
||||
_EXIT_LINES = 2
|
||||
|
||||
#: Cells one ←/→ press shifts the highlighted row by — the app-wide select list's own
|
||||
#: step (:attr:`~meshterm.ui.tui.select.SelectScreen._HSCROLL_STEP`), so a row here
|
||||
#: scrolls at the rate a row anywhere else does.
|
||||
@@ -179,13 +168,13 @@ class LiveFeedScreen(Screen):
|
||||
Every nav key here moves the *cursor* over the feed rather than a scroll offset,
|
||||
but the vocabulary is the same either way — the window follows the highlight — so
|
||||
the shared labels stand. ``Top`` and ``Bottom`` stay literal on purpose: the top of
|
||||
this list is the pin riding the newest packet, and its bottom is the ``Back`` row
|
||||
one past the oldest, which is where End actually lands. ``Top`` is how the pin is
|
||||
reached where there is no hint line to name it — a feed read down into history
|
||||
resumes following in one chip.
|
||||
this list is the pin riding the newest packet and its bottom is the oldest one,
|
||||
which is where End actually lands. ``Top`` is how the pin is reached where there is
|
||||
no hint line to name it — a feed read down into history resumes following in one
|
||||
chip.
|
||||
|
||||
A feed with nothing in it still has that ``Back`` row, and nowhere to move to, so
|
||||
all four chips go dim until the first packet arrives.
|
||||
A feed with nothing in it has no cursor and nowhere to move to, so all four chips
|
||||
go dim until the first packet arrives.
|
||||
"""
|
||||
from .tui.fkeys import default_lane
|
||||
|
||||
@@ -245,16 +234,15 @@ class LiveFeedScreen(Screen):
|
||||
self._feed: deque[PacketEntry] = deque(maxlen=_FEED_CAP)
|
||||
for obs in list(seed)[-_FEED_CAP:][::-1]:
|
||||
self._feed.append(PacketEntry.from_observation(obs))
|
||||
#: The highlighted feed row, or ``None`` when the cursor rests on the ``Back``
|
||||
#: row past the oldest packet — the screen's other cursor stop, and the only one
|
||||
#: an empty feed offers. Starts on the newest packet.
|
||||
#: The highlighted feed row, or ``None`` when there is no row to highlight —
|
||||
#: an empty feed, which offers no cursor stop at all. Starts on the newest packet.
|
||||
self._selected: Optional[int] = 0 if self._feed else None
|
||||
#: Whether the cursor is on the *pin* — the stop above row 0, which holds the
|
||||
#: topmost position rather than a packet (see the module docstring). Implies
|
||||
#: ``_selected == 0``: the pin is a mode on the newest row, so everything that
|
||||
#: reads the highlight (the window fit, the viewer, the ``←→`` scroll) needs no
|
||||
#: special case; only the cursor mark drawn in the pointer lane differs. A feed
|
||||
#: with nothing in it has no row to pin to, so it opens on ``Back`` instead.
|
||||
#: with nothing in it has no row to pin to, and no cursor at all.
|
||||
self._pinned: bool = bool(self._feed)
|
||||
#: The feed's window within the fixed screen (its rows scroll under the heading).
|
||||
self._feed_window = ListWindow()
|
||||
@@ -339,11 +327,10 @@ class LiveFeedScreen(Screen):
|
||||
elif action in ("home", "ctrl_home"):
|
||||
# Home jumps to the pin — the top of a live feed is the *following* state, so
|
||||
# "take me back to the top" resumes the stream rather than parking on whichever
|
||||
# packet happens to be newest this instant. End goes to the list's last row,
|
||||
# which — as on every list in the app — is ``Back`` (the oldest packet is one ↑).
|
||||
# packet happens to be newest this instant. End goes to the oldest packet.
|
||||
self._select_stop(0)
|
||||
elif action in ("end", "ctrl_end"):
|
||||
self._select_stop(len(self._feed) + 1)
|
||||
self._select_stop(len(self._feed))
|
||||
elif action == "left":
|
||||
self._scroll_line(-_HSCROLL_STEP)
|
||||
elif action == "right":
|
||||
@@ -360,42 +347,39 @@ class LiveFeedScreen(Screen):
|
||||
|
||||
@property
|
||||
def _cursor(self) -> int:
|
||||
"""The cursor as one index over the screen's stops, from the pin down to ``Back``.
|
||||
"""The cursor as one index over the screen's stops: the pin, then the feed's rows.
|
||||
|
||||
The stops are the pin (0), then the feed's rows (``1 .. len(feed)``), then the exit
|
||||
row one past them — so every move stays a clamp on this one number, the pin
|
||||
included. That the pin and row 0 draw on the *same line* is a rendering detail;
|
||||
as cursor positions they are two, which is exactly what makes ``↓`` off the pin
|
||||
land on the newest packet rather than the second one.
|
||||
The stops are the pin (0), then the feed's rows (``1 .. len(feed)``) — so every
|
||||
move stays a clamp on this one number, the pin included. That the pin and row 0
|
||||
draw on the *same line* is a rendering detail; as cursor positions they are two,
|
||||
which is exactly what makes ``↓`` off the pin land on the newest packet rather
|
||||
than the second one.
|
||||
|
||||
An empty feed has no row to pin to, so it leaves ``Back`` as the only stop there is.
|
||||
An empty feed has no row to pin to, and so no stops at all.
|
||||
"""
|
||||
if self._pinned:
|
||||
if self._pinned or self._selected is None:
|
||||
return 0
|
||||
return len(self._feed) + 1 if self._selected is None else self._selected + 1
|
||||
return self._selected + 1
|
||||
|
||||
def _move_selection(self, delta: int) -> None:
|
||||
"""Step the cursor by ``delta`` stops (off the oldest packet lands it on ``Back``)."""
|
||||
"""Step the cursor by ``delta`` stops (both ends clamp on a packet)."""
|
||||
self._select_stop(self._cursor + delta)
|
||||
|
||||
def _select_stop(self, index: int) -> None:
|
||||
"""Move the cursor to one stop — the pin, a feed row, or ``Back`` — and repaint.
|
||||
"""Move the cursor to one stop — the pin or a feed row — and repaint.
|
||||
|
||||
Args:
|
||||
index: The stop to land on, clamped into range (see :attr:`_cursor`). Both ends
|
||||
clamp rather than wrap, so a key held down settles at an end.
|
||||
"""
|
||||
if not self._feed: # nothing to pin or select: Back is the whole cursor space
|
||||
if not self._feed: # nothing to pin or select: the screen has no cursor
|
||||
self._pinned = False
|
||||
self._selected = None
|
||||
self._session.invalidate()
|
||||
return
|
||||
index = max(0, min(index, len(self._feed) + 1))
|
||||
index = max(0, min(index, len(self._feed)))
|
||||
self._pinned = index == 0
|
||||
if index <= len(self._feed):
|
||||
self._selected = max(0, index - 1)
|
||||
else:
|
||||
self._selected = None
|
||||
self._selected = max(0, index - 1)
|
||||
self._session.invalidate()
|
||||
|
||||
def _select_row(self, row: int) -> None:
|
||||
@@ -409,11 +393,8 @@ class LiveFeedScreen(Screen):
|
||||
self._select_stop(row + 1)
|
||||
|
||||
def _commit(self) -> None:
|
||||
"""Enter: open the highlighted packet, or leave when the cursor is on ``Back``."""
|
||||
if self._selected is None:
|
||||
self.resolve(None) # the exit row leaves exactly as Esc does
|
||||
else:
|
||||
self._open_packet()
|
||||
"""Enter: open the highlighted packet (an empty feed has none to open)."""
|
||||
self._open_packet()
|
||||
|
||||
def _open_packet(self) -> None:
|
||||
"""Float the packet viewer over the highlighted feed row.
|
||||
@@ -455,7 +436,7 @@ class LiveFeedScreen(Screen):
|
||||
screen's sticky-header machinery: the chrome above and below is struck from the
|
||||
viewport first and the feed windows *inside* what is left (see
|
||||
:meth:`_feed_lines`), so the body never scrolls — the header can't travel off the
|
||||
top of it, and ``Back`` can't sink past the bottom.
|
||||
top of it, and the oldest packet can't sink past the bottom.
|
||||
"""
|
||||
if self._selected is not None:
|
||||
self._selected = min(self._selected, len(self._feed) - 1) if self._feed else None
|
||||
@@ -466,27 +447,11 @@ class LiveFeedScreen(Screen):
|
||||
lines = [render_to_ansi(self._heading(), width, no_wrap=True)]
|
||||
if self._feed: # a header over nothing is noise; the empty note speaks for itself
|
||||
lines.append(render_to_ansi(self._column_header(show_label), width, no_wrap=True))
|
||||
win = max(1, self._scroll_viewport - len(lines) - _EXIT_LINES)
|
||||
win = max(1, self._scroll_viewport - len(lines))
|
||||
lines.extend(self._feed_lines(width, win, show_label))
|
||||
lines.extend(self._exit_lines(width))
|
||||
self._scroll_total = max(1, len(lines))
|
||||
return lines
|
||||
|
||||
def _exit_lines(self, width: int) -> list[str]:
|
||||
"""The pinned exit group: one blank separator, then the bare word ``Back``.
|
||||
|
||||
The very rows :func:`~meshterm.ui.menus.back_rows` gives a select list, drawn here
|
||||
by hand because the feed is a rendered screen rather than a list of choices — same
|
||||
blank line, same bare word, no arrow and no icon, and the same ``❯`` cursor over a
|
||||
highlighted row when it is the stop the cursor rests on.
|
||||
"""
|
||||
selected = self._selected is None
|
||||
row = Text(_CURSOR if selected else " ", style="cursor" if selected else "")
|
||||
row.append("Back")
|
||||
if selected:
|
||||
row.style = "cursor"
|
||||
return ["", render_to_ansi(row, width, no_wrap=True)]
|
||||
|
||||
def _heading(self) -> Text:
|
||||
"""The feed's pinned status line, with a live-light for the hub."""
|
||||
heading = Text("newest first · Enter opens a packet ", style="muted")
|
||||
|
||||
+27
-36
@@ -1,16 +1,14 @@
|
||||
"""Shared select-menu chrome: the pieces every list screen builds the same way.
|
||||
|
||||
MeshTerm's list screens (the config editors, the channel manager, Watchtower, Courier,
|
||||
the pickers) all end in the same furniture: label-and-description rows padded into
|
||||
aligned lanes, a blank line, then the exit group — a plain ``Back`` row, or the
|
||||
``✓ Apply / ✗ Back — discard`` pair once changes are staged. Before this module each
|
||||
screen hand-rolled its own copy, and they drifted (``← Back``, ``← Close``, missing
|
||||
blank lines, ``✖`` for ``✗``). These helpers are now the one way to build that
|
||||
furniture, so the app's exit language and row alignment stay uniform by construction:
|
||||
the pickers) all share the same furniture: label-and-description rows padded into
|
||||
aligned lanes. Before this module each screen hand-rolled its own copy, and they drifted
|
||||
(``← Back``, ``← Close``, missing blank lines, ``✖`` for ``✗``). These helpers are now
|
||||
the one way to build it, so the app's row language and alignment stay uniform by
|
||||
construction:
|
||||
|
||||
* :func:`back_rows` — the standard exit group: one blank separator, then ``Back``.
|
||||
* :func:`exit_rows` — the staged-changes variant: ``✓ Apply n staged changes`` above an
|
||||
err-tinted ``✗ Back — discard staged changes`` (or the plain group when clean).
|
||||
* :func:`exit_rows` — the staged-changes exit group: ``✓ Apply n staged changes`` above
|
||||
an err-tinted ``✗ Back — discard staged changes``, and *nothing at all* when clean.
|
||||
* :func:`menu_rows` — label + muted description :class:`Choice` rows in two aligned
|
||||
lanes, padded in display cells so double-width emoji can't skew the description
|
||||
column (the Device actions presentation).
|
||||
@@ -21,9 +19,11 @@ furniture, so the app's exit language and row alignment stay uniform by construc
|
||||
* :func:`changes_phrase` — ``"1 staged change"`` / ``"3 staged changes"``.
|
||||
* :func:`confirm_discard` — the shared are-you-sure dialog for leaving staged changes.
|
||||
|
||||
House rules the helpers encode (see the UX standards in ``CLAUDE.md``): the exit row is
|
||||
always the bare word ``Back`` — no arrow, no icon — with exactly one blank separator
|
||||
line above it; ``✓``/``✗`` (U+2713/U+2717) are THE status marks, styled ``ok``/``err``.
|
||||
House rules the helpers encode (see the UX standards in ``CLAUDE.md``): a list carries
|
||||
no exit row — Esc leaves, and a row repeating it earned nothing for its two lines; the
|
||||
one survivor is the staged-changes pair, which is a choice rather than an exit and keeps
|
||||
its blank separator line above it. ``✓``/``✗`` (U+2713/U+2717) are THE status marks,
|
||||
styled ``ok``/``err``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -103,7 +103,7 @@ def command_label(label: LabelT) -> LabelT:
|
||||
:data:`~meshterm.platforms.Platform.menu_icons`). The icon is taken to be everything
|
||||
before the label's first space, and only when that head starts with a non-alphanumeric
|
||||
character — so ``"🗑 Clear this slot…"`` and ``"↻ Read settings"`` both lose their
|
||||
head while ``"Back"`` and ``"Trace target"`` pass through untouched.
|
||||
head while ``"Reorder"`` and ``"Trace target"`` pass through untouched.
|
||||
|
||||
What must *not* come through here: a glyph carrying data (a channel's openness, a
|
||||
packet's class, a node's type) or a status mark on an outcome or commit row
|
||||
@@ -129,37 +129,29 @@ def command_label(label: LabelT) -> LabelT:
|
||||
return label[cut:]
|
||||
|
||||
|
||||
def back_rows(value: Any = None) -> list:
|
||||
"""The standard exit group closing a select list: a blank line, then ``Back``.
|
||||
|
||||
Args:
|
||||
value: The value the Back row resolves with (``None`` reads as cancel for
|
||||
most callers; the config editors pass their own sentinel).
|
||||
|
||||
Returns:
|
||||
``[Separator(" "), Choice("Back", value)]`` — append to the end of the items.
|
||||
"""
|
||||
return [Separator(" "), Choice(title="Back", value=value)]
|
||||
|
||||
|
||||
def exit_rows(staged: int, *, apply_value: Any, back_value: Any) -> list:
|
||||
"""The editor exit group: Apply joins Back once there is something staged.
|
||||
"""The editor exit group — nothing at all until there is something staged.
|
||||
|
||||
With nothing staged this is exactly :func:`back_rows`. With changes staged, an
|
||||
ok-marked ``✓ Apply …`` row sits above an err-marked ``✗ Back — discard staged
|
||||
changes`` so the consequence of leaving is spelled out (the config editor's
|
||||
long-standing presentation, now shared).
|
||||
A list does not advertise its own exit: Esc leaves, on both platforms, and a row
|
||||
that only repeated it cost two lines of every screen to say what Esc already said
|
||||
(the app-wide ``Back`` row, retired 2026-08-29). What survives here is the case
|
||||
where leaving is not merely leaving: with changes staged, an ok-marked
|
||||
``✓ Apply …`` row sits above an err-marked ``✗ Back — discard staged changes``.
|
||||
That pair is a *choice*, not an exit — ``Apply`` has no key of its own, so it needs
|
||||
a visible counterpart naming what the other way out costs — and a choice keeps its
|
||||
rows for the same reason a confirm dialog keeps its Cancel button.
|
||||
|
||||
Args:
|
||||
staged: How many changes are staged (0 = the plain Back group).
|
||||
staged: How many changes are staged (0 = no rows at all).
|
||||
apply_value: The value the Apply row resolves with.
|
||||
back_value: The value the Back row resolves with.
|
||||
back_value: The value the Back row resolves with — identical to what Esc
|
||||
resolves, since both run the caller's discard confirm.
|
||||
|
||||
Returns:
|
||||
The rows to append: a blank separator, then the one- or two-row exit group.
|
||||
The rows to append: nothing when clean, else a blank separator and the pair.
|
||||
"""
|
||||
if not staged:
|
||||
return back_rows(back_value)
|
||||
return []
|
||||
return [
|
||||
Separator(" "),
|
||||
Choice(
|
||||
@@ -393,7 +385,6 @@ def fit_cells(text: str, width: int, *, align: str = "left") -> str:
|
||||
|
||||
__all__ = [
|
||||
"Lane",
|
||||
"back_rows",
|
||||
"changes_phrase",
|
||||
"column_header",
|
||||
"confirm_discard",
|
||||
|
||||
@@ -413,7 +413,6 @@ class NodeDetailScreen(Screen):
|
||||
routes: Optional[_RoutesView] = None,
|
||||
info_actions: Optional[list[_Action]] = None,
|
||||
trace_action: Optional[_Action] = None,
|
||||
tail_actions: Optional[list[_Action]] = None,
|
||||
) -> None:
|
||||
"""Build the page over resolved display data.
|
||||
|
||||
@@ -435,7 +434,6 @@ class NodeDetailScreen(Screen):
|
||||
trace_action: The Routes tab's ``Trace — auto route …`` action, shown only when
|
||||
there are no routes to list (with routes listed, Enter on a route row is the
|
||||
trace entry point), or ``None``.
|
||||
tail_actions: The always-available actions closing every tab (Back).
|
||||
"""
|
||||
super().__init__()
|
||||
self.title = title
|
||||
@@ -447,7 +445,6 @@ class NodeDetailScreen(Screen):
|
||||
self._routes = routes
|
||||
self._info_actions = info_actions or []
|
||||
self._trace_action = trace_action
|
||||
self._tail_actions = tail_actions or []
|
||||
self._tab_index = 0
|
||||
self._row_index = 0
|
||||
#: The highlighted route on the Routes tab (drives the graph); tracks the cursor as
|
||||
@@ -592,10 +589,7 @@ class NodeDetailScreen(Screen):
|
||||
self.resolve("trace")
|
||||
else:
|
||||
assert isinstance(payload, _Action)
|
||||
# Back leaves the page exactly as Esc does — it resolves the same
|
||||
# CANCEL the opener's loop breaks on, not a "back" token the loop would
|
||||
# ignore and re-show the page over.
|
||||
self.resolve(CANCEL if payload.key == "back" else payload.key)
|
||||
self.resolve(payload.key)
|
||||
elif action == "tab":
|
||||
self._switch_tab(1)
|
||||
elif action == "shift_tab":
|
||||
@@ -686,7 +680,6 @@ class NodeDetailScreen(Screen):
|
||||
focus.append(("action", self._trace_action))
|
||||
elif tab is not None and tab.kind == "info":
|
||||
focus.extend(("action", a) for a in self._info_actions)
|
||||
focus.extend(("action", a) for a in self._tail_actions)
|
||||
return focus
|
||||
|
||||
# --- rendering -------------------------------------------------------------
|
||||
@@ -724,16 +717,10 @@ class NodeDetailScreen(Screen):
|
||||
)
|
||||
)
|
||||
|
||||
# The action rows are fixed chrome too — a leading blank, one line per row, a blank
|
||||
# setting Back apart when rows precede it — struck before the stage draws so it can
|
||||
# size against them.
|
||||
# The action rows are fixed chrome too — a leading blank, one line per row —
|
||||
# struck before the stage draws so it can size against them.
|
||||
actions = [payload for _kind, payload in focus if _kind == "action"]
|
||||
action_lines = 1 + len(actions) + (
|
||||
1
|
||||
if len(actions) > 1
|
||||
and any(a.key == "back" for a in actions if isinstance(a, _Action))
|
||||
else 0
|
||||
)
|
||||
action_lines = (1 + len(actions)) if actions else 0
|
||||
|
||||
# -- the stage, sized to what the viewport leaves, closed by a faint rule.
|
||||
route_blocks: list[list[str]] = []
|
||||
@@ -776,12 +763,11 @@ class NodeDetailScreen(Screen):
|
||||
self._list_hidden = top > 0 or below > 0
|
||||
|
||||
# -- the pinned action rows (the route rows precede them in focus order).
|
||||
lines.append("")
|
||||
if actions:
|
||||
lines.append("")
|
||||
base = len(route_blocks)
|
||||
for j, payload in enumerate(actions):
|
||||
assert isinstance(payload, _Action)
|
||||
if payload.key == "back" and j > 0:
|
||||
lines.append("") # set the exit row apart, as the menus do
|
||||
selected = base + j == self._row_index
|
||||
if selected:
|
||||
self._cursor = len(lines)
|
||||
@@ -1372,8 +1358,6 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> b
|
||||
trace_action: Optional[_Action] = None
|
||||
if not you and node_id and not (routes_view is not None and routes_view.routes):
|
||||
trace_action = _Action("trace", "🎯", "", "Trace — auto route …")
|
||||
tail_actions = [_Action("back", "", "", "Back")]
|
||||
|
||||
title = f"Node — {label}" if not you else f"Node — {label} (you)"
|
||||
# Whether the visit ended by deleting the contact — the caller's cue to rebuild its list.
|
||||
contact_removed = False
|
||||
@@ -1388,7 +1372,6 @@ async def open_node_detail(ctx: "AppContext", contact: Optional["Contact"]) -> b
|
||||
routes=routes_view,
|
||||
info_actions=info_actions,
|
||||
trace_action=trace_action,
|
||||
tail_actions=tail_actions,
|
||||
)
|
||||
action = await session.run_screen(screen)
|
||||
if action is CANCEL or action is None:
|
||||
|
||||
@@ -47,7 +47,7 @@ from ..persistence.repository import DiscoveredPath
|
||||
from ..services import trace_runner
|
||||
from ..services.records import CATEGORIES, CATEGORY_BY_ID, Category, _local_xy
|
||||
from .mapcanvas import RGB, MapCanvas
|
||||
from .menus import back_rows, command_icon, fit_cells, marked_label, section_heading
|
||||
from .menus import command_icon, fit_cells, marked_label, section_heading
|
||||
from .pathgraph import PathLayer, render_path_graph
|
||||
from .pathline import path_line
|
||||
from .theme import name_style, snr_style
|
||||
@@ -209,7 +209,7 @@ class RecordDialog(Screen):
|
||||
self._shape = list(shape) if shape else None
|
||||
self._reliability = reliability
|
||||
self._type_of = type_of
|
||||
self._actions = ("trace", "delete", "back")
|
||||
self._actions = ("trace", "delete")
|
||||
self._index = 0
|
||||
self._cursor: Optional[int] = None
|
||||
# The composed card above the action rows, per width (see render_body).
|
||||
@@ -244,8 +244,7 @@ class RecordDialog(Screen):
|
||||
self._follow = False
|
||||
self.scroll_to_bottom()
|
||||
elif action == "enter":
|
||||
key = self._actions[self._index]
|
||||
self.resolve(None if key == "back" else key)
|
||||
self.resolve(self._actions[self._index])
|
||||
elif action == "escape":
|
||||
self.resolve(None)
|
||||
|
||||
@@ -468,18 +467,14 @@ class RecordDialog(Screen):
|
||||
lines.append("")
|
||||
self._cursor = None
|
||||
for i, key in enumerate(self._actions):
|
||||
if key == "back":
|
||||
lines.append("")
|
||||
selected = i == self._index
|
||||
row = Text("❯ " if selected else " ", style="cursor" if selected else "")
|
||||
if key == "trace":
|
||||
row.append_text(marked_label(
|
||||
"👣", "Trace this path — reopen in Trace path", "accent"
|
||||
))
|
||||
elif key == "delete":
|
||||
row.append_text(marked_label("🗑", "Delete record…", "err"))
|
||||
else:
|
||||
row.append("Back")
|
||||
row.append_text(marked_label("🗑", "Delete record…", "err"))
|
||||
if selected:
|
||||
row.style = "cursor"
|
||||
self._cursor = len(lines)
|
||||
@@ -787,7 +782,6 @@ async def open_records(ctx: "AppContext") -> dict:
|
||||
),
|
||||
value=category.id,
|
||||
))
|
||||
rows.extend(back_rows("__back__"))
|
||||
picked = await session.run_screen(
|
||||
SelectScreen(
|
||||
"Delete a discipline's records",
|
||||
@@ -797,7 +791,7 @@ async def open_records(ctx: "AppContext") -> dict:
|
||||
wrap=False,
|
||||
)
|
||||
)
|
||||
if picked in (CANCEL, None, "__back__"):
|
||||
if picked is CANCEL or picked is None: # Esc
|
||||
return None
|
||||
category = CATEGORY_BY_ID[str(picked)]
|
||||
count = len(ctx.repo.discoveries(category.id))
|
||||
@@ -837,8 +831,8 @@ async def open_records(ctx: "AppContext") -> dict:
|
||||
hscroll_from=lanes.cell_len,
|
||||
))
|
||||
total = len(ctx.repo.discoveries())
|
||||
items.append(Separator(" "))
|
||||
if total:
|
||||
items.append(Separator(" "))
|
||||
items.append(Choice(
|
||||
title=marked_label("🗑", "Delete a discipline's records…", "err"),
|
||||
value=("del_cat", None, 0, None),
|
||||
@@ -847,7 +841,6 @@ async def open_records(ctx: "AppContext") -> dict:
|
||||
title=marked_label("🗑", "Delete all records…", "err"),
|
||||
value=("del_all", None, 0, None),
|
||||
))
|
||||
items.extend(back_rows(("back", None, 0, None)))
|
||||
browser = SelectScreen(
|
||||
"Trophy case",
|
||||
items,
|
||||
@@ -856,7 +849,7 @@ async def open_records(ctx: "AppContext") -> dict:
|
||||
hscroll=True, # a long walk slides under ←→ instead of dying at the fold
|
||||
)
|
||||
picked = await session.run_screen(browser)
|
||||
if picked is CANCEL or picked is None or picked[0] == "back":
|
||||
if picked is CANCEL or picked is None: # Esc
|
||||
return {"records": total}
|
||||
# Every pick opens a dialog that belongs *over* the trophy case — the discipline
|
||||
# picker, the delete confirms, a record's floating story. run_screen just popped the
|
||||
|
||||
@@ -96,7 +96,7 @@ from ..services import trace_runner
|
||||
from ..services.records import first_repeated_edge
|
||||
from ..services.topology import render_forced_spec
|
||||
from .braillechart import meter
|
||||
from .menus import back_rows, command_icon, marked_label, section_heading
|
||||
from .menus import command_icon, marked_label, section_heading
|
||||
from .theme import snr_style
|
||||
from .tui.render import render_lines, render_to_ansi
|
||||
from .tui.screen import ListWindow, Screen
|
||||
@@ -484,7 +484,7 @@ class TraceScreen(Screen):
|
||||
# walk is asymmetric enough to flip end-for-end, so only it offers Reverse.
|
||||
# The cursor opens on Trace either way.
|
||||
actions = ["compose", "explore"] if mode == "target" else ["compose", "reverse"]
|
||||
actions += ["width", "samples", "trace", "back"]
|
||||
actions += ["width", "samples", "trace"]
|
||||
self._actions: tuple[str, ...] = tuple(actions)
|
||||
self._index = self._actions.index("trace")
|
||||
self._pin_cursor = False # only pin the view while ↑/↓ are actually in use
|
||||
@@ -717,9 +717,6 @@ class TraceScreen(Screen):
|
||||
self._reverse_path()
|
||||
elif key == "explore" and self._explore is not None:
|
||||
self._open_flow(self._explore)
|
||||
elif key == "back":
|
||||
self.cancel()
|
||||
self.resolve(None)
|
||||
|
||||
def _open_flow(
|
||||
self, flow: PathFlow, seed: Optional[str] = None, focus_trace: bool = False
|
||||
@@ -820,8 +817,6 @@ class TraceScreen(Screen):
|
||||
lines.append("")
|
||||
self._cursor: Optional[int] = None
|
||||
for i, key in enumerate(self._actions):
|
||||
if key == "back":
|
||||
lines.append("") # Back is its own group, set apart like the menus do
|
||||
selected = i == self._index
|
||||
text = self._action_text(key, selected)
|
||||
text.no_wrap = True
|
||||
@@ -911,7 +906,7 @@ class TraceScreen(Screen):
|
||||
n = self._sample_count()
|
||||
_icon(text, "#", "accent")
|
||||
text.append(f"Sample count — {n} trace{'s' if n != 1 else ''}")
|
||||
elif key == "trace":
|
||||
else: # trace — the row the cursor opens on
|
||||
_icon(text, "▶", "ok")
|
||||
if self._mode == "path" and not self._effective_spec()[0]:
|
||||
text.append("Trace — compose a path first", style="muted")
|
||||
@@ -921,8 +916,6 @@ class TraceScreen(Screen):
|
||||
text.append(f"Trace — {n} paced transmissions")
|
||||
else:
|
||||
text.append("Trace — one transmission")
|
||||
else:
|
||||
text.append("Back")
|
||||
if selected:
|
||||
text.style = "cursor"
|
||||
return text
|
||||
@@ -2020,7 +2013,6 @@ async def _open_session(
|
||||
value=("probe", None),
|
||||
)
|
||||
)
|
||||
items.extend(back_rows(("back", None)))
|
||||
picked = await session.run_screen(
|
||||
SelectScreen(
|
||||
f"Explore paths — {target_label}",
|
||||
@@ -2031,7 +2023,7 @@ async def _open_session(
|
||||
hscroll=True, # a long candidate row slides under ←→ instead of truncating
|
||||
)
|
||||
)
|
||||
if picked is CANCEL or picked is None or picked[0] == "back":
|
||||
if picked is CANCEL or picked is None: # Esc
|
||||
return None
|
||||
if picked[0] == "use":
|
||||
return picked[1].spec(target_hash, width_bytes)
|
||||
|
||||
+21
-15
@@ -792,11 +792,11 @@ class ReorderScreen(Screen):
|
||||
Move the cursor with ↑/↓; press Enter on a row to *grab* it, then ↑/↓ carry it up and
|
||||
down the list; press Enter again to *drop* it. Below the list sit the action rows,
|
||||
following the config editor's pattern: once the order has actually changed, an
|
||||
ok-tinted *Apply* joins an err-tinted *Back — discard*; while it is untouched there is
|
||||
only a plain *Back*. Enter on Apply commits, resolving with the final order as a list
|
||||
of the original row indices (so ``[2, 0, 1]`` means "the row that started third is now
|
||||
first"); Enter on Back — like Esc anywhere — resolves :data:`CANCEL` so the caller
|
||||
keeps the original order.
|
||||
ok-tinted *Apply* joins an err-tinted *Back — discard*; while it is untouched there
|
||||
are no action rows at all, because Esc already leaves. Enter on Apply commits,
|
||||
resolving with the final order as a list of the original row indices (so ``[2, 0, 1]``
|
||||
means "the row that started third is now first"); Enter on Back — like Esc anywhere —
|
||||
resolves :data:`CANCEL` so the caller keeps the original order.
|
||||
"""
|
||||
|
||||
#: Action-row sentinels (kept distinct from list positions, which are ints).
|
||||
@@ -861,13 +861,13 @@ class ReorderScreen(Screen):
|
||||
]
|
||||
|
||||
def _actions(self) -> list[tuple[str, Text]]:
|
||||
"""The action rows below the list, matching the config editor's exit group:
|
||||
Apply joins Back only once there is a change to apply, and Back then spells
|
||||
out the consequence of leaving.
|
||||
"""The action rows below the list, matching the config editor's exit group.
|
||||
|
||||
An untouched order offers none: Esc leaves, and a row saying so was retired
|
||||
app-wide. A changed one offers the pair, because Apply has no key of its own and
|
||||
its counterpart names what leaving costs.
|
||||
"""
|
||||
if self._dirty():
|
||||
return self._dirty_actions()
|
||||
return [(self._BACK, Text("Back"))]
|
||||
return self._dirty_actions() if self._dirty() else []
|
||||
|
||||
def render_body(self, width: int) -> list[str]:
|
||||
"""Render the rows, a blank spacer, then the action group, marking the cursor."""
|
||||
@@ -885,8 +885,10 @@ class ReorderScreen(Screen):
|
||||
overflow="ellipsis")
|
||||
text.truncate(width)
|
||||
lines.append(render_to_ansi(text, width))
|
||||
lines.append("")
|
||||
for i, (_key, label) in enumerate(self._actions()):
|
||||
actions = self._actions()
|
||||
if actions:
|
||||
lines.append("")
|
||||
for i, (_key, label) in enumerate(actions):
|
||||
if n + i == self._index:
|
||||
# The cursor row takes the highlight like the list rows above it,
|
||||
# trading the ✓/✗ tint for the highlight.
|
||||
@@ -907,7 +909,11 @@ class ReorderScreen(Screen):
|
||||
def handle(self, action: str, data: str = "") -> None:
|
||||
"""Move the cursor, carry a grabbed row, grab/drop, run an action, or cancel on Esc."""
|
||||
n = len(self._order)
|
||||
total = n + len(self._actions())
|
||||
actions = self._actions()
|
||||
total = n + len(actions)
|
||||
# A change undone while the cursor sat on an action row would strand it past the
|
||||
# end; clamp before anything reads it.
|
||||
self._index = min(self._index, max(0, total - 1))
|
||||
if action == "up":
|
||||
if self._grabbed and self._index > 0:
|
||||
self._order[self._index - 1], self._order[self._index] = (
|
||||
@@ -925,7 +931,7 @@ class ReorderScreen(Screen):
|
||||
elif action == "enter":
|
||||
if self._index < n:
|
||||
self._grabbed = not self._grabbed # Enter grabs a row, Enter again drops it
|
||||
elif self._actions()[self._index - n][0] == self._APPLY:
|
||||
elif actions[self._index - n][0] == self._APPLY:
|
||||
self.resolve(list(self._order))
|
||||
else:
|
||||
super().handle("escape") # Back resolves CANCEL, same as Esc
|
||||
|
||||
@@ -201,7 +201,6 @@ class TxSweepScreen(Screen):
|
||||
rows = ["route", "range", "step", "samples", "sweep"]
|
||||
if self._can_apply():
|
||||
rows.append("apply")
|
||||
rows.append("back")
|
||||
return tuple(rows)
|
||||
|
||||
@property
|
||||
@@ -341,9 +340,6 @@ class TxSweepScreen(Screen):
|
||||
self._open_flow(self._pick_step)
|
||||
elif key == "samples":
|
||||
self._open_flow(self._pick_samples)
|
||||
elif key == "back":
|
||||
self.cancel()
|
||||
self.resolve(None)
|
||||
|
||||
def _open_flow(self, flow: Callable[[], None]) -> None:
|
||||
"""Float a parameter flow over the screen (one at a time, never mid-sweep)."""
|
||||
@@ -370,8 +366,6 @@ class TxSweepScreen(Screen):
|
||||
actions = self._actions
|
||||
self._index = min(self._index, len(actions) - 1)
|
||||
for i, key in enumerate(actions):
|
||||
if key == "back":
|
||||
lines.append("") # Back is its own group, set apart like the menus do
|
||||
selected = i == self._index
|
||||
text = self._action_text(key, selected)
|
||||
text.no_wrap = True
|
||||
@@ -423,12 +417,10 @@ class TxSweepScreen(Screen):
|
||||
elif key == "sweep":
|
||||
_icon(text, "▶", "ok")
|
||||
text.append(f"Sweep — up to {self.estimated_traces()} paced transmissions")
|
||||
elif key == "apply":
|
||||
else: # apply — present only once there is a winner to set
|
||||
_icon(text, "★", "ok")
|
||||
best = self._result.best_tx if self._result is not None else "?"
|
||||
text.append(f"Apply winner — set TX {best} on {self._admin_label}")
|
||||
else:
|
||||
text.append("Back")
|
||||
if selected:
|
||||
text.style = "cursor"
|
||||
return text
|
||||
|
||||
@@ -23,7 +23,7 @@ from rich.text import Text
|
||||
from ..core.models import Contact
|
||||
from ..core.watch_store import OFF, SILENCE_CHOICES_H, Alert, WatchedNode
|
||||
from ..services.trace_runner import make_name_key_resolver
|
||||
from .menus import back_rows, command_label, marked_label, section_heading
|
||||
from .menus import command_label, marked_label, section_heading
|
||||
from .theme import name_style
|
||||
from .tui import Choice, Separator
|
||||
from .widgets import _DEFAULT_GLYPH, _NODE_GLYPHS, _age_seconds, _format_age
|
||||
@@ -222,7 +222,6 @@ def _menu_items(
|
||||
)
|
||||
)
|
||||
|
||||
items.extend(back_rows()) # a visible exit beside Esc
|
||||
return items
|
||||
|
||||
|
||||
@@ -359,13 +358,12 @@ async def _node_rules(ctx: "AppContext", key: str) -> None:
|
||||
), "snr"),
|
||||
Separator(" "),
|
||||
Choice(marked_label("✗", "Stop watching this node", "err"), "unwatch"),
|
||||
*back_rows(),
|
||||
]
|
||||
picked = await session.select(
|
||||
f"Rules — {entry.name}", items, filterable=False,
|
||||
footer_hint="↑↓ move · Enter change · Esc back",
|
||||
)
|
||||
if picked is None: # Close, or Esc
|
||||
if picked is None: # Esc
|
||||
return
|
||||
if picked == "silence":
|
||||
await _pick_silence(ctx, key, entry)
|
||||
|
||||
@@ -392,7 +392,7 @@ async def test_recreating_a_slot_refiles_messages_to_the_new_channel(ctx: AppCon
|
||||
from meshterm.core.channels import channel_identity
|
||||
from meshterm.core.events import MeshEvent
|
||||
from meshterm.core.models import Message
|
||||
from meshterm.ui.channels import _BACK, _CLEAR, _CREATE, manage_channels
|
||||
from meshterm.ui.channels import _CLEAR, _CREATE, manage_channels
|
||||
|
||||
device = await ctx.device()
|
||||
await device.set_channel(0, "Public", DEFAULT_PUBLIC_SECRET)
|
||||
@@ -409,9 +409,9 @@ async def test_recreating_a_slot_refiles_messages_to_the_new_channel(ctx: AppCon
|
||||
await ctx.chat._queue.join()
|
||||
|
||||
# Drive the manager: open Public's detail → clear it, then create a new private
|
||||
# channel (which reuses freed slot 0), then back out.
|
||||
# channel (which reuses freed slot 0), then leave with Esc.
|
||||
ctx.ui = _ScriptedUi(
|
||||
selects=[0, _CLEAR, _CREATE, _BACK],
|
||||
selects=[0, _CLEAR, _CREATE, None],
|
||||
texts=["Ops"], # the new channel's name
|
||||
dialogs=["clear"], # confirm the clear on its Cancel/Clear dialog
|
||||
)
|
||||
|
||||
+14
-13
@@ -412,7 +412,7 @@ async def test_editor_restaging_the_current_value_clears_the_stage(ctx: AppConte
|
||||
("text", "Changed"),
|
||||
("select", "name"),
|
||||
("text", str(current)), # back to what the device already has
|
||||
("select", "__cancel__"), # nothing staged now — closes without a discard dialog
|
||||
("select", None), # nothing staged now — Esc closes without a discard dialog
|
||||
])
|
||||
assert await edit_config(ctx) is None
|
||||
|
||||
@@ -435,7 +435,7 @@ async def test_editor_repicking_the_cadence_in_force_clears_the_stage(ctx: AppCo
|
||||
("select", 4),
|
||||
("select", "__advert_direct__"),
|
||||
("select", 1), # back to the default in force
|
||||
("select", "__cancel__"), # nothing staged now — closes without a discard dialog
|
||||
("select", None), # nothing staged now — Esc closes without a discard dialog
|
||||
])
|
||||
assert await edit_config(ctx) is None
|
||||
|
||||
@@ -465,8 +465,8 @@ async def test_editor_discards_staged_changes_when_confirmed(ctx: AppContext) ->
|
||||
|
||||
|
||||
async def test_editor_clean_close_needs_no_confirmation(ctx: AppContext) -> None:
|
||||
"""With nothing staged, Close leaves immediately — no dialog in the script."""
|
||||
_install(ctx, [("select", "__cancel__")])
|
||||
"""With nothing staged, Esc leaves immediately — no dialog in the script."""
|
||||
_install(ctx, [("select", None)])
|
||||
assert await edit_config(ctx) is None
|
||||
|
||||
|
||||
@@ -474,7 +474,7 @@ async def test_editor_menu_pins_the_column_header_over_the_category(ctx: AppCont
|
||||
"""Scrolled deep, the lane names stay overhead with the category heading under them."""
|
||||
from meshterm.ui.tui import SelectScreen, frame
|
||||
|
||||
ui = _install(ctx, [("select", "__cancel__")])
|
||||
ui = _install(ctx, [("select", None)])
|
||||
assert await edit_config(ctx) is None
|
||||
menu = ui.session.pushed[0]
|
||||
# Re-open the same rows highlighting a row in the last category, so the list scrolls
|
||||
@@ -483,7 +483,8 @@ async def test_editor_menu_pins_the_column_header_over_the_category(ctx: AppCont
|
||||
visible, above, _below = frame._visible_slice(deep, deep.render_body(100), 6)
|
||||
top = [_ANSI.sub("", row).strip() for row in visible[:2]]
|
||||
assert top[0].startswith("SETTING") and top[0].endswith("DESCRIPTION")
|
||||
assert top[1] == "── Background adverts ──"
|
||||
# Whichever section the window's top row fell in, its heading pins under the lanes.
|
||||
assert top[1].startswith("── ") and top[1].endswith(" ──")
|
||||
assert above is True
|
||||
assert any("Flood advert" in _ANSI.sub("", row) for row in visible)
|
||||
|
||||
@@ -587,7 +588,7 @@ async def test_actions_factory_reset_gates_on_typed_confirmation(ctx: AppContext
|
||||
_install(ctx, [
|
||||
("select", "__reset__"),
|
||||
("typed_confirm", False),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert await device.get_custom_vars() == {"mode": "test"}
|
||||
@@ -596,7 +597,7 @@ async def test_actions_factory_reset_gates_on_typed_confirmation(ctx: AppContext
|
||||
_install(ctx, [
|
||||
("select", "__reset__"),
|
||||
("typed_confirm", True),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert await device.get_custom_vars() == {}
|
||||
@@ -611,7 +612,7 @@ async def test_actions_import_key_gates_on_typed_confirmation(ctx: AppContext) -
|
||||
("select", "import"),
|
||||
("text", new_key),
|
||||
("typed_confirm", True),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert await device.export_private_key() == new_key
|
||||
@@ -622,7 +623,7 @@ async def test_actions_reboot_on_simulator_stays_on_the_screen(ctx: AppContext)
|
||||
ui = _install(ctx, [
|
||||
("select", "__reboot__"),
|
||||
("dialog", "reboot"),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert ctx.reboot_in_progress is False
|
||||
@@ -638,7 +639,7 @@ async def test_actions_sync_clock_corrects_the_device_time(ctx: AppContext) -> N
|
||||
ui = _install(ctx, [
|
||||
("select", "__sync_clock__"),
|
||||
("dialog", "sync"),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert abs((await device.get_time()) - int(time.time())) <= 2
|
||||
@@ -652,7 +653,7 @@ async def test_actions_sync_clock_cancel_leaves_the_clock_alone(ctx: AppContext)
|
||||
_install(ctx, [
|
||||
("select", "__sync_clock__"),
|
||||
("dialog", None),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert abs((await device.get_time()) - before) <= 2 # still ticking on the old drift
|
||||
@@ -682,7 +683,7 @@ async def test_actions_backup_writes_immediately(ctx: AppContext, tmp_path: Path
|
||||
ui = _install(ctx, [
|
||||
("select", "__backup__"),
|
||||
("path", str(target)),
|
||||
("select", "__cancel__"),
|
||||
("select", None),
|
||||
])
|
||||
await device_actions(ctx)
|
||||
assert target.exists()
|
||||
|
||||
@@ -275,7 +275,7 @@ def test_contacts_screen_lists_contacts_in_the_shared_lanes() -> None:
|
||||
import re
|
||||
|
||||
from meshterm.core.models import Contact, utcnow
|
||||
from meshterm.ui.contacts_screen import _BACK, _PURGE, YOU, ContactsScreen
|
||||
from meshterm.ui.contacts_screen import _PURGE, YOU, ContactsScreen
|
||||
from meshterm.ui.tui.screen import CANCEL
|
||||
|
||||
contacts = [
|
||||
@@ -297,9 +297,9 @@ def test_contacts_screen_lists_contacts_in_the_shared_lanes() -> None:
|
||||
assert f"{7:>5}" in body # Alice's overheard packets, right-aligned in its lane
|
||||
assert "never" in body # Bob has no last_seen
|
||||
# Each contact row carries the Contact itself, so Enter hands the whole record on; the
|
||||
# tail closes the list with the purge action and the Back exit row.
|
||||
assert [c.value for c in choices[-2:]] == [_PURGE, _BACK]
|
||||
assert all(isinstance(c.value, Contact) for c in choices[1:-2])
|
||||
# tail closes the list with the purge action (there is no exit row — Esc leaves).
|
||||
assert choices[-1].value == _PURGE
|
||||
assert all(isinstance(c.value, Contact) for c in choices[1:-1])
|
||||
|
||||
# Plain arrows move the highlight without touching the sort.
|
||||
before = (screen._sort.column, screen._sort.ascending)
|
||||
@@ -655,15 +655,14 @@ async def test_the_list_rebuilds_when_the_detail_page_deletes_the_contact(
|
||||
|
||||
|
||||
def test_contacts_screen_tail_offers_purge_only_when_populated() -> None:
|
||||
"""A populated list closes with the purge action + Back; an empty one has no tail action."""
|
||||
"""A populated list closes with the purge action; an empty one has no tail at all."""
|
||||
from meshterm.core.models import Contact
|
||||
from meshterm.ui.contacts_screen import _BACK, _PURGE, ContactsScreen
|
||||
from meshterm.ui.contacts_screen import _PURGE, ContactsScreen
|
||||
|
||||
populated = ContactsScreen(
|
||||
"Us", "cc" * 32, [Contact(name="Alice", public_key="aa" * 32)], 1, {}, _contacts_sort()
|
||||
)
|
||||
tail_values = [c.value for c in populated._choices()][-2:]
|
||||
assert tail_values == [_PURGE, _BACK]
|
||||
assert populated._choices()[-1].value == _PURGE
|
||||
|
||||
empty = ContactsScreen("Us", "cc" * 32, [], 1, {}, _contacts_sort())
|
||||
values = [c.value for c in empty._choices()]
|
||||
|
||||
+9
-11
@@ -118,10 +118,6 @@ class _Entry:
|
||||
|
||||
name: str
|
||||
factory: Callable[[int, int], Screen]
|
||||
#: Whether this screen ends in the app's standard exit group (a blank line then the
|
||||
#: bare word "Back") — true only for the ``SelectScreen``-family list screens; the rest
|
||||
#: exit via Esc (their ``footer_hint`` says so) with no dedicated exit row to find.
|
||||
has_exit_group: bool = False
|
||||
|
||||
|
||||
# --- factories: one per screen the interactive menu can open ---------------------------
|
||||
@@ -183,7 +179,6 @@ def _node_detail(cols: int, rows: int) -> Screen:
|
||||
_Action("remove", "🗑", "err", "Remove contact…"),
|
||||
],
|
||||
trace_action=_Action("trace", "\U0001f3af", "", "Trace — auto route …"),
|
||||
tail_actions=[_Action("back", "", "", "Back")],
|
||||
)
|
||||
|
||||
|
||||
@@ -420,7 +415,7 @@ def _support_project(cols: int, rows: int) -> Screen:
|
||||
|
||||
_ENTRIES: list[_Entry] = [
|
||||
_Entry("dashboard", _dashboard),
|
||||
_Entry("contacts", _contacts, has_exit_group=True),
|
||||
_Entry("contacts", _contacts),
|
||||
_Entry("node_detail", _node_detail),
|
||||
_Entry("map", _map),
|
||||
_Entry("chat", _chat),
|
||||
@@ -430,7 +425,7 @@ _ENTRIES: list[_Entry] = [
|
||||
_Entry("message_paths", _message_paths),
|
||||
_Entry("remote_cli", _remote_cli),
|
||||
_Entry("path_composer", _path_composer),
|
||||
_Entry("courier_outbox", _courier_outbox, has_exit_group=True),
|
||||
_Entry("courier_outbox", _courier_outbox),
|
||||
_Entry("record_dialog", _record_dialog),
|
||||
_Entry("packet_viewer", _packet_viewer),
|
||||
_Entry("trace", _trace),
|
||||
@@ -530,10 +525,13 @@ def test_gallery_screen_fits_its_platform(
|
||||
composed = frame.compose_base(Text(""), screen, screen.footer_hint, cols, rows)
|
||||
_assert_fits(composed.split("\n"), cols, "compose_base")
|
||||
|
||||
if entry.has_exit_group:
|
||||
lines = _plain(screen.render_body(cols)).splitlines()
|
||||
assert lines[-1].strip() == "Back", f"{entry.name}: exit row missing, got {lines[-1]!r}"
|
||||
assert lines[-2].strip() == "", f"{entry.name}: no blank separator before Back"
|
||||
# No screen carries an exit row. Esc leaves — it is on both platforms' keyboards and
|
||||
# every footer_hint says so — and a row repeating it cost two lines of every screen,
|
||||
# which on the PicoCalc's 26 is a row in thirteen. The one surviving "Back" is the
|
||||
# staged-changes discard half ("✗ Back — discard …"), which is a choice rather than an
|
||||
# exit and never reads as a bare word.
|
||||
for line in _plain(screen.render_body(cols)).splitlines():
|
||||
assert line.strip() != "Back", f"{entry.name}: an exit row came back: {line!r}"
|
||||
|
||||
# P3 assertions, on the *rendered ANSI* (the theme/fold contracts, not the config):
|
||||
# picocalc output may carry no truecolor or 256-colour SGR (the console has 16 slots,
|
||||
|
||||
@@ -360,8 +360,7 @@ async def test_trace_screen_composer_updates_the_spec() -> None:
|
||||
return "3d,f2,3d" # one forced hop: outbound, target, then the mirrored return
|
||||
|
||||
screen, _ = _trace_screen(compose_path=compose)
|
||||
screen.handle("down") # Trace → Back…
|
||||
screen.handle("down") # …wrapping onto Compose path, the first row
|
||||
screen.handle("down") # Trace is the last row, so ↓ wraps onto Compose path
|
||||
screen.handle("enter")
|
||||
await asyncio.sleep(0)
|
||||
assert asked == [""]
|
||||
@@ -437,7 +436,11 @@ async def test_trace_screen_action_labels_share_one_column() -> None:
|
||||
|
||||
|
||||
async def test_trace_screen_action_cursor_commits_the_selected_row() -> None:
|
||||
"""↑↓ move over the action rows; Enter commits the one under the cursor."""
|
||||
"""↑↓ move over the action rows; Enter commits the one under the cursor.
|
||||
|
||||
The rows are the screen's own verbs and nothing else — no exit row closes them, so
|
||||
Trace is the last stop and ↓ from it wraps straight back to Compose path.
|
||||
"""
|
||||
opened: list[str] = []
|
||||
|
||||
async def width_flow(current): # noqa: ANN001
|
||||
@@ -446,9 +449,9 @@ async def test_trace_screen_action_cursor_commits_the_selected_row() -> None:
|
||||
|
||||
screen, _ = _trace_screen(pick_width=width_flow)
|
||||
body = _plain(screen.render_body(100))
|
||||
# The menu order the actions read in: build first, tune, then transmit, then out.
|
||||
# The menu order the actions read in: build first, tune, then transmit.
|
||||
labels = ["Compose path", "Explore paths", "Path width — 2 bytes per hop",
|
||||
"Sample count — 1 trace", "Trace — one transmission", "Back"]
|
||||
"Sample count — 1 trace", "Trace — one transmission"]
|
||||
positions = [body.index(label) for label in labels]
|
||||
assert positions == sorted(positions)
|
||||
screen.handle("up") # Trace → Sample count
|
||||
@@ -493,12 +496,14 @@ async def test_trace_screen_hotkeys_are_retired() -> None:
|
||||
assert not screen._running
|
||||
|
||||
|
||||
async def test_trace_screen_back_row_resolves_like_escape() -> None:
|
||||
"""The Back row leaves the screen exactly as Esc does."""
|
||||
async def test_trace_screen_carries_no_exit_row() -> None:
|
||||
"""The screen offers only its own verbs; Esc is the way out, and Enter never is."""
|
||||
screen, _ = _trace_screen()
|
||||
screen.future = asyncio.get_running_loop().create_future()
|
||||
screen.handle("down") # Trace → Back
|
||||
screen.handle("enter")
|
||||
assert "Back" not in _plain(screen.render_body(100))
|
||||
screen.handle("down") # Trace wraps to Compose path, not onto an exit row
|
||||
assert not screen.future.done()
|
||||
screen.handle("escape")
|
||||
assert screen.future.result() is None
|
||||
|
||||
|
||||
|
||||
+34
-29
@@ -72,8 +72,8 @@ def _stripped(lines: list[str]) -> list[str]:
|
||||
|
||||
|
||||
def _rows(screen: LiveFeedScreen, width: int) -> list[str]:
|
||||
"""Just the packet rows — the body past its chrome, above the pinned exit group."""
|
||||
return _stripped(screen.render_body(width))[2:-2]
|
||||
"""Just the packet rows — the body past its heading and column header."""
|
||||
return _stripped(screen.render_body(width))[2:]
|
||||
|
||||
|
||||
def _col(line: str, needle: str) -> int:
|
||||
@@ -335,7 +335,7 @@ def test_livefeed_home_resumes_following_from_deep_in_the_history() -> None:
|
||||
"""Home lands on the pin, not merely on whichever packet is newest right now."""
|
||||
screen = _screen(seed=[_obs(node=f"n{i}", age_s=i) for i in range(10)])
|
||||
screen.handle("end")
|
||||
assert screen._selected is None and not screen._pinned
|
||||
assert screen._selected == 9 and not screen._pinned # the oldest packet
|
||||
screen.handle("home")
|
||||
assert screen._pinned and screen._selected == 0
|
||||
screen.on_event(MeshEvent.observation_event(_obs(node="a1b2")))
|
||||
@@ -368,59 +368,64 @@ def test_livefeed_page_keys_move_the_feed_selection() -> None:
|
||||
screen.handle("pageup")
|
||||
assert screen._selected == 0 # …and stops at the pin rather than wrapping
|
||||
|
||||
for _ in range(5): # paged past the oldest packet, the cursor lands on Back and stays
|
||||
for _ in range(5): # paged past the oldest packet, the cursor clamps on it
|
||||
screen.handle("pagedown")
|
||||
assert screen._selected is None
|
||||
assert screen._selected == 19
|
||||
|
||||
|
||||
def test_livefeed_ends_in_the_apps_exit_group() -> None:
|
||||
"""The screen closes with the standard exit group, pinned to the foot of the body."""
|
||||
def test_livefeed_carries_no_exit_row() -> None:
|
||||
"""The screen ends on the feed itself: Esc leaves, so no row is spent saying so.
|
||||
|
||||
The window still fits the viewport with the chrome struck off it — losing the exit
|
||||
group gave its two lines back to the packets rather than to a gap.
|
||||
"""
|
||||
seed = [_obs(node=f"n{i}", age_s=i) for i in range(40)]
|
||||
screen = _screen(seed=seed)
|
||||
screen.note_viewport(24)
|
||||
lines = _stripped(screen.render_body(100))
|
||||
assert len(lines) <= 24 # the group is chrome: it fits, it doesn't grow
|
||||
assert lines[-2].strip() == "" # exactly one blank separator above it…
|
||||
assert lines[-1].strip() == "Back" # …then the bare word, no arrow and no icon
|
||||
assert "↓" in lines[-3] and "more" in lines[-3] # the feed windows above it
|
||||
assert len(lines) <= 24 # the body fits, it doesn't grow
|
||||
assert "Back" not in " ".join(lines)
|
||||
assert lines[-1].strip() # the last line is content, not a gap
|
||||
assert "↓" in lines[-1] and "more" in lines[-1] # …the marker counting what's below
|
||||
|
||||
# It stays put as the feed scrolls: the packets travel under it, it does not.
|
||||
# The heading and column header stay put as the feed scrolls under them.
|
||||
screen.handle("end")
|
||||
screen.handle("up") # onto the oldest packet, so the window really has scrolled
|
||||
after = _stripped(screen.render_body(100))
|
||||
assert "↑" in after[2] and "more" in after[2]
|
||||
assert after[-1].strip() == "Back" and after[-2].strip() == ""
|
||||
assert "Back" not in " ".join(after)
|
||||
|
||||
|
||||
def test_livefeed_back_row_is_the_cursors_last_stop() -> None:
|
||||
"""↓ off the oldest packet lands on Back, End jumps to it, and Enter there leaves."""
|
||||
def test_livefeed_cursor_stops_on_the_oldest_packet() -> None:
|
||||
"""↓ clamps on the oldest packet and End jumps to it — there is no row past it."""
|
||||
screen = _screen(seed=[_obs(node="n0", age_s=1), _obs(node="n1", age_s=0)])
|
||||
screen.future = _Fut()
|
||||
|
||||
screen.handle("down") # off the pin, onto the newest
|
||||
screen.handle("down")
|
||||
assert screen._selected == 1 # the oldest packet
|
||||
screen.handle("down")
|
||||
assert screen._selected is None # past the oldest packet: Back
|
||||
assert _stripped(screen.render_body(100))[-1].startswith("❯ Back")
|
||||
screen.handle("down")
|
||||
assert screen._selected is None # …and the cursor stops there
|
||||
assert screen._selected == 1 # …and the cursor stops there
|
||||
screen.handle("up")
|
||||
assert screen._selected == 1 # back onto the oldest packet
|
||||
assert screen._selected == 0
|
||||
screen.handle("end")
|
||||
assert screen._selected is None # End is the list's last row
|
||||
assert screen._selected == 1 # End is the oldest packet
|
||||
|
||||
screen.handle("enter") # Enter on Back leaves…
|
||||
assert screen.future.done() and screen.future.value is None # …exactly as Esc does
|
||||
screen.handle("escape") # …and Esc is the way out
|
||||
assert screen.future.done() and screen.future.value is None
|
||||
|
||||
|
||||
def test_livefeed_empty_feed_still_offers_a_way_out() -> None:
|
||||
"""With nothing heard, Back is the only stop there is — and it is already the cursor's."""
|
||||
def test_livefeed_empty_feed_draws_its_note_and_nothing_else() -> None:
|
||||
"""With nothing heard there is no cursor at all — just the note, and Esc to leave."""
|
||||
screen = _screen()
|
||||
screen.future = _Fut()
|
||||
lines = _stripped(screen.render_body(100))
|
||||
assert "nothing heard yet" in lines[1]
|
||||
assert lines[-1].startswith("❯ Back")
|
||||
screen.handle("up") # nowhere else to go
|
||||
assert screen._selected is None and _stripped(screen.render_body(100))[-1].startswith("❯ ")
|
||||
assert "Back" not in " ".join(lines)
|
||||
assert not any(line.startswith("❯") for line in lines) # nothing to point at
|
||||
screen.handle("up") # nowhere to go, and no crash on the way
|
||||
assert screen._selected is None and not screen._pinned
|
||||
screen.handle("enter") # …and Enter opens nothing rather than leaving by accident
|
||||
assert not screen.future.done()
|
||||
|
||||
|
||||
def test_livefeed_windows_inside_the_fixed_screen() -> None:
|
||||
|
||||
+6
-15
@@ -11,7 +11,6 @@ from rich.text import Text
|
||||
|
||||
from meshterm.ui.menus import (
|
||||
Lane,
|
||||
back_rows,
|
||||
changes_phrase,
|
||||
column_header,
|
||||
exit_rows,
|
||||
@@ -23,21 +22,13 @@ from meshterm.ui.menus import (
|
||||
from meshterm.ui.tui import Choice, Separator
|
||||
|
||||
|
||||
def test_back_rows_are_one_blank_line_then_bare_back() -> None:
|
||||
"""The exit group is exactly: a blank separator, then the unadorned word Back."""
|
||||
rows = back_rows("sentinel")
|
||||
assert len(rows) == 2
|
||||
assert isinstance(rows[0], Separator) and rows[0].title == " "
|
||||
assert isinstance(rows[1], Choice)
|
||||
assert rows[1].title == "Back" # no arrow, no icon — the app-wide exit word
|
||||
assert rows[1].value == "sentinel"
|
||||
def test_exit_rows_clean_state_is_nothing_at_all() -> None:
|
||||
"""A list never advertises its own exit: with nothing staged there are no rows.
|
||||
|
||||
|
||||
def test_exit_rows_clean_state_is_plain_back() -> None:
|
||||
"""With nothing staged the editor exit group collapses to the plain Back group."""
|
||||
rows = exit_rows(0, apply_value="A", back_value="B")
|
||||
assert [type(r) for r in rows] == [Separator, Choice]
|
||||
assert rows[1].title == "Back" and rows[1].value == "B"
|
||||
Esc leaves, on both platforms, so the app-wide ``Back`` row was retired — what
|
||||
survives is the staged-changes pair below, which is a choice rather than an exit.
|
||||
"""
|
||||
assert exit_rows(0, apply_value="A", back_value="B") == []
|
||||
|
||||
|
||||
def test_exit_rows_staged_state_spells_out_the_consequence() -> None:
|
||||
|
||||
+21
-21
@@ -518,7 +518,6 @@ def _screen(**over) -> NodeDetailScreen:
|
||||
routes=_RoutesView(note="no route observed yet — trace to discover one"),
|
||||
info_actions=[_Action("timemachine", "⏳", "", "Time machine — 42 receptions")],
|
||||
trace_action=_Action("trace", "🎯", "", "Trace — auto route …"),
|
||||
tail_actions=[_Action("back", "", "", "Back")],
|
||||
)
|
||||
kwargs.update(over)
|
||||
return NodeDetailScreen(**kwargs)
|
||||
@@ -531,14 +530,15 @@ def test_node_detail_screen_renders_its_sections() -> None:
|
||||
body = _plain(screen.render_body(72))
|
||||
assert "Hub" in body and "repeater" in body # the pinned identity header
|
||||
assert "│ Info │" in body and "42" in body # the vitals moved into the boxed Info tab
|
||||
assert "Time machine" in body and "Back" in body # the Info actions + shared tail
|
||||
assert "Time machine" in body # the Info tab's own action
|
||||
assert "Back" not in body # no exit row anywhere: Esc leaves
|
||||
assert "────────" in body # the faint rule closing the stage
|
||||
assert "no route observed yet" not in body # the Routes stage waits on its own tab
|
||||
|
||||
screen.handle("tab")
|
||||
body = _plain(screen.render_body(72))
|
||||
assert "│ Routes │" in body and "no route observed yet" in body
|
||||
assert "Trace" in body and "Back" in body
|
||||
assert "Trace" in body and "Back" not in body
|
||||
assert "packets" not in body # the vitals stay on the Info tab
|
||||
# Every rendered line fits the 72-column standard.
|
||||
for line in screen.render_body(72):
|
||||
@@ -602,8 +602,6 @@ def test_node_detail_screen_cursor_and_commit() -> None:
|
||||
# The cursor opens on the Info tab's first row (Time machine) and is always reported,
|
||||
# so the frame can keep it visible on a terminal too short for the pinned layout.
|
||||
assert screen.cursor_line() is not None
|
||||
screen.handle("down") # onto Back
|
||||
screen.handle("up") # and back onto Time machine
|
||||
screen.render_body(72)
|
||||
screen.handle("enter")
|
||||
assert resolved == ["timemachine"]
|
||||
@@ -612,16 +610,19 @@ def test_node_detail_screen_cursor_and_commit() -> None:
|
||||
assert resolved == ["timemachine", CANCEL]
|
||||
|
||||
|
||||
def test_node_detail_back_row_leaves_like_escape() -> None:
|
||||
"""Committing the Back row resolves CANCEL — the same leave Esc does — not a stray token
|
||||
the opener's loop would ignore and re-show the page over."""
|
||||
def test_node_detail_carries_no_exit_row() -> None:
|
||||
"""The page offers no Back row: Esc leaves, and a row repeating it was retired.
|
||||
|
||||
What the page *does* offer is only its own verbs, so the action cursor never has a
|
||||
do-nothing stop to arrow past on the way to them.
|
||||
"""
|
||||
screen = _screen()
|
||||
resolved: list = []
|
||||
screen.resolve = lambda value: resolved.append(value) # type: ignore[method-assign]
|
||||
|
||||
screen.render_body(72)
|
||||
screen.handle("down") # Time machine -> Back
|
||||
screen.handle("enter")
|
||||
screen.note_viewport(30)
|
||||
assert "Back" not in _plain(screen.render_body(72))
|
||||
screen.handle("escape")
|
||||
assert resolved == [CANCEL]
|
||||
|
||||
|
||||
@@ -641,13 +642,11 @@ def _two_routes() -> _RoutesView:
|
||||
def test_node_detail_screen_route_selection_arms_the_trace() -> None:
|
||||
"""↑/↓ over the route rows moves the graph highlight and the spec a trace would arm on."""
|
||||
screen = _screen(routes=_two_routes(), tabs=[_Tab("Routes", "routes")])
|
||||
# Focusables: route 0, route 1, Time machine, Back — with routes listed, the rows are
|
||||
# the trace entry points, so no dedicated Trace action row renders.
|
||||
# Focusables: route 0, route 1 — with routes listed, the rows are the trace entry
|
||||
# points, so no dedicated Trace action row renders, and the tab carries no other row.
|
||||
assert screen.selected_spec() == "3d,f2,3d"
|
||||
screen.handle("down") # onto route 1
|
||||
assert screen._route_sel == 1 and screen.selected_spec() == "a1,f2,a1"
|
||||
screen.handle("down") # onto Time machine — the pick holds
|
||||
assert screen.selected_spec() == "a1,f2,a1"
|
||||
screen.note_viewport(30)
|
||||
body = _plain(screen.render_body(72))
|
||||
assert "via Hub …" in body and "via Alt …" in body # both rows drew, …-marked as openers
|
||||
@@ -738,9 +737,10 @@ def test_node_detail_screen_context_line_absent_when_theres_nothing_to_show() ->
|
||||
screen.note_viewport(30)
|
||||
lines = screen.render_body(72)
|
||||
path_idx = next(i for i, l in enumerate(lines) if "f2 aa" in _plain([l]))
|
||||
# The very next line is already the next chunk of chrome (the rule/actions), not a blank
|
||||
# or muted context line — nothing hangs under a route that earned no context.
|
||||
assert not _plain([lines[path_idx + 1]]).strip().startswith("weakest")
|
||||
# Nothing at all hangs under a route that earned no context: the pathline is the last
|
||||
# thing the page draws (the tab carries no action rows), not a muted context line.
|
||||
rest = _plain(lines[path_idx + 1:]).strip()
|
||||
assert not rest.startswith("weakest") and not rest
|
||||
|
||||
|
||||
def test_node_detail_screen_hscrolls_the_selected_pathline() -> None:
|
||||
@@ -978,8 +978,8 @@ def test_route_labels_light_through_a_coalesced_hop() -> None:
|
||||
|
||||
|
||||
def test_node_detail_route_list_windows_inside_the_page() -> None:
|
||||
"""With more routes than fit, the list windows with edge markers — the graph and the
|
||||
action rows never leave the screen, however many routes a busy node has."""
|
||||
"""With more routes than fit, the list windows with edge markers — the pinned chrome
|
||||
never leaves the screen, however many routes a busy node has."""
|
||||
routes = _RoutesView(
|
||||
routes=[
|
||||
_Route(draw=(f"{i:x}{i:x}" * 6,), spec=f"s{i}", path=Text(f"route {i}"), context=Text(""))
|
||||
@@ -995,7 +995,7 @@ def test_node_detail_route_list_windows_inside_the_page() -> None:
|
||||
assert len(lines) <= 30 # the body fits the viewport — nothing scrolls off
|
||||
body = _plain(lines)
|
||||
assert "↓" in body and "more" in body # the edge marker counts the hidden routes
|
||||
assert "Back" in body # the pinned tail never leaves
|
||||
assert "── Routes ──" in body # the pinned chrome above the list never leaves
|
||||
assert "PgUp/PgDn scroll" in screen.footer_hint # paging advertised only when needed
|
||||
|
||||
# Walking the cursor to the last route slides the window down to keep it visible.
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_record_dialog_shows_stats_route_and_the_trace_action() -> None:
|
||||
assert "Trace this path" in body # the renamed action (was "Walk again")
|
||||
assert "Walk again" not in body
|
||||
assert "Delete record" in body
|
||||
assert "Back" in body
|
||||
assert "Back" not in body # no exit row: Esc closes the story
|
||||
|
||||
|
||||
def test_record_dialog_draws_the_walk_as_a_route_graph() -> None:
|
||||
@@ -349,7 +349,7 @@ async def test_delete_all_confirm_floats_over_the_browser(tui_ctx) -> None:
|
||||
confirm.resolve(CANCEL) # Esc — back out without deleting
|
||||
again = await _step_until(lambda: _trophy_case(session, other_than=browser))
|
||||
assert again is not None, "the browser never reopened after the confirm"
|
||||
again.resolve(("back", None, 0, None)) # leave the trophy case
|
||||
again.resolve(None) # Esc leaves the trophy case
|
||||
result = await task
|
||||
finally:
|
||||
if not task.done():
|
||||
@@ -388,7 +388,7 @@ async def test_delete_a_disciplines_records_is_a_popup_over_the_browser(tui_ctx)
|
||||
picker.resolve(CANCEL) # Esc — abandon the pick
|
||||
again = await _step_until(lambda: _trophy_case(session, other_than=browser))
|
||||
assert again is not None
|
||||
again.resolve(("back", None, 0, None))
|
||||
again.resolve(None) # Esc
|
||||
result = await task
|
||||
finally:
|
||||
if not task.done():
|
||||
@@ -477,7 +477,7 @@ async def test_the_board_pins_its_discipline_heading_and_description(tui_ctx) ->
|
||||
assert _plain([visible[0]]).strip() == f"── {board.icon} {board.title} ──"
|
||||
assert _plain([visible[1]]).strip().startswith(board.description[:20])
|
||||
assert above is True
|
||||
browser.resolve(("back", None, 0, None))
|
||||
browser.resolve(None) # Esc
|
||||
await task
|
||||
finally:
|
||||
if not task.done():
|
||||
@@ -557,7 +557,7 @@ async def test_browser_cuts_every_row_the_way_it_cuts_the_highlighted_one(tui_ct
|
||||
assert all(re.search(r"#\d+ .*nodes ★ → ", row) for row in walks), walks
|
||||
# …and runs on past the lane rather than closing on a rescued second endpoint.
|
||||
assert all(row.rstrip().endswith("…") for row in walks), walks
|
||||
browser.resolve(("back", None, 0, None))
|
||||
browser.resolve(None) # Esc
|
||||
await task
|
||||
finally:
|
||||
if not task.done():
|
||||
|
||||
+23
-6
@@ -606,14 +606,18 @@ def test_reorder_apply_row_commits_new_order() -> None:
|
||||
|
||||
|
||||
def test_reorder_actions_follow_the_dirty_state() -> None:
|
||||
"""Untouched order offers a lone Back; a change swaps in Apply plus discard-Back."""
|
||||
"""Untouched order offers no action row at all; a change brings Apply plus discard-Back.
|
||||
|
||||
Esc leaves either way, so an untouched list spends nothing on saying so — the pair
|
||||
appears only once there is something to apply, and Apply has no key of its own.
|
||||
"""
|
||||
screen = ReorderScreen("order", ["a", "b", "c"])
|
||||
assert [key for key, _ in screen._actions()] == ["back"]
|
||||
assert screen._actions() == []
|
||||
screen.handle("enter")
|
||||
screen.handle("down") # dirty now
|
||||
assert [key for key, _ in screen._actions()] == ["apply", "back"]
|
||||
screen.handle("up") # moved back home — clean again
|
||||
assert [key for key, _ in screen._actions()] == ["back"]
|
||||
assert screen._actions() == []
|
||||
|
||||
|
||||
def test_reorder_back_row_and_escape_cancel_discarding_moves() -> None:
|
||||
@@ -633,13 +637,26 @@ def test_reorder_back_row_and_escape_cancel_discarding_moves() -> None:
|
||||
|
||||
|
||||
def test_reorder_cursor_wraps_through_the_action_rows() -> None:
|
||||
"""↑ from the first row lands on the last action row; ↓ from there wraps back to the top."""
|
||||
"""↑ from the first row lands on the last row; ↓ from there wraps back to the top.
|
||||
|
||||
Clean, the list is the whole cursor space; once dirty the two action rows join it and
|
||||
the wrap runs through them.
|
||||
"""
|
||||
screen = ReorderScreen("order", ["a", "b"])
|
||||
screen.handle("up") # wrap: onto the lone Back row
|
||||
assert screen._index == 2
|
||||
screen.handle("up") # wrap: onto the last list row, there being no action rows
|
||||
assert screen._index == 1
|
||||
screen.handle("down") # wrap forward to the first list row
|
||||
assert screen._index == 0
|
||||
|
||||
screen.handle("enter") # grab row 0…
|
||||
screen.handle("down") # …and carry it down: dirty, so Apply and Back join the space
|
||||
screen.handle("enter") # drop it — the cursor rode it to the last list row
|
||||
screen.handle("down") # off the list, onto Apply
|
||||
screen.handle("down") # …then the discard-Back row below it
|
||||
assert screen._index == 3
|
||||
screen.handle("down") # and round to the top again
|
||||
assert screen._index == 0
|
||||
|
||||
|
||||
def test_reorder_ignores_typed_characters_including_space() -> None:
|
||||
"""Typed characters — the spacebar included — neither grab a row nor resolve the screen."""
|
||||
|
||||
Reference in new issue
Block a user