Added _get_display_name() and _update() to Menu()
* _update() * Calls _get_display_name() * Used to update the state of the menu * Will add set logic to this method later
This commit is contained in:
parent
7a9c569251
commit
8cedac738e
1 changed files with 35 additions and 0 deletions
|
|
@ -76,9 +76,21 @@ class Menu():
|
|||
self.separator = '─'
|
||||
self.title = title
|
||||
|
||||
def _get_display_name(self, name, details, index=None, no_checkboxes=True):
|
||||
# pylint: disable=no-self-use
|
||||
"""Format display name based on details and args, returns str."""
|
||||
checkmark = '✓' if 'DISPLAY' in os.environ else '*'
|
||||
display_name = f'{index if index else name[:1].upper()}: '
|
||||
|
||||
# Add enabled status if necessary
|
||||
if not no_checkboxes:
|
||||
display_name += f'[{checkmark if details["Enabled"] else " "}] '
|
||||
|
||||
# Add name
|
||||
display_name += name
|
||||
|
||||
# Done
|
||||
return display_name
|
||||
|
||||
def _get_separator_string(self):
|
||||
"""Format separator length based on name lengths, returns str."""
|
||||
|
|
@ -122,6 +134,29 @@ class Menu():
|
|||
menu_lines = [str(line) for line in menu_lines]
|
||||
print('\n'.join(menu_lines))
|
||||
|
||||
def _update_menu(self, single_selection=True):
|
||||
"""Update menu items in preparation for printing to screen."""
|
||||
index = 0
|
||||
|
||||
# Numbered sections
|
||||
for section in (self.sets, self.toggles, self.options):
|
||||
for name, details in section.items():
|
||||
index += 1
|
||||
details['Display Name'] = self._get_display_name(
|
||||
name,
|
||||
details,
|
||||
index=index,
|
||||
no_checkboxes=single_selection,
|
||||
)
|
||||
|
||||
# Actions
|
||||
for name, details in self.actions.items():
|
||||
details['Display Name'] = self._get_display_name(
|
||||
name,
|
||||
details,
|
||||
no_checkboxes=True,
|
||||
)
|
||||
|
||||
def add_action(self, name, details=None):
|
||||
"""Add action to menu."""
|
||||
details = details if details else {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue