diff --git a/CHANGES.rst b/CHANGES.rst index 51f47dc3f..d5705f711 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/src/click/formatting.py b/src/click/formatting.py index 1e59fc220..ddd2a2f82 100644 --- a/src/click/formatting.py +++ b/src/click/formatting.py @@ -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, diff --git a/tests/test_formatting.py b/tests/test_formatting.py index ec32bf92f..f957e0128 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -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