diff --git a/IPython/utils/io.py b/IPython/utils/io.py index 46296be..088c5be 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -155,11 +155,13 @@ class Tee(object): self.close() -def ask_yes_no(prompt,default=None): +def ask_yes_no(prompt, default=None, interrupt=None): """Asks a question and returns a boolean (y/n) answer. If default is given (one of 'y','n'), it is used if the user input is - empty. Otherwise the question is repeated until an answer is given. + empty. If interrupt is given (one of 'y','n'), it is used if the user + presses Ctrl-C. Otherwise the question is repeated until an answer is + given. An EOF is treated as the default answer. If there is no default, an exception is raised to prevent infinite loops. @@ -174,7 +176,8 @@ def ask_yes_no(prompt,default=None): if not ans: # response was an empty string ans = default except KeyboardInterrupt: - pass + if interrupt: + ans = interrupt except EOFError: if default in answers.keys(): ans = default