Keep asking until we get a real y or n — never auto-cancel.
(question)
| 102 | console.rule(style="dim") |
| 103 | |
| 104 | def confirm(question) -> bool: |
| 105 | """Keep asking until we get a real y or n — never auto-cancel.""" |
| 106 | sys.stdout.flush() |
| 107 | sys.stderr.flush() |
| 108 | while True: |
| 109 | try: |
| 110 | ans = console.input(f"\n⚠ {question} [y/N]: ").strip().lower() |
| 111 | if ans in ("y", "yes"): |
| 112 | return True |
| 113 | if ans in ("n", "no", ""): |
| 114 | # Only accept empty as No if it was a deliberate Enter |
| 115 | # Re-prompt if stdin might have leftover newlines |
| 116 | return False |
| 117 | except EOFError: |
| 118 | # stdin closed (e.g. piped input) — default to False |
| 119 | return False |
| 120 | except KeyboardInterrupt: |
| 121 | print() |
| 122 | return False |