ui: use match statement where practicable

This commit is contained in:
The MMGen Project 2025-09-23 09:20:54 +00:00
commit 5463f60376
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2

View file

@ -107,14 +107,14 @@ def keypress_confirm(
from .term import get_char
while True:
reply = get_char(prompt, immed_chars='yYnN').strip('\n\r')
if not reply:
match get_char(prompt, immed_chars='yYnN').strip('\n\r'):
case '':
msg_r(nl)
return do_return(default_yes)
elif reply in 'yYnN':
case 'y' | 'Y' | 'n' | 'N' as reply:
msg_r(nl)
return do_return(reply in 'yY')
else:
case _:
msg_r('\nInvalid reply\n' if verbose else '\r')
def do_pager(text):
@ -153,12 +153,12 @@ def do_license_msg(cfg, *, immed=False):
from .term import get_char
prompt = "Press 'w' for conditions and warranty info, or 'c' to continue: "
while True:
reply = get_char(prompt, immed_chars=('', 'wc')[bool(immed)])
if reply == 'w':
match get_char(prompt, immed_chars=('', 'wc')[bool(immed)]):
case 'w':
do_pager(gpl.conditions)
elif reply == 'c':
case 'c':
msg('')
break
else:
case _:
msg_r('\r')
msg('')