line_input(): cleanups, fix readline text insert bug
This commit is contained in:
parent
0a15625e83
commit
47a5da0418
1 changed files with 7 additions and 9 deletions
16
mmgen/ui.py
16
mmgen/ui.py
|
|
@ -54,24 +54,22 @@ def line_input(cfg,prompt,echo=True,insert_txt='',hold_protect=True):
|
|||
except ImportError:
|
||||
return False
|
||||
|
||||
if not sys.stdout.isatty():
|
||||
msg_r(prompt)
|
||||
prompt = ''
|
||||
|
||||
if hold_protect:
|
||||
from .term import kb_hold_protect
|
||||
kb_hold_protect()
|
||||
|
||||
if cfg.test_suite_popen_spawn:
|
||||
msg(prompt)
|
||||
sys.stderr.flush()
|
||||
reply = os.read(0,4096).decode().rstrip('\n') # strip NL to mimic behavior of input()
|
||||
elif echo or not sys.stdin.isatty():
|
||||
readline = insert_txt and sys.stdin.isatty() and get_readline()
|
||||
if readline:
|
||||
elif not sys.stdin.isatty():
|
||||
msg_r(prompt)
|
||||
reply = input('')
|
||||
elif echo:
|
||||
readline = get_readline()
|
||||
if readline and insert_txt:
|
||||
readline.set_startup_hook(lambda: readline.insert_text(insert_txt))
|
||||
reply = input(prompt)
|
||||
if readline:
|
||||
if readline and insert_txt:
|
||||
readline.set_startup_hook(lambda: readline.insert_text(''))
|
||||
else:
|
||||
from getpass import getpass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue