From 20787da275fd21f1f6e66dc885cc275cc2ebc1ac Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 26 Dec 2019 17:19:26 -0700 Subject: [PATCH] Optionally disallow empty responses to input_text --- scripts/wk/std.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index 88d70d25..ab72314a 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -807,7 +807,7 @@ def get_log_filepath(): return log_filepath -def input_text(prompt='Enter text'): +def input_text(prompt='Enter text', allow_empty_response=True): """Get text from user, returns string.""" prompt = str(prompt) response = None @@ -823,6 +823,11 @@ def input_text(prompt='Enter text'): # Ignore and try again LOG.warning('Exception occured', exc_info=True) print('', flush=True) + if not allow_empty_response: + if response is None or not response.strip(): + # The None check here is used to avoid a TypeError if response is None + print(f'\r{prompt}', end='', flush=True) + response = None return response