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:
CLITHEMEfollows the cli-theme convention. Adarkorlightvalue (optionally amode:variantlikedark:solarized) is a deliberate override and wins outright;autofalls through.COLORFGBGis 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:
--themeon the command line;<CLI>_THEMEin the environment;themein the CLI’s configuration file;CLICK_EXTRA_THEMEin the environment;the built-in
darkdefault.
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 |
|---|---|---|
16 named ANSI colors |
Process-wide default. Follows the user’s terminal palette. |
|
16 named ANSI colors |
Tuned for white backgrounds: no bright variants, blue replaces cyan. |
|
24-bit RGB |
Warm-toned dark theme with selective accent contrast. |
|
24-bit RGB |
High-contrast dark theme with vivid neon accents. |
|
24-bit RGB |
Cool-toned dark theme built around frost-blue and aurora accents. |
|
24-bit RGB |
Classic dark theme with high-saturation magenta and lime accents. |
|
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 viacloup.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-darkshould 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 unlessCOLORTERMis set to an explicit non-truecolor value orTERMends in-16color(seeclick_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 wayman-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_commandbright_whiteboldUsage: my-cli [OPTIONS] COMMAND [ARGS]...headingbright_blueunderlineOptions:constraintmagenta(mutually exclusive)aliascyanboldshow, ls Show the current state.alias_secondarycyanbold dimshow (ls) Show the current state.
criticalredboldCRITICAL: Database connection lost.errorredERROR: Configuration file not found.warningyellowWARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debugblueDEBUG: Resolved /etc/myapp/config.toml.optioncyanbold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommandcyanboldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choicemagentabold--format [json|csv|xml] Output format. Defaults to json.
metavarcyandim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket- dim
--port INTEGER [env var: PORT; default: 8080; required] envvaryellowdim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]defaultgreendim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_labelcyandim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
requiredreddim--token TEXT Authentication token. [required]argumentcyanitalicUsage: cp [OPTIONS] SRC DST Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecatedbright_yellow--old-api Legacy endpoint. (DEPRECATED: use --new-api instead) --legacy Kept for compatibility. (deprecated: removed in v9)
separatorbright_whitebold dimsearchgreen--retry-budget INTEGER The retry budget.
successgreenâś“ database migration completed âś“ 1,245 records imported
subheadingblueâ—Ľ 3 mails sharing hash a1b2c3d4 â—Ľ 7 mails sharing hash e5f6a7b8
dracula¶
invoked_command#f8f8f2boldUsage: my-cli [OPTIONS] COMMAND [ARGS]...heading#ff79c6underlineOptions:constraint#ff79c6(mutually exclusive)alias#8be9fdboldshow, ls Show the current state.alias_secondary#8be9fdbold dimshow (ls) Show the current state.
critical#ff5555boldCRITICAL: Database connection lost.error#ff5555ERROR: Configuration file not found.warning#ffb86cWARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debug#6272a4DEBUG: Resolved /etc/myapp/config.toml.option#bd93f9bold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommand#bd93f9boldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choice#ff79c6bold--format [json|csv|xml] Output format. Defaults to json.
metavar#bd93f9dim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket#6272a4--port INTEGER [env var: PORT; default: 8080; required]envvar#ffb86cdim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]default#50fa7bdim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_label#bd93f9dim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
required#ff5555dim--token TEXT Authentication token. [required]argument#bd93f9italicUsage: 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#f8f8f2bold dimsearch#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_commandblackboldUsage: my-cli [OPTIONS] COMMAND [ARGS]...headingmagentaunderlineOptions:constraintmagenta(mutually exclusive)aliasblueboldshow, ls Show the current state.alias_secondarybluebold dimshow (ls) Show the current state.
criticalredboldCRITICAL: Database connection lost.errorredERROR: Configuration file not found.warningmagentaWARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debugbluedimDEBUG: Resolved /etc/myapp/config.toml.optionbluebold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommandblueboldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choicemagentabold--format [json|csv|xml] Output format. Defaults to json.
metavarbluedim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket- dim
--port INTEGER [env var: PORT; default: 8080; required] envvarmagentadim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]defaultgreendim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_labelbluedim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
requiredreddim--token TEXT Authentication token. [required]argumentblueitalicUsage: cp [OPTIONS] SRC DST Usage: pack [OPTIONS] [FILES]... [OUTPUT]
deprecatedred--old-api Legacy endpoint. (DEPRECATED: use --new-api instead) --legacy Kept for compatibility. (deprecated: removed in v9)
separatorblackbold dimsearchgreen--retry-budget INTEGER The retry budget.
successgreenâś“ database migration completed âś“ 1,245 records imported
subheadingbluedimâ—Ľ 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#f8f8f2boldUsage: my-cli [OPTIONS] COMMAND [ARGS]...heading#a6e22eunderlineOptions:constraint#ae81ff(mutually exclusive)alias#a6e22eboldshow, ls Show the current state.alias_secondary#a6e22ebold dimshow (ls) Show the current state.
critical#f92672boldCRITICAL: Database connection lost.error#f92672ERROR: Configuration file not found.warning#fd971fWARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debug#75715eDEBUG: Resolved /etc/myapp/config.toml.option#66d9efbold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommand#66d9efboldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choice#ae81ffbold--format [json|csv|xml] Output format. Defaults to json.
metavar#66d9efdim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket#75715e--port INTEGER [env var: PORT; default: 8080; required]envvar#fd971fdim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]default#e6db74dim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_label#66d9efdim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
required#f92672dim--token TEXT Authentication token. [required]argument#66d9efitalicUsage: 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#f8f8f2bold dimsearch#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#eceff4boldUsage: my-cli [OPTIONS] COMMAND [ARGS]...heading#5e81acunderlineOptions:constraint#b48ead(mutually exclusive)alias#8fbcbbboldshow, ls Show the current state.alias_secondary#8fbcbbbold dimshow (ls) Show the current state.
critical#bf616aboldCRITICAL: Database connection lost.error#bf616aERROR: Configuration file not found.warning#d08770WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debug#4c566aDEBUG: Resolved /etc/myapp/config.toml.option#81a1c1bold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommand#81a1c1boldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choice#b48eadbold--format [json|csv|xml] Output format. Defaults to json.
metavar#81a1c1dim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket#4c566a--port INTEGER [env var: PORT; default: 8080; required]envvar#d08770dim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]default#a3be8cdim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_label#81a1c1dim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
required#bf616adim--token TEXT Authentication token. [required]argument#81a1c1italicUsage: 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#e5e9f0bold dimsearch#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#eee8d5boldUsage: my-cli [OPTIONS] COMMAND [ARGS]...heading#6c71c4underlineOptions:constraint#6c71c4(mutually exclusive)alias#2aa198boldshow, ls Show the current state.alias_secondary#2aa198bold dimshow (ls) Show the current state.
critical#dc322fboldCRITICAL: Database connection lost.error#dc322fERROR: Configuration file not found.warning#b58900WARNING: Requested 16 jobs exceeds the 8 logical CPUs: honored, but pays only for I/O-bound work.debug#586e75DEBUG: Resolved /etc/myapp/config.toml.option#268bd2bold--config LOCATION Location of the configuration file. -v, --verbose Increase verbosity.
subcommand#268bd2boldCommands: backup Snapshot the data store. restore Restore from a snapshot.
choice#6c71c4bold--format [json|csv|xml] Output format. Defaults to json.
metavar#268bd2dim italic--output TEXT Destination file. --workers INTEGER Worker count.
bracket#586e75--port INTEGER [env var: PORT; default: 8080; required]envvar#cb4b16dim--threshold INTEGER Acceptable error rate. [env var: THRESHOLD, TEST_THRESHOLD]default#859900dim italic--output FILENAME Destination file. [default: out.csv] --retries INTEGER Retry budget. [default: 5]
range_label#268bd2dim--level INTEGER RANGE Verbosity level. [0<=x<=9] --port INTEGER RANGE Bind port. [x>=1024]
required#dc322fdim--token TEXT Authentication token. [required]argument#268bd2italicUsage: 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#93a1a1bold dimsearch#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-identitytheme 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-indarkpalette.ThemeOptiondoes not callset_default_theme: per-invocation choices live onctx.metainstead.click_extra.cli_wrapper.patch_click()callsset_default_theme()to override the fallback for the entire patched session, andclick_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 viaHelpTheme.cascade. Unset slots inherit from the built-in, so a one-line override likeoption = { 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 lightwith--no-coloremits no ANSI codes.--theme darkwith--color(the default) emits the dark theme’s ANSI codes.NO_COLOR=1in the environment overrides any--themechoice 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.