kiwi-scp/src/kiwi/misc.py

38 lines
923 B
Python
Raw Normal View History

def _surround(string, bang):
midlane = f"{bang * 3} {string} {bang * 3}"
sidelane = bang*len(midlane)
return f"{sidelane}\n{midlane}\n{sidelane}"
2020-08-18 13:05:19 +00:00
def _emphasize(lines):
if isinstance(lines, list):
return '\n'.join([_emphasize(line) for line in lines])
elif lines:
return f">>> {lines} <<<"
else:
return lines
def are_you_sure(prompt, default="no"):
if default.lower() == 'yes':
suffix = "[YES|no]"
else:
suffix = "[yes|NO]"
answer = input(
2020-08-18 13:05:19 +00:00
f"{_surround('MUST HAVE CAREFULING IN PROGRESS', '!')}\n"
f"\n"
2020-08-18 13:05:19 +00:00
f"{_emphasize(prompt)}\n"
f"\n"
f"Are you sure you want to proceed? {suffix} "
).strip().lower()
if answer == '':
answer = default
while answer not in ['yes', 'no']:
answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower()
return answer == 'yes'