Skip to content

Commit 760d3c7

Browse files
paginate autocompletion suggestions
1 parent 9b6aa7b commit 760d3c7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

bpython/curtsiesfrontend/replpainter.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def paint_current_line(rows, columns, current_display_line):
4848
return fsarray(lines, width=columns)
4949

5050

51+
def paginate(rows, matches, current, words_wide):
52+
if current not in matches:
53+
current = matches[0]
54+
per_page = rows * words_wide
55+
current_page = matches.index(current) // per_page
56+
return matches[per_page * current_page:per_page * (current_page + 1)]
57+
5158
def matches_lines(rows, columns, matches, current, config, format):
5259
highlight_color = func_for_letter(config.color_scheme['operator'].lower())
5360

@@ -60,6 +67,8 @@ def matches_lines(rows, columns, matches, current, config, format):
6067
if current:
6168
current = format(current)
6269

70+
matches = paginate(rows, matches, current, words_wide)
71+
6372
matches_lines = [fmtstr(' ').join(color(m.ljust(max_match_width))
6473
if m != current
6574
else highlight_color(
@@ -163,12 +172,15 @@ def paint_infobox(rows, columns, matches, funcprops, arg_pos, match, docstring,
163172
if not (rows and columns):
164173
return fsarray(0, 0)
165174
width = columns - 4
166-
lines = ((formatted_argspec(funcprops, arg_pos, width, config)
167-
if funcprops else []) +
168-
(matches_lines(rows, width, matches, match, config, format)
169-
if matches else []) +
170-
(formatted_docstring(docstring, width, config)
171-
if docstring else []))
175+
from_argspec = (formatted_argspec(funcprops, arg_pos, width, config)
176+
if funcprops else [])
177+
from_doc = (formatted_docstring(docstring, width, config)
178+
if docstring else [])
179+
from_matches = (matches_lines(max(1, rows - len(from_argspec) - 2),
180+
width, matches, match, config, format)
181+
if matches else [])
182+
183+
lines = from_argspec + from_matches + from_doc
172184

173185
def add_border(line):
174186
"""Add colored borders left and right to a line."""

0 commit comments

Comments
 (0)