Always use text as item if no item was specified
When an option is passed without an item attached we now always use the label as item. This was the behaviour for __init__() and is now also the behaviour of add_option().
This commit is contained in:
parent
85c3c5c947
commit
22307bc4ae
|
@ -70,6 +70,10 @@ class CliMenuTheme:
|
||||||
BOLD_HIGHLIGHT = CliMenuStyle(header_style='bold', highlight_style='bold fg:black bg:white')
|
BOLD_HIGHLIGHT = CliMenuStyle(header_style='bold', highlight_style='bold fg:black bg:white')
|
||||||
|
|
||||||
|
|
||||||
|
class _EmptyParameter:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CliMenu:
|
class CliMenu:
|
||||||
default_style = CliMenuTheme.BASIC
|
default_style = CliMenuTheme.BASIC
|
||||||
default_cursor = CliMenuCursor.TRIANGLE
|
default_cursor = CliMenuCursor.TRIANGLE
|
||||||
|
@ -110,7 +114,7 @@ class CliMenu:
|
||||||
elif isinstance(option, dict):
|
elif isinstance(option, dict):
|
||||||
self.add_option(**option)
|
self.add_option(**option)
|
||||||
elif isinstance(option, str):
|
elif isinstance(option, str):
|
||||||
self.add_option(option, option)
|
self.add_option(option)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Option needs to be either tuple, dict or string, found '{}' of type {}"
|
raise ValueError("Option needs to be either tuple, dict or string, found '{}' of type {}"
|
||||||
.format(option, type(option)))
|
.format(option, type(option)))
|
||||||
|
@ -122,7 +126,9 @@ class CliMenu:
|
||||||
for text in title.split('\n'):
|
for text in title.split('\n'):
|
||||||
self._items.append(_CliMenuHeader(text, indent=indent))
|
self._items.append(_CliMenuHeader(text, indent=indent))
|
||||||
|
|
||||||
def add_option(self, text, item=None):
|
def add_option(self, text, item=_EmptyParameter):
|
||||||
|
if item == _EmptyParameter:
|
||||||
|
item = text
|
||||||
self._items.append(_CliMenuOption(text, self._item_num, item=item))
|
self._items.append(_CliMenuOption(text, self._item_num, item=item))
|
||||||
self._item_num += 1
|
self._item_num += 1
|
||||||
|
|
||||||
|
@ -334,7 +340,7 @@ class CliMultiMenu(CliMenu):
|
||||||
self._selection_icons = selection_icons if selection_icons is not None else self.default_selection_icons
|
self._selection_icons = selection_icons if selection_icons is not None else self.default_selection_icons
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def add_option(self, text, item=None, selected=False):
|
def add_option(self, text, item=_EmptyParameter, selected=False):
|
||||||
super().add_option(text, item)
|
super().add_option(text, item)
|
||||||
if selected:
|
if selected:
|
||||||
self._multi_selected.append(len(self._items) - 1)
|
self._multi_selected.append(len(self._items) - 1)
|
||||||
|
|
Loading…
Reference in New Issue