def exit_loop_on_q_esc(key: str): """End urwid.MainLoop on keypress of 'q' or 'esc'.""" if key in {'q', 'Q', 'esc'}: raise urwid.ExitMainLoop()