def userquery(prompt, 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.
+ returned. An empty response will match the first value in responses. The
+ input buffer is *not* cleared prior to the prompt!
prompt: a String.
responses: a List of Strings.
while True:
response=raw_input("["+string.join([colours[i](responses[i]) for i in range(len(responses))],"/")+"] ")
for key in responses:
- if response and response.upper()==key[:len(response)].upper():
+ # 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,
except (EOFError, KeyboardInterrupt):
continue with the merge or abort. Using \fB\-\-ask\fR is more efficient than
using \fB\-\-pretend\fR and then executing the same command without
\fB\-\-pretend\fR, as dependencies will only need to be calculated once.
+\fBWARNING: If the "Enter" key is pressed at the prompt (with no other input),
+it is interpreted as acceptance of the first choice. Note that the input
+buffer is not cleared prior to the prompt, so an accidental press of the
+"Enter" key at any time prior to the prompt will be interpreted as a choice!\fR
.TP
.BR "\-\-buildpkg " (\fB\-b\fR)
Tells emerge to build binary packages for all ebuilds processed in
print " ask whether to continue with the merge or abort. Using --ask is"
print " more efficient than using --pretend and then executing the same"
print " command without --pretend, as dependencies will only need to be"
- print " calculated once."
+ print " calculated once. WARNING: If the \"Enter\" key is pressed at the"
+ print " prompt (with no other input), it is interpreted as acceptance of"
+ print " the first choice. Note that the input buffer is not cleared prior"
+ print " to the prompt, so an accidental press of the \"Enter\" key at any"
+ print " time prior to the prompt will be interpreted as a choice!"
print
print " "+green("--buildpkg")+" ("+green("-b")+" short option)"
print " Tell emerge to build binary packages for all ebuilds processed"