Skip to content

Commit b2ae604

Browse files
mitigate jarring scroll up on completion
-max completion box size calculated from space on screen -prefer displaying box below, but if scroll require display above -scroll down 10 lines on startup
1 parent 4e92abd commit b2ae604

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

‎bpython/curtsies.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def after_suspend():
122122
window.__enter__()
123123
interrupting_refresh()
124124

125+
def get_top_usable_line():
126+
return window.top_usable_row
127+
125128
# global for easy introspection `from bpython.curtsies import repl`
126129
global repl
127130
with Repl(config=config,
@@ -137,9 +140,12 @@ def after_suspend():
137140
interactive=interactive,
138141
orig_tcattrs=input_generator.original_stty,
139142
on_suspend=on_suspend,
140-
after_suspend=after_suspend) as repl:
143+
after_suspend=after_suspend,
144+
get_top_usable_line=get_top_usable_line) as repl:
141145
repl.height, repl.width = window.t.height, window.t.width
142146

147+
repl.request_paint_to_pad_bottom = 10
148+
143149
def process_event(e):
144150
"""If None is passed in, just paint the screen"""
145151
try:

‎bpython/curtsiesfrontend/repl.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ def __init__(self,
303303
interactive=True,
304304
orig_tcattrs=None,
305305
on_suspend=lambda *args: None,
306-
after_suspend=lambda *args: None):
306+
after_suspend=lambda *args: None,
307+
get_top_usable_line=lambda: 0):
307308
"""
308309
locals_ is a mapping of locals to pass into the interpreter
309310
config is a bpython config.Struct with config attributes
@@ -323,6 +324,7 @@ def __init__(self,
323324
original terminal state, useful for shelling out with normal terminal
324325
on_suspend will be called on sigtstp
325326
after_suspend will be called when process foregrounded after suspend
327+
get_top_usable_line returns the top line of the terminal owned
326328
"""
327329

328330
logger.debug("starting init")
@@ -417,6 +419,7 @@ def smarter_request_reload(files_modified=()):
417419
self.orig_tcattrs = orig_tcattrs
418420
self.on_suspend = on_suspend
419421
self.after_suspend = after_suspend
422+
self.get_top_usable_line = get_top_usable_line
420423

421424
self.coderunner = CodeRunner(self.interp, self.request_refresh)
422425
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout)
@@ -426,6 +429,8 @@ def smarter_request_reload(files_modified=()):
426429
# next paint should clear screen
427430
self.request_paint_to_clear_screen = False
428431

432+
self.request_paint_to_pad_bottom = 0
433+
429434
# offscreen command yields results different from scrollback bufffer
430435
self.inconsistent_history = False
431436

@@ -1169,6 +1174,10 @@ def paint(self, about_to_exit=False, user_quit=False):
11691174
if self.request_paint_to_clear_screen: # or show_status_bar and about_to_exit ?
11701175
self.request_paint_to_clear_screen = False
11711176
arr = FSArray(min_height + current_line_start_row, width)
1177+
elif self.request_paint_to_pad_bottom:
1178+
# min_height - 1 for startup banner with python version
1179+
arr = FSArray(min(self.request_paint_to_pad_bottom, min_height - 1), width)
1180+
self.request_paint_to_pad_bottom = 0
11721181
else:
11731182
arr = FSArray(0, width)
11741183
# TODO test case of current line filling up the whole screen (there
@@ -1265,7 +1274,8 @@ def move_screen_up(current_line_start_row):
12651274
if self.list_win_visible and not self.coderunner.running:
12661275
logger.debug('infobox display code running')
12671276
visible_space_above = history.height
1268-
visible_space_below = min_height - current_line_end_row - 1
1277+
potential_space_below = min_height - current_line_end_row - 1
1278+
visible_space_below = potential_space_below - self.get_top_usable_line()
12691279

12701280
info_max_rows = max(visible_space_above, visible_space_below)
12711281
infobox = paint.paint_infobox(info_max_rows,
@@ -1276,12 +1286,16 @@ def move_screen_up(current_line_start_row):
12761286
self.current_match,
12771287
self.docstring,
12781288
self.config,
1279-
self.matches_iter.completer.format if self.matches_iter.completer else None)
1289+
self.matches_iter.completer.format
1290+
if self.matches_iter.completer
1291+
else None)
12801292

1281-
if visible_space_above >= infobox.height and self.config.curtsies_list_above:
1282-
arr[current_line_start_row - infobox.height:current_line_start_row, 0:infobox.width] = infobox
1283-
else:
1293+
if visible_space_below >= infobox.height or not self.config.curtsies_list_above:
1294+
if visible_space_below < infobox.height:
1295+
raise ValueError('whoops %r %r' % (visible_space_below, infobox.height))
12841296
arr[current_line_end_row + 1:current_line_end_row + 1 + infobox.height, 0:infobox.width] = infobox
1297+
else:
1298+
arr[current_line_start_row - infobox.height:current_line_start_row, 0:infobox.width] = infobox
12851299
logger.debug('slamming infobox of shape %r into arr of shape %r', infobox.shape, arr.shape)
12861300

12871301
logger.debug('about to exit: %r', about_to_exit)

0 commit comments

Comments
 (0)