index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Daniel Girtler <blackrabbit256@gmail.com> | 2022-09-12 05:23:21 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-11 21:23:21 +0200 |
commit | 94df913e0f2e68178ad64d385bbc453416b7e4b0 (patch) | |
tree | 7daa03555a3a0ff9834f91166481c41a2a6e0346 /archinstall/lib/menu | |
parent | c373607f8c9548bf9de55988629b747f32d67b3d (diff) |
-rw-r--r-- | archinstall/lib/menu/menu.py | 18 |
diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py index 16153e2c..112bc0ae 100644 --- a/archinstall/lib/menu/menu.py +++ b/archinstall/lib/menu/menu.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from enum import Enum, auto from os import system -from typing import Dict, List, Union, Any, TYPE_CHECKING, Optional +from typing import Dict, List, Union, Any, TYPE_CHECKING, Optional, Callable from archinstall.lib.menu.simple_menu import TerminalMenu @@ -52,9 +52,9 @@ class Menu(TerminalMenu): sort :bool = True, preset_values :Union[str, List[str]] = None, cursor_index : Optional[int] = None, - preview_command=None, - preview_size=0.75, - preview_title='Info', + preview_command: Optional[Callable] = None, + preview_size: float = 0.75, + preview_title: str = 'Info', header :Union[List[str],str] = None, raise_error_on_interrupt :bool = False, raise_error_warning_msg :str = '', @@ -152,6 +152,7 @@ class Menu(TerminalMenu): self._multi = multi self._raise_error_on_interrupt = raise_error_on_interrupt self._raise_error_warning_msg = raise_error_warning_msg + self._preview_command = preview_command menu_title = f'\n{title}\n\n' @@ -198,7 +199,7 @@ class Menu(TerminalMenu): # show_search_hint=True, preselected_entries=self.preset_values, cursor_index=self.cursor_index, - preview_command=preview_command, + preview_command=lambda x: self._preview_wrapper(preview_command, x), preview_size=preview_size, preview_title=preview_title, raise_error_on_interrupt=self._raise_error_on_interrupt, @@ -235,6 +236,13 @@ class Menu(TerminalMenu): else: return MenuSelection(type_=MenuSelectionType.Esc) + def _preview_wrapper(self, preview_command: Optional[Callable], current_selection: str) -> Optional[str]: + if preview_command: + if self._default_option is not None and f'{self._default_option} {self._default_str}' == current_selection: + current_selection = self._default_option + return preview_command(current_selection) + return None + def run(self) -> MenuSelection: ret = self._show() |