def select_mod(
choices: Sequence[Mod],
header: Optional[str] = None,
footer: Optional[str] = None,
) -> Optional[Mod]:
"""Present user with a TUI menu and return his choice.
Keyword arguments:
choices: The :class:`Mod`s to choose from.
header: Optional menu heading.
footer: Optional menu footing.
Returns:
The selected mod.
"""
menu = ModMenu(choices)
head = urwid.Text(('title', header), align='center') if header else None
foot = urwid.Text(('description', footer), align='center') if footer else None # noqa: E501
if head or foot:
top = urwid.Frame(menu, head, foot)
else:
top = menu
try:
colors = curses.tigetnum('colors')
except curses.error: # Uninitialized terminal
colors = 16
event_loop = urwid.MainLoop(
top,
palette=ModMenu.palette,
unhandled_input=exit_loop_on_q_esc,
)
event_loop.screen.set_terminal_properties(colors=colors)
event_loop.run()
return menu.chosen
评论列表
文章目录