Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/menu/text_input.py
blob: 971df5fda14d0d97953baf138e0e0d5ce464fb84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import readline
import sys


class TextInput:
	def __init__(self, prompt: str, prefilled_text=''):
		self._prompt = prompt
		self._prefilled_text = prefilled_text

	def _hook(self):
		readline.insert_text(self._prefilled_text)
		readline.redisplay()

	def run(self) -> str:
		readline.set_pre_input_hook(self._hook)
		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