Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu/list_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/menu/list_manager.py')
-rw-r--r--archinstall/lib/menu/list_manager.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/archinstall/lib/menu/list_manager.py b/archinstall/lib/menu/list_manager.py
index 1e09d987..de18791c 100644
--- a/archinstall/lib/menu/list_manager.py
+++ b/archinstall/lib/menu/list_manager.py
@@ -3,6 +3,7 @@ from os import system
from typing import Any, TYPE_CHECKING, Dict, Optional, Tuple, List
from .menu import Menu
+from ..output import FormattedOutput
if TYPE_CHECKING:
_: Any
@@ -34,7 +35,7 @@ class ListManager:
self._data = copy.deepcopy(entries)
explainer = str(_('\n Choose an object from the list, and select one of the available actions for it to execute'))
- self._prompt = prompt + explainer if prompt else explainer
+ self._prompt = prompt if prompt else explainer
self._separator = ''
self._confirm_action = str(_('Confirm and exit'))
@@ -44,13 +45,18 @@ class ListManager:
self._base_actions = base_actions
self._sub_menu_actions = sub_menu_actions
- self._last_choice = None
+ self._last_choice: Optional[str] = None
@property
- def last_choice(self):
+ def last_choice(self) -> Optional[str]:
return self._last_choice
- def run(self):
+ def is_last_choice_cancel(self) -> bool:
+ if self._last_choice is not None:
+ return self._last_choice == self._cancel_action
+ return False
+
+ def run(self) -> List[Any]:
while True:
# this will return a dictionary with the key as the menu entry to be displayed
# and the value is the original value from the self._data container
@@ -75,11 +81,12 @@ class ListManager:
self._data = self.handle_action(choice.value, None, self._data)
elif choice.value in self._terminate_actions:
break
- else: # an entry of the existing selection was choosen
- selected_entry = data_formatted[choice.value]
+ else: # an entry of the existing selection was chosen
+ selected_entry = data_formatted[choice.value] # type: ignore
self._run_actions_on_entry(selected_entry)
- self._last_choice = choice
+ self._last_choice = choice.value # type: ignore
+
if choice.value == self._cancel_action:
return self._original_data # return the original list
else:
@@ -121,22 +128,41 @@ class ListManager:
if choice.value and choice.value != self._cancel_action:
self._data = self.handle_action(choice.value, entry, self._data)
- def selected_action_display(self, selection: Any) -> str:
- # this will return the value to be displayed in the
- # "Select an action for '{}'" string
- raise NotImplementedError('Please implement me in the child class')
+ def reformat(self, data: List[Any]) -> Dict[str, Optional[Any]]:
+ """
+ Default implementation of the table to be displayed.
+ Override if any custom formatting is needed
+ """
+ table = FormattedOutput.as_table(data)
+ rows = table.split('\n')
+
+ # these are the header rows of the table and do not map to any User obviously
+ # we're adding 2 spaces as prefix because the menu selector '> ' will be put before
+ # the selectable rows so the header has to be aligned
+ display_data: Dict[str, Optional[Any]] = {f' {rows[0]}': None, f' {rows[1]}': None}
+
+ for row, entry in zip(rows[2:], data):
+ row = row.replace('|', '\\|')
+ display_data[row] = entry
- def reformat(self, data: List[Any]) -> Dict[str, Any]:
- # this should return a dictionary of display string to actual data entry
- # mapping; if the value for a given display string is None it will be used
- # in the header value (useful when displaying tables)
+ return display_data
+
+ def selected_action_display(self, selection: Any) -> str:
+ """
+ this will return the value to be displayed in the
+ "Select an action for '{}'" string
+ """
raise NotImplementedError('Please implement me in the child class')
def handle_action(self, action: Any, entry: Optional[Any], data: List[Any]) -> List[Any]:
- # this function is called when a base action or
- # a specific action for an entry is triggered
+ """
+ this function is called when a base action or
+ a specific action for an entry is triggered
+ """
raise NotImplementedError('Please implement me in the child class')
- def filter_options(self, selection :Any, options :List[str]) -> List[str]:
- # filter which actions to show for an specific selection
+ def filter_options(self, selection: Any, options: List[str]) -> List[str]:
+ """
+ filter which actions to show for an specific selection
+ """
return options