Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HelpFormatter.write_text() to use the full line width #1872

Merged
merged 1 commit into from May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`


janluke marked this conversation as resolved.
Show resolved Hide resolved
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