A popup with nothing under it floats over the menu, never over an empty frame
The menu is popped while a tool runs, so a lead-in question — the TX optimize link, the node to manage, the password that follows it — had a blank base pushed under it to draw as a box at all. A dialog is smaller than the frame, and what shows around it should be the page it was reached from: the root the menu already declares for ^W is now the base _floated pushes on an empty stack, and the reconnect dialog draws over it too, so the menu loop stops forgetting its root on the way out. A session with no root declared keeps the blank fallback. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
13f0c647de
commit
b1dbbe5a5a
5 files changed
+81
-31
No files matched your search
+23
-19
@@ -588,7 +588,11 @@ async def _menu_loop(ctx: AppContext, session: TuiSession) -> None:
|
||||
The menu is still *popped* while a full-screen tool runs (only a ``popup`` tool floats
|
||||
over it). That is presentation, not navigation — the tool would hide it anyway — and the
|
||||
screen object outliving the pop is what makes returning feel like a pop rather than a
|
||||
rebuild.
|
||||
rebuild. It is also what a tool's lead-in question floats over: declared as the
|
||||
session's root, the menu is the base pushed under any popup that would otherwise be
|
||||
the only frame (``TuiSession._floated``), so a dialog always shows the page it was
|
||||
reached from around it. The root is left declared on the way out for the same reason
|
||||
— the reconnect dialog draws over it — and the next menu simply declares itself.
|
||||
|
||||
Args:
|
||||
ctx: The shared application context.
|
||||
@@ -607,20 +611,17 @@ async def _menu_loop(ctx: AppContext, session: TuiSession) -> None:
|
||||
)
|
||||
session.set_root(menu)
|
||||
loop = asyncio.get_running_loop()
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
await _menu_round(ctx, session, menu, tools, loop)
|
||||
except _Quit as chosen:
|
||||
ctx.unpair_on_exit = chosen.unpair
|
||||
return
|
||||
except PopToMenu:
|
||||
# ^W from somewhere deep. Every frame between there and here has already
|
||||
# popped itself on the way out; nothing is left to do but disarm and redraw
|
||||
# the menu the user asked for.
|
||||
session.unwound()
|
||||
finally:
|
||||
session.set_root(None)
|
||||
while True:
|
||||
try:
|
||||
await _menu_round(ctx, session, menu, tools, loop)
|
||||
except _Quit as chosen:
|
||||
ctx.unpair_on_exit = chosen.unpair
|
||||
return
|
||||
except PopToMenu:
|
||||
# ^W from somewhere deep. Every frame between there and here has already
|
||||
# popped itself on the way out; nothing is left to do but disarm and redraw
|
||||
# the menu the user asked for.
|
||||
session.unwound()
|
||||
|
||||
|
||||
class _Quit(Exception):
|
||||
@@ -1059,10 +1060,13 @@ async def _handle_disconnect(ctx: AppContext, session: TuiSession) -> bool:
|
||||
dialog = ReconnectDialog("Waiting for your device — reconnect it to resume.")
|
||||
dialog.future = asyncio.get_running_loop().create_future()
|
||||
# The session stack was cleared before we were called (see _session_loop), so push a
|
||||
# clean, empty base frame for the popup to float over. A lone floating screen with nothing
|
||||
# beneath it is drawn as the *base* (framed chrome, no centered panel) rather than as a
|
||||
# window — the base gives it something to center over, both horizontally and vertically.
|
||||
base = ScrollScreen("", floating=False, footer_hint="")
|
||||
# base frame for the popup to float over. A lone floating screen with nothing beneath it
|
||||
# is drawn as the *base* (framed chrome, no centered panel) rather than as a window —
|
||||
# the base gives it something to center over, both horizontally and vertically. The
|
||||
# base is the menu the reader was working from (still declared as the root), so the
|
||||
# dialog reads as an interruption of the page rather than as a blank slate; a session
|
||||
# that never reached the menu gets an empty frame.
|
||||
base = session.root or ScrollScreen("", floating=False, footer_hint="")
|
||||
session.push(base)
|
||||
session.push(dialog)
|
||||
animator = asyncio.ensure_future(_animate_dialog(session, dialog))
|
||||
|
||||
@@ -511,7 +511,8 @@ class TuiSession:
|
||||
# another screen — see :meth:`request_pop_all`.
|
||||
self._unwinding = False
|
||||
# The screen the unwind lands on (the main menu), so ^W can no-op when it is already
|
||||
# the top rather than pointlessly rebuilding it. ``None`` until the menu declares it.
|
||||
# the top rather than pointlessly rebuilding it — and what a popup floats over when
|
||||
# nothing else is pushed (see :meth:`_floated`). ``None`` until the menu declares it.
|
||||
self._root: Screen | None = None
|
||||
|
||||
# --- stack ---------------------------------------------------------------
|
||||
@@ -580,13 +581,20 @@ class TuiSession:
|
||||
|
||||
The main menu calls this with its own list. Only two things depend on it: ^W is a
|
||||
no-op while the root is already the top screen (you cannot go back to where you
|
||||
are), and nothing else in the app needs to know which screen is the menu.
|
||||
are), and a popup with nothing under it floats over the root rather than over an
|
||||
empty frame (:meth:`_floated`). Nothing else in the app needs to know which screen
|
||||
is the menu.
|
||||
|
||||
Args:
|
||||
screen: The root screen, or ``None`` to forget it (the menu on its way out).
|
||||
screen: The root screen, or ``None`` to forget it.
|
||||
"""
|
||||
self._root = screen
|
||||
|
||||
@property
|
||||
def root(self) -> Screen | None:
|
||||
"""The declared navigation root (the main menu), or ``None`` before it is declared."""
|
||||
return self._root
|
||||
|
||||
def request_pop_all(self) -> bool:
|
||||
"""Arm the unwind to the navigation root (the ^W key). Returns whether it fired.
|
||||
|
||||
@@ -1273,14 +1281,18 @@ class TuiSession:
|
||||
"""Guarantee that whatever is pushed inside the block draws as a box, not full-frame.
|
||||
|
||||
On an empty stack a lone floating screen is drawn *as* the background — framed
|
||||
chrome filling the terminal, no popup (see :meth:`_base_index`) — so a blank base
|
||||
is pushed first (the trick the reconnect dialog and the message popup already use)
|
||||
and popped once the block ends. With a background already present there is nothing
|
||||
to do: the dialog simply floats over it.
|
||||
chrome filling the terminal, no popup (see :meth:`_base_index`) — so a base is
|
||||
pushed first and popped once the block ends. The base is the **root** (the main
|
||||
menu, popped while a tool runs but still the screen the reader chose the tool
|
||||
from), so a question asked on the way into a tool floats over the menu it came
|
||||
from: a dialog is smaller than the frame, and what shows around it should be the
|
||||
page behind it, never an empty frame. A blank base is the fallback for a session
|
||||
with no root declared. With a background already present there is nothing to do:
|
||||
the dialog simply floats over it.
|
||||
"""
|
||||
backdrop: ScrollScreen | None = None
|
||||
backdrop: Screen | None = None
|
||||
if not self._stack:
|
||||
backdrop = ScrollScreen("", floating=False, footer_hint="")
|
||||
backdrop = self._root or ScrollScreen("", floating=False, footer_hint="")
|
||||
self.push(backdrop)
|
||||
try:
|
||||
yield
|
||||
|
||||
@@ -706,6 +706,7 @@ class _FakeSession:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.stack: list = []
|
||||
self.root = None # no menu ever declared itself: the dialog gets a blank base
|
||||
|
||||
def push(self, screen) -> None:
|
||||
self.stack.append(screen)
|
||||
|
||||
@@ -427,6 +427,37 @@ async def test_a_wizard_turns_one_box_between_its_steps() -> None:
|
||||
]
|
||||
|
||||
|
||||
async def test_a_popup_with_nothing_under_it_floats_over_the_menu() -> None:
|
||||
"""A question asked on the way into a tool shows the menu around it, never an empty frame.
|
||||
|
||||
The menu is popped while a tool runs, so a lead-in picker used to be the only frame and
|
||||
was drawn full-frame — and the blank base that fixed that showed nothing behind the
|
||||
box. A dialog is smaller than the frame, so what shows around it is the page it was
|
||||
reached from: the root the menu declared is the base pushed under it, and popped with
|
||||
it, so the tool's own page opens over nothing.
|
||||
"""
|
||||
menu = SelectScreen("What would you like to do?", [Choice("TX optimize", "tx")])
|
||||
seen: list = []
|
||||
|
||||
with create_pipe_input() as inp:
|
||||
session = _session(inp)
|
||||
session.set_root(menu)
|
||||
|
||||
async def main() -> None:
|
||||
ask = asyncio.ensure_future(
|
||||
session.select("Node to manage", [Choice("Hilltop", "h")], floating=True)
|
||||
)
|
||||
box = await _screen_at(session, 2)
|
||||
seen.append((session._base_screen(), box.floating, session._has_float()))
|
||||
box.resolve("h")
|
||||
assert await asyncio.wait_for(ask, timeout=2) == "h"
|
||||
assert session._stack == [], "the menu is the tool's to re-push, not the popup's"
|
||||
|
||||
await asyncio.wait_for(session.run(main()), timeout=5)
|
||||
|
||||
assert seen == [(menu, True, True)], "drawn as a box over the menu"
|
||||
|
||||
|
||||
async def test_a_wizard_step_may_float_its_own_prompt_over_the_box() -> None:
|
||||
"""A step with nothing to list (a typed value) runs as an awaitable above the box.
|
||||
|
||||
|
||||
@@ -107,11 +107,13 @@ async def test_present_clears_the_buffer_either_way() -> None:
|
||||
|
||||
|
||||
async def test_message_dialog_floats_over_a_blank_backdrop_end_to_end() -> None:
|
||||
"""On an empty stack the popup pushes a blank base beneath itself, then pops both.
|
||||
"""On an empty stack the popup pushes a base beneath itself, then pops both.
|
||||
|
||||
This is the main-menu tool path: the menu is popped while a tool runs, so without
|
||||
the backdrop the lone dialog would be drawn as the base (full-frame). Driving a
|
||||
real session with piped keys proves Enter (OK) dismisses it and the stack unwinds.
|
||||
the backdrop the lone dialog would be drawn as the base (full-frame). The base is
|
||||
the menu itself once one has declared itself the root; a session that never reached
|
||||
one, like this bare session, gets a blank frame. Driving a real session with piped
|
||||
keys proves Enter (OK) dismisses it and the stack unwinds.
|
||||
"""
|
||||
from prompt_toolkit.input.defaults import create_pipe_input
|
||||
from prompt_toolkit.output import DummyOutput
|
||||
|
||||
Reference in new issue
Block a user