rich-click icon indicating copy to clipboard operation
rich-click copied to clipboard

Newline Characters Not Rendered in CLI Command Epilog

Open cpalau opened this issue 1 year ago • 2 comments

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

cpalau avatar Sep 17 '24 10:09 cpalau

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 avatar Sep 17 '24 14:09 dwreeves

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!

dwreeves avatar Oct 02 '24 22:10 dwreeves

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
    """
)

ewels avatar Nov 10 '24 22:11 ewels