aboutsummaryrefslogtreecommitdiff
path: root/app/ui/tui.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/ui/tui.py')
-rw-r--r--app/ui/tui.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/app/ui/tui.py b/app/ui/tui.py
index bf17f7d..6d768dd 100644
--- a/app/ui/tui.py
+++ b/app/ui/tui.py
@@ -24,9 +24,10 @@ Common key bindings:
instead, so the caller can fall back a screen
(confirm() historically names this cancel_value)
-On screens without typed text (menus, confirm, tree, browser) 'q' also
-aborts — even when a back_value is set, so Esc means "back" while 'q'
-still means "quit". Inside text editors 'q' is an ordinary character.
+On screens without typed text (menus, confirm, tree, browser) 'q'
+behaves exactly like Esc: it goes back when a back/cancel value is set,
+otherwise it aborts the wizard. Inside text editors 'q' is an ordinary
+character.
When the terminal has no color support the theme degrades to
bold/reverse/dim.
"""
@@ -93,7 +94,8 @@ def flash(scr, text: str, kind: str = "warn") -> None:
raise WizardCancelled()
-# Esc and 'q' both abort on screens without typed text ('q' is an
+# On screens without typed text, Esc and 'q' mean the same thing: go
+# back when a back/cancel value is set, abort otherwise ('q' is an
# ordinary character inside text editors).
_CANCEL_KEYS = (27, ord("q"))
@@ -637,7 +639,8 @@ def menu(scr, title: str, options: Sequence[tuple], default_index: int = 0,
status table.
Esc (or 'q') aborts the wizard unless BACK_VALUE is given (not None),
- in which case Esc returns it so the caller can fall back a screen.
+ in which case either key returns it so the caller can fall back a
+ screen.
"""
if not options:
raise ValueError("menu() needs at least one option")
@@ -676,7 +679,7 @@ def menu(scr, title: str, options: Sequence[tuple], default_index: int = 0,
frame.cursor = base + cursor
frame.draw()
key = frame.get_key(cancel_keys=())
- if key == 27 and back_value is not None:
+ if key in _CANCEL_KEYS and back_value is not None:
return back_value
if key in _CANCEL_KEYS:
raise WizardCancelled()
@@ -720,6 +723,7 @@ def line_edit(scr, title: str, default: str,
frame.draw()
curses = frame.curses
key = frame.get_key(cancel_keys=()) # handle Esc manually below
+ # 'q' is an ordinary character in a text editor; only Esc cancels.
if key == 27 and back_value is not None:
return back_value
if key == 27:
@@ -807,7 +811,7 @@ def form(scr, title: str, fields: Sequence[dict],
frame.draw()
curses = frame.curses
key = frame.get_key(cancel_keys=())
- if key == 27 and back_value is not None:
+ if key in _CANCEL_KEYS and back_value is not None:
return back_value
if key in _CANCEL_KEYS:
raise WizardCancelled()
@@ -921,8 +925,8 @@ def browse_directory(scr, title: str,
lets a subdirectory that already looks like the target (e.g. an
'audio.cpp' checkout containing 'model_specs/') be picked in one
keystroke. Esc (or 'q') aborts the wizard unless BACK_VALUE is given
- (not None), in which case Esc returns it so the caller can fall back
- a screen.
+ (not None), in which case either key returns it so the caller can
+ fall back a screen.
"""
footer = ("Up/Down = move Enter = open/use Left = parent "
"e = type path Esc = cancel")
@@ -993,7 +997,7 @@ def browse_directory(scr, title: str,
frame.draw()
curses = frame.curses
key = frame.get_key(cancel_keys=())
- if key == 27 and back_value is not None:
+ if key in _CANCEL_KEYS and back_value is not None:
return back_value
if key in _CANCEL_KEYS:
raise WizardCancelled()
@@ -1072,7 +1076,8 @@ def checkbox_tree(scr, title: str, families: List[dict],
family has more than one option — a single option needs no tag.
Family and option rows are left-justified like a DOS list. Esc (or
'q') aborts the wizard unless BACK_VALUE is given (not None), in
- which case Esc returns it so the caller can fall back a screen.
+ which case either key returns it so the caller can fall back a
+ screen.
"""
if not families:
raise ValueError("checkbox_tree() needs at least one family")
@@ -1141,7 +1146,7 @@ def checkbox_tree(scr, title: str, families: List[dict],
frame.draw()
curses = frame.curses
key = frame.get_key(cancel_keys=())
- if key == 27 and back_value is not None:
+ if key in _CANCEL_KEYS and back_value is not None:
return back_value
if key in _CANCEL_KEYS:
raise WizardCancelled()