Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/user_interaction/general_conf.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/user_interaction/general_conf.py')
-rw-r--r--archinstall/lib/user_interaction/general_conf.py138
1 files changed, 86 insertions, 52 deletions
diff --git a/archinstall/lib/user_interaction/general_conf.py b/archinstall/lib/user_interaction/general_conf.py
index c42e9e27..d4dc60db 100644
--- a/archinstall/lib/user_interaction/general_conf.py
+++ b/archinstall/lib/user_interaction/general_conf.py
@@ -3,6 +3,9 @@ from __future__ import annotations
import logging
from typing import List, Any, Optional, Dict, TYPE_CHECKING
+import archinstall
+
+from ..menu.menu import MenuSelectionType
from ..menu.text_input import TextInput
from ..locale_helpers import list_keyboard_languages, list_timezones
@@ -22,11 +25,12 @@ 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'))
if preset:
- preset_val = 'yes'
+ preset_val = Menu.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
+ preset_val = Menu.no()
+ choice = Menu(prompt, Menu.yes_no(), skip=False, preset_values=preset_val, default_option=Menu.yes()).run()
+
+ return False if choice.value == Menu.no() else True
def ask_hostname(preset: str = None) -> str:
@@ -38,23 +42,31 @@ def ask_for_a_timezone(preset: str = None) -> str:
timezones = list_timezones()
default = 'UTC'
- selected_tz = Menu(_('Select a timezone'),
- list(timezones),
- skip=False,
- preset_values=preset,
- default_option=default).run()
+ choice = Menu(
+ _('Select a timezone'),
+ list(timezones),
+ preset_values=preset,
+ default_option=default
+ ).run()
- return selected_tz
+ match choice.type_:
+ case MenuSelectionType.Esc: return preset
+ case MenuSelectionType.Selection: return choice.value
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()
- return selected_audio
+ no_audio = str(_('No audio server'))
+ choices = ['pipewire', 'pulseaudio'] if desktop else ['pipewire', 'pulseaudio', no_audio]
+ default = 'pipewire' if desktop else no_audio
+
+ choice = Menu(_('Choose an audio server'), choices, preset_values=preset, default_option=default).run()
+ match choice.type_:
+ case MenuSelectionType.Esc: return preset
+ case MenuSelectionType.Selection: return choice.value
-def select_language(default_value: str, preset_value: str = None) -> str:
+
+def select_language(preset_value: str = None) -> str:
"""
Asks the user to select a language
Usually this is combined with :ref:`archinstall.list_keyboard_languages`.
@@ -64,16 +76,19 @@ def select_language(default_value: str, preset_value: str = None) -> str:
"""
kb_lang = list_keyboard_languages()
# sort alphabetically and then by length
- # it's fine if the list is big because the Menu
- # 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,
- preset_values=preset_value,
- sort=False).run()
- return selected_lang
+ selected_lang = Menu(
+ _('Select keyboard layout'),
+ sorted_kb_lang,
+ preset_values=preset_value,
+ sort=False
+ ).run()
+
+ if selected_lang.value is None:
+ return preset_value
+
+ return selected_lang.value
def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
@@ -89,24 +104,27 @@ def select_mirror_regions(preset_values: Dict[str, Any] = {}) -> Dict[str, Any]:
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()
+ selected_mirror = Menu(
+ _('Select one of the regions to download packages from'),
+ list(mirrors.keys()),
+ preset_values=preselected,
+ multi=True,
+ explode_on_interrupt=True
+ ).run()
- if selected_mirror is not None:
- return {selected: mirrors[selected] for selected in selected_mirror}
-
- return {}
+ match selected_mirror.type_:
+ case MenuSelectionType.Ctrl_c: return {}
+ case MenuSelectionType.Esc: return preset_values
+ case _: return {selected: mirrors[selected] for selected in selected_mirror.value}
def select_archinstall_language(default='English'):
- languages = Translation.get_all_names()
- language = Menu(_('Select Archinstall language'), languages, default_option=default).run()
+ languages = Translation.get_available_lang()
+ language = Menu(_('Archinstall language'), languages, default_option=default).run()
return language
-def select_profile() -> Optional[Profile]:
+def select_profile(preset) -> Optional[Profile]:
"""
# Asks the user to select a profile from the available profiles.
#
@@ -124,13 +142,27 @@ def select_profile() -> Optional[Profile]:
options[option] = profile
title = _('This is a list of pre-programmed profiles, they might make it easier to install things like desktop environments')
-
- selection = Menu(title=title, p_options=list(options.keys())).run()
-
- if selection is not None:
- return options[selection]
-
- return None
+ warning = str(_('Are you sure you want to reset this setting?'))
+
+ selection = Menu(
+ title=title,
+ p_options=list(options.keys()),
+ explode_on_interrupt=True,
+ explode_warning=warning
+ ).run()
+
+ match selection.type_:
+ case MenuSelectionType.Selection:
+ return options[selection.value] if selection.value is not None else None
+ case MenuSelectionType.Ctrl_c:
+ archinstall.storage['profile_minimal'] = False
+ archinstall.storage['_selected_servers'] = []
+ archinstall.storage['_desktop_profile'] = None
+ archinstall.arguments['desktop-environment'] = None
+ archinstall.arguments['gfx_driver_packages'] = None
+ return None
+ case MenuSelectionType.Esc:
+ return None
def ask_additional_packages_to_install(pre_set_packages: List[str] = []) -> List[str]:
@@ -171,14 +203,16 @@ def select_additional_repositories(preset: List[str]) -> List[str]:
repositories = ["multilib", "testing"]
- additional_repositories = Menu(_('Choose which optional additional repositories to enable'),
- repositories,
- sort=False,
- multi=True,
- preset_values=preset,
- default_option=[]).run()
-
- if additional_repositories is not None:
- return additional_repositories
-
- return []
+ choice = Menu(
+ _('Choose which optional additional repositories to enable'),
+ repositories,
+ sort=False,
+ multi=True,
+ preset_values=preset,
+ explode_on_interrupt=True
+ ).run()
+
+ match choice.type_:
+ case MenuSelectionType.Esc: return preset
+ case MenuSelectionType.Ctrl_c: return []
+ case MenuSelectionType.Selection: return choice.value