Add handling of signal interrupt and EOF at input prompts (#2154)
This commit is contained in:
parent
dc69acd4b4
commit
5e59acf937
|
|
@ -177,5 +177,5 @@ def save_config(config: Dict):
|
|||
case "all":
|
||||
config_output.save(dest_path)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -134,7 +134,10 @@ def select_disk_config(
|
|||
output = "You will use whatever drive-setup is mounted at the specified directory\n"
|
||||
output += "WARNING: Archinstall won't check the suitability of this setup\n"
|
||||
|
||||
path = prompt_dir(str(_('Enter the root directory of the mounted devices: ')), output)
|
||||
try:
|
||||
path = prompt_dir(str(_('Enter the root directory of the mounted devices: ')), output)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
return preset
|
||||
mods = disk.device_handler.detect_pre_mounted_mods(path)
|
||||
|
||||
return disk.DiskLayoutConfiguration(
|
||||
|
|
|
|||
|
|
@ -28,14 +28,15 @@ def ask_ntp(preset: bool = True) -> bool:
|
|||
|
||||
|
||||
def ask_hostname(preset: str = '') -> str:
|
||||
while True:
|
||||
hostname = TextInput(
|
||||
str(_('Desired hostname for the installation: ')),
|
||||
preset
|
||||
).run().strip()
|
||||
hostname = TextInput(
|
||||
str(_('Desired hostname for the installation: ')),
|
||||
preset
|
||||
).run().strip()
|
||||
|
||||
if hostname:
|
||||
return hostname
|
||||
if not hostname:
|
||||
return preset
|
||||
|
||||
return hostname
|
||||
|
||||
|
||||
def ask_for_a_timezone(preset: Optional[str] = None) -> Optional[str]:
|
||||
|
|
|
|||
|
|
@ -75,7 +75,11 @@ class UserList(ListManager):
|
|||
prompt = '\n\n' + str(_('Enter username (leave blank to skip): '))
|
||||
|
||||
while True:
|
||||
username = input(prompt).strip(' ')
|
||||
try:
|
||||
username = input(prompt).strip(' ')
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
return None
|
||||
|
||||
if not username:
|
||||
return None
|
||||
if not self._check_for_correct_username(username):
|
||||
|
|
|
|||
|
|
@ -17,7 +17,12 @@ def get_password(prompt: str = '') -> Optional[str]:
|
|||
if not prompt:
|
||||
prompt = _("Enter a password: ")
|
||||
|
||||
while password := getpass.getpass(prompt):
|
||||
while True:
|
||||
try:
|
||||
password = getpass.getpass(prompt)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
break
|
||||
|
||||
if len(password.strip()) <= 0:
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import readline
|
||||
import sys
|
||||
|
||||
|
||||
class TextInput:
|
||||
|
|
@ -12,6 +13,14 @@ class TextInput:
|
|||
|
||||
def run(self) -> str:
|
||||
readline.set_pre_input_hook(self._hook)
|
||||
result = input(self._prompt)
|
||||
try:
|
||||
result = input(self._prompt)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
# To make sure any output that may follow
|
||||
# will be on the line after the prompt
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
result = ''
|
||||
readline.set_pre_input_hook()
|
||||
return result
|
||||
|
|
|
|||
Loading…
Reference in New Issue