Newlines confuse word wrapping
See original GitHub issueI am using Python 3.7.0 on Mac OS X 10.13.6, with Click 7.0. I make this small script:
import click
@click.command()
@click.option('--zero-replacement', default=[1.0, 0.0, 0.0, 0.0], nargs=4, type=click.FLOAT, help="Four decimal numbers separated by spaces, representing the replacement vec4 that all-zero weights will be replaced with. Default is 1 0 0 0")
def example(zero_replacement):
pass
example()
I run python3 example.py --help
. It prints:
Usage: example.py [OPTIONS]
Options:
--zero-replacement FLOAT... Four decimal numbers separated by spaces,
representing the replacement vec4 that all-zero
weights will be replaced with. Default is 1 0 0
0
--help Show this message and exit.
Oh… that “1 0 0 [newline] 0” is a little confusing. I think, I will put a newline before “Default is”. So my code is now:
import click
@click.command()
@click.option('--zero-replacement', default=[1.0, 0.0, 0.0, 0.0], nargs=4, type=click.FLOAT, help="Four decimal numbers separated by spaces, representing the replacement vec4 that all-zero weights will be replaced with.\nDefault is 1 0 0 0")
def example(zero_replacement):
pass
example()
This prints:
Usage: example.py [OPTIONS]
Options:
--zero-replacement FLOAT... Four decimal numbers separated by spaces,
representing the replacement vec4 that all-zero
weights will be replaced with.
Default is 1 0 0
0
--help Show this message and exit.
Notice the last 0 gets an auto-line-break even though there is plenty of room for it. It is like the wordwrap algorithm is treating \n as a single-width character.
I see #834 suggests in future Click might delete newlines. That’s not what I want in this case, but if that were the behavior I would at least understand it. But this looks clearly wrong.
One more weirdness. I look in the documentation and see instructions for preventing rewrapping https://click.palletsprojects.com/en/7.x/documentation/#preventing-rewrapping “Rewrapping can be disabled on a per-paragraph basis by adding a line with solely the \b escape marker in it.”
Well, I only want a single newline, not a paragraph. But I decide to try this:
import click
@click.command()
@click.option('--zero-replacement', default=[1.0, 0.0, 0.0, 0.0], nargs=4, type=click.FLOAT, help="Four decimal numbers separated by spaces, representing the replacement vec4 that all-zero weights will be replaced with.\n\b\nDefault is 1 0 0 0")
def example(zero_replacement):
pass
example()
But when I run it:
Usage: example.py [OPTIONS]
Options:
--zero-replacement FLOAT... Four decimal numbers separated by spaces,
representing the replacement vec4 that all-zero
weights will be replaced with.
Default is 1 0
0 0
--help Show this message and exit.
It wrapped sooner! It appears to be treating the \n\b\n as THREE characters.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Try this, a little hacky workaround.
Turns out the underlying
wrap_text
function already takes apreserve_paragraphs
option, but it’s not enabled for option help text right now. This enables the behavior in the command help text where\n\n
is preserved and each paragraph is wrapped separately.This isn’t exactly what @mcclure asked for, since they wanted to use a single newline, but I don’t know if that’s possible right now. I can’t see a way to distinguish an intentional single line break from the line breaks in an indented
"""
multiline string that need to be rewrapped (#834) without adding more complexity than I’m comfortable with. I think combined with #1075 it should still be visually distinct.