diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-10-24 06:55:34 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-10-24 06:55:34 +0000 |
commit | cccca42d0470d9a2a972e8130418d82e97aa89b9 (patch) | |
tree | 2c45e45ab95b2ab8e7eb3b793ffee6a69638bd1b /pym/_emerge/userquery.py | |
parent | 40dd1f931f49b543229be30df8df303de987b8d8 (diff) | |
download | portage-cccca42d0470d9a2a972e8130418d82e97aa89b9.tar.gz portage-cccca42d0470d9a2a972e8130418d82e97aa89b9.tar.bz2 portage-cccca42d0470d9a2a972e8130418d82e97aa89b9.zip |
Bug #134466 - Add a --ask-enter-invalid option. When used together with the
--ask option, interpret a single "Enter" key press as invalid input. This
helps prevent accidental acceptance of the first choice.
svn path=/main/trunk/; revision=14710
Diffstat (limited to 'pym/_emerge/userquery.py')
-rw-r--r-- | pym/_emerge/userquery.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/pym/_emerge/userquery.py b/pym/_emerge/userquery.py index 5da236007..f177c9e87 100644 --- a/pym/_emerge/userquery.py +++ b/pym/_emerge/userquery.py @@ -8,11 +8,12 @@ import sys from portage.output import bold, create_color_func -def userquery(prompt, responses=None, colours=None): +def userquery(prompt, enter_invalid, responses=None, colours=None): """Displays a prompt and a set of responses, then waits for a response which is checked against the responses and the first to match is - returned. An empty response will match the first value in responses. The - input buffer is *not* cleared prior to the prompt! + returned. An empty response will match the first value in responses, + unless enter_invalid is True. The input buffer is *not* cleared prior + to the prompt! prompt: a String. responses: a List of Strings. @@ -42,10 +43,12 @@ def userquery(prompt, responses=None, colours=None): response=input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ") else: response=raw_input("["+"/".join([colours[i](responses[i]) for i in range(len(responses))])+"] ") - for key in responses: - # An empty response will match the first value in responses. - if response.upper()==key[:len(response)].upper(): - return key + if response or not enter_invalid: + for key in responses: + # An empty response will match the + # first value in responses. + if response.upper()==key[:len(response)].upper(): + return key print("Sorry, response '%s' not understood." % response, end=' ') except (EOFError, KeyboardInterrupt): print("Interrupted.") |