From f377c63a391d583a7855deeb45b0ab5e736cce32 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 7 Oct 2021 13:12:09 +0000 Subject: [PATCH] line_input(): skip readline text insert if 'insert_txt' is empty --- mmgen/util.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mmgen/util.py b/mmgen/util.py index be108544..a6cb2868 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -768,8 +768,12 @@ class pwfile_reuse_warning(oneshot_warning): oneshot_warning.__init__(self,div=fn,fmt_args=[fn],reverse=True) def line_input(prompt,echo=True,insert_txt=''): - - assert prompt,'calling line_input() with an empty prompt not allowed due to readline issues' + """ + multi-line prompts OK + one-line prompts must begin at beginning of line + empty prompts forbidden due to interactions with readline + """ + assert prompt,'calling line_input() with an empty prompt forbidden' def init_readline(): try: @@ -777,8 +781,11 @@ def line_input(prompt,echo=True,insert_txt=''): except ImportError: return False else: - readline.set_startup_hook(lambda: readline.insert_text(insert_txt)) - return True + if insert_txt: + readline.set_startup_hook(lambda: readline.insert_text(insert_txt)) + return True + else: + return False if not sys.stdout.isatty(): msg_r(prompt) @@ -792,9 +799,9 @@ def line_input(prompt,echo=True,insert_txt=''): sys.stderr.flush() reply = os.read(0,4096).decode() elif echo or not sys.stdin.isatty(): - using_readline = init_readline() if sys.stdin.isatty() else False + clear_buffer = init_readline() if sys.stdin.isatty() else False reply = input(prompt) - if using_readline: + if clear_buffer: import readline readline.set_startup_hook(lambda: readline.insert_text('')) else: