Skip to content
Myr

Add subsequent indent outside of the text wrapper

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This prevents it from being included in the text width.

authored by Simon Jagoe · committed by Simon Jagoe · parent 4336a5d · Browse files · 1 file+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−4 removed

  • other:+12 added−4 removed

1 file+12 added−4 removed

modified:click/formatting.py+12 added-4 removed
16 unmodified lines
17 row = tuple(row)18 yield row + ('',) * (col_count - len(row))192021def add_subsequent_indent(text, subsequent_indent):22 lines = text.splitlines()23 lines = [lines[0]] + [subsequent_indent + line for line in lines[1:]]24 return '\n'.join(lines)252627def wrap_text(text, width=78, initial_indent='', subsequent_indent='',28 preserve_paragraphs=False):29 """A helper function that intelligently wraps text. By default, it30 assumes that it operates on a single paragraph of text but if the
15 unmodified lines
46 """47 from ._textwrap import TextWrapper48 text = text.expandtabs()49 wrapper = TextWrapper(width, initial_indent=initial_indent,44 subsequent_indent=subsequent_indent,50 subsequent_indent='',51 replace_whitespace=False)52 if not preserve_paragraphs:47 return wrapper.fill(text)53 return add_subsequent_indent(wrapper.fill(text), subsequent_indent)5455 p = []56 buf = []57 indent = None
22 unmodified lines
80 rv = []81 for indent, raw, text in p:82 with wrapper.extra_indent(' ' * indent):83 if raw:78 rv.append(wrapper.indent_only(text))84 rv.append(add_subsequent_indent(wrapper.indent_only(text),85 subsequent_indent))86 else:80 rv.append(wrapper.fill(text))87 rv.append(add_subsequent_indent(wrapper.fill(text),88 subsequent_indent))8990 return '\n\n'.join(rv)9192
157 unmodified lines