ewels / rich-click

Format click help output nicely with rich.
https://ewels.github.io/rich-click/
MIT License
616 stars 35 forks source link

Newline Characters Not Rendered in CLI Command Epilog #206

Closed cpalau closed 7 hours ago

cpalau commented 1 month ago

Version: rich-click 1.8.3

I have a problem with newline characters (\n) in the epilog text. CLI text is not being properly rendered when output to the terminal. This results in the epilog text appearing as a single continuous line, despite attempts to format it with line breaks.

I tried """, adding \n and I have the image results. Tried in Windows, Linux and OSX with same results.

Tried different ways like:

@form4.command(
    epilog="""
        Examples:,
        python etl.py form4 process,
        python etl.py form4 process --sec-rss-feed,
        python etl.py form4 process --sec-accession-number 0001425287-24-000117,
        python etl.py form4 process --sec-accession-number 0001425287-24-000117 --download-only
    """
)

Any help ? Thanks!

image

dwreeves commented 1 month ago

Hi @cpalau.

Just posting to acknowledge I see your issue!

I'm on the busy side for the next couple days and I'll be able to look more into this either on Friday or more likely Sunday.

dwreeves commented 1 month ago

Hello @cpalau, sorry to get back so late.

The newline behavior is deliberate; see #49 for more discussion. I believe the intent was to mimic general markdown behavior.

The way to work around it is to add double newlines, so \n\n instead of \n.

TERMINAL_WIDTH=80 python hello.py --help

 Usage: hello.py [OPTIONS]                                                      

 Simple program that greets NAME.                                               

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --name    TEXT  The person to greet.                                         │
│ --help          Show this message and exit.                                  │
╰──────────────────────────────────────────────────────────────────────────────╯

 For more information, visit our website. That's all!                           
 Have a good day                                                                

This should definitely be documented, since it isn't right now.

Newline control is a wishlist item in #179, which I am behind on to be honest. (My new job has ramped up in terms of workload, I've fallen behind on a lot of open source.)

Hopefully this solves your issue!

ewels commented 7 hours ago

Closing as duplicate of https://github.com/ewels/rich-click/issues/49

Note that if you use the \b escape character in the docstring then newlines will work as you expect in your example. However I just tried this in epilog and it has no effect, so you'll need double newlines there for now:

@form4.command(
    epilog="""
        Examples:

        python etl.py form4 process,

        python etl.py form4 process --sec-rss-feed,

        python etl.py form4 process --sec-accession-number 0001425287-24-000117,

        python etl.py form4 process --sec-accession-number 0001425287-24-000117 --download-only
    """
)