X Tutup
Skip to content

Commit aa909d4

Browse files
committed
Fix redrawing of backspace, del and clrtobol on long lines.
This will close issue #25.
1 parent 1c86e7f commit aa909d4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bpython/cli.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,13 @@ def bs(self, delete_tabs=True):
14911491
y -= 1
14921492
x = gethw()[1]
14931493

1494+
# Delete following lines if the current string is greater than the
1495+
# screen width. Curses does not handle that on its own.
1496+
width = self.scr.getmaxyx()[1]
1497+
for y in xrange(self.iy + 1, self.iy + len(self.s) // width + 2):
1498+
self.scr.move(y, 0)
1499+
self.scr.clrtoeol()
1500+
14941501
if not self.cpos:
14951502
# I know the nested if blocks look nasty. :(
14961503
if self.atbol() and delete_tabs:
@@ -1502,8 +1509,7 @@ def bs(self, delete_tabs=True):
15021509
else:
15031510
self.s = self.s[:-self.cpos-1] + self.s[-self.cpos:]
15041511

1505-
for _ in range(n):
1506-
self.scr.delch(y, x - n)
1512+
self.print_line(self.s, clr=True)
15071513

15081514
return n
15091515

@@ -1540,6 +1546,13 @@ def yank_from_buffer(self):
15401546

15411547
def clrtobol(self):
15421548
"""Clear from cursor to beginning of line; usual C-u behaviour"""
1549+
# It seems as if curses does not handle this on its own, which
1550+
# makes me sad.
1551+
width = self.scr.getmaxyx()[1]
1552+
for y in xrange(self.iy + 1, self.iy + len(self.s) // width + 2):
1553+
self.scr.move(y, 0)
1554+
self.scr.clrtoeol()
1555+
15431556
if not self.cpos:
15441557
self.s = ''
15451558
else:
@@ -1564,9 +1577,6 @@ def p_key(self):
15641577

15651578
if self.c in (chr(127), 'KEY_BACKSPACE'):
15661579
self.bs()
1567-
# Redraw (as there might have been highlighted parens)
1568-
self.print_line('')
1569-
self.print_line(self.s)
15701580
self.complete()
15711581
return ''
15721582

0 commit comments

Comments
 (0)
X Tutup