Click Help Colors
click-help-colors is a Python library that provides colorization for help messages in Click, a popular library for creating command-line interfaces. It allows users to customize the colors of headers, options, and custom elements within their CLI's help output, enhancing readability and user experience. The current version is 0.9.4. Its release cadence is irregular, with updates typically driven by compatibility requirements with new Click versions or feature enhancements.
Warnings
- breaking Older versions of `click-help-colors` were incompatible with Click 8.0. Ensure you are using `click-help-colors` version 0.9.0 or newer for full compatibility with Click 8.x and above.
- gotcha Click 8.0 dropped support for Python 2 and Python 3.5. If you are using `click-help-colors` with Click 8.0+, your project must be running on Python 3.6 or newer.
- gotcha Custom help option colors (`help_options_custom_colors`) need to be specified carefully. Keys in this dictionary should exactly match the option string (e.g., '--my-option' or '-m') for the color to apply correctly.
Install
-
pip install click-help-colors
Imports
- HelpColorsGroup
from click_help_colors import HelpColorsGroup
- HelpColorsCommand
from click_help_colors import HelpColorsCommand
Quickstart
import click
from click_help_colors import HelpColorsGroup, HelpColorsCommand
@click.group(
cls=HelpColorsGroup,
help_headers_color='yellow',
help_options_color='green',
help_options_custom_colors={'command2': 'red'}
)
def cli():
"""A command line interface with colored help.
This is a demonstration of click-help-colors.
"""
pass
@cli.command(
cls=HelpColorsCommand,
help_headers_color=None,
help_options_color=None,
help_options_custom_colors={'--count': 'cyan'}
)
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', default='World', help='The person to greet.')
def command1(count, name):
"""Greets the given NAME for a total of COUNT times."""
for x in range(count):
click.echo(f"Hello {name}!")
@cli.command()
def command2():
"""Another command with default colors."""
click.echo('This is command 2')
if __name__ == '__main__':
cli()