Skip to content
Myr

HelpFormatter.write_text uses full width

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

authored by Gianluca Gippetto · committed by David Lord · parent 5215fc1 · Browse files · 3 files+13 added−2 removed
This commit

State

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

Diff stats

3 files+13 added−2 removed

  • tests:+10 added−0 removed
  • other:+3 added−2 removed

3 files+13 added−2 removed

modified:src/click/formatting.py+1 added-2 removed
193 unmodified lines
194 def write_text(self, text: str) -> None:195 """Writes re-indented text into the buffer. This rewraps and196 preserves paragraphs.197 """198 text_width = max(self.width - self.current_indent, 11)198 indent = " " * self.current_indent199 self.write(200 wrap_text(201 text,203 text_width,202 self.width,203 initial_indent=indent,204 subsequent_indent=indent,205 preserve_paragraphs=True,206 )
95 unmodified lines
modified:tests/test_formatting.py+10 added
333 unmodified lines
334def test_formatting_with_options_metavar_empty(runner):335 cli = click.Command("cli", options_metavar="", params=[click.Argument(["var"])])336 result = runner.invoke(cli, ["--help"])337 assert "Usage: cli VAR\n" in result.output338339340def test_help_formatter_write_text():341 text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"342 formatter = click.HelpFormatter(width=len(" Lorem ipsum dolor sit amet,"))343 formatter.current_indent = 2344 formatter.write_text(text)345 actual = formatter.getvalue()346 expected = " Lorem ipsum dolor sit amet,\n consectetur adipiscing elit\n"347 assert actual == expected
modified:CHANGES.rst+2 added
213 unmodified lines
214 returned string could be as long as ``max_width + 3``. :issue:`1849`215- When defining a parameter, ``default`` is validated with216 ``multiple`` and ``nargs``. More validation is done for values being217 processed as well. :issue:`1806`218- ``HelpFormatter.write_text`` uses the full line width when wrapping219 text. :issue:`1871`220221222Version 7.1.2223-------------
635 unmodified lines