Fix 2916 - Reinstate prompt in list menus (#2940)
* Reinstate prompt in list menus * Ruff
This commit is contained in:
parent
e51f7adf21
commit
198efb5f53
|
|
@ -58,7 +58,12 @@ class PartitioningList(ListManager):
|
||||||
}
|
}
|
||||||
|
|
||||||
display_actions = list(self._actions.values())
|
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
|
@override
|
||||||
def selected_action_display(self, selection: PartitionModification) -> str:
|
def selected_action_display(self, selection: PartitionModification) -> str:
|
||||||
|
|
@ -186,8 +191,8 @@ class PartitioningList(ListManager):
|
||||||
|
|
||||||
def _set_btrfs_subvolumes(self, partition: PartitionModification) -> None:
|
def _set_btrfs_subvolumes(self, partition: PartitionModification) -> None:
|
||||||
partition.btrfs_subvols = SubvolumeMenu(
|
partition.btrfs_subvols = SubvolumeMenu(
|
||||||
str(_("Manage btrfs subvolumes for current partition")),
|
partition.btrfs_subvols,
|
||||||
partition.btrfs_subvols
|
None
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
def _prompt_formatting(self, partition: PartitionModification) -> None:
|
def _prompt_formatting(self, partition: PartitionModification) -> None:
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,23 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
class SubvolumeMenu(ListManager):
|
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 = [
|
self._actions = [
|
||||||
str(_('Add subvolume')),
|
str(_('Add subvolume')),
|
||||||
str(_('Edit subvolume')),
|
str(_('Edit subvolume')),
|
||||||
str(_('Delete 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
|
@override
|
||||||
def selected_action_display(self, selection: SubvolumeModification) -> str:
|
def selected_action_display(self, selection: SubvolumeModification) -> str:
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,13 @@ class UserList(ListManager):
|
||||||
str(_('Promote/Demote user')),
|
str(_('Promote/Demote user')),
|
||||||
str(_('Delete 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
|
@override
|
||||||
def selected_action_display(self, selection: User) -> str:
|
def selected_action_display(self, selection: User) -> str:
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,13 @@ class ManualNetworkConfig(ListManager):
|
||||||
str(_('Edit interface')),
|
str(_('Edit interface')),
|
||||||
str(_('Delete 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
|
@override
|
||||||
def selected_action_display(self, selection: Nic) -> str:
|
def selected_action_display(self, selection: Nic) -> str:
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ if TYPE_CHECKING:
|
||||||
class ListManager:
|
class ListManager:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
prompt: str,
|
|
||||||
entries: list[Any],
|
entries: list[Any],
|
||||||
base_actions: list[str],
|
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
|
:param prompt: Text which will appear at the header
|
||||||
|
|
@ -38,8 +38,7 @@ class ListManager:
|
||||||
self._original_data = copy.deepcopy(entries)
|
self._original_data = copy.deepcopy(entries)
|
||||||
self._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: str | None = prompt
|
||||||
self._prompt = prompt if prompt else explainer
|
|
||||||
|
|
||||||
self._separator = ''
|
self._separator = ''
|
||||||
self._confirm_action = str(_('Confirm and exit'))
|
self._confirm_action = str(_('Confirm and exit'))
|
||||||
|
|
@ -66,8 +65,12 @@ class ListManager:
|
||||||
# and the value is the original value from the self._data container
|
# and the value is the original value from the self._data container
|
||||||
data_formatted = self.reformat(self._data)
|
data_formatted = self.reformat(self._data)
|
||||||
options = self._prepare_selection(data_formatted)
|
options = self._prepare_selection(data_formatted)
|
||||||
|
|
||||||
header = self._get_header(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]
|
items = [MenuItem(o[0], value=o[1]) for o in options]
|
||||||
group = MenuItemGroup(items, sort_items=False)
|
group = MenuItemGroup(items, sort_items=False)
|
||||||
|
|
||||||
|
|
@ -76,7 +79,7 @@ class ListManager:
|
||||||
header=header,
|
header=header,
|
||||||
search_enabled=False,
|
search_enabled=False,
|
||||||
allow_skip=False,
|
allow_skip=False,
|
||||||
alignment=Alignment.CENTER,
|
alignment=Alignment.CENTER
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
match result.type_:
|
match result.type_:
|
||||||
|
|
@ -149,16 +152,19 @@ class ListManager:
|
||||||
Default implementation of the table to be displayed.
|
Default implementation of the table to be displayed.
|
||||||
Override if any custom formatting is needed
|
Override if any custom formatting is needed
|
||||||
"""
|
"""
|
||||||
table = FormattedOutput.as_table(data)
|
display_data: dict[str, Any | None] = {}
|
||||||
rows = table.split('\n')
|
|
||||||
|
|
||||||
# these are the header rows of the table and do not map to any User obviously
|
if data:
|
||||||
# we're adding 2 spaces as prefix because the menu selector '> ' will be put before
|
table = FormattedOutput.as_table(data)
|
||||||
# the selectable rows so the header has to be aligned
|
rows = table.split('\n')
|
||||||
display_data: dict[str, Any | None] = {f'{rows[0]}': None, f'{rows[1]}': None}
|
|
||||||
|
|
||||||
for row, entry in zip(rows[2:], data):
|
# these are the header rows of the table and do not map to any User obviously
|
||||||
display_data[row] = entry
|
# 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
|
||||||
|
|
||||||
return display_data
|
return display_data
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,12 @@ class CustomMirrorList(ListManager):
|
||||||
str(_('Change custom mirror')),
|
str(_('Change custom mirror')),
|
||||||
str(_('Delete custom mirror'))
|
str(_('Delete custom mirror'))
|
||||||
]
|
]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
'',
|
|
||||||
custom_mirrors,
|
custom_mirrors,
|
||||||
[self._actions[0]],
|
[self._actions[0]],
|
||||||
self._actions[1:]
|
self._actions[1:],
|
||||||
|
''
|
||||||
)
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue