Skip to content

rich_click.rich_click_theme

Attributes

NameDescription
COLORSNo description.
FORMATSNo description.
ThemeTypeNo description.

Classes

NameDescription
RichClickThemeA named set of styles for the help output. Select one with --theme or the theme setting.
RichClickThemeNotFoundRaise when a theme is not found.

Functions

NameDescription
get_themeGet the theme based on the string name.
parse_background_themeParse a light/dark theme pair such as "dark:nord-modern,light:solarized-modern".
resolve_background_themePick a theme name based on the terminal background.
theme_needs_backgroundWhether picking this theme depends on the terminal background.

COLORSattributemodule attribute#

COLORS: dict[str, RichClickTheme] = _colors

FORMATSattributemodule attribute#

FORMATS: dict[str, RichClickTheme] = {
  'box': RichClickTheme(
    name='box',
    description='[b](Default)[/b] Original rich-click format with boxes',
    styles=_BOX_STYLES
  ),
  'square': RichClickTheme(
    name='square',
    description='Original rich-click format with square boxes',
    styles={
      : _BOX_STYLES,
      'style_options_panel_box': 'SQUARE',
      'style_commands_panel_box': 'SQUARE',
      'style_errors_panel_box': 'SQUARE'
    }
  ),
  'nu': RichClickTheme(
    name='nu',
    description='Great balance of compactness, legibility, and style',
    post_combine_callback=_not_dim_title_callback,
    styles={
      'style_options_panel_box': 'HORIZONTALS_DOUBLE_TOP',
      'style_commands_panel_box': 'HORIZONTALS_DOUBLE_TOP',
      'style_errors_panel_box': 'ROUNDED',
      'style_options_table_box': None,
      'style_commands_table_box': None,
      'style_options_table_expand': False,
      'style_commands_table_expand': False,
      'panel_title_string': '{}',
      'style_options_panel_padding': 0,
      'style_commands_panel_padding': 0,
      'deprecated_string': '(Deprecated)',
      'deprecated_with_reason_string': '(Deprecated: {})',
      'default_string': '(Default: {})',
      'envvar_string': '(Env: {})',
      'required_long_string': '(Required)',
      'range_string': '{}',
      'append_range_help_string': '(Range: {})',
      'append_metavars_help_string': '\\[{}]',
      'required_short_string': '#',
      'padding_header_text': (0, 1, 1, 1),
      'padding_helptext': (0, 1, 1, 1),
      'padding_usage': (0, 1, 1, 1),
      'delimiter_comma': ',',
      'delimiter_slash': '/',
      'panel_title_padding': 1,
      'options_table_column_types': ['required', 'opt_long', 'opt_short', 'help'],
      'commands_table_column_types': ['name', 'aliases', 'help'],
      'options_table_help_sections': ['help', 'metavar', 'required', 'default', 'envvar', 'deprecated'],
      'commands_table_help_sections': ['help', 'deprecated'],
      'panel_inline_help_delimiter': ' - ',
      'padding_epilog': (0, 0, 1, 1),
      'padding_footer_text': (0, 0, 1, 1),
      'panel_inline_help_in_title': False
    }
  ),
  'slim': RichClickTheme(
    name='slim',
    description='Simple, classic, no-fuss CLI format',
    post_combine_callback=_not_dim_title_callback,
    styles={
      'style_options_panel_box': 'BLANK',
      'style_commands_panel_box': 'BLANK',
      'style_errors_panel_box': 'ROUNDED',
      'style_options_table_box': None,
      'style_commands_table_box': None,
      'style_options_table_expand': False,
      'style_commands_table_expand': False,
      'panel_title_string': '{}:',
      'style_options_panel_padding': (0, 0, 0, 1),
      'style_commands_panel_padding': (0, 0, 0, 1),
      'padding_header_text': (0, 0, 1, 0),
      'padding_helptext': (0, 0, 1, 0),
      'padding_usage': (0, 0, 1, 0),
      'padding_epilog': (0, 0, 1, 0),
      'padding_footer_text': (0, 0, 1, 0),
      'options_table_column_types': ['opt_short', 'opt_long_metavar', 'help'],
      'commands_table_column_types': ['name_with_aliases', 'help'],
      'options_table_help_sections': ['help', 'range', 'required', 'default', 'envvar', 'deprecated'],
      'commands_table_help_sections': ['help', 'deprecated'],
      'append_metavars_help_string': '<{}>',
      'envvar_string': '\\[env: {}=]',
      'delimiter_comma': ', ',
      'delimiter_slash': '/',
      'panel_title_padding': 0,
      'panel_inline_help_in_title': True,
      'panel_inline_help_delimiter': ' ',
      'deprecated_string': '\\[deprecated]',
      'deprecated_with_reason_string': '\\[deprecated: {}]',
      'default_string': '\\[default={}]',
      'required_long_string': '\\[required]',
      'range_string': '{}',
      'append_range_help_string': '\\[range: {}]',
      'required_short_string': '*'
    }
  ),
  'modern': RichClickTheme(
    name='modern',
    description='Beautiful modern look',
    post_combine_callback=_not_dim_title_callback,
    styles={
      'style_options_panel_box': None,
      'style_commands_panel_box': None,
      'style_errors_panel_box': 'ROUNDED',
      'style_options_table_box': 'HORIZONTALS_TOP',
      'style_commands_table_box': 'HORIZONTALS_TOP',
      'style_options_table_expand': True,
      'style_commands_table_expand': True,
      'panel_title_string': '{}',
      'style_options_panel_padding': 0,
      'style_commands_panel_padding': 0,
      'padding_header_text': (1, 2, 0, 3),
      'padding_helptext': (0, 2, 1, 2),
      'padding_usage': (1, 2, 1, 2),
      'options_table_column_types': ['opt_short', 'opt_long', 'metavar', 'help'],
      'commands_table_column_types': ['name', 'aliases', 'help'],
      'options_table_help_sections': ['required', 'help', 'envvar', 'default', 'deprecated'],
      'commands_table_help_sections': ['help', 'deprecated'],
      'deprecated_string': '\\[deprecated]',
      'deprecated_with_reason_string': '\\[deprecated: {}]',
      'envvar_string': '\\[env={}]',
      'default_string': '\\[default={}]',
      'append_metavars_help_string': '\\[{}]',
      'panel_inline_help_in_title': True,
      'delimiter_comma': ', ',
      'delimiter_slash': ' / ',
      'panel_title_padding': 0,
      'required_short_string': '*',
      'panel_inline_help_delimiter': ' - ',
      'required_long_string': '\\[required]',
      'range_string': '[{}]',
      'append_range_help_string': '\\[{}]',
      'padding_epilog': (0, 2, 1, 2),
      'padding_footer_text': (0, 2, 1, 2)
    }
  ),
  'robo': RichClickTheme(
    name='robo',
    description='Spacious with sharp corners',
    post_combine_callback=_not_dim_title_callback,
    styles={
      'style_options_panel_box': 'SQUARE',
      'style_commands_panel_box': 'SQUARE',
      'style_errors_panel_box': 'SQUARE',
      'style_options_table_box': None,
      'style_commands_table_box': None,
      'style_options_panel_padding': (1, 2),
      'style_commands_panel_padding': (1, 2),
      'style_options_table_expand': True,
      'style_commands_table_expand': True,
      'padding_header_text': (0, 0, 1, 0),
      'padding_helptext': (0, 0, 1, 0),
      'padding_usage': (0, 0, 1, 0),
      'deprecated_string': '❮[b]DEPRECATED[/b]❯',
      'deprecated_with_reason_string': '❮[b]DEPRECATED:[/b] {}❯',
      'envvar_string': '❮[b]ENV:[/b] {}=❯',
      'default_string': '❮[b]DEFAULT:[/b] {}❯',
      'append_metavars_help_string': '❮{}❯',
      'required_short_string': '*',
      'required_long_string': '❮[b]REQUIRED[/b]❯',
      'range_string': '{}',
      'append_range_help_string': '❮[b]RANGE[/b]: {}❯',
      'options_table_column_types': ['opt_primary', 'opt_secondary', 'metavar', 'help'],
      'commands_table_column_types': ['name', 'aliases', 'help'],
      'options_table_help_sections': ['required', 'help', 'deprecated', 'default', 'envvar'],
      'commands_table_help_sections': ['help', 'deprecated'],
      'delimiter_comma': ', ',
      'delimiter_slash': ' / ',
      'panel_title_padding': 2,
      'panel_title_string': '{}',
      'panel_inline_help_delimiter': ' - ',
      'padding_epilog': (0, 0, 1, 0),
      'padding_footer_text': (0, 0, 1, 0),
      'panel_inline_help_in_title': False
    }
  )
}

ThemeTypeattributemodule attribute#

ThemeType = Literal['color', 'format', 'combined']

RichClickThemeclass#

class RichClickTheme(name: str, *, description: str | None = None, hidden: bool = False, styles: dict[str, Any] | None = None, primary_colors: list[StyleType] | None = None, post_combine_callback: Callable[[dict[str, Any]], dict[str, Any]] | None = None, light_variant: str | None = None)

A named set of styles for the help output. Select one with --theme or the theme setting.

Create RichTheme instance.

Parameters

NameTypeDefaultDescription
namestrrequiredName of the theme.
descriptionstr | NoneNoneDescription for the theme.
hiddenboolFalseIf true, hide from rich-click –themes.
stylesdict[str, Any] | NoneNoneDict of styles that are applied.
primary_colorslist[StyleType] | NoneNoneDescription of which colors are applied. Does not do anything, just serves as documentation.
post_combine_callbackCallable[[dict[str, Any]], dict[str, Any]] | NoneNoneAfter combining two themes, function is called which adjusts the styles.
light_variantstr | NoneNoneName of a color palette to use instead of this one when the terminal has a light background.

descriptionattributeinstance attribute#

description = description

hiddenattributeinstance attribute#

hidden = hidden

light_variantattributeinstance attribute#

light_variant = light_variant

nameattributeinstance attribute#

name = name

post_combine_callbackattributeinstance attribute#

post_combine_callback = post_combine_callback

primary_colorsattributeinstance attribute#

primary_colors = primary_colors or []

stylesattributeinstance attribute#

styles = styles or {}

combinemethod#

def combine(other: RichClickTheme) -> RichClickTheme

RichClickThemeNotFoundclass#

class RichClickThemeNotFound(KeyError)

Bases: KeyError

Raise when a theme is not found.

get_themefunction#

def get_theme(theme: str, raise_key_error: bool = True, resolve_background: bool = True) -> RichClickTheme

Get the theme based on the string name.

If resolve_background is true, the terminal background may be detected to pick from a light/dark pair, or to use a palette’s light variant.

parse_background_themefunction#

def parse_background_theme(theme: str) -> dict[str, str] | None

Parse a light/dark theme pair such as "dark:nord-modern,light:solarized-modern".

Returns None if the string is not a theme pair.

resolve_background_themefunction#

def resolve_background_theme(theme: str) -> str

Pick a theme name based on the terminal background.

  • Light/dark pairs ("dark:nord-modern,light:solarized-modern") resolve to one of the two themes. If the background cannot be detected, the first theme listed is used.
  • Palettes with a light variant (e.g. nord) switch to it (nord_light) on light backgrounds.
  • All other theme names are returned unchanged.

theme_needs_backgroundfunction#

def theme_needs_background(theme: str) -> bool

Whether picking this theme depends on the terminal background.