Skip to content

Commit 6835619

Browse files
committed
Don't try to clear lines greater than screen height in clear_wrapped_lines().
Also use clear_wrapped_lines() in fwd().
1 parent 016952b commit 6835619

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

bpython/cli.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ def clear_current_line(self):
339339
def clear_wrapped_lines(self):
340340
"""Clear the wrapped lines of the current input."""
341341
# curses does not handle this on its own. Sad.
342-
width = self.scr.getmaxyx()[1]
343-
for y in xrange(self.iy + 1, self.iy + len(self.s) // width + 1):
342+
height, width = self.scr.getmaxyx()
343+
max_y = min(self.iy + len(self.s) // width + 1, height)
344+
for y in xrange(self.iy + 1, max_y):
344345
self.scr.move(y, 0)
345346
self.scr.clrtoeol()
346347

@@ -478,12 +479,7 @@ def fwd(self):
478479
"""Same as back() but, well, forward"""
479480

480481
self.cpos = 0
481-
482-
width = self.scr.getmaxyx()[1]
483-
for y in xrange(self.iy + 1, self.iy + len(self.s) // width + 1):
484-
self.scr.move(y, 0)
485-
self.scr.clrtoeol()
486-
482+
self.clear_wrapped_lines()
487483
self.rl_history.enter(self.s)
488484
self.s = self.rl_history.forward()
489485
self.print_line(self.s, clr=True)

0 commit comments

Comments
 (0)