Path composer: Esc already cancels, so the Cancel row goes
The row's whole implementation was `super().handle("escape")` — Esc, spelled
out as a cursor stop. It cost a keypress on every platform (End then Enter,
against one Esc), sat below the row that commits so End landed on the way
out rather than on the thing you came to do, and taught nothing: Esc leaves
every other screen in the app without being told to.
The action group now ends where the actions do — Use this path, then Auto
in target mode. Cancel stays where it earns its place: a dialog asking a
real question, where the choice is the point.
This commit is contained in:
1 parent
71f60c0eeb
commit
e86d6a705a
2 files changed
+12
-15
No files matched your search
@@ -87,9 +87,10 @@ AUTO_SPEC = ""
|
||||
_MAX_SUGGESTIONS = 12
|
||||
|
||||
#: Action-row sentinels (kept distinct from suggestion rows, which carry node ids).
|
||||
#: There is no cancel sentinel: leaving is Esc's, and a row that only pressed Esc for
|
||||
#: you cost a cursor stop above the row that commits.
|
||||
_USE = "use"
|
||||
_AUTO = "auto"
|
||||
_CANCEL = "cancel"
|
||||
|
||||
#: One-letter tags for the evidence classes backing a link, shown beside each
|
||||
#: suggestion: T(race), R(oute — the firmware's learned out_path), P(acket log),
|
||||
@@ -382,7 +383,6 @@ class PathComposerScreen(Screen):
|
||||
rows.append(("action", _USE))
|
||||
if self._mirrored: # a path walk has no target for the device to route to
|
||||
rows.append(("action", _AUTO))
|
||||
rows.append(("action", _CANCEL))
|
||||
return rows
|
||||
|
||||
def _spec(self) -> str:
|
||||
@@ -560,9 +560,7 @@ class PathComposerScreen(Screen):
|
||||
if not self._spec():
|
||||
label.append(" (add a hop first)", style="muted")
|
||||
return label
|
||||
if payload == _AUTO:
|
||||
return Text("Auto — let the device route")
|
||||
return Text.assemble(("✗ ", "err"), "Cancel")
|
||||
return Text("Auto — let the device route")
|
||||
|
||||
@property
|
||||
def dialog_width(self) -> int:
|
||||
@@ -681,8 +679,6 @@ class PathComposerScreen(Screen):
|
||||
self.resolve(spec)
|
||||
elif payload == _AUTO:
|
||||
self.resolve(AUTO_SPEC)
|
||||
else:
|
||||
super().handle("escape")
|
||||
|
||||
def handle(self, action: str, data: str = "") -> None:
|
||||
"""Move the cursors, edit the entry, add/remove hops, or commit/cancel."""
|
||||
|
||||
@@ -512,7 +512,7 @@ def test_composer_windows_rows_under_the_pinned_route_preview() -> None:
|
||||
assert "↓" in body and "more" in body # hidden rows are counted at the edge
|
||||
screen.handle("end") # cursor to the last action row — the window follows
|
||||
body = re.sub(r"\x1b\[[0-9;]*m", "", "\n".join(screen.render_body(90)))
|
||||
assert "Cancel" in body and "↑" in body
|
||||
assert "Auto" in body and "↑" in body
|
||||
|
||||
|
||||
def test_composer_typed_hex_adds_a_custom_hop_and_backspace_removes() -> None:
|
||||
@@ -670,23 +670,25 @@ def test_composer_use_row_names_the_action_not_the_path() -> None:
|
||||
|
||||
|
||||
async def test_composer_commits_spec_auto_and_cancel() -> None:
|
||||
"""Use resolves the spec with its mirrored return leg; Auto resolves empty; Esc cancels."""
|
||||
"""Use resolves the spec with its mirrored return leg; Auto resolves empty; Esc cancels.
|
||||
|
||||
Leaving is Esc's alone — the action group ends at Auto, so End lands on the last row
|
||||
that *does* something rather than on one that only pressed Esc on your behalf.
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
walks = [_traced(("3d", 12.0), (None, 12.0))]
|
||||
|
||||
screen = _composer(_topo(trace_paths=walks), hops=["3d63c6429436"])
|
||||
screen.future = asyncio.get_running_loop().create_future()
|
||||
screen.handle("end") # jump to the last action row (Cancel)…
|
||||
screen.handle("up") # …past Auto…
|
||||
screen.handle("end") # jump to the last action row (Auto)…
|
||||
screen.handle("up") # …up to "Use this path"
|
||||
screen.handle("enter")
|
||||
assert screen.future.result() == "3d,f2,3d"
|
||||
|
||||
auto = _composer(_topo(trace_paths=walks))
|
||||
auto.future = asyncio.get_running_loop().create_future()
|
||||
auto.handle("end")
|
||||
auto.handle("up") # "Auto — let the device route"
|
||||
auto.handle("end") # "Auto — let the device route" now closes the group
|
||||
auto.handle("enter")
|
||||
assert auto.future.result() == AUTO_SPEC
|
||||
|
||||
@@ -805,8 +807,7 @@ async def test_composer_path_mode_suggests_through_anything_and_commits_verbatim
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
screen.future = loop.create_future()
|
||||
screen.handle("end") # Cancel…
|
||||
screen.handle("up") # …up to "Use this path" (no Auto row between them)
|
||||
screen.handle("end") # "Use this path" — path mode ends the group there, no Auto row
|
||||
screen.handle("enter")
|
||||
assert screen.future.result() == "3d,f2"
|
||||
|
||||
|
||||
Reference in new issue
Block a user