Skip to content

6. The CLI

cargo install rs-rich-cli      # installs a binary called `rich`

The pictures on this page are the commands' own output, exported with --export-svg from the fixtures scripts/smoke_cli.py writes (python3 scripts/smoke_cli.py --screenshots docs/media/guide).

Rendering a file

With no mode flag, the type is detected from the extension:

rich README.md          # markdown
rich data.json          # pretty JSON
rich main.rs            # syntax highlighted
rich table.csv          # a table
rich notebook.ipynb     # a Jupyter notebook

rich notes.md, for example:

Markdown rendered with a centred heading, bullets, a quote and a code block

and rich team.csv --title Team:

A table with a title, a header row and a right-aligned numeric column

Force a mode when the extension lies, or when reading stdin:

rich --markdown notes.txt
cat main.rs | rich --syntax -

- means standard input.

Printing markup

rich -p "[bold red]Alert[/] disk at [bold]91%[/]"

Alert in bold red, then disk at 91%, with the number highlighted

Bad markup is reported rather than printed literally:

$ rich -p "[/nope]"
rich: markup error: closing tag '[/nope]' at position 0 doesn't match any open tag
$ echo $?
4

Exit code 4 means a parse or render error in the input; the CLI guide lists every exit code.

Fetching a URL

rich https://raw.githubusercontent.com/Textualize/rich/master/README.md

The render mode comes from the flag, else the URL's extension, else the response Content-Type.

Decorating output

rich --panel rounded --title "Notes" --style "bold blue" notes.md
rich --padding 1,4 --center report.md
rich --width 60 --rule "Section"

The first, on the same notes.md:

The Markdown notes in a rounded panel titled Notes, the text in bold blue

and the last:

A rule 60 columns wide with Section in the middle

Exporting

Both exports write to a path and leave the terminal output intact, so you get both at once:

rich -m README.md --export-html readme.html
rich -m README.md --export-svg readme.svg
rich -m README.md -o readme.html --export-svg readme.svg   # both

-o is short for --export-html. The HTML is self-contained — no external CSS, fonts or images. The SVG loads its font from a CDN, so it needs a network connection to show in the intended typeface; every picture on this site is an SVG export like this one.

Paging

rich --pager long-document.md

Pages through $PAGER (falling back to less -R, then more), keeping the styling, unlike piping to a pager yourself.

More commands

Beyond rendering files, rich has tool commands: inspect explores JSON, YAML, TOML, XML, INI and dotenv as a tree; diff compares text files or renders a patch; view shows any file; hex, unicode and ansi explain look inside bytes, characters and escape sequences; env lists environment variables with secrets masked; capture runs a command and shows or exports its output; and doctor reports what rich detected. The CLI walkthrough shows each one. Two of them:

rich inspect deploy.yaml

deploy.yaml as a tree of keys and values

rich diff greet.py greet_v2.py

A unified diff with line numbers and highlighted changes

Full option list

rich --help prints every option, grouped by topic, and rich COMMAND --help shows one command. The CLI reference is generated from that help text.