From 47a5da0418ac7d781035cdcec5823a105103aeca Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 25 Sep 2023 13:25:01 +0000 Subject: [PATCH] line_input(): cleanups, fix readline text insert bug --- mmgen/ui.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mmgen/ui.py b/mmgen/ui.py index bfccf78e..81494919 100755 --- a/mmgen/ui.py +++ b/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