-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Add support for colorizing code examples in argparse description/epilog #142389
Description
Today, argparse does not support any native way to colorize code snippets in help descriptions. Example commands blend in with surrounding text, making help output harder to scan:

Allowing users to specify that they want to colorize an example in help text is a common UX pattern in modern CLI frameworks. Both Typer and rich-click support markup in help text via Rich's console markup (e.g., [green]text[/green]). Now that argparse supports colorization, it would be nice to add similar functionality. I think this is perhaps the last remaining gap in argparse's colorization support. I'm proposing a limited semantic markup approach:
epilog="""Examples:
[cmd]python -m myapp --verbose run[/cmd]
"""
After:
This support could potentially be expanded out later to support more sophisticated syntax highlighting (e.g. [python]...[/python]), since we already have a lot of this tokenization logic in place in _colorize.py. However, I'd like to start here before boiling the ocean.
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status