Busy screens: stop the spinner starving the work it reports on

On the PicoCalc a repaint costs about 154ms, and these two loops waited 60ms
(the overlay) and 120ms (the splash) between them — rates hardcoded past
spinner_interval(), which every other animated wait in the app already sleeps
on. The animation asked for repaints faster than the console could finish them,
so it took the event loop from the device read it was covering for: the wait got
slower for being animated, and the spinner stuttered anyway. Both defer to the
platform now (0.5s there, 0.12s on the desktop).

Two calls were also blocking the loop outright, which stops the animation dead
however it is paced. Enumerating serial ports is a SetupAPI/sysfs walk — behind
the "Scanning for companion devices…" splash, and again on every poll of the
reconnect dialog — so both go to a thread. The UI itself cannot: prompt_toolkit
owns the loop for render and keys. Moving the blocking work off it is the same
fix from the other side.

Two tests: neither busy screen may carry a spin rate of its own, and the
spinner advances *during* an awaited read rather than only side of it.

Also drops the "· experimental" tag from the network-device row.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-08-25 02:12:26 -04:00
1 parent fae342c2bd
commit e0a681b293
5 files changed
+71 -14

No files matched your search

+2 -5
View File
@@ -669,14 +669,11 @@ def _action_rows() -> list:
"""The trailing splash rows: name a network device by hand, then quit.
A network (TCP) companion doesn't advertise and isn't attached, so it can't be scanned
for — the "add a network device" row opens a host:port prompt to name one. It's flagged
experimental (TCP companion support is still settling), with the tag in the cautionary
hue so it reads as a caveat rather than a description. The Quit row mirrors the main menu.
The leading spaces line both up under the device-name column.
for — the "add a network device" row opens a host:port prompt to name one. The Quit row
mirrors the main menu. The leading spaces line both up under the device-name column.
"""
add_row = Text()
add_row.append(f" {_TCP_ICON} Add a network device…")
add_row.append(" · experimental", style="warn")
return [
Separator(" "),
Choice(title=add_row, value=_ADD_TCP),
+3 -1
View File
@@ -957,7 +957,9 @@ async def _auto_reconnect(ctx: AppContext, dialog: ReconnectDialog) -> None:
# ``create_ble``/``create_tcp`` connect by address/endpoint and fail fast when absent.
if ctx.active_transport == "serial":
port = ctx.active_port
if port is not None and not serial_port_present(port):
# Off the loop: the probe enumerates ports, which blocks long enough to stall
# the very spinner this dialog is showing while it waits.
if port is not None and not await asyncio.to_thread(serial_port_present, port):
await asyncio.sleep(_LIVENESS_POLL_S)
continue
try:
+14 -5
View File
@@ -44,6 +44,7 @@ from .prompt import (
Validator,
)
from .screen import CANCEL, BusyScreen, Screen, ScrollScreen
from .spinner import spinner_interval
from .select import Choice, ReorderScreen, SelectScreen, Separator
#: Every Ctrl-letter chord the app binds, keyed by the bare lowercase letter — the single
@@ -695,7 +696,7 @@ class TuiSession:
title: str = "",
banner: Optional[Any] = None,
footnote: Optional[str] = None,
interval: float = 0.12,
interval: Optional[float] = None,
) -> Any:
"""Await ``coro`` while showing an animated spinner on the chromeless splash.
@@ -710,11 +711,15 @@ class TuiSession:
title: Optional panel title for the splash box.
banner: Wordmark rows drawn above the box (as on the other startup splashes).
footnote: Muted line drawn below the box.
interval: Seconds between spinner frames.
interval: Seconds between spinner frames. Defaults to the platform's cadence,
which is the point on a slow console: a repaint there costs more than this
loop used to wait between them, so a hardcoded rate spent the whole event
loop redrawing the spinner and starved the very work it was reporting on.
Returns:
Whatever ``coro`` resolves to.
"""
tick = spinner_interval() if interval is None else interval
screen = BusyScreen(message, title=title)
screen.chrome = False
screen.banner = banner
@@ -723,7 +728,7 @@ class TuiSession:
async def animate() -> None:
while True:
await asyncio.sleep(interval)
await asyncio.sleep(tick)
screen.tick()
self.invalidate()
@@ -997,7 +1002,7 @@ class TuiSession:
message: str = "",
*,
title: str = "",
interval: float = 0.06,
interval: Optional[float] = None,
) -> AsyncIterator[BusyOverlay]:
"""Float a skeleton card on top of everything for the duration of a block.
@@ -1020,10 +1025,14 @@ class TuiSession:
message: An optional caption drawn beside the working chip.
title: An optional heading naming the screen being fetched.
interval: Seconds between animation frames (also the fade's repaint cadence).
Defaults to the platform's cadence — see :meth:`busy_startup`, which this
shares a hazard with: the card animates *over* a device read, so a rate the
console can't sustain steals the loop from the read it is covering for.
Yields:
The live :class:`BusyOverlay`, in case the caller wants to update its caption.
"""
tick = spinner_interval() if interval is None else interval
# A nested busy_overlay keeps the outer one (the outermost wait owns the screen); its
# own body still runs, it just doesn't install a second card.
if self._overlay is not None:
@@ -1036,7 +1045,7 @@ class TuiSession:
async def animate() -> None:
while True:
await asyncio.sleep(interval)
await asyncio.sleep(tick)
overlay.tick()
# Only repaint when the card is actually on screen, so an overlay waiting
# behind a live prompt doesn't churn that prompt's repaints for nothing.