_emerge.UserQuery module

class _emerge.UserQuery.UserQuery(myopts)

Bases: object

The UserQuery class is used to prompt the user with a set of responses, as well as accepting and handling the responses.

query(prompt, enter_invalid, responses=None, colours=None)

Display a prompt and a set of responses, then waits for user input and check it against the responses. The first match is returned.

An empty response will match the first value in the list of responses, unless enter_invalid is True. The input buffer is not cleared prior to the prompt!

prompt: The String to display as a prompt. responses: a List of Strings with the acceptable responses. colours: a List of Functions taking and returning a String, used to process the responses for display. Typically these will be functions like red() but could be e.g. lambda x: “DisplayString”.

If responses is omitted, it defaults to [“Yes”, “No”], [green, red]. If only colours is omitted, it defaults to [bold, …].

Returns a member of the List responses. (If called without optional arguments, it returns “Yes” or “No”.)

KeyboardInterrupt is converted to SystemExit to avoid tracebacks being printed.