usage.py 文件源码

python
阅读 43 收藏 0 点赞 0 评论 0

项目:rcli 作者: contains-io 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号