Usage¶
Installation¶
rich-gradient-cli requires Python 3.11 or newer. Install it with any of:
With Homebrew, trust the tap first. Homebrew won't load formulae from a third-party tap until you do:
New releases reach the Homebrew tap about a day after PyPI.
Check that it works with gradient --version.
Text¶
Literal text and stdin (echo "piped text" | gradient -) are printed as gradient text. Rich console markup such as [b]bold[/b] is parsed unless you pass --no-markup.
gradient -p '[bold]Bold[/bold], [italic]italic[/italic] and [u]underlined[/u]' --colors red,gold,lime
To style particular words or patterns, use --highlight-word WORD=STYLE or --highlight-regex PATTERN=STYLE. Both can be repeated.
gradient --colors magenta,cyan --highlight-word 'error=bold white on red' -s bold 'Highlight error text'
Files and URLs¶
The file extension picks the renderable:
| Extension | Rendered as |
|---|---|
.md, .markdown |
Markdown |
.rst |
reStructuredText |
.ipynb |
Jupyter notebook |
.json |
Pretty-printed JSON |
.csv, .tsv |
Table |
.txt, no extension |
Gradient text |
| anything else | Syntax-highlighted code |
http(s):// URLs and - (stdin) work the same way as files. A URL uses the extension of its path. Stdin has no extension, so add a mode flag such as --markdown when you pipe in anything other than plain text.
gradient README.md
gradient doc.rst
gradient notebook.ipynb
gradient data.csv
gradient config.json
gradient pyproject.toml -n -g --head 20
gradient https://example.com/page.md
cat <<'EOF' | gradient - --markdown --colors magenta,cyan
# Hello
Some **bold** and *italic* text.
- one
- two
EOF
cat <<'EOF' | gradient - --rst --colors orange,magenta
Title
=====
Some *emphasis* and a list:
- one
- two
EOF
cat <<'EOF' | gradient - --ipynb --colors cyan,magenta
{"cells":[{"cell_type":"code","execution_count":1,"source":["print(1 + 1)"],"outputs":[{"output_type":"stream","text":["2\n"]}]}],"metadata":{"kernelspec":{"language":"python"}}}
EOF
cat <<'EOF' | gradient - --json --colors cyan,magenta
{"name": "gradient", "tags": ["cli", "rich"], "stars": 5}
EOF
cat <<'EOF' | gradient - --csv --colors cyan,magenta
name,language,stars
rich,python,50000
typer,python,15000
uv,rust,40000
EOF
Panels and rules¶
--panel BOX wraps any renderable in a gradient panel. The box styles are ascii, ascii2, square, rounded, heavy, double and none. Add --title and --caption to label the panel, and --border-only to color just the border and leave the content as it is.
--rule draws a horizontal rule with the text as its title.
Trees, columns, spectrum and inspect¶
--tree shows a directory (or lines of text) as a tree, --columns lays each line out as a column cell, --spectrum shows the color palette, and --inspect reports on a Python object.
Warning
--inspect imports or evaluates its argument as Python. Never pass it text you don't trust.
Animation¶
--animate animates the gradient in an interactive terminal. Add --duration SECONDS to stop automatically; otherwise press Ctrl+C to stop it.
When the output is not a terminal (for example, piped to a file), a single static frame is printed instead. --animate cannot be combined with --export-svg, --export-html or --pager.
Export and paging¶
gradient README.md --export-svg readme.svg # print, then also save as SVG
gradient README.md -o readme.html # ... or as HTML
gradient README.md --pager # scroll through it in a pager
Telemetry¶
Telemetry is off by default. Manage it with gradient --telemetry enable|disable|status. Even when enabled, events are sent only if AMPLITUDE_API_KEY is also set.