index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-10-18 10:46:28 +0200 |
---|---|---|
committer | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-10-18 10:46:28 +0200 |
commit | a60a3ca812619ace82993272233b9783cf4bc4fe (patch) | |
tree | 093609cb307be5deffdbaa46bf2d30c63d41f981 /archinstall | |
parent | 60aaae4337c90bea3d485f58f7ab206cb1539a74 (diff) |
-rw-r--r-- | archinstall/lib/user_interaction.py | 28 |
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 23141fa9..e5ca01d3 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -5,6 +5,34 @@ from .locale_helpers import search_keyboard_layout ## TODO: Some inconsistencies between the selection processes. ## Some return the keys from the options, some the values? +def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True): + """ + A generic select function that does not output anything + other than the options and their indexs. As an example: + + generic_select(["first", "second", "third option"]) + 1: first + 2: second + 3: third option + """ + + if type(options) == dict: options = list(options) + if sort: options = sorted(list(options)) + if len(options) <= 0: raise RequirementError('generic_select() requires at least one option to operate.') + + for index, option in enumerate(options): + print(f"{index}: {option}") + + selected_option = input(input_text) + if selected_option.isdigit(): + selected_option = dict_o_disks[int(selected_option)-1] + elif selected_option in dict_o_disks: + pass # We gave a correct absolute value + else: + raise RequirementError(f'Selected option "{selected_option}" does not exist in available options: {options}') + + return selected_option + def select_disk(dict_o_disks): """ Asks the user to select a harddrive from the `dict_o_disks` selection. |