From dc4609ebaa9b38048cd9a7777a193aa0bb73b03e Mon Sep 17 00:00:00 2001 From: Daniel Girtler Date: Tue, 26 Nov 2024 20:37:53 +1100 Subject: [PATCH 1/2] Reinstate prompt in list menus --- archinstall/lib/disk/partitioning_menu.py | 11 +++++-- archinstall/lib/disk/subvolume_menu.py | 14 ++++++-- .../lib/interactions/manage_users_conf.py | 8 ++++- archinstall/lib/interactions/network_menu.py | 8 ++++- archinstall/lib/menu/list_manager.py | 33 +++++++++++-------- archinstall/lib/mirrors.py | 5 +-- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/archinstall/lib/disk/partitioning_menu.py b/archinstall/lib/disk/partitioning_menu.py index 9d4913c71c..723e372d6a 100644 --- a/archinstall/lib/disk/partitioning_menu.py +++ b/archinstall/lib/disk/partitioning_menu.py @@ -54,7 +54,12 @@ def __init__(self, prompt: str, device: BDevice, device_partitions: list[Partiti } display_actions = list(self._actions.values()) - super().__init__(prompt, device_partitions, display_actions[:2], display_actions[3:]) + super().__init__( + device_partitions, + display_actions[:2], + display_actions[3:], + prompt + ) def selected_action_display(self, selection: PartitionModification) -> str: if selection.status == ModificationStatus.Create: @@ -179,8 +184,8 @@ def _toggle_mount_option( def _set_btrfs_subvolumes(self, partition: PartitionModification) -> None: partition.btrfs_subvols = SubvolumeMenu( - str(_("Manage btrfs subvolumes for current partition")), - partition.btrfs_subvols + partition.btrfs_subvols, + None ).run() def _prompt_formatting(self, partition: PartitionModification) -> None: diff --git a/archinstall/lib/disk/subvolume_menu.py b/archinstall/lib/disk/subvolume_menu.py index f5b3034f89..81ef29d665 100644 --- a/archinstall/lib/disk/subvolume_menu.py +++ b/archinstall/lib/disk/subvolume_menu.py @@ -12,13 +12,23 @@ class SubvolumeMenu(ListManager): - def __init__(self, prompt: str, btrfs_subvols: list[SubvolumeModification]): + def __init__( + self, + btrfs_subvols: list[SubvolumeModification], + prompt: str | None = None + ): self._actions = [ str(_('Add subvolume')), str(_('Edit subvolume')), str(_('Delete subvolume')) ] - super().__init__(prompt, btrfs_subvols, [self._actions[0]], self._actions[1:]) + + super().__init__( + btrfs_subvols, + [self._actions[0]], + self._actions[1:], + prompt + ) def selected_action_display(self, selection: SubvolumeModification) -> str: return str(selection.name) diff --git a/archinstall/lib/interactions/manage_users_conf.py b/archinstall/lib/interactions/manage_users_conf.py index c93e8c58e3..0540ac5216 100644 --- a/archinstall/lib/interactions/manage_users_conf.py +++ b/archinstall/lib/interactions/manage_users_conf.py @@ -22,7 +22,13 @@ def __init__(self, prompt: str, lusers: list[User]): str(_('Promote/Demote user')), str(_('Delete User')) ] - super().__init__(prompt, lusers, [self._actions[0]], self._actions[1:]) + + super().__init__( + lusers, + [self._actions[0]], + self._actions[1:], + prompt + ) def selected_action_display(self, selection: User) -> str: return selection.username diff --git a/archinstall/lib/interactions/network_menu.py b/archinstall/lib/interactions/network_menu.py index 0c8528e776..d31bb6df58 100644 --- a/archinstall/lib/interactions/network_menu.py +++ b/archinstall/lib/interactions/network_menu.py @@ -20,7 +20,13 @@ def __init__(self, prompt: str, preset: list[Nic]): str(_('Edit interface')), str(_('Delete interface')) ] - super().__init__(prompt, preset, [self._actions[0]], self._actions[1:]) + + super().__init__( + preset, + [self._actions[0]], + self._actions[1:], + prompt + ) def selected_action_display(self, selection: Nic) -> str: return selection.iface if selection.iface else '' diff --git a/archinstall/lib/menu/list_manager.py b/archinstall/lib/menu/list_manager.py index 2addb5e68a..d1a05d1784 100644 --- a/archinstall/lib/menu/list_manager.py +++ b/archinstall/lib/menu/list_manager.py @@ -2,7 +2,6 @@ from typing import TYPE_CHECKING, Any from archinstall.tui import Alignment, MenuItem, MenuItemGroup, ResultType, SelectMenu - from ..output import FormattedOutput if TYPE_CHECKING: @@ -12,10 +11,10 @@ class ListManager: def __init__( self, - prompt: str, entries: list[Any], base_actions: list[str], - sub_menu_actions: list[str] + sub_menu_actions: list[str], + prompt: str | None = None ): """ :param prompt: Text which will appear at the header @@ -34,8 +33,7 @@ def __init__( self._original_data = copy.deepcopy(entries) 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 if prompt else explainer + self._prompt: str | None = prompt self._separator = '' self._confirm_action = str(_('Confirm and exit')) @@ -62,8 +60,12 @@ def run(self) -> list[Any]: # and the value is the original value from the self._data container data_formatted = self.reformat(self._data) options = self._prepare_selection(data_formatted) + header = self._get_header(data_formatted) + if self._prompt is not None: + header = f'{self._prompt}\n\n{header}' + items = [MenuItem(o[0], value=o[1]) for o in options] group = MenuItemGroup(items, sort_items=False) @@ -72,7 +74,7 @@ def run(self) -> list[Any]: header=header, search_enabled=False, allow_skip=False, - alignment=Alignment.CENTER, + alignment=Alignment.CENTER ).run() match result.type_: @@ -145,16 +147,19 @@ def reformat(self, data: list[Any]) -> dict[str, Any | None]: Default implementation of the table to be displayed. Override if any custom formatting is needed """ - table = FormattedOutput.as_table(data) - rows = table.split('\n') + display_data: dict[str, Any | None] = {} + + if data: + 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, Any | None] = {f'{rows[0]}': None, f'{rows[1]}': None} + # 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 = {f'{rows[0]}': None, f'{rows[1]}': None} - for row, entry in zip(rows[2:], data): - display_data[row] = entry + for row, entry in zip(rows[2:], data): + display_data[row] = entry return display_data diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py index 42f65cbd5f..42550796ab 100644 --- a/archinstall/lib/mirrors.py +++ b/archinstall/lib/mirrors.py @@ -125,11 +125,12 @@ def __init__(self, custom_mirrors: list[CustomMirror]): str(_('Change custom mirror')), str(_('Delete custom mirror')) ] + super().__init__( - '', custom_mirrors, [self._actions[0]], - self._actions[1:] + self._actions[1:], + '' ) def selected_action_display(self, selection: CustomMirror) -> str: From ad34e6071f1c0436355da15c52a1668d36335f36 Mon Sep 17 00:00:00 2001 From: Daniel Girtler Date: Tue, 26 Nov 2024 20:44:43 +1100 Subject: [PATCH 2/2] Ruff --- archinstall/lib/menu/list_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall/lib/menu/list_manager.py b/archinstall/lib/menu/list_manager.py index 9dfa79a05c..8bd1dea2f9 100644 --- a/archinstall/lib/menu/list_manager.py +++ b/archinstall/lib/menu/list_manager.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Any from archinstall.tui import Alignment, MenuItem, MenuItemGroup, ResultType, SelectMenu + from ..output import FormattedOutput if TYPE_CHECKING: