##// END OF EJS Templates
custom keyboard interrupt handling in ask_yes_no...
Paul Ivanov -
Show More
@@ -155,11 +155,13 b' class Tee(object):'
155 self.close()
155 self.close()
156
156
157
157
158 def ask_yes_no(prompt,default=None):
158 def ask_yes_no(prompt, default=None, interrupt=None):
159 """Asks a question and returns a boolean (y/n) answer.
159 """Asks a question and returns a boolean (y/n) answer.
160
160
161 If default is given (one of 'y','n'), it is used if the user input is
161 If default is given (one of 'y','n'), it is used if the user input is
162 empty. Otherwise the question is repeated until an answer is given.
162 empty. If interrupt is given (one of 'y','n'), it is used if the user
163 presses Ctrl-C. Otherwise the question is repeated until an answer is
164 given.
163
165
164 An EOF is treated as the default answer. If there is no default, an
166 An EOF is treated as the default answer. If there is no default, an
165 exception is raised to prevent infinite loops.
167 exception is raised to prevent infinite loops.
@@ -174,7 +176,8 b' def ask_yes_no(prompt,default=None):'
174 if not ans: # response was an empty string
176 if not ans: # response was an empty string
175 ans = default
177 ans = default
176 except KeyboardInterrupt:
178 except KeyboardInterrupt:
177 pass
179 if interrupt:
180 ans = interrupt
178 except EOFError:
181 except EOFError:
179 if default in answers.keys():
182 if default in answers.keys():
180 ans = default
183 ans = default
General Comments 0
You need to be logged in to leave comments. Login now