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.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/ui/tui.py b/app/ui/tui.py
index b1b18f1..11f5653 100644
--- a/app/ui/tui.py
+++ b/app/ui/tui.py
@@ -669,6 +669,41 @@ def confirm(scr, question: str, default: bool = False,
return index == 0
+def confirm_yn_cancel(scr, question: str) -> str:
+ """Ask QUESTION with Yes / No / Cancel buttons; return the answer.
+
+ Like ``confirm``, but with a third Cancel button and a string result:
+ "yes", "no", or "cancel". Tab or the arrow keys cycle all three
+ buttons (wrapping around), Enter activates the highlighted one (Yes
+ starts highlighted), y/n answer directly, and Esc (or 'q') counts as
+ Cancel.
+ """
+ frame = Frame(scr, question,
+ "Tab/arrows = switch Enter = confirm y/n "
+ "Esc = cancel")
+ index = 0
+ while True:
+ frame.rows = []
+ frame.cursor = None
+ frame.buttons = (["Yes", "No", "Cancel"], index)
+ frame.draw()
+ curses = frame.curses
+ key = frame.get_key(cancel_keys=())
+ if key in _CANCEL_KEYS:
+ return "cancel"
+ if key in (9, curses.KEY_RIGHT, curses.KEY_DOWN, ord("l")):
+ index = (index + 1) % 3
+ elif key in (curses.KEY_BTAB, curses.KEY_LEFT, curses.KEY_UP,
+ ord("h")):
+ index = (index - 1) % 3
+ elif key in (ord("y"), ord("Y")):
+ return "yes"
+ elif key in (ord("n"), ord("N")):
+ return "no"
+ elif key in (10, 13):
+ return ("yes", "no", "cancel")[index]
+
+
# ---------------------------------------------------------------------------
# Widget: single-choice menu
# ---------------------------------------------------------------------------