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