Themes¶

Click Extra exposes a small theming system that controls every color used in help screens: options, choices, metavars, arguments, CLI names, defaults, environment variables, log levels, and more. Seven themes ship by default, and downstream projects can register their own.

The --theme option¶

Every command and group built with @click_extra.command / @click_extra.group automatically gets a --theme flag, alongside the other default options.

from click_extra import command, echo

@command
def weather():
    """Show the local weather forecast."""
    echo("Sunny, 22°C.")
$ weather --theme light --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

The flag is eager, so it is processed before any other option and before help is rendered. The picked theme is stored on the active Click context’s meta dict under click_extra.context.THEME and inherits down to subcommands, so a parent group’s --theme applies to every child. See the available keys table for the full inventory you can read from your own callbacks.

Automatic background detection¶

Pass --theme=auto to pick between the built-in dark and light palettes from the terminal’s background, mirroring --color=auto. Every Click Extra CLI accepts it:

$ weather --theme auto --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

Detection reads two environment variables and uses the first that resolves:

  1. CLITHEME follows the cli-theme convention. A dark or light value (optionally a mode:variant like dark:solarized) is a deliberate override and wins outright; auto falls through.

  2. COLORFGBG is set by a few terminals (rxvt, Konsole) and cached by shell-term-background at shell startup; the background is the last ;-separated field. It is read last because it is frequently stale: it reflects the value when the terminal launched and is not refreshed when you switch themes.

When none of them resolves, auto falls back to dark, so Click Extra’s default is preserved. The --theme default itself stays dark: a CLI that never asks for auto keeps the dark palette. The value is listed among the choices in --help and offered by shell completion all the same, since every Click Extra CLI takes it whether or not its author thought about it.

To make detection the effective default for your CLI, set theme = "auto" in your config file the same way you would pin any other palette:

[weather]
theme = "auto"

Querying the terminal directly¶

The environment variables above only help if something already populated them. To detect the background on terminals that set none of them, Click Extra can ask the terminal directly with an xterm OSC 11 query: it writes an escape sequence and reads the background color back. This is opt-in because it reads stdin (which can interfere with a CLI that consumes stdin itself) and only works on POSIX terminals.

Enable it by swapping the default --theme option for a ThemeOption built with query_background=True:

from click_extra import command, echo
from click_extra.commands import default_params
from click_extra.theme import ThemeOption

forecast_params = [
    ThemeOption(default="auto", query_background=True)
    if isinstance(param, ThemeOption)
    else param
    for param in default_params()
]

@command(params=forecast_params)
def forecast():
    """Show the weekly forecast."""
    echo("Rain on Thursday.")
$ forecast --help
Usage: forecast [OPTIONS]

  Show the weekly forecast.

Options:
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               auto]
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/forecast/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

forecast now defaults to the detected theme: absent a CLITHEME override, it runs the live query, which outranks the possibly-stale COLORFGBG, and only falls back to dark when neither settles the question. The query is a no-op when stdin or stdout is not a terminal (a pipe, a file, a captured test stream).

Caution

Background detection through COLORFGBG or the live query is best-effort. COLORFGBG is often missing or stale; terminal multiplexers (tmux, screen) cache or mangle the OSC 11 reply; and the query reads stdin. When the choice has to be deterministic, set --theme explicitly (on the command line or in your config file), or export CLITHEME.

The same dark-or-light question turns up across the ecosystem, split along the same environment-variable-versus-live-query line. shell-term-background (POSIX shell) and its Python reader term-background cache the answer into COLORFGBG, while the Rust crates terminal-light, termbg and terminal-colorsaurus query OSC 10/11 directly (the last two also read the Windows console).

Configuration file¶

Like every other default option, --theme reads its value from pyproject.toml:

[tool.weather]
theme = "light"

Now invocations of the weather CLI pick up the light theme without passing --theme on the command line.

Environment variables¶

To settle on one palette for every Click Extra CLI on your machine, export CLICK_EXTRA_THEME from your shell profile:

$ export CLICK_EXTRA_THEME=nord

Every command built with Click Extra reads it, including the foreign CLIs run through click-extra wrap. It takes the same values as the flag, auto included.

$ weather --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

Click derives a second variable from the command’s own name, <CLI>_THEME, which themes that one CLI. Being the more specific of the two, it wins:

$ weather --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

An unknown palette name is reported as a warning and ignored, leaving the default in place. A typo in a shell profile would otherwise break every Click Extra CLI at once, starting with the ones you need to fix it:

$ weather
warning: Ignoring CLICK_EXTRA_THEME='zenburn': not one of [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark].
warning: Ignoring CLICK_EXTRA_THEME='zenburn': not one of [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark].
Sunny, 22°C.

Precedence¶

Most specific first:

  1. --theme on the command line;

  2. <CLI>_THEME in the environment;

  3. theme in the CLI’s configuration file;

  4. CLICK_EXTRA_THEME in the environment;

  5. the built-in dark default.

The machine-wide variable sits below the configuration file on purpose: anything a user wrote for one CLI in particular says more about what they want from that CLI than a preference they set once for everything. The color variables rank the same way.

Caution

A configuration file is read too late to repaint the screens that render and exit (--help, --version, --man, --params): those are settled from the command line and the environment only. Everything the command itself prints goes through the full chain above.

Built-in themes¶

Name

Color model

Notes

dark

16 named ANSI colors

Process-wide default. Follows the user’s terminal palette.

light

16 named ANSI colors

Tuned for white backgrounds: no bright variants, blue replaces cyan.

solarized-dark

24-bit RGB

Warm-toned dark theme with selective accent contrast.

dracula

24-bit RGB

High-contrast dark theme with vivid neon accents.

nord

24-bit RGB

Cool-toned dark theme built around frost-blue and aurora accents.

monokai

24-bit RGB

Classic dark theme with high-saturation magenta and lime accents.

manpage

None (monochrome)

Bold literals, italic replaceable, no color. Shadows a man page.

Each row is keyed by the --theme choice value; access the instance via BUILTIN_THEMES["<name>"] (like BUILTIN_THEMES["dark"]). Click any name to jump to that theme’s palette listing below.

Click each tab below for a live render of the theme applied to the same weather CLI’s --help output. Colors are produced at Sphinx build time, not screenshots.

$ weather --theme dark --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme light --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme solarized-dark --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme dracula --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme nord --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme monokai --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.
$ weather --theme manpage --help
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

Tip

Prefer the terminal? Run click-extra themes to print the same gallery in your shell. The themes demo subcommand renders one sample help screen under every registered palette in turn, alphabetically: the built-in ones, plus any a configuration file adds. Name the palettes you want to compare to render only those, in the order given, as click-extra themes nord dracula. It takes auto too, and labels the screen with the palette that resolves to. A terminal keeps a single background, so the light-background themes (light, manpage) look washed out on a dark terminal, and the dark themes look washed out on a light one.

Three flavors ship with Click Extra:

  • ANSI themes (dark, light) use the 16 named ANSI colors via cloup.styling.Color, so the rendered colors track whatever palette the user’s terminal is configured with. Pick these when you want to blend in with the user’s terminal theme.

  • Branded themes (solarized-dark, dracula, nord, monokai) emit 24-bit RGB triplets from each theme’s canonical palette. Pick these when the theme name implies specific colors (solarized-dark should look like Solarized, not “whatever the terminal calls cyan”). On a terminal that does not advertise truecolor, click-extra downsamples each triplet to the nearest 256-color cell itself rather than leaving the conversion to the terminal: the choice is optimistic, keeping 24-bit unless COLORTERM is set to an explicit non-truecolor value or TERM ends in -16color (see click_extra.styling.supports_truecolor). Each theme’s slot mapping is hand-curated: there’s no automated translation from generic color-scheme formats, because none of them expose the same semantic roles we care about (option, metavar, choice, deprecated, envvar, …).

  • Monochrome theme (manpage) uses no color at all: it renders literal tokens bold and replaceable tokens italic, the way man-pages(7) typesets a command. Pick it for low-color terminals, screenshots, or output meant to read like a man page. The bold/italic split is the one in literal and replaceable slots.

click_extra.theme.BUILTIN_THEMES maps the names above to their HelpTheme instances, and theme_registry starts with the same entries. Both are mappings that build a theme on its first lookup: importing Click Extra builds none, and a help screen builds only the one it renders with. Call theme.to_dict() to get a palette as a TOML/JSON-friendly dict.

Palettes¶

Every styled slot of each built-in theme, with the swatch and attribute decorations rendered live at Sphinx build time. The block below iterates BUILTIN_THEMES and calls palette_html() for each: downstream projects with their own custom themes can drop the same loop into their own docs to get matching swatch listings.

dark¶

invoked_command
bright_white bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
bright_blue underline
Options:
constraint
magenta
(mutually exclusive)
alias
cyan bold
  show, ls     Show the current state.
alias_secondary
cyan bold dim
  show (ls)     Show the current state.
critical
red bold
CRITICAL: Database connection lost.
error
red
ERROR: Configuration file not found.
warning
yellow
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
blue
DEBUG: Resolved /etc/myapp/config.toml.
option
cyan bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
cyan bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
magenta bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
cyan dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
dim
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
yellow dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
green dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
cyan dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
red dim
--token TEXT    Authentication token.  [required]
argument
cyan italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
bright_yellow
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
bright_white bold dim
search
green
--retry-budget INTEGER    The retry budget.
success
green
âś“ database migration completed
âś“ 1,245 records imported
subheading
blue
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8

dracula¶

invoked_command
#f8f8f2 bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
#ff79c6 underline
Options:
constraint
#ff79c6
(mutually exclusive)
alias
#8be9fd bold
  show, ls     Show the current state.
alias_secondary
#8be9fd bold dim
  show (ls)     Show the current state.
critical
#ff5555 bold
CRITICAL: Database connection lost.
error
#ff5555
ERROR: Configuration file not found.
warning
#ffb86c
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
#6272a4
DEBUG: Resolved /etc/myapp/config.toml.
option
#bd93f9 bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
#bd93f9 bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
#ff79c6 bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
#bd93f9 dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
#6272a4
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
#ffb86c dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
#50fa7b dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
#bd93f9 dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
#ff5555 dim
--token TEXT    Authentication token.  [required]
argument
#bd93f9 italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
#ffb86c
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
#f8f8f2 bold dim
search
#f1fa8c
--retry-budget INTEGER    The retry budget.
success
#50fa7b
âś“ database migration completed
âś“ 1,245 records imported
subheading
#8be9fd
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8

light¶

invoked_command
black bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
magenta underline
Options:
constraint
magenta
(mutually exclusive)
alias
blue bold
  show, ls     Show the current state.
alias_secondary
blue bold dim
  show (ls)     Show the current state.
critical
red bold
CRITICAL: Database connection lost.
error
red
ERROR: Configuration file not found.
warning
magenta
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
blue dim
DEBUG: Resolved /etc/myapp/config.toml.
option
blue bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
blue bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
magenta bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
blue dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
dim
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
magenta dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
green dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
blue dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
red dim
--token TEXT    Authentication token.  [required]
argument
blue italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
red
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
black bold dim
search
green
--retry-budget INTEGER    The retry budget.
success
green
âś“ database migration completed
âś“ 1,245 records imported
subheading
blue dim
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8

manpage¶

invoked_command
bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
underline
Options:
alias
bold
  show, ls     Show the current state.
alias_secondary
bold
  show (ls)     Show the current state.
option
bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
argument
italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
separator
bold

monokai¶

invoked_command
#f8f8f2 bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
#a6e22e underline
Options:
constraint
#ae81ff
(mutually exclusive)
alias
#a6e22e bold
  show, ls     Show the current state.
alias_secondary
#a6e22e bold dim
  show (ls)     Show the current state.
critical
#f92672 bold
CRITICAL: Database connection lost.
error
#f92672
ERROR: Configuration file not found.
warning
#fd971f
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
#75715e
DEBUG: Resolved /etc/myapp/config.toml.
option
#66d9ef bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
#66d9ef bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
#ae81ff bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
#66d9ef dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
#75715e
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
#fd971f dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
#e6db74 dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
#66d9ef dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
#f92672 dim
--token TEXT    Authentication token.  [required]
argument
#66d9ef italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
#fd971f
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
#f8f8f2 bold dim
search
#e6db74
--retry-budget INTEGER    The retry budget.
success
#a6e22e
âś“ database migration completed
âś“ 1,245 records imported
subheading
#a6e22e
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8

nord¶

invoked_command
#eceff4 bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
#5e81ac underline
Options:
constraint
#b48ead
(mutually exclusive)
alias
#8fbcbb bold
  show, ls     Show the current state.
alias_secondary
#8fbcbb bold dim
  show (ls)     Show the current state.
critical
#bf616a bold
CRITICAL: Database connection lost.
error
#bf616a
ERROR: Configuration file not found.
warning
#d08770
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
#4c566a
DEBUG: Resolved /etc/myapp/config.toml.
option
#81a1c1 bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
#81a1c1 bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
#b48ead bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
#81a1c1 dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
#4c566a
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
#d08770 dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
#a3be8c dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
#81a1c1 dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
#bf616a dim
--token TEXT    Authentication token.  [required]
argument
#81a1c1 italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
#d08770
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
#e5e9f0 bold dim
search
#ebcb8b
--retry-budget INTEGER    The retry budget.
success
#a3be8c
âś“ database migration completed
âś“ 1,245 records imported
subheading
#88c0d0
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8

solarized-dark¶

invoked_command
#eee8d5 bold
Usage: my-cli [OPTIONS] COMMAND [ARGS]...
heading
#6c71c4 underline
Options:
constraint
#6c71c4
(mutually exclusive)
alias
#2aa198 bold
  show, ls     Show the current state.
alias_secondary
#2aa198 bold dim
  show (ls)     Show the current state.
critical
#dc322f bold
CRITICAL: Database connection lost.
error
#dc322f
ERROR: Configuration file not found.
warning
#b58900
WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.
debug
#586e75
DEBUG: Resolved /etc/myapp/config.toml.
option
#268bd2 bold
--config LOCATION    Location of the configuration file.
-v, --verbose        Increase verbosity.
subcommand
#268bd2 bold
Commands:
  backup        Snapshot the data store.
  restore       Restore from a snapshot.
choice
#6c71c4 bold
--format [json|csv|xml]   Output format. Defaults to json.
metavar
#268bd2 dim italic
--output TEXT       Destination file.
--workers INTEGER   Worker count.
bracket
#586e75
--port INTEGER    [env var: PORT; default: 8080; required]
envvar
#cb4b16 dim
--threshold INTEGER   Acceptable error rate.
                      [env var: THRESHOLD, TEST_THRESHOLD]
default
#859900 dim italic
--output FILENAME    Destination file.  [default: out.csv]
--retries INTEGER    Retry budget.  [default: 5]
range_label
#268bd2 dim
--level INTEGER RANGE    Verbosity level.  [0<=x<=9]
--port INTEGER RANGE     Bind port.        [x>=1024]
required
#dc322f dim
--token TEXT    Authentication token.  [required]
argument
#268bd2 italic
Usage: cp [OPTIONS] SRC DST
Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecated
#d33682
--old-api    Legacy endpoint. (DEPRECATED: use --new-api instead)
--legacy     Kept for compatibility. (deprecated: removed in v9)
separator
#93a1a1 bold dim
search
#b58900
--retry-budget INTEGER    The retry budget.
success
#859900
âś“ database migration completed
âś“ 1,245 records imported
subheading
#2aa198
â—Ľ 3 mails sharing hash a1b2c3d4
â—Ľ 7 mails sharing hash e5f6a7b8
from click_extra.theme import BUILTIN_THEMES
from click_extra.sphinx.theme_docs import palette_html

for name, theme in BUILTIN_THEMES.items():
    print(f"#### `{name}`")
    print()
    print(palette_html(theme))
    print()

Module exports¶

click_extra.theme exposes a colorless theme and a pair of accessor helpers:

  • NOCOLOR_THEME: an all-identity theme used when ANSI rendering is suppressed.

  • get_default_theme() / set_default_theme(theme): read or override the process-wide fallback. The default is the built-in dark palette. ThemeOption does not call set_default_theme: per-invocation choices live on ctx.meta instead. click_extra.cli_wrapper.patch_click() calls set_default_theme() to override the fallback for the entire patched session, and click_extra.cli_wrapper.unpatch_click() then gives back the default it replaced.

Use click_extra.theme.get_current_theme() to read the theme that applies to the current invocation: it consults the active Click context first and falls back to get_default_theme().

Adding a new built-in theme¶

A built-in theme is one entry of the _BUILTIN_THEME_DEFINITIONS mapping in click_extra/theme.py: map the theme’s name to one mapping per styled slot, the shape HelpTheme.from_dict reads and a [tool.<cli>.themes.<name>] table takes:

# click_extra/theme.py

_BUILTIN_THEME_DEFINITIONS = {
    # ...
    # Zenburn by Jani Nurminen, from the https://kippura.org/zenburnpage/ palette.
    "zenburn": {
        "invoked_command": {"fg": "#dcdccc", "bold": True},
        "heading": {"fg": "#8cd0d3", "bold": True, "underline": True},
        "option": {"fg": "#8cd0d3"},
        # ... fill in the rest of the slots.
    },
}

Entries are kept in alphabetical order; tests/test_theme.py enforces this. The slot mapping is the work: generic color-scheme catalogs (base16, pygments, iTerm palettes) don’t expose the semantic roles Click Extra needs (option, metavar, choice, deprecated, envvar, …), so each theme is hand-curated. Use the existing solarized-dark, dracula, nord, and monokai entries as templates.

Registering a custom theme¶

The list of valid --theme choices is pulled from click_extra.theme.theme_registry (plus per-invocation overrides from --config) at parse time. To add your own theme from a downstream package, call register_theme() before declaring your commands:

from click_extra import (
    BUILTIN_THEMES,
    Color,
    Style,
    command,
    echo,
    register_theme,
)

NEON = BUILTIN_THEMES["dark"].with_(
    heading=Style(fg=Color.bright_magenta, bold=True, underline=True),
    option=Style(fg=Color.bright_cyan),
    choice=Style(fg=Color.bright_yellow),
)
register_theme("neon", NEON)


@command
def cocktail():
    """Mix a cocktail."""
    echo("Cheers!")

After this runs, cocktail --theme neon becomes a valid invocation, and cocktail --help lists neon alongside the built-in choices.

Tip

For themes that depend on runtime state (terminal-background detection, environment variables, user settings), compute the HelpTheme once at startup and pass it to register_theme. The registry holds plain instances only: if you need lazy or per-invocation resolution, load the theme from [tool.<cli>.themes.<name>] (see Themes from your --config file below) so it lands on ctx.meta rather than the process-wide registry.

Anatomy of a theme¶

HelpTheme is a frozen dataclass that extends cloup.HelpTheme with extra styling slots for log levels and Click Extra’s own categories.

Use with_() to derive a new theme that only overrides a few styles:

from click_extra import BUILTIN_THEMES, Style, Color

minimal = BUILTIN_THEMES["dark"].with_(
    option=Style(fg=Color.white),
    choice=Style(fg=Color.white, dim=True),
)

with_() returns the same instance when no styles change and validates that all keyword arguments match a known field, so typos like optoin=... raise immediately.

Literal and replaceable slots¶

The styling slots carry a second, coarser classification borrowed from man-pages(7): literal tokens the user types verbatim versus replaceable tokens the user substitutes with a real value. Man pages render the former in bold and the latter in italic, “even in the SYNOPSIS section”. click_extra.theme records that mapping as two frozensets of slot names:

  • LITERAL_STYLES: invoked_command, subcommand, alias, alias_secondary, option, choice, separator.

  • REPLACEABLE_STYLES: metavar, argument.

Every remaining slot (log levels, the [default: ...] and [env var: ...] bracket fields, headings, …) sits outside the dichotomy. Every built-in theme applies this split: literal slots render bold and replaceable slots italic, even inside the color palettes, and the manpage theme renders it with nothing else. The man-page generator follows the same split, setting each token in roff’s \fB or \fI.

Cross-reference highlighting¶

The cross_ref_highlight flag (default True) controls whether option names, choices, arguments, metavars, and CLI names are highlighted wherever they appear in free-form prose. Disable it for a calmer help screen:

calm = BUILTIN_THEMES["dark"].with_(cross_ref_highlight=False)

See Cross-reference highlighting for the details on what stays styled when the flag is off.

Manual loading from a mapping¶

HelpTheme.to_dict() and HelpTheme.from_dict() round-trip a theme through plain mappings, so a theme can live in a TOML, JSON, or YAML file alongside the rest of an application’s configuration:

[my_theme]
option = { fg = "cyan" }
heading = { fg = "bright_blue", bold = true, underline = true }
choice = { fg = "magenta" }
import tomllib
from pathlib import Path

from click_extra import HelpTheme, register_theme

raw = tomllib.loads(Path("config.toml").read_text())
register_theme("my_theme", HelpTheme.from_dict(raw["my_theme"]))

to_dict() only emits slots that diverge from the default (identity / None), and from_dict() raises TypeError on unknown keys, so configuration typos surface at load time rather than silently producing a half-styled theme.

For the much more common case where the theme should live in the same --config file the CLI already reads, see the next section: click-extra wires the loader for you.

Themes from your config file¶

ConfigOption recognizes a themes sub-table inside the app’s section. Every [<cli>.themes.<name>] entry is parsed via HelpTheme.from_dict and made available to --theme for the duration of the invocation, with two distinct behaviors depending on whether <name> matches a built-in:

  • Override an existing palette. Re-declare a built-in name (dark, dracula, light, …) and the slots you set are overlaid on top of the built-in palette via HelpTheme.cascade. Unset slots inherit from the built-in, so a one-line override like option = { fg = "bright_cyan" } is enough.

  • Define a new palette. Use any other name and --theme <name> becomes a valid choice for that invocation. Unset slots default to no styling (identity), so you typically declare a slot for every category you care about.

In both cases the theme registry mutation is per-invocation: it lives on ctx.meta under click_extra.context.THEME_OVERRIDES and never touches the module-level theme_registry. Sphinx builds, test runners, and any other host process running multiple CLI invocations back-to-back never leak themes between them.

Override an existing built-in¶

from click_extra import command, echo

@command
def weather():
    """Show the local weather forecast."""
    echo("Sunny, 22°C.")

Drop the override under [<cli>.themes.dark] in your weather.toml:

[weather.themes.dark]
option = { fg = "bright_cyan" }
choice = { fg = "yellow", bold = true }

Then ask for --help with the override applied (the rest of the dark palette stays put):

$ weather --config /tmp/tmpigj8gvbl/weather.toml --help
Load configuration matching /tmp/tmpigj8gvbl/weather.toml
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               dark]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

Define a brand-new theme¶

[weather.themes.midnight]
option = { fg = "blue", bold = true }
heading = { fg = "magenta" }
choice = { fg = "yellow" }
default = { fg = "green", italic = true }

The new name immediately shows up in --help’s --theme metavar and is selectable on the command line:

$ weather --config /tmp/tmpndfipi9m/weather.toml --help
Load configuration matching /tmp/tmpndfipi9m/weather.toml
Usage: weather [OPTIONS]

  Show the local weather forecast.

Options:
  -h, --help                   Show this message and exit.

Configuration options:
  --config LOCATION            Location of the configuration file. Supports
                               local path with glob patterns or remote URL.
                               [default: ~/.config/weather/]
  --no-config                  Ignore all configuration files and only use
                               command line parameters and environment
                               variables.
  --validate-config LOCATION   Validate the configuration file and exit.
  --export-config FORMAT       Export the configuration in the selected format
                               to <stdout>, then exit.

Output options:
  --accessible                 Accessibility mode: disable colors and render
                               tables in a borderless, screen-reader-friendly
                               format.
  --color [auto|always|never]  Colorize the output. A bare --color is the same
                               as --color=always.  [default: auto]
  --no-color                   Disable colorization (alias of --color=never).
  --progress / --no-progress   Show progress indicators during long operations.
                               Disabled for non-interactive output (pipes, dumb
                               terminals, CI) and by --accessible.  [default:
                               progress]
  --theme [auto|dark|dracula|light|manpage|midnight|monokai|nord|solarized-dark]
                               Color theme used for help screens.  [default:
                               midnight]
  --table-format FORMAT        Rendering style of tables.  [default: rounded-
                               outline]

Logging options:
  --verbosity LEVEL            Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
                               [default: WARNING]
  -v, --verbose                Increase the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  -q, --quiet                  Decrease the default WARNING verbosity by one
                               level for each additional repetition of the
                               option.  [default: 0]
  --debug                      Shorthand for --verbosity DEBUG.

Introspection options:
  --time / --no-time           Measure and print elapsed execution time.
                               [default: no-time]
  --params                     Show all CLI parameters, their provenance,
                               defaults and value, then exit.
  --tree                       Show the tree of nested subcommands and exit.
  --man                        Read the command's manual page and exit.
  --help-format [carapace|json|json-full|man|markdown|markdown-full]
                               Render the command in the given format and exit.
  --version                    Show the version and exit.

The same [weather] theme = "midnight" selector you’d use for a built-in works here: pre-pick the new theme as the default for invocations of this CLI.

Validation¶

Malformed entries surface as ValidationError with a path rooted at the configuration file root, both during --validate-config and at normal load time:

[weather.themes.midnight]
optoin = { fg = "blue" } # typo
$ weather --validate-config /tmp/tmpk6jooyk2/weather.toml
Configuration validation error: weather.themes.midnight: Unknown HelpTheme field(s): optoin

The built-in ConfigValidator for the themes sub-tree is auto-registered on every ConfigOption, so app authors don’t have to opt in. Apps that ship their own ConfigValidator continue to work alongside it.

Eyeball it before you ship it¶

A palette defined in a configuration file joins the gallery of click-extra themes, so you can see it drawn on a real help screen without wiring it into your own CLI first. Copy the table under a click-extra header, then name it:

[click-extra.themes.orchard]
heading = { fg = "bright_magenta", underline = true }
option = { fg = "bright_green", bold = true }
metavar = { fg = "yellow", italic = true }
$ click-extra --config orchard.toml themes orchard

Add auto to draw the palette your terminal resolves to right beside it, which says whether your own colors sit closer to the dark or the light built-in:

$ click-extra --config orchard.toml themes orchard auto

A terminal keeps one background, so the gallery cannot answer whether a palette reads on the other one. click-extra screenshot --background can: it draws the same screen on light chrome and on dark, side by side, which is the check a theme meant for both has to pass.

$ click-extra --config orchard.toml screenshot --output orchard-dark.svg -- my-cli --theme orchard --help
$ click-extra --config orchard.toml screenshot --output orchard-light.svg --background light -- my-cli --theme orchard --help

Interaction with --color / --no-color¶

--theme controls which colors are used. --color / --no-color controls whether colors are emitted at all. The two are independent:

  • --theme light with --no-color emits no ANSI codes.

  • --theme dark with --color (the default) emits the dark theme’s ANSI codes.

  • NO_COLOR=1 in the environment overrides any --theme choice by silencing all ANSI output.

The --color callback inspects the standard set of color environment variables (NO_COLOR, CLICOLOR, FORCE_COLOR, LLM, etc.) before the theme is applied: see COLOR_ENVVARS for the full list.