Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2916 - Reinstate prompt in list menus #2940

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions archinstall/lib/disk/partitioning_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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
)

@override
def selected_action_display(self, selection: PartitionModification) -> str:
Expand Down Expand Up @@ -186,8 +191,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:
Expand Down
14 changes: 12 additions & 2 deletions archinstall/lib/disk/subvolume_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,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
)

@override
def selected_action_display(self, selection: SubvolumeModification) -> str:
Expand Down
8 changes: 7 additions & 1 deletion archinstall/lib/interactions/manage_users_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
)

@override
def selected_action_display(self, selection: User) -> str:
Expand Down
8 changes: 7 additions & 1 deletion archinstall/lib/interactions/network_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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
)

@override
def selected_action_display(self, selection: Nic) -> str:
Expand Down
32 changes: 19 additions & 13 deletions archinstall/lib/menu/list_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,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
Expand All @@ -38,8 +38,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'))
Expand All @@ -66,8 +65,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)

Expand All @@ -76,7 +79,7 @@ def run(self) -> list[Any]:
header=header,
search_enabled=False,
allow_skip=False,
alignment=Alignment.CENTER,
alignment=Alignment.CENTER
).run()

match result.type_:
Expand Down Expand Up @@ -149,16 +152,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

Expand Down
5 changes: 3 additions & 2 deletions archinstall/lib/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,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:],
''
)

@override
Expand Down