Skip to content

Commit

Permalink
HelpFormatter.write_text uses full width
Browse files Browse the repository at this point in the history
  • Loading branch information
janluke authored and davidism committed May 11, 2021
1 parent 5215fc1 commit dcd991d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -215,6 +215,8 @@ Unreleased
- When defining a parameter, ``default`` is validated with
``multiple`` and ``nargs``. More validation is done for values being
processed as well. :issue:`1806`
- ``HelpFormatter.write_text`` uses the full line width when wrapping
text. :issue:`1871`


Version 7.1.2
Expand Down
3 changes: 1 addition & 2 deletions src/click/formatting.py
Expand Up @@ -195,12 +195,11 @@ def write_text(self, text: str) -> None:
"""Writes re-indented text into the buffer. This rewraps and
preserves paragraphs.
"""
text_width = max(self.width - self.current_indent, 11)
indent = " " * self.current_indent
self.write(
wrap_text(
text,
text_width,
self.width,
initial_indent=indent,
subsequent_indent=indent,
preserve_paragraphs=True,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_formatting.py
Expand Up @@ -335,3 +335,13 @@ def test_formatting_with_options_metavar_empty(runner):
cli = click.Command("cli", options_metavar="", params=[click.Argument(["var"])])
result = runner.invoke(cli, ["--help"])
assert "Usage: cli VAR\n" in result.output


def test_help_formatter_write_text():
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
formatter = click.HelpFormatter(width=len(" Lorem ipsum dolor sit amet,"))
formatter.current_indent = 2
formatter.write_text(text)
actual = formatter.getvalue()
expected = " Lorem ipsum dolor sit amet,\n consectetur adipiscing elit\n"
assert actual == expected

0 comments on commit dcd991d

Please sign in to comment.