Dialogs: multi-layer floats, red data-loss tier, unknown-relay hashes
Three independent consistency passes: 1. **Message paths: unknown relays as grey full-hash** The message-paths dialog showed unnamed relay hops as a single lit byte (e.g. `e8`). Now they render at the device's path-hash-mode width, muted grey, and annotated with their addressed byte — `e839f2 (e8)` — so the rows stay readable and cross-reference the route graph's byte labels (matching named hops' trace presentation). Added `hash_as_name` flag to path_text widget. 2. **Dialogs: multi-layer compositor + backdrop for empty stack** Opening a confirm over a floating popup used to stretch that popup to full-frame (the single-float compositor's bug). Now the compositor maintains a pool of _MAX_DIALOG_LAYERS=8 centered-box floats, each rendering one layer above the background — so a popup and its confirm both stay their own size. Also: button_dialog/typed_confirm/autocomplete now float over a blank base when the stack is empty (via _run_dialog_screen), guaranteeing popups render as small boxes on an empty stack, not full-frame chrome. Simplified message_dialog to delegate its backdrop logic to button_dialog. 3. **Data-loss dialogs: red `destructive` tier** Added a second caution tier to the dialog API: danger=True stays amber (disruptive: discard edits, reboot), destructive=True is red (irreversible data loss). Updated: single-record delete, channel "clear slot", courier "clear finished" (new confirm), and startup "remove device" (splash confirm). Per UX spec: bulk/irreversible deletions gate behind typed_confirm (also red); single-record delete is a red Cancel/[verb] button dialog. All changes are backward-compatible. Full suite: 793 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed391ab16e
commit
115fe6895d
14 files changed
+332
-76
No files matched your search
@@ -376,7 +376,7 @@ class _ScriptedUi:
|
||||
async def text(self, title: str, *, default: str = "", validate=None, help_text: str = "", password: bool = False): # noqa: ANN001, ANN201
|
||||
return self._texts.pop(0)
|
||||
|
||||
async def dialog(self, prompt, buttons, *, title: str = "", default: int = 0, keys=None, danger: bool = False): # noqa: ANN001, ANN201
|
||||
async def dialog(self, prompt, buttons, *, title: str = "", default: int = 0, keys=None, danger: bool = False, destructive: bool = False): # noqa: ANN001, ANN201
|
||||
return self._dialogs.pop(0)
|
||||
|
||||
|
||||
|
||||
@@ -67,6 +67,24 @@ def test_paths_screen_labels_every_relay_with_its_hash_byte() -> None:
|
||||
assert "Waymarker (a1)" in body
|
||||
|
||||
|
||||
def test_paths_screen_shows_unknown_relay_as_grey_mode_width_hash() -> None:
|
||||
"""An unnamed relay stands in its own hash at the device's path-hash width, muted
|
||||
grey and annotated with its addressed byte — not the bare one-byte prefix, lit."""
|
||||
now = utcnow()
|
||||
arrivals = [
|
||||
Arrival(when=now, hops=("3d63",), snr=4.0), # selected: a named relay
|
||||
Arrival(when=now + timedelta(seconds=2), hops=("e839f2ab",), snr=-2.0),
|
||||
]
|
||||
screen = _screen(arrivals, prefix_bytes=3) # 3-byte routing → e839f2
|
||||
lines = screen.render_body(76)
|
||||
row = next(ln for ln in lines if "e839f2" in _plain([ln]))
|
||||
assert "e839f2 (e8)" in _plain([row]) # mode-width identity, then the byte
|
||||
assert "38;2;148;163;184" in row # muted grey over the hash
|
||||
assert "38;2;94;234;212" not in row # never the brand highlight
|
||||
graph = _plain(lines).split("origin →")[0]
|
||||
assert "e8" in graph # the row's byte still cross-references the graph label
|
||||
|
||||
|
||||
def test_paths_screen_colours_selected_path_by_snr_over_gray() -> None:
|
||||
"""The selected path's edges take its arrival's SNR hue; the unused path stays gray."""
|
||||
screen = _screen(_arrivals()) # selected arrival's SNR is +4.0 dB → the "ok" band
|
||||
|
||||
@@ -129,6 +129,39 @@ async def test_message_dialog_floats_over_a_blank_backdrop_end_to_end() -> None:
|
||||
await asyncio.wait_for(session.run(main()), timeout=5)
|
||||
|
||||
|
||||
async def test_confirm_floats_over_an_existing_popup_end_to_end() -> None:
|
||||
"""A confirm opened over a floating detail popup renders and resolves — the render
|
||||
loop runs the multi-layer float pool for real (base + detail + confirm), the case
|
||||
the old single-float compositor stretched the detail to full-frame.
|
||||
"""
|
||||
from prompt_toolkit.input.defaults import create_pipe_input
|
||||
from prompt_toolkit.output import DummyOutput
|
||||
|
||||
from meshterm.ui.tui.screen import ScrollScreen
|
||||
from meshterm.ui.tui.select import Choice, SelectScreen
|
||||
|
||||
with create_pipe_input() as inp:
|
||||
session = TuiSession(input=inp, output=DummyOutput())
|
||||
|
||||
async def main() -> None:
|
||||
base = ScrollScreen(Text("channels"), title="Channels") # full-frame background
|
||||
detail = SelectScreen("Ops", [Choice("Clear", "clr")]) # a floating popup
|
||||
session.push(base)
|
||||
session.push(detail)
|
||||
# Two layers float over the one background while the confirm is up.
|
||||
assert session._base_screen() is base
|
||||
inp.send_text("\r") # Enter commits the confirm's default (Delete)
|
||||
confirmed = await session.button_dialog(
|
||||
"Clear Ops?", [("Cancel", 0), ("Clear", 1)], default=1, border_style="err"
|
||||
)
|
||||
assert confirmed == 1
|
||||
assert session._float_layers() == [detail] # confirm gone, detail still afloat
|
||||
session.pop(detail)
|
||||
session.pop(base)
|
||||
|
||||
await asyncio.wait_for(session.run(main()), timeout=5)
|
||||
|
||||
|
||||
# -- the message dialog's border tone -----------------------------------------------
|
||||
|
||||
|
||||
@@ -143,3 +176,46 @@ def test_message_border_echoes_the_strongest_tone() -> None:
|
||||
assert _message_border(ok) == "accent"
|
||||
assert _message_border(both) == "err"
|
||||
assert _message_border("plain string") == "accent"
|
||||
|
||||
|
||||
# -- the button dialog's caution tiers ----------------------------------------------
|
||||
|
||||
|
||||
class _ButtonRecordingSession:
|
||||
"""Records the styling kwargs :meth:`TuiUi.dialog` hands the button dialog."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.kwargs: dict[str, Any] = {}
|
||||
|
||||
async def button_dialog(self, prompt: str, buttons: list, **kwargs: Any) -> Any:
|
||||
self.kwargs = kwargs
|
||||
return buttons[-1][1]
|
||||
|
||||
|
||||
async def _dialog_styles(**kw: Any) -> dict[str, Any]:
|
||||
session = _ButtonRecordingSession()
|
||||
ui = TuiUi(session) # type: ignore[arg-type]
|
||||
await ui.dialog("Delete this record?", [("Cancel", False), ("Delete", True)], **kw)
|
||||
return session.kwargs
|
||||
|
||||
|
||||
async def test_dialog_destructive_tier_borders_red() -> None:
|
||||
"""A data-loss dialog draws in the reserved error red — prompt and border."""
|
||||
styles = await _dialog_styles(destructive=True)
|
||||
assert styles["border_style"] == "err"
|
||||
assert styles["prompt_style"] == "err"
|
||||
|
||||
|
||||
async def test_dialog_danger_tier_stays_amber() -> None:
|
||||
"""A merely-disruptive dialog keeps the amber caution tone, never the deletion red."""
|
||||
styles = await _dialog_styles(danger=True)
|
||||
assert styles["border_style"] == "warn"
|
||||
assert styles["prompt_style"] == "warn"
|
||||
|
||||
|
||||
async def test_dialog_plain_is_neutral_and_destructive_outranks_danger() -> None:
|
||||
"""No flag is the neutral accent frame; destructive wins over danger when both are set."""
|
||||
plain = await _dialog_styles()
|
||||
assert plain["border_style"] == "accent" and plain["prompt_style"] == ""
|
||||
both = await _dialog_styles(danger=True, destructive=True)
|
||||
assert both["border_style"] == "err" and both["prompt_style"] == "err"
|
||||
@@ -1377,6 +1377,42 @@ def test_session_stack_and_float_selection() -> None:
|
||||
assert not session._has_float()
|
||||
|
||||
|
||||
def test_session_stacks_every_dialog_over_one_full_frame_background() -> None:
|
||||
"""A dialog over a dialog: both float over the single background, neither full-frame.
|
||||
|
||||
The old compositor drew only the top float and rendered the second-from-top as the
|
||||
full-frame base — so opening a confirm over a popup stretched that popup to fill the
|
||||
frame. Now the background is the deepest full-frame screen and every floating layer
|
||||
above it stays its own centered box.
|
||||
"""
|
||||
session = TuiSession()
|
||||
channels = SelectScreen("Channels", [Choice("Ops", 1)]) # a tool's own floating list
|
||||
detail = SelectScreen("Ops (private)", [Choice("Clear", "clr")]) # its item popup
|
||||
confirm = ButtonDialog("Clear Ops?", [("Cancel", 0), ("Clear", 1)], border_style="err")
|
||||
for screen in (channels, detail, confirm):
|
||||
session.push(screen)
|
||||
|
||||
# The bottom (all-floating) screen is the one full-frame background; the detail popup
|
||||
# and the confirm both float over it — the detail is no longer promoted to the base.
|
||||
assert session._base_screen() is channels
|
||||
assert session._float_layers() == [detail, confirm]
|
||||
|
||||
session.pop(confirm)
|
||||
assert session._float_layers() == [detail] # detail stays a float, not full-frame
|
||||
assert session._base_screen() is channels
|
||||
|
||||
|
||||
def test_session_background_is_the_topmost_full_frame_screen() -> None:
|
||||
"""A non-floating screen (a map, a scroll window) is the background under any dialogs."""
|
||||
session = TuiSession()
|
||||
full = ScrollScreen(Text("map"), title="map") # floating=False
|
||||
dialog = ButtonDialog("go?", [("No", 0), ("Yes", 1)])
|
||||
session.push(full)
|
||||
session.push(dialog)
|
||||
assert session._base_screen() is full
|
||||
assert session._float_layers() == [dialog]
|
||||
|
||||
|
||||
# --- busy skeleton card ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,27 @@ def test_path_text_lights_the_hash_prefix() -> None:
|
||||
assert "77" in brand # the addressed prefix stands out within the hash
|
||||
|
||||
|
||||
def test_path_text_hash_as_name_shows_grey_identity_hash() -> None:
|
||||
"""An unnamed hop stands in its own hash at the mode width, muted, plus its byte."""
|
||||
text = path_text(
|
||||
["e839f2ab"], _resolve, prefix_bytes=3,
|
||||
show_hash=True, hash_bytes=1, hash_as_name=True,
|
||||
)
|
||||
assert text.plain == "e839f2 (e8)" # mode width identity, then the addressed byte
|
||||
styles = {text.plain[s.start : s.end]: str(s.style) for s in text.spans}
|
||||
assert styles.get("e839f2") == "muted" # greyed — colour is the "this is a name" cue
|
||||
assert not any(str(s.style) == "brand" for s in text.spans) # no prefix lit
|
||||
|
||||
|
||||
def test_path_text_hash_as_name_drops_the_byte_when_it_is_the_whole_hash() -> None:
|
||||
"""When the mode width is one byte, the identity already is the byte — no ``(e8)``."""
|
||||
text = path_text(
|
||||
["e839f2ab"], _resolve, prefix_bytes=1,
|
||||
show_hash=True, hash_bytes=1, hash_as_name=True,
|
||||
)
|
||||
assert text.plain == "e8"
|
||||
|
||||
|
||||
def test_path_text_trace_flavour_annotates_hashes_and_brackets_us() -> None:
|
||||
"""show_hash appends the addressed hash to names; None hops are our device."""
|
||||
text = path_text(
|
||||
|
||||
Reference in new issue
Block a user