Skip to content
Myr

Fix corner-case where subsequent wrapped lines are one character longer

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

than max width

authored by Simon Jagoe · committed by Simon Jagoe · parent ebd751c · Browse files · 2 files+12 added−5 removed
This commit

State

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

Diff stats

2 files+12 added−5 removed

  • tests:+6 added−1 removed
  • other:+6 added−4 removed

2 files+12 added−5 removed

modified:click/formatting.py+6 added-4 removed
44 unmodified lines
45 intelligently handle paragraphs.46 """47 from ._textwrap import TextWrapper48 text = text.expandtabs()49 post_wrap_indent = subsequent_indent[:-1]50 subsequent_indent = subsequent_indent[-1:]51 wrapper = TextWrapper(width, initial_indent=initial_indent,50 subsequent_indent='',52 subsequent_indent=subsequent_indent,53 replace_whitespace=False)54 if not preserve_paragraphs:53 return add_subsequent_indent(wrapper.fill(text), subsequent_indent)55 return add_subsequent_indent(wrapper.fill(text), post_wrap_indent)5657 p = []58 buf = []59 indent = None
23 unmodified lines
83 for indent, raw, text in p:84 with wrapper.extra_indent(' ' * indent):85 if raw:86 rv.append(add_subsequent_indent(wrapper.indent_only(text),85 subsequent_indent))87 post_wrap_indent))88 else:89 rv.append(add_subsequent_indent(wrapper.fill(text),88 subsequent_indent))90 post_wrap_indent))9192 return '\n\n'.join(rv)9394
157 unmodified lines
modified:tests/test_formatting.py+6 added-1 removed
64 unmodified lines
65 @click.argument('first')66 @click.argument('second')67 @click.argument('third')68 @click.argument('fourth')69 @click.argument('fifth')70 @click.argument('sixth')71 def command():72 """A command.73 """7475 # 54 is chosen as a lenthg where the second line is one character76 # longer than the maximum length.77 result = runner.invoke(cli, ['a_very_long', 'command', '--help'],78 terminal_width=54)79 assert not result.exception80 assert result.output.splitlines() == [81 'Usage: cli a_very_long command [OPTIONS] FIRST SECOND',78 ' THIRD FOURTH',82 ' THIRD FOURTH FIFTH',83 ' SIXTH',84 '',85 ' A command.',86 '',87 'Options:',
2 unmodified lines