Click Help Colors

0.9.4 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to apply colored help messages to both a Click group and a subcommand using `HelpColorsGroup` and `HelpColorsCommand`. It sets global header and option colors for the group, and then overrides or adds custom option colors for `command1`.

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

view raw JSON →