from typing import Optional def choice(default: str, options: str, msg: str) -> str: default = default.lower() formatted_options = "".join( [(opt + "/" if opt != default else default.upper() + "/") for opt in options] )[:-1] choice = input(msg + " [" + formatted_options + "] ") if choice == "": return default else: return choice.lower() def confirm(is_true_default: bool, msg: Optional[str] = ""): return ( choice( "y" if is_true_default else "n", "yn", (msg if msg != "" and msg != None else "Do you really want to continue?"), ) == "y" ) def confirm_overwrite(msg: Optional[str] = ""): return confirm( False, (msg if msg != "" else "Do you really want to overwrite your changes?") )