tui.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:mccurse 作者: khardix 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号