Rich-cli is a command line toolbox for fancy output in the terminal, built with Rich.
rich command to highlight a variety of file types in the terminal, with specialized rendering for Markdown and JSON files. Additionally you can markup and format text from the command line.
Rich-cli is distributed as a Python application, which you can install with Pip:
python -m pip install rich-cli
Alternatively, you can use
pipx to install it globally:
pipx install rich-cli
Once installed, you should have the
rich command on your path.
ℹ️ More information methods coming soon.
To syntax highlight a file enter
rich followed by a path. Many file formats are supported.
-n switch to enable line numbers. Add
-g to enable indentation guides.
rich loop.py -n -g
You can specify a theme with
rich loop.py --theme dracula
rich will wrap lines if they don’t fit within the available width. You can disable this behavior with
Rich will try to deduce the format of the via from the filename. If you want to override the auto-detected lexer you can explicitly set it with the
You can request markdown rendering by adding the
--markdown switch or
rich README.md -m
If your terminal supports hyperlinks, you can add
-y which will output hyperlinks rather than full URLs.
rich README.md --hyperlinks
You can request JSON pretty formatting and highlighting with the
rich cats.json --json
You can render a horizontal rule with
-u. Specify a rule style with
--rule-style. Set the character(s) to render the line with
rich "Hello [b]World[b]!" --rule rich "Hello [b]World[b]!" --rule --rule-style "red" rich "Hello [b]World[b]!" --rule --rule-style "red" --rule-char "="
rich command can read files from the internet you give it a URL starting with
rich https://raw.githubusercontent.com/Textualize/rich-cli/main/README.md --markdown
In addition to rendering to the console,
rich can write an HTML file. This works with any command. Add
-o followed by the output path.
rich README.md -o readme.html
After running this command you should find a “readme.html” in your current working directory.
If you add the
--p option then Rich will treat the first argument as console markup which allows you to insert styles with a markup similar in design to bbcode.
rich "Hello, [bold magenta]World[/]!" --print
Rich will word wrap your text by default by inserting newlines where appropriate. If you don’t want this behavior you can enable soft wrapping with
Reading from Stdin
rich accepts a path, you can enter
- which reads the content from stdin. You may want this if you are piping output from another process.
Note that when rich isn’t writing directly to the terminal it will disable ansi color codes, so you may want to add
-F to tell
rich you want to keep ansi codes in the output.
cat README.md | rich - --markdown --force-terminal
There are a number of additional switches you may add to modify the content rendered to the terminal. These options are universal and apply to all of the above features.
You can set a style to apply to the output with
-s. The styles are specified with this syntax.
rich "Hello, [b]World[/b]!" --print --style "on blue"
You can align output to the left, center, or right with the
--right options, or their single letter counterparts:
rich "Hello [b]World[/b]!" --print --center
You can set the width of the output with
-w and the desired width. Note that the default behavior is to wrap text.
rich "I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration." -p -w 40
You can set how
rich will justify text with
--text-full; or the single letter equivalents:
The difference between
--text-left may not be obvious unless you specify the width of the output. The
--right options will center the block of text within the terminal dimensions. Whereas, the
--text-right options define how text is rendered within that block.
In the following examples, we specify a width of 40 (
-w 40) which is center aligned with the
-c switch. Note how the
-F apply the text justification within the 40 character block:
rich "I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration." -p -w 40 -c -L rich "I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration." -p -w 40 -c -R rich "I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration." -p -w 40 -c -C rich "I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration." -p -w 40 -c -F
You can apply padding around the output with
rich "Hello [b]World[/b]!" -p -c --padding 3 --style "on blue"
You can draw a panel around content with
-a, which takes one of a number of styles.
rich "Hello, [b]World[/b]!" -p -a heavy