Compare commits

..

2 Commits

Author SHA1 Message Date
Sebastian Lohff 648d5c956e Use option text as title if no value is given
If the user only supplys a text for the option we used to return None as
item value. Now we return the text, so the user can easily get the value
back if they want to process it further and not only work with the given
option index (or supply the item twice).
2020-03-11 18:19:19 +01:00
Sebastian Lohff 8c6ee790bf Fix get_options() and num_options to work on options
get_options() and num_options used to work on all menu items, including
blank spaces and headers. Now these work only on options, as they were
originally intended
2020-03-11 18:18:26 +01:00
1 changed files with 4 additions and 4 deletions

View File

@ -99,10 +99,10 @@ class CliMenu:
if options: if options:
for option in options: for option in options:
if isinstance(option, tuple): if isinstance(option, tuple) and len(option) == 2:
self.add_option(*option) self.add_option(*option)
else: else:
self.add_option(option) self.add_option(option, option)
def add_header(self, title, indent=True): def add_header(self, title, indent=True):
for text in title.split('\n'): for text in title.split('\n'):
@ -120,11 +120,11 @@ class CliMenu:
return self._success return self._success
def get_options(self): def get_options(self):
return self._items return [_item for _item in self._items if isinstance(_item, CliMenuOption)]
@property @property
def num_options(self): def num_options(self):
return len(self._items) return self._item_num
def get_selection(self): def get_selection(self):
if self.success: if self.success: