Skip to content

Commit 5990b35

Browse files
author
Bob Farrell
committed
No more crashing on stupidly long entries in the autocomplete list
Thanks to habnabit for using lame modules that uncovered this one. committer: Bob Farrell <bob@keys.(none)>
1 parent 1411bfb commit 5990b35

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎bpython.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def lsize():
384384
if not wl:
385385
wl = 1
386386
cols = (max_w - 2) / wl
387-
rows = len( v_items ) / cols
387+
rows = len( v_items ) / (cols or 1)
388388

389389
if cols * rows < len( v_items ):
390390
rows += 1
@@ -399,13 +399,13 @@ def lsize():
399399
return True
400400

401401
if items:
402-
v_items = [ items[0] ] # visible items (we'll append until we can't fit any more in)
402+
v_items = [ items[0][:max_w-3] ] # visible items (we'll append until we can't fit any more in)
403403
lsize()
404404
else:
405405
v_items = []
406406

407407
for i in items[1:]:
408-
v_items.append( i )
408+
v_items.append( i[:max_w-3] )
409409
if not lsize():
410410
del v_items[-1]
411411
break
@@ -419,6 +419,8 @@ def lsize():
419419

420420
if topline and not v_items:
421421
w = max_w
422+
elif wl + 3 > max_w:
423+
w = max_w
422424
else:
423425
w = (cols + 1) * wl + 3
424426

@@ -438,7 +440,7 @@ def lsize():
438440
for ix, i in enumerate(v_items):
439441
padding = (wl - len(i)) * ' '
440442
self.list_win.addstr( i + padding, curses.color_pair( self._C["c"]+1 ) )
441-
if ix and not ix % cols and ix < len(v_items):
443+
if (cols == 1) or (ix and not ix % cols and ix < len(v_items)):
442444
self.list_win.addstr( '\n ' )
443445
#self.list_win.refresh()
444446
#time.sleep(0.5)

0 commit comments

Comments
 (0)