Browse Source

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.
master
Sebastian Lohff 3 years ago
parent
commit
d926606976
  1. 3
      clintermission/__init__.py
  2. 9
      clintermission/climenu.py

3
clintermission/__init__.py

@ -1,11 +1,12 @@ @@ -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,
]

9
clintermission/climenu.py

@ -293,3 +293,12 @@ class CliMenu: @@ -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…
Cancel
Save