Skip to content

Commit 221ecb7

Browse files
committed
Fix ungetch issues with Python 3.3.
The patch is from Andy. I'm just commiting it. Closes: #230, #231
1 parent 6ffb5de commit 221ecb7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

bpython/cli.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,15 @@ def get_key(self):
636636
if key:
637637
return key
638638
else:
639-
t = time.time()
640-
self.paste_mode = (
641-
t - self.last_key_press <= self.config.paste_time
642-
)
643-
self.last_key_press = t
644-
return key
639+
if key != '\x00':
640+
t = time.time()
641+
self.paste_mode = (
642+
t - self.last_key_press <= self.config.paste_time
643+
)
644+
self.last_key_press = t
645+
return key
646+
else:
647+
key = ''
645648
finally:
646649
if self.idle:
647650
self.idle(self)
@@ -1687,7 +1690,7 @@ def sigwinch(unused_scr):
16871690
def sigcont(unused_scr):
16881691
sigwinch(unused_scr)
16891692
# Forces the redraw
1690-
curses.ungetch('')
1693+
curses.ungetch('\x00')
16911694

16921695
def gethw():
16931696
"""I found this code on a usenet post, and snipped out the bit I needed,
@@ -1744,7 +1747,10 @@ def idle(caller):
17441747
caller.scr.nodelay(True)
17451748
key = caller.scr.getch()
17461749
caller.scr.nodelay(False)
1747-
curses.ungetch(key)
1750+
if key != -1:
1751+
curses.ungetch(key)
1752+
else:
1753+
curses.ungetch('\x00')
17481754
caller.statusbar.check()
17491755
caller.check()
17501756

0 commit comments

Comments
 (0)