-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_tools.py
45 lines (37 loc) · 1.2 KB
/
cli_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright © 2017-2023 All rights reserved.
# Sad Crab Company. Contacts: mailto:[email protected]
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
from __future__ import annotations
def press_enter() -> None:
input("Press Enter to continue")
def confirm(prompt: str, strict: bool = False, default: bool | None = None) -> bool:
if not prompt.endswith("\n"):
prompt += "\n"
prompt += "Type 'yes' or 'no'"
if default is None:
prompt += "\n"
elif default is True:
prompt += " (default 'yes')\n"
else:
prompt += " (default 'no')\n"
while True:
rv = input(prompt).lower()
if rv == "yes":
return True
elif rv == "no":
return False
elif strict:
print("You should type 'yes' or 'no'")
elif rv == "y":
return True
elif rv == "n":
return False
elif default is not None:
return default
def prompt_input(prompt: str):
if not prompt.endswith("\n"):
prompt += "\n"
while True:
rv = input(prompt).lower()
if confirm(f"You input - [{rv}].\nAre you sure? ", default=True):
return rv