Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/user_interaction.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/user_interaction.py')
-rw-r--r--archinstall/lib/user_interaction.py109
1 files changed, 82 insertions, 27 deletions
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index f01f7597..ddd388dc 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -9,6 +9,7 @@ import signal
import sys
import time
from collections.abc import Iterable
+from copy import copy
from typing import List, Any, Optional, Dict, Union, TYPE_CHECKING
# https://stackoverflow.com/a/39757388/929999
@@ -274,21 +275,29 @@ class MiniCurses:
return response
-def ask_for_swap():
+def ask_for_swap(preset :bool = True) -> bool:
+ if preset:
+ preset_val = 'yes'
+ else:
+ preset_val = 'no'
prompt = _('Would you like to use swap on zram?')
- choice = Menu(prompt, ['yes', 'no'], default_option='yes').run()
+ choice = Menu(prompt, ['yes', 'no'], default_option='yes', preset_values=preset_val).run()
return False if choice == 'no' else True
-def ask_ntp() -> bool:
+def ask_ntp(preset :bool = True) -> bool:
prompt = str(_('Would you like to use automatic time synchronization (NTP) with the default time servers?\n'))
prompt += str(_('Hardware time and other post-configuration steps might be required in order for NTP to work.\nFor more information, please check the Arch wiki'))
- choice = Menu(prompt, ['yes', 'no'], skip=False, default_option='yes').run()
+ if preset:
+ preset_val = 'yes'
+ else:
+ preset_val = 'no'
+ choice = Menu(prompt, ['yes', 'no'], skip=False, preset_values=preset_val, default_option='yes').run()
return False if choice == 'no' else True
-def ask_hostname():
- hostname = input(_('Desired hostname for the installation: ')).strip(' ')
+def ask_hostname(preset :str = None) -> str :
+ hostname = TextInput(_('Desired hostname for the installation: '),preset).run().strip(' ')
return hostname
@@ -341,7 +350,7 @@ def ask_for_additional_users(prompt :str = '') -> tuple[dict[str, dict[str, str
return users, superusers
-def ask_for_a_timezone() -> str:
+def ask_for_a_timezone(preset :str = None) -> str:
timezones = list_timezones()
default = 'UTC'
@@ -349,18 +358,28 @@ def ask_for_a_timezone() -> str:
_('Select a timezone'),
list(timezones),
skip=False,
+ preset_values=preset,
default_option=default
).run()
return selected_tz
-def ask_for_bootloader(advanced_options :bool = False) -> str:
+def ask_for_bootloader(advanced_options :bool = False, preset :str = None) -> str:
+
+ if preset == 'systemd-bootctl':
+ preset_val = 'systemd-boot' if advanced_options else 'no'
+ elif preset == 'grub-install':
+ preset_val = 'grub' if advanced_options else 'yes'
+ else:
+ preset_val = preset
+
bootloader = "systemd-bootctl" if has_uefi() else "grub-install"
if has_uefi():
if not advanced_options:
bootloader_choice = Menu(
_('Would you like to use GRUB as a bootloader instead of systemd-boot?'),
['yes', 'no'],
+ preset_values=preset_val,
default_option='no'
).run()
@@ -369,7 +388,7 @@ def ask_for_bootloader(advanced_options :bool = False) -> str:
else:
# We use the common names for the bootloader as the selection, and map it back to the expected values.
choices = ['systemd-boot', 'grub', 'efistub']
- selection = Menu(_('Choose a bootloader'), choices).run()
+ selection = Menu(_('Choose a bootloader'), choices,preset_values=preset_val).run()
if selection != "":
if selection == 'systemd-boot':
bootloader = 'systemd-bootctl'
@@ -381,12 +400,13 @@ def ask_for_bootloader(advanced_options :bool = False) -> str:
return bootloader
-def ask_for_audio_selection(desktop :bool = True) -> str:
+def ask_for_audio_selection(desktop :bool = True, preset :str = None) -> str:
audio = 'pipewire' if desktop else 'none'
choices = ['pipewire', 'pulseaudio'] if desktop else ['pipewire', 'pulseaudio', 'none']
selected_audio = Menu(
_('Choose an audio server'),
choices,
+ preset_values=preset,
default_option=audio,
skip=False
).run()
@@ -424,7 +444,7 @@ def ask_additional_packages_to_install(pre_set_packages :List[str] = []) -> List
return packages
-def ask_to_configure_network() -> Dict[str, Any]:
+def ask_to_configure_network(preset :Dict[str, Any] = {}) -> Dict[str, Any]:
# Optionally configure one network interface.
# while 1:
# {MAC: Ifname}
@@ -433,12 +453,27 @@ def ask_to_configure_network() -> Dict[str, Any]:
'network_manager': str(_('Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)')),
**list_interfaces()
}
+ # for this routine it's easier to set the cursor position rather than a preset value
+ cursor_idx = None
+ if preset:
+ if preset['type'] == 'iso_config':
+ cursor_idx = 0
+ elif preset['type'] == 'network_manager':
+ cursor_idx = 1
+ else:
+ try :
+ # let's hope order in dictionaries stay
+ cursor_idx = list(interfaces.values()).index(preset.get('type'))
+ except ValueError:
+ pass
- nic = Menu(_('Select one network interface to configure'), list(interfaces.values())).run()
+ nic = Menu(_('Select one network interface to configure'), interfaces.values(),cursor_index=cursor_idx).run()
if not nic:
return {}
+ # nic = network_manager_nt
+
if nic == interfaces['iso_config']:
return {'type': 'iso_config'}
elif nic == interfaces['network_manager']:
@@ -448,16 +483,23 @@ def ask_to_configure_network() -> Dict[str, Any]:
# For selecting modes without entering text within brackets,
# printing out this part separate from options, passed in
# `generic_select`
+ # we only keep data if it is the same nic as before
+ if preset.get('type') != nic:
+ preset_d = {'type': nic, 'dhcp': True, 'ip': None, 'gateway': None, 'dns': []}
+ else:
+ preset_d = copy(preset)
+
modes = ['DHCP (auto detect)', 'IP (static)']
default_mode = 'DHCP (auto detect)'
+ cursor_idx = 0 if preset_d.get('dhcp',True) else 1
prompt = _('Select which mode to configure for "{}" or skip to use default mode "{}"').format(nic, default_mode)
- mode = Menu(prompt, modes, default_option=default_mode).run()
-
+ mode = Menu(prompt, modes, default_option=default_mode, cursor_index=cursor_idx).run()
+ # TODO preset values for ip and gateway
if mode == 'IP (static)':
while 1:
prompt = _('Enter the IP and subnet for {} (example: 192.168.0.5/24): ').format(nic)
- ip = input(prompt).strip()
+ ip = TextInput(prompt,preset_d.get('ip')).run().strip()
# Implemented new check for correct IP/subnet input
try:
ipaddress.ip_interface(ip)
@@ -471,7 +513,7 @@ def ask_to_configure_network() -> Dict[str, Any]:
# Implemented new check for correct gateway IP address
while 1:
- gateway = input(_('Enter your gateway (router) IP address or leave blank for none: ')).strip()
+ gateway = TextInput(_('Enter your gateway (router) IP address or leave blank for none: '),preset_d.get('gateway')).run().strip()
try:
if len(gateway) == 0:
gateway = None
@@ -486,7 +528,11 @@ def ask_to_configure_network() -> Dict[str, Any]:
)
dns = None
- dns_input = input(_('Enter your DNS servers (space separated, blank for none): ')).strip()
+ if preset_d.get('dns'):
+ preset_d['dns'] = ' '.join(preset_d['dns'])
+ else:
+ preset_d['dns'] = None
+ dns_input = TextInput(_('Enter your DNS servers (space separated, blank for none): '),preset_d['dns']).run().strip()
if len(dns_input):
dns = dns_input.split(' ')
@@ -847,7 +893,7 @@ def select_profile() -> Optional[Profile]:
return None
-def select_language(default_value :str) -> str:
+def select_language(default_value :str, preset_value :str = None) -> str:
"""
Asks the user to select a language
Usually this is combined with :ref:`archinstall.list_keyboard_languages`.
@@ -861,11 +907,11 @@ def select_language(default_value :str) -> str:
# allows for searching anyways
sorted_kb_lang = sorted(sorted(list(kb_lang)), key=len)
- selected_lang = Menu(_('Select Keyboard layout'), sorted_kb_lang, default_option=default_value, sort=False).run()
+ selected_lang = Menu(_('Select Keyboard layout'), sorted_kb_lang, default_option=default_value, preset_values=preset_value, sort=False).run()
return selected_lang
-def select_mirror_regions() -> Dict[str, Any]:
+def select_mirror_regions(preset_values :Dict[str, Any] = {}) -> Dict[str, Any]:
"""
Asks the user to select a mirror or region
Usually this is combined with :ref:`archinstall.list_mirrors`.
@@ -873,11 +919,15 @@ def select_mirror_regions() -> Dict[str, Any]:
:return: The dictionary information about a mirror/region.
:rtype: dict
"""
-
+ if preset_values is None:
+ preselected = None
+ else:
+ preselected = list(preset_values.keys())
mirrors = list_mirrors()
selected_mirror = Menu(
_('Select one of the regions to download packages from'),
list(mirrors.keys()),
+ preset_values=preselected,
multi=True
).run()
@@ -887,7 +937,7 @@ def select_mirror_regions() -> Dict[str, Any]:
return {}
-def select_harddrives() -> Optional[str]:
+def select_harddrives(preset : List[str] = []) -> List[str]:
"""
Asks the user to select one or multiple hard drives
@@ -896,10 +946,11 @@ def select_harddrives() -> Optional[str]:
"""
hard_drives = all_blockdevices(partitions=False).values()
options = {f'{option}': option for option in hard_drives}
-
+ preset_disks = {f'{option}':option for option in preset}
selected_harddrive = Menu(
_('Select one or more hard drives to use and configure'),
list(options.keys()),
+ preset_values=list(preset_disks.keys()),
multi=True
).run()
@@ -943,7 +994,7 @@ def select_driver(options :Dict[str, Any] = AVAILABLE_GFX_DRIVERS, force_ask :bo
raise RequirementError("Selecting drivers require a least one profile to be given as an option.")
-def select_kernel() -> List[str]:
+def select_kernel(preset :List[str] = None) -> List[str]:
"""
Asks the user to select a kernel for system.
@@ -959,11 +1010,12 @@ def select_kernel() -> List[str]:
kernels,
sort=True,
multi=True,
+ preset_values=preset,
default_option=default_kernel
).run()
return selected_kernels
-def select_additional_repositories() -> List[str]:
+def select_additional_repositories(preset :List[str]) -> List[str]:
"""
Allows the user to select additional repositories (multilib, and testing) if desired.
@@ -978,6 +1030,7 @@ def select_additional_repositories() -> List[str]:
repositories,
sort=False,
multi=True,
+ preset_values=preset,
default_option=[]
).run()
@@ -986,7 +1039,7 @@ def select_additional_repositories() -> List[str]:
return []
-def select_locale_lang(default):
+def select_locale_lang(default :str,preset :str = None) -> str :
locales = list_locales()
locale_lang = set([locale.split()[0] for locale in locales])
@@ -994,13 +1047,14 @@ def select_locale_lang(default):
_('Choose which locale language to use'),
locale_lang,
sort=True,
+ preset_values=preset,
default_option=default
).run()
return selected_locale
-def select_locale_enc(default):
+def select_locale_enc(default :str,preset :str = None) -> str:
locales = list_locales()
locale_enc = set([locale.split()[1] for locale in locales])
@@ -1008,6 +1062,7 @@ def select_locale_enc(default):
_('Choose which locale encoding to use'),
locale_enc,
sort=True,
+ preset_values=preset,
default_option=default
).run()