Fix menu alignment (#1102)
Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
parent
bcd810d2d2
commit
184373ee84
|
|
@ -90,6 +90,10 @@ class Selector:
|
||||||
self.mandatory = mandatory
|
self.mandatory = mandatory
|
||||||
self._no_store = no_store
|
self._no_store = no_store
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self) -> str:
|
||||||
|
return self._description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dependencies(self) -> List:
|
def dependencies(self) -> List:
|
||||||
return self._dependencies
|
return self._dependencies
|
||||||
|
|
@ -115,7 +119,7 @@ class Selector:
|
||||||
def update_description(self, description :str):
|
def update_description(self, description :str):
|
||||||
self._description = description
|
self._description = description
|
||||||
|
|
||||||
def menu_text(self) -> str:
|
def menu_text(self, padding: int = 0) -> str:
|
||||||
if self._description == '': # special menu option for __separator__
|
if self._description == '': # special menu option for __separator__
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
@ -128,14 +132,14 @@ class Selector:
|
||||||
current = str(self._current_selection)
|
current = str(self._current_selection)
|
||||||
|
|
||||||
if current:
|
if current:
|
||||||
padding = 35 - len(str(self._description))
|
padding += 5
|
||||||
current = ' ' * padding + f'SET: {current}'
|
description = str(self._description).ljust(padding, ' ')
|
||||||
|
current = str(_('set: {}').format(current))
|
||||||
|
else:
|
||||||
|
description = self._description
|
||||||
|
current = ''
|
||||||
|
|
||||||
return f'{self._description} {current}'
|
return f'{description} {current}'
|
||||||
|
|
||||||
@property
|
|
||||||
def text(self):
|
|
||||||
return self.menu_text()
|
|
||||||
|
|
||||||
def set_current_selection(self, current :Optional[str]):
|
def set_current_selection(self, current :Optional[str]):
|
||||||
self._current_selection = current
|
self._current_selection = current
|
||||||
|
|
@ -262,8 +266,13 @@ class GeneralMenu:
|
||||||
return preview()
|
return preview()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _get_menu_text_padding(self, entries: List[Selector]):
|
||||||
|
return max([len(selection.description) for selection in entries])
|
||||||
|
|
||||||
def _find_selection(self, selection_name: str) -> Tuple[str, Selector]:
|
def _find_selection(self, selection_name: str) -> Tuple[str, Selector]:
|
||||||
option = [(k, v) for k, v in self._menu_options.items() if v.text.strip() == selection_name.strip()]
|
padding = self._get_menu_text_padding(list(self._menu_options.values()))
|
||||||
|
option = [(k, v) for k, v in self._menu_options.items() if v.menu_text(padding).strip() == selection_name.strip()]
|
||||||
|
|
||||||
if len(option) != 1:
|
if len(option) != 1:
|
||||||
raise ValueError(f'Selection not found: {selection_name}')
|
raise ValueError(f'Selection not found: {selection_name}')
|
||||||
config_name = option[0][0]
|
config_name = option[0][0]
|
||||||
|
|
@ -275,14 +284,18 @@ class GeneralMenu:
|
||||||
# we synch all the options just in case
|
# we synch all the options just in case
|
||||||
for item in self.list_options():
|
for item in self.list_options():
|
||||||
self.synch(item)
|
self.synch(item)
|
||||||
self.post_callback # as all the values can vary i have to exec this callback
|
|
||||||
|
self.post_callback() # as all the values can vary i have to exec this callback
|
||||||
cursor_pos = None
|
cursor_pos = None
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Before continuing, set the preferred keyboard layout/language in the current terminal.
|
# Before continuing, set the preferred keyboard layout/language in the current terminal.
|
||||||
# This will just help the user with the next following questions.
|
# This will just help the user with the next following questions.
|
||||||
self._set_kb_language()
|
self._set_kb_language()
|
||||||
enabled_menus = self._menus_to_enable()
|
enabled_menus = self._menus_to_enable()
|
||||||
menu_options = [m.text for m in enabled_menus.values()]
|
|
||||||
|
padding = self._get_menu_text_padding(list(enabled_menus.values()))
|
||||||
|
menu_options = [m.menu_text(padding) for m in enabled_menus.values()]
|
||||||
|
|
||||||
selection = Menu(
|
selection = Menu(
|
||||||
_('Set/Modify the below options'),
|
_('Set/Modify the below options'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue