Merge branch 'main' into cardputer-zero

This commit is contained in:
Jean-Pierre Martineau committed 2026-10-02 03:13:56 -04:00
commit 032e686beb
6 files changed
+95 -4

No files matched your search

+8 -1
View File
@@ -48,7 +48,7 @@ from .tui import (
TuiSession,
)
from .tui.emoji_width import install as install_emoji_widths
from .tui.fkeys import FPair
from .tui.fkeys import EMPTY_LANE, FPair
from .tui.spinner import spinner_interval
from .widgets import battery_cell
@@ -514,6 +514,12 @@ async def _confirm_quit(ctx: AppContext, session: TuiSession) -> bool:
if await _can_unpair(ctx):
buttons.append(("Unpair & quit", "unpair"))
buttons.append(("Quit", "quit"))
# On a handheld the question keeps the chip that asked it: F3, where the menu's
# ``Quit?`` sat, reads ``Quit!`` here and sends the same ``quit`` — which, while this
# confirm is up, leaves at once (see TuiSession.request_quit), as a second ^Q does.
# So the way out from the menu is one key pressed twice (JP, 2026-10-02).
lane = list(EMPTY_LANE)
lane[2] = FPair("Quit!", "quit")
choice = await session.button_dialog(
"Are you sure you want to quit?",
buttons,
@@ -526,6 +532,7 @@ async def _confirm_quit(ctx: AppContext, session: TuiSession) -> bool:
button_style="selected",
button_idle_style="muted",
border_style="warn",
lane=lane,
)
if choice == "unpair":
ctx.unpair_on_exit = True
+18 -1
View File
@@ -8,7 +8,8 @@ prompt shares the framework's look, layering, resize, and Esc-to-cancel behavior
from __future__ import annotations
from collections.abc import Callable
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING
from rich.cells import cell_len
from rich.console import Group, RenderableType
@@ -19,6 +20,9 @@ from .render import render_lines, right_aligned_tail
from .screen import Screen
from .spinner import Spinner
if TYPE_CHECKING:
from .fkeys import FPair
#: A validator returns ``True`` when the input is acceptable, or an error message to show.
Validator = Callable[[str], "bool | str"]
@@ -506,6 +510,7 @@ class ButtonDialog(_KeylessDialog):
button_style: str = "selected",
button_idle_style: str = "muted",
border_style: str = "accent",
lane: Sequence[FPair | None] | None = None,
) -> None:
"""Build a button dialog.
@@ -525,8 +530,12 @@ class ButtonDialog(_KeylessDialog):
button_style: Rich style for the highlighted button.
button_idle_style: Rich style for the un-highlighted buttons.
border_style: Rich style for the dialog border (read by the frame compositor).
lane: An F-key lane for the one question that has a chip worth offering — the
quit confirm's, whose F3 is the chip that asked it, pressed again (see
``menu._confirm_quit``). ``None`` keeps a prompt's empty lane.
"""
super().__init__()
self._lane = tuple(lane) if lane is not None else None
self.title = title
self.footer_hint = footer_hint
self.border_style = border_style
@@ -550,6 +559,14 @@ class ButtonDialog(_KeylessDialog):
return list(self._prompt.split("\n")) or [Text("")]
return [Text(self._prompt, style=self._prompt_style)]
@property
def picocalc_lane(self):
"""The caller's lane where one was given, else a prompt's empty one.
The per-deck definition, as every screen's is; the Cardputer's deck follows it.
"""
return self._lane if self._lane is not None else super().picocalc_lane
@property
def _button_row_width(self) -> int:
"""Display width of the button row (`` Label `` cells joined by 4-space gaps)."""
+2
View File
@@ -1360,6 +1360,7 @@ class TuiSession:
button_style: str = "selected",
button_idle_style: str = "muted",
border_style: str = "accent",
lane: Sequence[fkeys.FPair | None] | None = None,
) -> Any:
"""Show a centered button dialog; return the chosen value or ``None`` if cancelled.
@@ -1380,6 +1381,7 @@ class TuiSession:
button_style=button_style,
button_idle_style=button_idle_style,
border_style=border_style,
lane=lane,
)
result = await self.run_dialog(screen)
return None if result is CANCEL else result