def _wrap_definition_section(source, width):
# type: (str, int) -> str
"""Wrap the given definition section string to the current terminal size.
Note:
Auto-adjusts the spacing between terms and definitions.
Args:
source: The section string to wrap.
Returns:
The wrapped section string.
"""
index = source.index('\n') + 1
definitions, max_len = _get_definitions(source[index:])
sep = '\n' + ' ' * (max_len + 4)
lines = [source[:index].strip()]
for arg, desc in six.iteritems(definitions):
wrapped_desc = sep.join(textwrap.wrap(desc, width - max_len - 4))
lines.append(' {arg:{size}} {desc}'.format(
arg=arg,
size=str(max_len),
desc=wrapped_desc
))
return '\n'.join(lines)
评论列表
文章目录