PicoCalc: the title bar says how to leave the screen

This platform has no footer hint line — the F-key lane stands where it would be,
and the lane only advertises what its five slots do — so Esc, the key every
screen answers to and the reason no screen spends a row on a Back item, was
nowhere on the screen.

It now rides the title bar's tail, last, after the clip arrows and in the same
"↑↓ · hint" shape a floating dialog's subtitle already uses. The verb is the
screen's own: the atom is lifted off its footer hint (the grammar puts Esc last,
so the tail of the hint is the clause), which is how a value picker says keep and
the main menu says quit, and a screen naming no way out advertises none. It gives
way before it crowds the title — the verb first, then the key, then the cells
back.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-30 02:20:44 -04:00
1 parent c1db8e5a31
commit 7c36f809fd
2 files changed
+86 -4

No files matched your search

+40 -4
View File
@@ -7,6 +7,7 @@ header and footer so the whole view fits the terminal exactly (never overflowing
from __future__ import annotations
import re
from collections import OrderedDict
from typing import Callable, Optional, Sequence
@@ -178,13 +179,30 @@ def _panel_box(
_BASE_BOX_CACHE: Optional[tuple[tuple, list[str]]] = None
#: The screen's own way out, lifted off the end of its footer hint. The grammar is
#: mandated — "navigation keys, then action keys, **Esc last**" — so the last atom is the
#: Esc clause wherever a screen has one, and its verb is the true one for that surface
#: (``back`` on a screen, ``quit`` at the main menu, ``keep`` in a value picker).
_ESC_ATOM = re.compile(r"(?:^|·\s*)(Esc\s+\S+)\s*$")
#: Rule cells the title keeps on each side before the bar gives the Esc hint back. Below
#: this the title is being crowded, which is the one thing the hint must not do.
_MIN_RULE = 2
def _esc_hint(hint: str) -> str:
"""The ``Esc …`` atom a screen's footer hint ends on, or ``""`` where it has none."""
found = _ESC_ATOM.search(hint or "")
return found.group(1) if found else ""
def _title_bar(screen: Screen, cols: int, more_above: bool, more_below: bool) -> Text:
"""The borderless frame's one-row title bar: a centered title on a bold rule, clip arrows.
The Panel border's whole vocabulary — where you are (title) and whether the list
continues (the ``↑↓ more`` subtitle) — compressed into a single row so the body wins
back three rows and four columns on the PicoCalc. Shape:
``──── Title ──────────── ↑↓``, echoing
``──── Title ─────── ↑↓ · Esc back``, echoing
:func:`~meshterm.ui.menus.section_heading`'s heading language.
The title is centered in the rule exactly as Rich's ``Panel`` centers its own
@@ -194,12 +212,30 @@ def _title_bar(screen: Screen, cols: int, more_above: bool, more_below: bool) ->
variant, which is for auxiliary text riding *alongside* a border (a footer hint, the
subtitle's own "more" label below), not the border's own glyphs. The ``↑↓`` clip
arrows keep that muted hint style, matching a bordered panel's own subtitle.
The bar's tail also carries **the way out** (JP, 2026-08-30). This platform has no
footer hint line — the F-key lane stands where it would be, and the lane advertises
only what its five slots do — so nothing on the screen said that Esc leaves, which is
the one key every screen answers to and the reason no screen spends a row on a *Back*
item. It rides here in the same muted hint style as the arrows, in the same
``↑↓ · hint`` shape a floating dialog's subtitle already uses, and it is **last** on
the row because that is where the footer's grammar puts it. The verb is the screen's
own (:func:`_esc_hint` lifts the atom off its footer hint, so a value picker says
``keep`` and the main menu says ``quit``); a screen whose hint names no Esc gets
nothing. Compact by construction: where a long title would be crowded, the atom drops
to a bare ``Esc`` and then out altogether — the title is what the reader came for.
"""
border = "accent"
tail = ""
arrows = ""
if more_above or more_below:
tail = ("↑" if more_above else " ") + ("↓" if more_below else " ")
tail_span = len(tail) + 1 if tail else 0 # the space in front of the arrows
arrows = ("↑" if more_above else " ") + ("↓" if more_below else " ")
label_w = cell_len(screen.title) + 2 if screen.title else 0 # a space either side
atom = _esc_hint(screen.footer_hint)
for esc in (atom, "Esc" if atom else "", ""):
tail = " · ".join(part for part in (arrows, esc) if part)
tail_span = cell_len(tail) + 1 if tail else 0 # the space in front of the tail
if not esc or cols - tail_span - label_w >= 2 * _MIN_RULE:
break
rule_span = max(0, cols - tail_span)
bar = Text()
+46
View File
@@ -46,6 +46,52 @@ def test_borderless_frame_swaps_the_panel_for_a_title_bar() -> None:
assert plain[2].startswith("row 0")
def _bar(title: str, hint: str, cols: int = 53, *, below: bool = True) -> str:
"""The borderless title bar's plain text for a screen with ``title`` and ``hint``."""
screen = ScrollScreen(Text("x"), title=title, floating=False)
screen._footer_hint = hint
return frame._title_bar(screen, cols, False, below).plain
def test_the_title_bar_says_how_to_leave_the_screen() -> None:
"""This platform has no footer hint line, so the way out rides the bar's tail.
The F-key lane stands where the footer would be and only advertises what its slots do,
which left Esc — the key every screen answers to, and the reason no screen carries a
*Back* row — completely unadvertised (JP, 2026-08-30). It lands last, after the clip
arrows, in the ``↑↓ · hint`` shape a floating dialog's subtitle already uses.
"""
bar = _bar("Chrome probe", "↑↓ move · Enter open · Esc back")
assert bar.rstrip().endswith("↓ · Esc back")
assert "Chrome probe" in bar
def test_the_bar_speaks_the_screen_s_own_esc_verb() -> None:
"""Lifted off the screen's own footer hint, so each surface keeps its true verb."""
assert _bar("MeshTerm", "↑↓ move · Enter open · Esc quit").endswith("Esc quit")
assert _bar("Path width", "↑↓ move · Enter set · Esc keep").endswith("Esc keep")
# A hint that names no way out advertises none — the lane's rule, one row up.
assert "Esc" not in _bar("Working", "↑↓ move")
def test_the_esc_hint_gives_way_before_it_crowds_the_title() -> None:
"""Compact by construction: the verb goes first, then the atom, and the title stays.
Two rungs down, in order — a long title keeps the key without its verb, a longer one
takes the cells back altogether. The title is what the reader came for.
"""
verbless = _bar("Trace — YUL-Cartierville over a spec", "↑↓ move · Esc back")
assert verbless.rstrip().endswith("· Esc") # the verb went, the key stayed
assert "Esc back" not in verbless
crowded = _bar("Trace — YUL-Cartierville over a longer spec", "↑↓ move · Esc back")
assert "Esc" not in crowded
for bar in (verbless, crowded):
assert "YUL-Cartierville" in bar and cell_len(bar) <= 53
def test_bordered_frame_is_unchanged_on_regular() -> None:
set_platform(REGULAR)
composed = frame.compose_base(Text("hdr"), _screen(), "hint", 72, 24).split("\n")