def prefixed_wrap(prefix, text, width=None, indent=0):
"""
Wrap text with a prefix and optionally indenting the second and
later lines. If the width is None, the terminal size will be
used. (See terminal_size() for details.)
"""
if width is None:
height, width = terminal_size()
wrapped = textwrap.wrap(text, width - len(prefix))
leader = " " * (len(prefix) + indent)
lines = [wrapped.pop(0)]
lines.extend(["%s%s" % (leader, line)
for line in wrapped])
return "%s%s" % (prefix, "\n".join(lines))
评论列表
文章目录