X Tutup
Skip to content

Commit 8ce1746

Browse files
committed
Implement backspace support in FakeStdin.readline().
Also silently ignore control characters or any other special keys.
1 parent cd3b707 commit 8ce1746

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

bpython/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ def readline(self):
186186
try:
187187
while True:
188188
key = self.interface.get_key()
189+
if key in [curses.erasechar(), 'KEY_BACKSPACE']:
190+
buffer = buffer[:-1]
191+
y, x = self.interface.scr.getyx()
192+
if x:
193+
self.interface.scr.delch(y, x - 1)
194+
continue
195+
elif (key != '\n' and
196+
(len(key) > 1 or unicodedata.category(key) == 'Cc')):
197+
continue
189198
sys.stdout.write(key)
190199
# Include the \n in the buffer - raw_input() seems to deal with trailing
191200
# linebreaks and will break if it gets an empty string.

0 commit comments

Comments
 (0)
X Tutup