From 4c3e78c39c81d2997e88b84e1b5a25b244e870e4 Mon Sep 17 00:00:00 2001 From: historia Date: Tue, 25 Aug 2026 21:02:21 -0400 Subject: feat: prompt to save settings when going back from settings menu --- app/ui/tui.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/ui/tui.py') 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 # --------------------------------------------------------------------------- -- cgit v1.2.3