Skip to content

Commit 28521a4

Browse files
author
Marien Zwart
committed
urwid: do something useful on ctrl+c during editing.
1 parent ad51de2 commit 28521a4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

bpython/urwid.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,20 @@ def start(self):
789789
self.prompt(False)
790790

791791
def keyboard_interrupt(self):
792-
# Do we need to do more here? Break out of multiline input perhaps?
793-
self.echo('KeyboardInterrupt')
792+
# If the user is currently editing, interrupt him. This
793+
# mirrors what the regular python REPL does.
794+
if self.edit is not None:
795+
# XXX this is a lot of code, and I am not sure it is
796+
# actually enough code. Needs some testing.
797+
self.edit.make_readonly()
798+
self.edit = None
799+
self.buffer = []
800+
self.echo('KeyboardInterrupt')
801+
self.prompt(False)
802+
else:
803+
# I do not quite remember if this is reachable, but let's
804+
# be safe.
805+
self.echo('KeyboardInterrupt')
794806

795807
def prompt(self, more):
796808
# Clear current output here, or output resulting from the

0 commit comments

Comments
 (0)