summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/userquery.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-10-24 07:06:38 +0000
committerZac Medico <zmedico@gentoo.org>2009-10-24 07:06:38 +0000
commit91eb98301496a5dae1fe75dcbcb77abe3fb4135a (patch)
tree707dc67e49103e66d0b4e0ad9912d2af418236a2 /pym/_emerge/userquery.py
parent060eceac479fc2b48a6ec264c4e47a1df7df1994 (diff)
downloadportage-91eb98301496a5dae1fe75dcbcb77abe3fb4135a.tar.gz
portage-91eb98301496a5dae1fe75dcbcb77abe3fb4135a.tar.bz2
portage-91eb98301496a5dae1fe75dcbcb77abe3fb4135a.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. (trunk r14710) svn path=/main/branches/2.1.7/; revision=14719
Diffstat (limited to 'pym/_emerge/userquery.py')
-rw-r--r--pym/_emerge/userquery.py17
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.")