Skip to content

API Reference

CLI entry point

rich_gradient_cli

rich-gradient-cli: render text, files, URLs, and stdin with rich-gradient.

The package exposes a single Typer application, :data:app, installed as the gradient console script.

VERSION module-attribute

VERSION = version('rich-gradient-cli')

__all__ module-attribute

__all__ = ['VERSION', 'app', 'entrypoint']

__version__ module-attribute

__version__ = VERSION

app module-attribute

app = Typer(add_completion=False, rich_markup_mode='rich', no_args_is_help=False, context_settings={'help_option_names': ['--help']}, help='Render text, files, URLs, or stdin with a [b]rich-gradient[/b] gradient.\n\nRESOURCE is a file path, an http(s) URL, [b]-[/b] for stdin, or literal text. The renderable is auto-detected from the file extension unless a mode flag such as [b]--markdown[/b] is given.', epilog='https://maxludden.github.io/rich-gradient-cli')

entrypoint

entrypoint() -> None

Console-script entry point for gradient.

Runs the app, then sends the opt-in telemetry event only when the command completed successfully (not for --help, --telemetry or usage errors).

Command

rich_gradient_cli.cli

The gradient command: one command, modeled on Textualize/rich-cli.

ANIMATION module-attribute

ANIMATION = 'Animation'

CONTENT module-attribute

CONTENT = 'Content'

EXIT_ERROR module-attribute

EXIT_ERROR = 1

GRADIENT module-attribute

GRADIENT = 'Gradient'

LAYOUT module-attribute

LAYOUT = 'Layout'

OUTPUT module-attribute

OUTPUT = 'Output'

RENDERABLE module-attribute

RENDERABLE = 'Renderable'

VERSION module-attribute

VERSION = version('rich-gradient-cli')

__all__ module-attribute

__all__ = ['VERSION', 'app', 'invoked_mode', 'main']

app module-attribute

app = Typer(add_completion=False, rich_markup_mode='rich', no_args_is_help=False, context_settings={'help_option_names': ['--help']}, help='Render text, files, URLs, or stdin with a [b]rich-gradient[/b] gradient.\n\nRESOURCE is a file path, an http(s) URL, [b]-[/b] for stdin, or literal text. The renderable is auto-detected from the file extension unless a mode flag such as [b]--markdown[/b] is given.', epilog='https://maxludden.github.io/rich-gradient-cli')

invoked_mode module-attribute

invoked_mode: str | None = None

Box

Bases: str, Enum

Panel border styles (keys of :data:rich_gradient_cli.options.BOXES).

ASCII class-attribute instance-attribute
ASCII = 'ascii'
ASCII2 class-attribute instance-attribute
ASCII2 = 'ascii2'
DOUBLE class-attribute instance-attribute
DOUBLE = 'double'
HEAVY class-attribute instance-attribute
HEAVY = 'heavy'
NONE class-attribute instance-attribute
NONE = 'none'
ROUNDED class-attribute instance-attribute
ROUNDED = 'rounded'
SQUARE class-attribute instance-attribute
SQUARE = 'square'

SpectrumOutput

Bases: str, Enum

Output format for --spectrum.

CSV class-attribute instance-attribute
CSV = 'csv'
HEX class-attribute instance-attribute
HEX = 'hex'
NAMES class-attribute instance-attribute
NAMES = 'names'
TABLE class-attribute instance-attribute
TABLE = 'table'

TelemetryAction

Bases: str, Enum

Actions accepted by --telemetry.

DISABLE class-attribute instance-attribute
DISABLE = 'disable'
ENABLE class-attribute instance-attribute
ENABLE = 'enable'
STATUS class-attribute instance-attribute
STATUS = 'status'

VerticalAlign

Bases: str, Enum

Vertical alignment.

BOTTOM class-attribute instance-attribute
BOTTOM = 'bottom'
MIDDLE class-attribute instance-attribute
MIDDLE = 'middle'
TOP class-attribute instance-attribute
TOP = 'top'

main

main(resource: Annotated[Optional[str], Argument(metavar="[PATH,TEXT,URL, or '-']", show_default=False, help="File, URL, '-' for stdin, or literal text.")] = None, print_: Annotated[bool, Option(--print, -p, help='Print console markup as gradient text.', rich_help_panel=RENDERABLE)] = False, rule: Annotated[bool, Option(--rule, -u, help='Display a horizontal rule titled RESOURCE.', rich_help_panel=RENDERABLE)] = False, json_: Annotated[bool, Option(--json, -J, help='Display as JSON.', rich_help_panel=RENDERABLE)] = False, markdown: Annotated[bool, Option(--markdown, -m, help='Display as Markdown.', rich_help_panel=RENDERABLE)] = False, rst: Annotated[bool, Option(--rst, help='Display reStructuredText.', rich_help_panel=RENDERABLE)] = False, csv_: Annotated[bool, Option(--csv, help='Display CSV/TSV as a table.', rich_help_panel=RENDERABLE)] = False, ipynb: Annotated[bool, Option(--ipynb, help='Display a Jupyter notebook.', rich_help_panel=RENDERABLE)] = False, syntax: Annotated[bool, Option(--syntax, help='Syntax highlighting.', rich_help_panel=RENDERABLE)] = False, inspect: Annotated[bool, Option(--inspect, help="Inspect a Python object, e.g. 'str' or 'rich.console.Console'. Imports/evals RESOURCE: never pass untrusted text.", rich_help_panel=RENDERABLE)] = False, tree: Annotated[bool, Option(--tree, help='Display a directory (or lines of text) as a tree.', rich_help_panel=RENDERABLE)] = False, columns: Annotated[bool, Option(--columns, help='Lay out each line as a column cell.', rich_help_panel=RENDERABLE)] = False, spectrum: Annotated[bool, Option(--spectrum, help='Show the rich-gradient color spectrum.', rich_help_panel=RENDERABLE)] = False, colors: Annotated[Optional[str], Option(--colors, envvar=GRADIENT_COLORS, metavar=COLORS, help='Comma-separated gradient colors (names, hex, CSS names).', rich_help_panel=GRADIENT)] = None, bgcolors: Annotated[Optional[str], Option(--bgcolors, metavar=COLORS, help='Comma-separated background colors.', rich_help_panel=GRADIENT)] = None, rainbow: Annotated[bool, Option(--rainbow, help='Use the rainbow spectrum (ignores --colors).', rich_help_panel=GRADIENT)] = False, hues: Annotated[int | None, Option(--hues, min=2, max=17, help='Number of spectrum hues for --rainbow / no colors (default 5), or for --spectrum (default all 17).', rich_help_panel=GRADIENT)] = None, repeat_scale: Annotated[Optional[float], Option(--repeat - scale, min=0.01, help='How many times the gradient repeats across the output.', rich_help_panel=GRADIENT)] = None, highlight_word: Annotated[Optional[list[str]], Option(--highlight - word, metavar='WORD=STYLE', help='Style a word (repeatable).', rich_help_panel=GRADIENT)] = None, highlight_regex: Annotated[Optional[list[str]], Option(--highlight - regex, metavar='PATTERN=STYLE', help='Style regex matches (repeatable).', rich_help_panel=GRADIENT)] = None, animate: Annotated[bool, Option(--animate, help='Animate the gradient (interactive terminals only).', rich_help_panel=GRADIENT)] = False, duration: Annotated[Optional[float], Option(--duration, min=0.01, help='Stop animating after this many seconds.', rich_help_panel=GRADIENT)] = None, left: Annotated[bool, Option(--left, -l, help='Align block to the left.', rich_help_panel=LAYOUT)] = False, right: Annotated[bool, Option(--right, -r, help='Align block to the right.', rich_help_panel=LAYOUT)] = False, center: Annotated[bool, Option(--center, -c, help='Align block to the center.', rich_help_panel=LAYOUT)] = False, text_left: Annotated[bool, Option(--text - left, -L, help='Justify text to the left.', rich_help_panel=LAYOUT)] = False, text_right: Annotated[bool, Option(--text - right, -R, help='Justify text to the right.', rich_help_panel=LAYOUT)] = False, text_center: Annotated[bool, Option(--text - center, -C, help='Justify text to the center.', rich_help_panel=LAYOUT)] = False, text_full: Annotated[bool, Option(--text - full, -F, help='Justify text to both edges.', rich_help_panel=LAYOUT)] = False, vertical_align: Annotated[VerticalAlign, Option(--vertical - align, help='Vertically align the block.', rich_help_panel=LAYOUT)] = VerticalAlign.MIDDLE, width: Annotated[Optional[int], Option(--width, -w, min=1, metavar=SIZE, help='Fit output to SIZE characters.', rich_help_panel=LAYOUT)] = None, max_width: Annotated[Optional[int], Option(--max - width, -W, min=1, metavar=SIZE, help='Set maximum width to SIZE characters.', rich_help_panel=LAYOUT)] = None, expand: Annotated[Optional[bool], Option(--expand / --no - expand, -e, help='Expand to full width (default: auto).', rich_help_panel=LAYOUT)] = None, padding: Annotated[Optional[str], Option(--padding, -d, metavar=(TOP, RIGHT, BOTTOM, LEFT), help='Padding around output: 1, 2 or 4 comma-separated integers.', rich_help_panel=LAYOUT)] = None, panel: Annotated[Optional[Box], Option(--panel, -a, metavar=BOX, help='Wrap the output in a gradient panel: ascii, ascii2, square, rounded, heavy, double, none.', rich_help_panel=LAYOUT)] = None, panel_style: Annotated[str, Option(--panel - style, -S, metavar=STYLE, help='Panel border style.', rich_help_panel=LAYOUT)] = '', border_only: Annotated[bool, Option(--border - only, help='With --panel, paint only the border with the gradient; the content keeps its own colors.', rich_help_panel=LAYOUT)] = False, title: Annotated[Optional[str], Option(--title, metavar=TEXT, help='Panel (or table) title.', rich_help_panel=LAYOUT)] = None, caption: Annotated[Optional[str], Option(--caption, metavar=TEXT, help='Panel (or table) caption.', rich_help_panel=LAYOUT)] = None, style: Annotated[str, Option(--style, -s, metavar=STYLE, help='Rich style applied to the text.', rich_help_panel=CONTENT)] = '', markup: Annotated[bool, Option(--markup / --no - markup, help='Parse Rich console markup in text.', rich_help_panel=CONTENT)] = True, emoji: Annotated[bool, Option(--emoji, -j, help='Enable emoji codes such as :sparkles:.', rich_help_panel=CONTENT)] = False, hyperlinks: Annotated[bool, Option(--hyperlinks, -y, help='Render hyperlinks in Markdown.', rich_help_panel=CONTENT)] = False, no_wrap: Annotated[bool, Option(--no - wrap, help="Don't word wrap text or code.", rich_help_panel=CONTENT)] = False, tab_size: Annotated[int, Option(--tab - size, min=1, help='Tab width.', rich_help_panel=CONTENT)] = 4, head: Annotated[Optional[int], Option(--head, -h, min=1, metavar=LINES, help='Display the first LINES (--syntax, --csv, --ipynb; ignored elsewhere).', rich_help_panel=CONTENT)] = None, tail: Annotated[Optional[int], Option(--tail, -t, min=1, metavar=LINES, help='Display the last LINES (--syntax, --csv, --ipynb; ignored elsewhere).', rich_help_panel=CONTENT)] = None, lexer: Annotated[Optional[str], Option(--lexer, -x, metavar=LEXER, help='Pygments lexer for --syntax.', rich_help_panel=CONTENT)] = None, theme: Annotated[str, Option(--theme, envvar=RICH_THEME, metavar=THEME, help='Pygments theme for code.', rich_help_panel=CONTENT)] = 'monokai', line_numbers: Annotated[bool, Option(--line - numbers, -n, help='Show line numbers.', rich_help_panel=CONTENT)] = False, guides: Annotated[bool, Option(--guides, -g, help='Show indentation guides.', rich_help_panel=CONTENT)] = False, rule_style: Annotated[str, Option(--rule - style, metavar=STYLE, help='Style for --rule.', rich_help_panel=CONTENT)] = '', rule_char: Annotated[Optional[str], Option(--rule - char, metavar=CHARACTER, help='Single character for --rule (overrides --thickness).', rich_help_panel=CONTENT)] = None, thickness: Annotated[int, Option(--thickness, min=0, max=3, help='Rule thickness, 0-3.', rich_help_panel=CONTENT)] = 2, delimiter: Annotated[Optional[str], Option(--delimiter, metavar=CHAR, help='CSV delimiter (default: auto-detect).', rich_help_panel=CONTENT)] = None, no_header: Annotated[bool, Option(--no - header, help='Treat the first CSV row as data.', rich_help_panel=CONTENT)] = False, max_depth: Annotated[int, Option(--max - depth, min=1, help='Directory depth for --tree.', rich_help_panel=CONTENT)] = 2, spectrum_output_: Annotated[SpectrumOutput, Option(--spectrum - output, help='Format for --spectrum.', rich_help_panel=CONTENT)] = SpectrumOutput.TABLE, export_html: Annotated[Optional[str], Option(--export - html, -o, metavar=PATH, help='Write HTML to PATH.', rich_help_panel=OUTPUT)] = None, export_svg: Annotated[Optional[str], Option(--export - svg, metavar=PATH, help='Write SVG to PATH.', rich_help_panel=OUTPUT)] = None, pager: Annotated[bool, Option(--pager, help='Display in an interactive pager.', rich_help_panel=OUTPUT)] = False, force_terminal: Annotated[bool, Option(--force - terminal, help='Keep ANSI codes when not writing to a terminal.', rich_help_panel=OUTPUT)] = False, telemetry: Annotated[Optional[TelemetryAction], Option(--telemetry, callback=_telemetry_callback, is_eager=True, metavar=[enable | disable | status], help='Manage opt-in anonymous usage telemetry, then exit.', rich_help_panel=OUTPUT)] = None, version_: Annotated[bool, Option(--version, -v, callback=_version_callback, is_eager=True, help='Print version and exit.', rich_help_panel=OUTPUT)] = False) -> None

Render text, files, URLs, or stdin with a [b]rich-gradient[/b] gradient.

RESOURCE is a file path, an http(s) URL, [b]-[/b] for stdin, or literal text. The renderable is auto-detected from the file extension unless a flag such as [b]--markdown[/b] is given.

Rendering

rich_gradient_cli.render

Build the rich-gradient renderable for a resource.

DEFAULT_HUES module-attribute

DEFAULT_HUES = 5

Hues used by --rainbow / no --colors when --hues isn't given.

SPECTRUM_HUES module-attribute

SPECTRUM_HUES = 17

Hues shown by --spectrum when --hues isn't given: the full palette.

__all__ module-attribute

__all__ = ['RenderConfig', 'Runnable', 'build_inner', 'build_output', 'build_rule', 'resolve_expand', 'slice_lines', 'spectrum_output']

RenderConfig dataclass

RenderConfig(colors: str | None = None, bgcolors: str | None = None, rainbow: bool = False, hues: int | None = None, repeat_scale: float | None = None, highlight_words: list[str] = list(), highlight_regex: list[str] = list(), animate: bool = False, duration: float | None = None, align: str = 'left', text_align: str = 'default', vertical_align: str = 'middle', expand: bool | None = None, padding: str | None = None, panel: bool = False, box: str = 'rounded', panel_style: str = '', border_only: bool = False, title: str | None = None, caption: str | None = None, style: str = '', markup: bool = True, emoji: bool = False, hyperlinks: bool = False, no_wrap: bool = False, tab_size: int = 4, head: int | None = None, tail: int | None = None, lexer: str | None = None, theme: str = 'monokai', line_numbers: bool = False, guides: bool = False, rule_char: str | None = None, thickness: int = 2, delimiter: str | None = None, no_header: bool = False, max_depth: int = 2, rule_style: str = '', spectrum_output: str = 'table')

Every option that influences rendering, independent of the CLI layer.

align class-attribute instance-attribute
align: str = 'left'
animate class-attribute instance-attribute
animate: bool = False
bgcolors class-attribute instance-attribute
bgcolors: str | None = None
border_only class-attribute instance-attribute
border_only: bool = False
box class-attribute instance-attribute
box: str = 'rounded'
caption class-attribute instance-attribute
caption: str | None = None
colors class-attribute instance-attribute
colors: str | None = None
delimiter class-attribute instance-attribute
delimiter: str | None = None
duration class-attribute instance-attribute
duration: float | None = None
emoji class-attribute instance-attribute
emoji: bool = False
expand class-attribute instance-attribute
expand: bool | None = None
guides class-attribute instance-attribute
guides: bool = False
head class-attribute instance-attribute
head: int | None = None
highlight_regex class-attribute instance-attribute
highlight_regex: list[str] = field(default_factory=list)
highlight_words class-attribute instance-attribute
highlight_words: list[str] = field(default_factory=list)
hues class-attribute instance-attribute
hues: int | None = None
hyperlinks: bool = False
lexer class-attribute instance-attribute
lexer: str | None = None
line_numbers class-attribute instance-attribute
line_numbers: bool = False
markup class-attribute instance-attribute
markup: bool = True
max_depth class-attribute instance-attribute
max_depth: int = 2
no_header class-attribute instance-attribute
no_header: bool = False
no_wrap class-attribute instance-attribute
no_wrap: bool = False
padding class-attribute instance-attribute
padding: str | None = None
panel class-attribute instance-attribute
panel: bool = False
panel_style class-attribute instance-attribute
panel_style: str = ''
rainbow class-attribute instance-attribute
rainbow: bool = False
repeat_scale class-attribute instance-attribute
repeat_scale: float | None = None
rule_char class-attribute instance-attribute
rule_char: str | None = None
rule_style class-attribute instance-attribute
rule_style: str = ''
spectrum_output class-attribute instance-attribute
spectrum_output: str = 'table'
style class-attribute instance-attribute
style: str = ''
tab_size class-attribute instance-attribute
tab_size: int = 4
tail class-attribute instance-attribute
tail: int | None = None
text_align class-attribute instance-attribute
text_align: str = 'default'
theme class-attribute instance-attribute
theme: str = 'monokai'
thickness class-attribute instance-attribute
thickness: int = 2
title class-attribute instance-attribute
title: str | None = None
vertical_align class-attribute instance-attribute
vertical_align: str = 'middle'

Runnable

Bases: Protocol

An animated rich-gradient object that can be run to completion.

run
run() -> None

Run the animation until it finishes or is interrupted.

build_inner

build_inner(mode: Mode, resource: Resource, cfg: RenderConfig) -> RenderableType

Build the plain Rich renderable for mode (before gradient styling).

build_output

build_output(mode: Mode, resource: Resource, cfg: RenderConfig, console: Console, *, animated: bool) -> RenderableType | Runnable

Build the final gradient renderable (or an animation to run()).

The plain renderable for mode is padded, then wrapped in a gradient Panel (--panel) or a plain Gradient.

build_rule

build_rule(resource: Resource, cfg: RenderConfig, *, animated: bool) -> RenderableType | Runnable

Build a gradient rule whose title is the resource text.

panel_border_color

panel_border_color(cfg: RenderConfig) -> bool

Return whether --panel-style sets a foreground color for the border.

rich-gradient's Panel replaces a border foreground color with the gradient, so a colored --panel-style needs a plain Rich panel instead.

resolve_expand

resolve_expand(mode: Mode, cfg: RenderConfig) -> bool

Decide whether the gradient spans the full width.

Panels, Markdown and code fill the terminal; text, tables, JSON, trees and columns shrink to their content so the gradient is visible across it.

resolve_object

resolve_object(expression: str) -> Any

Resolve a dotted module.attr path, falling back to eval.

Dotted paths are imported without eval; any other expression is evaluated, exactly like rich --inspect.

Warning

Importing a dotted path executes that module, and any other expression is passed to eval. Never pass untrusted text to --inspect.

Raises:

Type Description
ResourceError

If the expression cannot be resolved.

slice_lines

slice_lines(text: str, head: int | None, tail: int | None) -> str

Keep only the first head or last tail lines of text.

spectrum_output

spectrum_output(cfg: RenderConfig) -> RenderableType

Render the palette (all 17 hues unless --hues is given) as a table, or as plain names/hex/csv text.

Resources

rich_gradient_cli.resource

Locate and read the RESOURCE argument (file, URL, stdin, or literal text).

EXTENSION_MODES module-attribute

EXTENSION_MODES: dict[str, Mode] = {'.md': MARKDOWN, '.markdown': MARKDOWN, '.json': JSON, '.csv': CSV, '.tsv': CSV, '.rst': RST, '.ipynb': IPYNB}

MAX_DOWNLOAD_BYTES module-attribute

MAX_DOWNLOAD_BYTES = 10 * 1024 * 1024

URL_TIMEOUT module-attribute

URL_TIMEOUT = 10.0

USER_AGENT module-attribute

USER_AGENT = 'rich-gradient-cli'

__all__ module-attribute

__all__ = ['EXTENSION_MODES', 'Mode', 'Resource', 'ResourceError', 'detect_mode', 'is_url', 'read_resource']

Mode

Bases: str, Enum

The renderable used to display a resource.

COLUMNS class-attribute instance-attribute
COLUMNS = 'columns'
CSV class-attribute instance-attribute
CSV = 'csv'
INSPECT class-attribute instance-attribute
INSPECT = 'inspect'
IPYNB class-attribute instance-attribute
IPYNB = 'ipynb'
JSON class-attribute instance-attribute
JSON = 'json'
MARKDOWN class-attribute instance-attribute
MARKDOWN = 'markdown'
RST class-attribute instance-attribute
RST = 'rst'
RULE class-attribute instance-attribute
RULE = 'rule'
SPECTRUM class-attribute instance-attribute
SPECTRUM = 'spectrum'
SYNTAX class-attribute instance-attribute
SYNTAX = 'syntax'
TEXT class-attribute instance-attribute
TEXT = 'text'
TREE class-attribute instance-attribute
TREE = 'tree'

Resource dataclass

Resource(text: str, name: str = '', is_literal: bool = False, path: Path | None = None)

Content read from a RESOURCE argument.

Attributes:

Name Type Description
text str

The decoded content (or literal text).

name str

A file name, URL path, or "" for stdin and literal text.

is_literal bool

True when the argument itself was the content.

path Path | None

The local path when the resource is an existing file or directory.

is_literal class-attribute instance-attribute
is_literal: bool = False
name class-attribute instance-attribute
name: str = ''
path class-attribute instance-attribute
path: Path | None = None
suffix property
suffix: str

Lower-cased file extension of :attr:name, including the dot.

text instance-attribute
text: str

ResourceError

Bases: Exception

Raised when a resource cannot be read or rendered (exit code 1).

detect_mode

detect_mode(resource: Resource) -> Mode

Choose a mode from the resource's extension, defaulting to plain text.

is_url

is_url(value: str) -> bool

Return whether value is an http:// or https:// URL.

read_resource

read_resource(resource: str | None, *, allow_directory: bool = False) -> Resource

Resolve a RESOURCE argument into content.

- (or None with piped stdin) reads stdin, http(s):// URLs are downloaded, existing files are read as UTF-8, and anything else is treated as literal text.

Parameters:

Name Type Description Default
resource str | None

The positional argument, or None if omitted.

required
allow_directory bool

Return an empty :class:Resource for directories instead of raising (used by --tree).

False

Raises:

Type Description
ResourceError

On unreadable files, directories, bad UTF-8, or HTTP failures.

Option parsing

rich_gradient_cli.options

Parsers that turn raw command-line strings into typed values.

BOXES module-attribute

BOXES: dict[str, Box] = {'ascii': ASCII, 'ascii2': ASCII2, 'square': SQUARE, 'rounded': ROUNDED, 'heavy': HEAVY, 'double': DOUBLE}

__all__ module-attribute

__all__ = ['BOXES', 'parse_colors', 'parse_mapping', 'parse_padding', 'parse_style', 'validate_colors', 'validate_highlights']

parse_colors

parse_colors(colors: str | None) -> list[str] | None

Split a comma-separated color list.

Parameters:

Name Type Description Default
colors str | None

Raw --colors value, e.g. "red,#0ff,tomato".

required

Returns:

Type Description
list[str] | None

The stripped, non-empty tokens, or None when colors is empty.

parse_mapping

parse_mapping(values: Sequence[str] | None) -> Mapping[str, str] | None

Parse repeated KEY=VALUE options into a mapping.

Raises:

Type Description
ValueError

If an item is not of the form KEY=VALUE.

parse_padding

parse_padding(padding: str | None) -> int | tuple[int, int] | tuple[int, int, int, int] | None

Parse CSS-style padding such as "1", "1,2" or "1,2,3,4".

Raises:

Type Description
ValueError

If the string is not 1, 2 or 4 comma-separated integers.

parse_style

parse_style(style: str | None) -> Style

Parse a Rich style string, returning a null style when empty.

Raises:

Type Description
ValueError

If style is not a valid Rich style.

validate_colors

validate_colors(colors: str | None) -> list[str] | None

Split a comma-separated color list and check every color parses.

Raises:

Type Description
ValueError

If any token is not a Rich color, hex code, or CSS name.

validate_highlights

validate_highlights(values: Sequence[str] | None, *, regex: bool = False) -> Mapping[str, str] | None

Parse KEY=STYLE highlights, checking each style (and pattern if regex).

Raises:

Type Description
ValueError

On a malformed item, an invalid style, or an invalid regex.

Export

rich_gradient_cli.export

Export renderables to SVG or HTML files.

__all__ module-attribute

__all__ = ['export_renderable']

export_renderable

export_renderable(renderable: RenderableType, *, svg: str | None = None, html: str | None = None, width: int | None = None) -> None

Render renderable to a recording console and save SVG and/or HTML.

Parameters:

Name Type Description Default
renderable RenderableType

What to render.

required
svg str | None

Destination SVG path, if any.

None
html str | None

Destination HTML path, if any.

None
width int | None

Console width in cells; defaults to Rich's detected width.

None

Raises:

Type Description
OSError

If a destination cannot be written.

Telemetry

rich_gradient_cli.telemetry

Opt-in, anonymous usage telemetry for the gradient CLI.

Nothing is sent unless the user runs gradient telemetry enable and an AMPLITUDE_API_KEY is present in the environment. The only data sent is the event name Command Run, the render mode, and a random install ID that is generated locally on enable and never derived from the machine or user.

API_KEY_ENV module-attribute

API_KEY_ENV = 'AMPLITUDE_API_KEY'

EVENT_NAME module-attribute

EVENT_NAME = 'Command Run'

FLUSH_TIMEOUT_SECONDS module-attribute

FLUSH_TIMEOUT_SECONDS = 5.0

REGION_ENV module-attribute

REGION_ENV = 'AMPLITUDE_SERVER_ZONE'

config_path

config_path() -> Path

Return the path of the telemetry config file (honors XDG_CONFIG_HOME).

disable

disable() -> None

Opt out and discard the stored install ID.

enable

enable() -> str

Opt in, generating a random install ID on first use; return the ID.

is_enabled

is_enabled() -> bool

Return True if the user has opted in to telemetry.

run_telemetry_action

run_telemetry_action(action: str) -> str

Apply enable, disable or status and return the message to show.

track_command

track_command(command: str) -> None

Send a Command Run event if opted in and a key is configured.

The process is short-lived, so the event is flushed and awaited before returning. Telemetry must never break the CLI: all failures are swallowed.