usage.py 文件源码

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

项目:rcli 作者: contains-io 项目源码 文件源码
def _wrap_section(source, width):
    # type: (str, int) -> str
    """Wrap the given section string to the current terminal size.

    Intelligently wraps the section string to the given width. When wrapping
    section lines, it auto-adjusts the spacing between terms and definitions.
    It also adjusts commands the fit the correct length for the arguments.

    Args:
        source: The section string to wrap.

    Returns:
        The wrapped section string.
    """
    if _get_section('usage', source):
        return _wrap_usage_section(source, width)
    if _is_definition_section(source):
        return _wrap_definition_section(source, width)
    lines = inspect.cleandoc(source).splitlines()
    paragraphs = (textwrap.wrap(line, width, replace_whitespace=False)
                  for line in lines)
    return '\n'.join(line for paragraph in paragraphs for line in paragraph)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号