Skip to content

Commit d2d3702

Browse files
committed
Fix scrolling in echo().
1 parent 6835619 commit d2d3702

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

bpython/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def clear_wrapped_lines(self):
340340
"""Clear the wrapped lines of the current input."""
341341
# curses does not handle this on its own. Sad.
342342
height, width = self.scr.getmaxyx()
343-
max_y = min(self.iy + len(self.s) // width + 1, height)
343+
max_y = min(self.iy + (self.ix + len(self.s)) // width + 1, height)
344344
for y in xrange(self.iy + 1, max_y):
345345
self.scr.move(y, 0)
346346
self.scr.clrtoeol()
@@ -459,6 +459,13 @@ def echo(self, s, redraw=True):
459459
# Replace NUL bytes, as addstr raises an exception otherwise
460460
s = s.replace('\x00', '')
461461

462+
screen_height, screen_width = self.scr.getmaxyx()
463+
if self.iy >= (screen_height - 1):
464+
lines = (self.ix + len(s)) // screen_width
465+
if lines > 0:
466+
self.scr.scroll(lines)
467+
self.iy -= lines
468+
self.scr.move(self.iy, self.ix)
462469
self.scr.addstr(s, a)
463470

464471
if redraw and not self.evaluating:

0 commit comments

Comments
 (0)