Skip to content

Commit 4553045

Browse files
committed
better formatting of docstring and, though i have no idea how, i fixed a crashy
bug, hooray
1 parent 76acaec commit 4553045

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

bpython/cli.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def _complete(self, unused_tab=False):
634634
self.scr.redrawwin()
635635
return False
636636
if self.current_func is not None:
637-
self.docstring = getattr(self.current_func, '__doc__', None)
637+
self.docstring = pydoc.getdoc(self.current_func)
638638

639639
if not e and matches:
640640
# remove duplicates and restore order
@@ -728,16 +728,12 @@ def lsize():
728728
del v_items[-(cols * (height_offset)):]
729729

730730
if self.docstring is None:
731-
self.list_win.resize(rows+2, w)
731+
self.list_win.resize(rows +2, w)
732732
else:
733-
self.list_win.resize(max_h, max_w)
734-
docstring = []
735-
for paragraph in self.docstring.split('\n'):
736-
for line in textwrap.wrap(paragraph, max_w - 2):
737-
docstring.append('\n %s' % (line,))
738-
docstring = docstring[:max_h]
733+
docstring = self.format_docstring(self.docstring, max_w - 2)
739734
docstring_string = ''.join(docstring)
740-
rows = len(docstring) + 1
735+
rows = len(docstring) - 3
736+
self.list_win.resize(rows + 2, max_w)
741737

742738
if down:
743739
self.list_win.mvwin(y+1, 0)
@@ -778,6 +774,19 @@ def lsize():
778774
self.scr.move(*self.scr.getyx())
779775
self.list_win.refresh()
780776

777+
def format_docstring(self, docstring, width):
778+
"""Take a string and try to format it into a sane list of strings to be
779+
put into the suggestion box."""
780+
781+
lines = docstring.split('\n')
782+
out = []
783+
for line in lines:
784+
out.append('\n')
785+
for block in textwrap.wrap(line, width):
786+
out.append(' ' + block)
787+
w = self.scr.getmaxyx()[1]
788+
return out
789+
781790
def mkargspec(self, topline, down):
782791
"""This figures out what to do with the argspec and puts it nicely into
783792
the list window. It returns the number of lines used to display the

0 commit comments

Comments
 (0)