hamdanal / rich-argparse

A rich help formatter for argparse
https://pypi.org/project/rich-argparse/
MIT License
129 stars 11 forks source link

Adding line breaks? #119

Open matanox opened 5 months ago

matanox commented 5 months ago

Of all aspects challenging the readability of an argparse output for the 95% of us, or making people avoid reading too much, perhaps the density of the text is one of the worst sticking points. This is because the chunking of the content is not very clear even with colors used: each option's description will begin either at the same line as the option name or on the next line ― yielding a complex layout which can IMHO be alleviated by an empty line between every pair of options, bestowing clear visual separation between the options being displayed.

Could be nice adding the option to add a line space between every pair of arguments (as well as before and after the whole output as a lesser concern).

atteggiani commented 4 months ago

Hi @matanox,

What you say could be effectively added as a built-in feature for rich_argparse.RichHelpFormatter (for example with an attibute newline_in_help=True). However, it can be achieved manually by using class_formatter = rich_argparse.RawTextRichHelpFormatter and adding two new lines at the end of each args help:

import argparse
from rich_argparse import RawTextRichHelpFormatter

parser = argparse.ArgumentParser(
    "PROG", formatter_class=RawTextRichHelpFormatter, add_help=False
)
parser.add_argument(
    "-h",
    "--help",
    action="help",
    help="show this help message and exit\n\n",
)
parser.add_argument(
    "--opt1",
    nargs="?",
    help="opt1 help\n\n",
)
parser.add_argument(
    "--opt2",
    nargs="+",
    help="opt2 help\n\n",
)
parser.print_help()

will have this output:

Screenshot 2024-06-28 at 12 22 38 PM