Add shortcut function to quickly get a selection result
cli_select_item() will instanciate a CliMenu and return a selection. If the selection is aborted an exception of the given class will be thrown.
This commit is contained in:
parent
3d1d2d5acd
commit
d926606976
|
@ -1,11 +1,12 @@
|
|||
# Written by Sebastian Lohff <seba@someserver.de>
|
||||
# Licensed under Apache License 2.0
|
||||
|
||||
from clintermission.climenu import CliMenu, CliMenuStyle, CliMenuCursor, CliMenuTheme
|
||||
from clintermission.climenu import CliMenu, CliMenuStyle, CliMenuCursor, CliMenuTheme, cli_select_item
|
||||
|
||||
__all__ = [
|
||||
CliMenu,
|
||||
CliMenuStyle,
|
||||
CliMenuCursor,
|
||||
CliMenuTheme,
|
||||
cli_select_item,
|
||||
]
|
||||
|
|
|
@ -293,3 +293,12 @@ class CliMenu:
|
|||
|
||||
app.run()
|
||||
self._ran = True
|
||||
|
||||
|
||||
def cli_select_item(options, header=None, abort_exc=ValueError, abort_text="Selection aborted.", style=None):
|
||||
"""Helper function to quickly get a selection with just a few arguments"""
|
||||
menu = CliMenu(header=header, options=options, style=style)
|
||||
if not menu.success:
|
||||
raise abort_exc(abort_text)
|
||||
|
||||
return menu.get_selection()
|
||||
|
|
Loading…
Reference in New Issue