Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu/table_selection_menu.py
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2023-04-19 20:55:42 +1000
committerGitHub <noreply@github.com>2023-04-19 12:55:42 +0200
commit00b0ae7ba439a5a420095175b3bedd52c569db51 (patch)
treef02d081e361d5e65603f74dea3873dcc6606cf7c /archinstall/lib/menu/table_selection_menu.py
parent5253e57e9f26cf3e59cb2460544af13f56e485bb (diff)
PyParted and a large rewrite of the underlying partitioning (#1604)
* Invert mypy files * Add optional pre-commit hooks * New profile structure * Serialize profiles * Use profile instead of classmethod * Custom profile setup * Separator between back * Support profile import via url * Move profiles module * Refactor files * Remove symlink * Add user to docker group * Update schema description * Handle list services * mypy fixes * mypy fixes * Rename profilesv2 to profiles * flake8 * mypy again * Support selecting DM * Fix mypy * Cleanup * Update greeter setting * Update schema * Revert toml changes * Poc external dependencies * Dependency support * New encryption menu * flake8 * Mypy and flake8 * Unify lsblk command * Update bootloader configuration * Git hooks * Fix import * Pyparted * Remove custom font setting * flake8 * Remove default preview * Manual partitioning menu * Update structure * Disk configuration * Update filesystem * luks2 encryption * Everything works until installation * Btrfsutil * Btrfs handling * Update btrfs * Save encryption config * Fix pipewire issue * Update mypy version * Update all pre-commit * Update package versions * Revert audio/pipewire * Merge master PRs * Add master changes * Merge master changes * Small renaming * Pull master changes * Reset disk enc after disk config change * Generate locals * Update naming * Fix imports * Fix broken sync * Fix pre selection on table menu * Profile menu * Update profile * Fix post_install * Added python-pyparted to PKGBUILD, this requires [testing] to be enabled in order to run makepkg. Package still works via python -m build etc. * Swaped around some setuptools logic in pyproject Since we define `package-data` and `packages` there should be no need for: ``` [tool.setuptools.packages.find] where = ["archinstall", "archinstall.*"] ``` * Removed pyproject collisions. Duplicate definitions. * Made sure pyproject.toml includes languages * Add example and update README * Fix pyproject issues * Generate locale * Refactor imports * Simplify imports * Add profile description and package examples * Align code * Fix mypy * Simplify imports * Fix saving config * Fix wrong luks merge * Refactor installation * Fix cdrom device loading * Fix wrongly merged code * Fix imports and greeter * Don't terminate on partprobe error * Use specific path on partprobe from luks * Update archinstall/lib/disk/device_model.py Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> * Update archinstall/lib/disk/device_model.py Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> * Update github workflow to test archinstall installation * Update sway merge * Generate locales * Update workflow --------- Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com> Co-authored-by: Anton Hvornum <anton@hvornum.se> Co-authored-by: Anton Hvornum <anton.feeds+github@gmail.com> Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com>
Diffstat (limited to 'archinstall/lib/menu/table_selection_menu.py')
-rw-r--r--archinstall/lib/menu/table_selection_menu.py68
1 files changed, 56 insertions, 12 deletions
diff --git a/archinstall/lib/menu/table_selection_menu.py b/archinstall/lib/menu/table_selection_menu.py
index 09cd6ee2..4cff7216 100644
--- a/archinstall/lib/menu/table_selection_menu.py
+++ b/archinstall/lib/menu/table_selection_menu.py
@@ -1,19 +1,24 @@
-from typing import Any, Tuple, List, Dict, Optional
+from typing import Any, Tuple, List, Dict, Optional, Callable
-from .menu import MenuSelectionType, MenuSelection
+from .menu import MenuSelectionType, MenuSelection, Menu
from ..output import FormattedOutput
-from ..menu import Menu
class TableMenu(Menu):
def __init__(
self,
title: str,
- data: List[Any] = [],
+ data: Optional[List[Any]] = None,
table_data: Optional[Tuple[List[Any], str]] = None,
+ preset: List[Any] = [],
custom_menu_options: List[str] = [],
default: Any = None,
- multi: bool = False
+ multi: bool = False,
+ preview_command: Optional[Callable] = None,
+ preview_title: str = 'Info',
+ preview_size: float = 0.0,
+ allow_reset: bool = True,
+ allow_reset_warning_msg: Optional[str] = None,
):
"""
param title: Text that will be displayed above the menu
@@ -29,10 +34,10 @@ class TableMenu(Menu):
param custom_options: List of custom options that will be displayed under the table
:type custom_menu_options: List
- """
- if not data and not table_data:
- raise ValueError('Either "data" or "table_data" must be provided')
+ :param preview_command: A function that should return a string that will be displayed in a preview window when a menu selection item is in focus
+ :type preview_command: Callable
+ """
self._custom_options = custom_menu_options
self._multi = multi
@@ -41,7 +46,7 @@ class TableMenu(Menu):
else:
header_padding = 2
- if len(data):
+ if data is not None:
table_text = FormattedOutput.as_table(data)
rows = table_text.split('\n')
table = self._create_table(data, rows, header_padding=header_padding)
@@ -53,20 +58,53 @@ class TableMenu(Menu):
data = table_data[0]
rows = table_data[1].split('\n')
table = self._create_table(data, rows, header_padding=header_padding)
+ else:
+ raise ValueError('Either "data" or "table_data" must be provided')
self._options, header = self._prepare_selection(table)
+ preset_values = self._preset_values(preset)
+
+ extra_bottom_space = True if preview_command else False
+
super().__init__(
title,
self._options,
+ preset_values=preset_values,
header=header,
skip_empty_entries=True,
show_search_hint=False,
- allow_reset=True,
multi=multi,
- default_option=default
+ default_option=default,
+ preview_command=lambda x: self._table_show_preview(preview_command, x),
+ preview_size=preview_size,
+ preview_title=preview_title,
+ extra_bottom_space=extra_bottom_space,
+ allow_reset=allow_reset,
+ allow_reset_warning_msg=allow_reset_warning_msg
)
+ def _preset_values(self, preset: List[Any]) -> List[str]:
+ # when we create the table of just the preset values it will
+ # be formatted a bit different due to spacing, so to determine
+ # correct rows lets remove all the spaces and compare apples with apples
+ preset_table = FormattedOutput.as_table(preset).strip()
+ data_rows = preset_table.split('\n')[2:] # get all data rows
+ pure_data_rows = [self._escape_row(row.replace(' ', '')) for row in data_rows]
+
+ # the actual preset value has to be in non-escaped form
+ pure_option_rows = {o.replace(' ', ''): self._unescape_row(o) for o in self._options.keys()}
+ preset_rows = [row for pure, row in pure_option_rows.items() if pure in pure_data_rows]
+
+ return preset_rows
+
+ def _table_show_preview(self, preview_command: Optional[Callable], selection: Any) -> Optional[str]:
+ if preview_command:
+ row = self._escape_row(selection)
+ obj = self._options[row]
+ return preview_command(obj)
+ return None
+
def run(self) -> MenuSelection:
choice = super().run()
@@ -79,6 +117,12 @@ class TableMenu(Menu):
return choice
+ def _escape_row(self, row: str) -> str:
+ return row.replace('|', '\\|')
+
+ def _unescape_row(self, row: str) -> str:
+ return row.replace('\\|', '|')
+
def _create_table(self, data: List[Any], rows: List[str], header_padding: int = 2) -> Dict[str, Any]:
# these are the header rows of the table and do not map to any data obviously
# we're adding 2 spaces as prefix because the menu selector '> ' will be put before
@@ -87,7 +131,7 @@ class TableMenu(Menu):
display_data = {f'{padding}{rows[0]}': None, f'{padding}{rows[1]}': None}
for row, entry in zip(rows[2:], data):
- row = row.replace('|', '\\|')
+ row = self._escape_row(row)
display_data[row] = entry
return display_data