From af8905177928a49fe0ac49b0af1ac5f2a2e0027c Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Wed, 7 May 2025 10:35:27 +0200 Subject: [PATCH] prompts can now have a default value when enter is pressed --- utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 8760d6b..da841b5 100644 --- a/utils.py +++ b/utils.py @@ -166,12 +166,18 @@ def run_git_cmd(cmd: list[str], repo_path: str) -> subprocess.CompletedProcess: ) -def prompt_yes_no(prompt: str) -> bool: +def prompt_yes_no(prompt: str, *, default: bool | None = None) -> bool: + choices = "y/n" + if default is not None: + choices = "Y/n" if default else "y/N" + while True: - ans = input(f"{prompt} [y/n]: ").strip().lower() + ans = input(f"{prompt} [{choices}]: ").strip().lower() if ans in {"y", "yes"}: return True elif ans in {"n", "no"}: return False + elif default is not None: + return default else: print("Please enter 'y' or 'n'.")