Skip to content

Commit

Permalink
Merge pull request #38 from florimondmanca/patch-1
Browse files Browse the repository at this point in the history
Improve handling of KeyboardInterrupt in prompt
  • Loading branch information
CITGuru committed Mar 26, 2019
2 parents 2be1e92 + 0fd724a commit 50f7e8f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions PyInquirer/prompt.py
Expand Up @@ -19,6 +19,7 @@ def prompt(questions, answers=None, **kwargs):
refresh_interval = kwargs.pop('refresh_interval', 0)
eventloop = kwargs.pop('eventloop', None)
kbi_msg = kwargs.pop('keyboard_interrupt_msg', 'Cancelled by user')
raise_kbi = kwargs.pop('raise_keyboard_interrupt', False)

for question in questions:
# import the question
Expand Down Expand Up @@ -86,10 +87,13 @@ def prompt(questions, answers=None, **kwargs):
except AttributeError as e:
print(e)
raise ValueError('No question type \'%s\'' % type)
except KeyboardInterrupt:
print('')
print(kbi_msg)
print('')
except KeyboardInterrupt as exc:
if raise_kbi:
raise exc from None
if kbi_msg:
print('')
print(kbi_msg)
print('')
return {}
return answers

Expand Down

0 comments on commit 50f7e8f

Please sign in to comment.