Options¶
The argument is a file, an http(s) URL, - for stdin, or literal text. Run gradient --help for the always-current list.
Options shared with rich-cli use the same spelling. Gradient options are long-only. -h means --head, so use --help for help.
Renderable¶
Pick at most one of these. Giving two is a usage error. With none, the file extension decides: .md is Markdown, .rst is reStructuredText, .ipynb is a notebook, .json is JSON, .csv/.tsv is a table, and any other file is syntax-highlighted. Literal text, stdin and .txt files are printed as gradient text.
| Flag | Renders |
|---|---|
-p, --print |
Gradient text with Rich console markup |
-u, --rule |
A rule titled with the text |
-J, --json |
Pretty-printed JSON |
-m, --markdown |
Markdown |
--rst |
reStructuredText |
--csv |
CSV/TSV as a table |
--ipynb |
Jupyter notebook |
--syntax |
Syntax-highlighted code |
--inspect |
A Python object, e.g. str or rich.console.Console (imports/evaluates its argument: never pass untrusted text) |
--tree |
A directory (or lines of text) as a tree |
--columns |
Each line as a column cell |
--spectrum |
The rich-gradient color palette |
Gradient¶
Colors can be Rich color names, hex codes (including the short #abc form) or CSS color names. An invalid color is a usage error.
| Option | Description |
|---|---|
--colors COLORS |
Comma-separated gradient colors. Can also be set with the GRADIENT_COLORS environment variable. |
--bgcolors COLORS |
Comma-separated background colors. |
--rainbow |
Use the full rainbow spectrum (ignores --colors). |
--hues N |
Number of spectrum hues (2-17) used by --rainbow and when no colors are given (default 5), or shown by --spectrum (default all 17). |
--repeat-scale N |
How many times the gradient repeats across the output. |
--highlight-word WORD=STYLE |
Style every occurrence of a word. Repeatable. |
--highlight-regex PATTERN=STYLE |
Style every regex match. Repeatable. |
--animate |
Animate the gradient (interactive terminals only). |
--duration SECONDS |
Stop animating after this many seconds. |
gradient --repeat-scale 1 --rule 'repeat 1' --colors red,cyan
gradient --repeat-scale 3 --rule 'repeat 3' --colors red,cyan
gradient --colors magenta,cyan -s bold --highlight-word 'error=bold white on red' --highlight-word 'ok=bold black on lime' 'ok ok error ok'
gradient --colors magenta,cyan -s bold --highlight-regex '\d+=bold black on yellow' 'Build 42 passed in 7 seconds'
--animate and --pager need an interactive terminal, so they have no screenshot.
Layout¶
| Option | Description |
|---|---|
-l, --left / -c, --center / -r, --right |
Align the whole block (default left). Rule titles default to center. |
-L, --text-left / -C, --text-center / -R, --text-right / -F, --text-full |
Justify the text inside the block (text and Markdown). |
--vertical-align top\|middle\|bottom |
Vertically align the block. Panels are always top-aligned. |
-w, --width SIZE |
Fit the output to SIZE characters. |
-W, --max-width SIZE |
Never be wider than SIZE characters. |
-e, --expand / --no-expand |
Fill the full width. By default panels, Markdown and code expand; everything else shrinks to its content. |
-d, --padding T,R,B,L |
Padding as 1, 2 or 4 comma-separated integers. |
-a, --panel BOX |
Wrap the output in a gradient panel: ascii, ascii2, square, rounded, heavy, double or none. |
-S, --panel-style STYLE |
Style of the panel border. A color (e.g. red or bold white) gives a solid border with the gradient on the content only; attributes alone (e.g. bold) keep the gradient border. |
--border-only |
With --panel, paint only the border (and its title) with the gradient. The content keeps its own colors. |
--title TEXT |
Panel title. Also used as a CSV table title, and as the rule title when no text is given. |
--caption TEXT |
Panel subtitle, or CSV table caption. |
gradient --left -w 60 --colors red,gold -s bold left
gradient --center -w 60 --colors red,gold -s bold center
gradient --right -w 60 --colors red,gold -s bold right
gradient -L -w 44 --colors cyan,magenta 'Gradients make terminal output easier to scan and a lot more fun to read.'
gradient -C -w 44 --colors cyan,magenta 'Gradients make terminal output easier to scan and a lot more fun to read.'
gradient -R -w 44 --colors cyan,magenta 'Gradients make terminal output easier to scan and a lot more fun to read.'
gradient -F -w 44 --colors cyan,magenta 'Gradients make terminal output easier to scan and a lot more fun to read.'
gradient -w 30 --colors lime,cyan 'Gradients make terminal output easier to scan and a lot more fun to read.'
gradient -W 40 --colors lime,cyan short
gradient --expand --colors red,blue -s bold expanded
gradient --no-expand --panel square --colors red,blue shrunk
gradient --panel ascii --colors cyan,magenta --no-expand -s bold ascii
gradient --panel square --colors cyan,magenta --no-expand -s bold square
gradient --panel rounded --colors cyan,magenta --no-expand -s bold rounded
gradient --panel heavy --colors cyan,magenta --no-expand -s bold heavy
gradient --panel double --colors cyan,magenta --no-expand -s bold double
gradient --panel rounded --title Build --caption '42 passed' --colors lime,cyan -s bold 'All checks passed.'
Content¶
| Option | Description |
|---|---|
-s, --style STYLE |
Rich style applied to the text, e.g. bold or italic underline. |
--markup / --no-markup |
Parse Rich console markup (on by default). |
-j, --emoji |
Replace emoji codes such as :sparkles:. |
-y, --hyperlinks |
Render hyperlinks in Markdown. |
--no-wrap |
Don't word-wrap text or code. |
--tab-size N |
Tab width. Default 4. |
-h, --head LINES / -t, --tail LINES |
Show only the first or last LINES (syntax, CSV and notebooks). |
-x, --lexer LEXER |
Pygments lexer for code. |
--theme THEME |
Pygments theme for code. Can also be set with RICH_THEME. Default monokai. |
-n, --line-numbers |
Show line numbers in code. |
-g, --guides |
Show indentation guides in code and JSON. |
--rule-style STYLE |
Style for --rule. |
--rule-char CHARACTER |
Single character to draw --rule with (overrides --thickness). |
--thickness 0-3 |
Rule thickness. Default 2. |
--delimiter CHAR |
CSV delimiter. Auto-detected by default. |
--no-header |
Treat the first CSV row as data. |
--max-depth N |
How many directory levels --tree shows. Default 2. |
--spectrum-output table\|names\|hex\|csv |
Output format for --spectrum. |
gradient --colors cyan,magenta '[bold]markup[/bold] is parsed'
gradient --no-markup --colors cyan,magenta '[bold]markup[/bold] is literal'
gradient pyproject.toml --syntax --head 4 --colors yellow,magenta
gradient pyproject.toml --syntax --tail 4 --colors yellow,magenta
cat <<'EOF' | gradient - --syntax --lexer python --theme dracula --colors cyan,magenta
def greet(name):
if name:
for _ in range(2):
print(f'hi {name}')
EOF
cat <<'EOF' | gradient - --syntax --lexer python -n --colors lime,cyan
def greet(name):
if name:
for _ in range(2):
print(f'hi {name}')
EOF
cat <<'EOF' | gradient - --syntax --lexer python -g --colors orange,magenta
def greet(name):
if name:
for _ in range(2):
print(f'hi {name}')
EOF
gradient --rule 'thickness 0' --thickness 0 --colors cyan,magenta
gradient --rule 'thickness 1' --thickness 1 --colors cyan,magenta
gradient --rule 'thickness 2' --thickness 2 --colors cyan,magenta
gradient --rule 'thickness 3' --thickness 3 --colors cyan,magenta
gradient --rule 'custom char' --rule-char '*' --colors cyan,magenta
cat <<'EOF' | gradient - --csv --delimiter ';' --colors cyan,magenta
name;language;stars
rich;python;50000
typer;python;15000
EOF
cat <<'EOF' | gradient - --csv --no-header --colors cyan,magenta
name,language,stars
rich,python,50000
typer,python,15000
uv,rust,40000
EOF
gradient --tree src --max-depth 1 --colors lime,cyan
gradient --tree src --max-depth 3 --colors lime,cyan
gradient --spectrum --spectrum-output names --hues 5
gradient --spectrum --spectrum-output hex --hues 5
Output¶
| Option | Description |
|---|---|
-o, --export-html PATH |
Also write the output to PATH as HTML. |
--export-svg PATH |
Also write the output to PATH as SVG. |
--pager |
Show the output in an interactive pager. |
--force-terminal |
Keep colors (ANSI codes) even when not writing to a terminal. |
--telemetry enable\|disable\|status |
Manage opt-in anonymous usage telemetry, then exit. |
-v, --version |
Print the version and exit. |
Warnings¶
Some options only apply to certain renderables. When an option has no effect, gradient prints a warning to stderr and carries on. For example, --head with Markdown, --title without --panel, or --panel with --rule.
Exit codes¶
| Code | Meaning |
|---|---|
0 |
Success. |
1 |
Runtime error: unreadable file, HTTP failure, invalid JSON or markup, and so on. |
2 |
Usage error: conflicting flags, or an invalid color, style, regex or padding. |