Rich-cli is a command line toolbox for fancy output in the terminal

Overview

Rich CLI

Rich-cli is a command line toolbox for fancy output in the terminal, built with Rich.

Rich-cli can syntax highlight a large number of file types in the terminal, with specialized rendering for Markdown and JSON files. The rich command also provides an interface to console text rendering with many options to format and style your output.

Installation

Rich-cli is distributed as a Python application, which you can install via 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.

rich --help

Syntax highlighting

To syntax highlight a file enter rich followed by the path to your file. Many file formats are supported!

rich loop.py

syntax1

Add the --line-number or -n switch to enable line numbers. Add --guides or -g to enable indentation guides.

rich loop.py -n -g

syntax2

You can specify a theme with --theme or -t.

rich loop.py --theme dracula

syntax3

By default, rich will wrap lines if they don't fit within the available width. You can disable this behavior with --no-wrap.

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 --lexer or -x switch.

Markdown

You can request markdown rendering by adding the --markdown switch or -m.

rich README.md -m

markdown1

If your terminal supports hyperlinks, you can add --hyperlinks or -y which will output hyperlinks rather than full URLs.

rich README.md --hyperlinks

JSON

You can request JSON pretty formatting and highlighting with the --json or -j switches.

rich cats.json --json

json1

Rules

You can render a horizontal rule with --rule or -u. Specify a rule style with --rule-style. Set the character(s) to render the line with --rule-char.

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 "="

syntax1

Network

The rich command can read files from the internet you give it a URL starting with http:// or https://.

rich https://raw.githubusercontent.com/Textualize/rich-cli/main/README.md --markdown

network

Exporting

In addition to rendering to the console, rich can write an HTML file. This works with any command. Add --export-html or -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.

Rich Printing

If you add the --print or --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

printing1

Soft wrapping

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 --soft.

Reading from Stdin

Where 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 --force-terminal or -F to tell rich you want to keep ansi codes in the output.

cat README.md | rich - --markdown --force-terminal

General Options

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.

Style

You can set a style to apply to the output with --style or -s. The styles are specified with this syntax.

rich "Hello, [b]World[/b]!" --print --style "on blue"

style1

Alignment

You can align output to the left, center, or right with the --left, --center, or --right options, or their single letter counterparts: -l, -c, or -r.

rich "Hello [b]World[/b]!" --print --center

alignment1

Width

You can set the width of the output with --width or -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

width

Text Justify

You can set how rich will justify text with --text-left, --text-right, --text-center, and --text-full; or the single letter equivalents: -L, -R, -C, and -F.

The difference between --left and --text-left may not be obvious unless you specify the width of the output. The --left, --center, and --right options will center the block of text within the terminal dimensions. Whereas, the --text-left, --text-center, and --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 -R, -C and -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

Padding

You can apply padding around the output with --padding or -d.

rich "Hello [b]World[/b]!" -p -c --padding 3 --style "on blue"

padding1

Panel

You can draw a panel around content with --panel or -a, which takes one of a number of styles.

rich "Hello, [b]World[/b]!" -p -a heavy

panel1

Comments
  • Unable to read files with no lexer

    Unable to read files with no lexer

    When trying to load a file that does not have a lexer (without specifying a lexer override via -x), the file fails to load:

    $ rich us1.env
    unable to read us1.env: no lexer for filename 'us1.env' found
    

    I would like to suggest a fallback to text lexer, perhaps with a warning message, instead of not displaying the file

    opened by liiight 9
  • Exporting colourful SVGs gives XML error

    Exporting colourful SVGs gives XML error

    I was wondering if I could get a little help.. 😬

    I'm trying to figure out a semi-generalised way for people to generate nice-looking SVGs showing command-line help output from ewels/rich-click.

    One approach that I tried is to set force_terminal=True or color_system="256" on the rich-click console object. This maintains colour through a pipe to rich-click nicely, however it kills the SVGs..

    See for example test.svg (doesn't render in GitHub comments). In the browser (Chrome, Safari), this renders with the following warning at the top:

    image

    Passing the file through the w3c validator tool gives slightly more detail:

    Error Line 45, Column 184: illegal XML character U+1b
    …-r1" x="0" y="20" textLength="1946.8">      β€¦
    

    Any ideas on how to either (a) fix this problem or (b) generate the SVGs in a better way?

    Thanks in advance!

    opened by ewels 8
  • select/copy/find during --pager?

    select/copy/find during --pager?

    I've been trying rich --pager as a less pager replacement. I've realized that I can't select words while in that mode, which prevents copy. Is there a way to allow selecting of words? (and ideally some sort of find?)

    opened by mlibbey 7
  • Bails out

    Bails out

    rich  ~/.emacs.d/config.org
    unable to read /home/xircon/.emacs.d/config.org: no lexer for filename 'config.org' found
    

    Org files are just text. Perhaps it should just "have a go" :smile:

    opened by xircon 5
  • Allow delimiters for output from Stdin

    Allow delimiters for output from Stdin

    On running the following command

    ps |rich - -m
    

    I got the following output

    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ PID TTY          TIME CMD                                                                                         β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    6697 pts/1    00:00:00 bash 6722 pts/1    00:00:36 fish 50260 pts/1    00:00:00 ps 50261 pts/1    00:00:00 rich
    

    So rich-cli is able to inspect the first line (header) correctly, but not the subsequent lines.

    Without rich-cli, I got the following output:

    $ ps
        PID TTY          TIME CMD
       6697 pts/1    00:00:00 bash
       6722 pts/1    00:00:37 fish
      50453 pts/1    00:00:00 ps
    

    Tested with commands like netstat.

    One possible solution could be to allow the users to specify the delimiters.

    I am wondering whether this could be a bug, since rich-cli is able to detect the first line.

    opened by johnsamuelwrites 5
  • rich-cli needs a --force-terminal

    rich-cli needs a --force-terminal

    We will need a --force-terminal switch (plus single letter -f if its free) which forces terminal output. To allow users to pip to a file while allowing ansi codes (for pagers etc).

    opened by willmcgugan 5
  • Is it possible to format outputs of commands executed?

    Is it possible to format outputs of commands executed?

    For example, the mosquitto_sub command can print data received through MQTT. It has a built-in formatting option using the -F flag. But I would like to have a better looking output that would be possible with Rich CLI. What's the best way to use it?

    I did the following and it worked so I assumed mosquitto would work too:

    echo '{"test":"OK"}' | rich - --json
    {
      "test": "OK"
    }
    

    I tried the following: mosquitto_sub -h test.mosquitto.org -t "181818/json" | rich - --json but did not get any output. Without | rich - --json I got this: {"test":"OK"}

    opened by StarOfSlytherin 4
  • No lexer fo csv

    No lexer fo csv

    Hi all,

    I can't seem to remedy this. I uninstalled/reinstalled and get the same thing. Any help would be greatly appreciated.

    > rich try.csv
    unable to read try.csv: no lexer for filename 'try.csv' found
    

    Thanks!!

    opened by bhintze 4
  • Some rst sections' content omitted from output

    Some rst sections' content omitted from output

    $ git clone https://github.com/pypa/setuptools
    $ rich setuptools/docs/pkg_resources.rst
    

    The last bunch of sections have headers but no content in the output, though content exists in the input.

    image

    opened by AndydeCleyre 4
  • Inconsistent header treatment for csv tables

    Inconsistent header treatment for csv tables

    Hello!

    I'm sorry I'm not sure exactly what's going on here, so I'll get to it. Using Zsh:

    $ rows=( Package,Version,Latest,Project 'tomli,2.0.0,2.0.1,~/Code/zpy' 'click,8.0.1,8.0.3,~/Code/archbuilder_iosevka' 'pep517,0.11.0,0.12.0,~/Code/archbuilder_iosevka' 'ruamel.yaml,0.17.17,0.17.21,~/Code/archbuilder_iosevka' 'tomli,1.2.1,2.0.1,~/Code/archbuilder_iosevka' )
    $ rich --csv - <<<${(F)rows}
    

    image

    $ rows=( 'Package,Version,Latest,Project' 'tomli,2.0.0,2.0.1,~/Code/zpy' 'click,8.0.1,8.0.3,~/Code/archbuilder_iosevka' 'pep517,0.11.0,0.12.0,~/Code/archbuilder_iosevka' 'ruamel.yaml,0.17.17,0.17.21,~/Code/archbuilder_iosevka' 'tomli,1.2.1,2.0.1,~/Code/archbuilder_iosevka' )
    $ rich --csv - <<<${(F)rows}
    

    Same result as above

    $ rows=( 'tomli,2.0.0,2.0.1,~/Code/zpy' 'click,8.0.1,8.0.3,~/Code/archbuilder_iosevka' 'pep517,0.11.0,0.12.0,~/Code/archbuilder_iosevka' 'ruamel.yaml,0.17.17,0.17.21,~/Code/archbuilder_iosevka' 'tomli,1.2.1,2.0.1,~/Code/archbuilder_iosevka' )
    $ rich --csv - <<<${(F)rows}
    

    image

    What determines whether the first row gets treated as a header?

    Thanks for any help!

    opened by AndydeCleyre 4
  • Some themes not working on the Windows Terminal

    Some themes not working on the Windows Terminal

    Some --themes are not working on my Windows Terminal (using Windows 11) although they seem to work on WSL on the same machine.

    Some of the themes not working include gruvbox-light, dracula, and friendly_grayscale (all taken from the pygments documentation here).

    Below you can find a screenshot showing the Windows terminal on the left and WSL on the right, both running rich-cli 1.3.0:

    1. I ran rich without specifying a theme;
    2. I ran rich with --theme dracula and the Windows terminal renders it with the same styling as if I had invented a random theme name;
    3. I ran rich with another theme that both terminals seem to recognise, although the colours don't match 100% (which is fine).

    _rich_cli_not_working

    Running python -m rich.palette gives this output:

    _rich_cli_not_working_palette

    opened by rodrigogiraoserrao 4
  • Bump certifi from 2021.10.8 to 2022.12.7

    Bump certifi from 2021.10.8 to 2022.12.7

    Bumps certifi from 2021.10.8 to 2022.12.7.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Align title to the left in markdown

    Align title to the left in markdown

    Hi,

    Concerning the markdown preview, I see that the titles are centered. I would like to have them on the left instead. How can I achieve this?

    Best regards

    opened by maxclac 0
  • Unable to install latest textual and rich-cli together

    Unable to install latest textual and rich-cli together

    Since rich-cli pins textual to 0.1.18 it's not possible to install Textual as suggested in the README:

    $ pip install --index-url=https://pypi.org/simple "textual[dev]"
    Defaulting to user installation because normal site-packages is not writeable
    Requirement already satisfied: textual[dev] in ./.local/lib/python3.7/site-packages (0.1.18)
      WARNING: textual 0.1.18 does not provide the extra 'dev'
    Requirement already satisfied: rich<13.0.0,>=12.3.0 in ./.local/lib/python3.7/site-packages (from textual[dev]) (12.6.0)
    $ python -m textual
    python: No module named textual.__main__; 'textual' is a package and cannot be directly executed
    
    opened by claviola 0
  • Fix duplicate options

    Fix duplicate options

    By capitalizing the emoji single-letter option to -J, a collision between JSON and emoji display options is removed.

    I also included a test that monkeypatches a private function of the click.decorators module to make it fail noisily when option names are duplicated. Could be useful if CI is implemented for this project.

    Fixes #73

    opened by edrogers 0
  • Reused option name: -j is used for both JSON and emoji options

    Reused option name: -j is used for both JSON and emoji options

    The -j option name is listed for both the "Display as JSON" and "Enable emoji code" options in the code and documentation (including the splash screen image in the README). Click's option decorator silently allows one to overwrite the other. As a result, the JSON display option currently has no single-letter option name. To use it, one has to call --json.

    Since the JSON option is older than the emoji option, I propose capitalizing the single-letter emoji option to -J. This would be a breaking change. I'll submit a PR for you to consider if this seems like a good approach.

    opened by edrogers 2
Releases(v1.8.0)
  • v1.8.0(May 7, 2022)

    Rich-cli will now export portable SVGs, which can be loaded in editors. Previously Rich SVGs would only render correctly within a browser.

    Screenshot 2022-05-07 at 15 57 54 Source code(tar.gz)
    Source code(zip)
  • v1.7.0(May 1, 2022)

    Rich-cli 1.7.0 Adds support for Jupyter notebook, with Markdown and syntax highlighting. The following video shows Notebook rendering in conjunction with the --pager option.

    https://user-images.githubusercontent.com/554369/166140064-0f3e14fa-4b08-494c-8fce-6d55e8ef3bd3.mov

    Also in this release is a new --export-svg option which will export anything you print via Rich as an SVG.

    The following command will render the first 10 entries in a CSV and export a filed called deniro.svg:

    rich deniro.csv --export-svg deniro.svg --head 10
    

    Here's what the output looks like in a browser:

    Screenshot 2022-05-01 at 09 45 18 Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Mar 23, 2022)

    [1.6.0] 2022-04-23

    Added

    • Added space key to page down to pager

    Changed

    • Change how code blocks in markdown are rendered (remove border, adding padding)
    • --theme and --lexer are now passed to Markdown and RST parsers
    • Improved CSV guessing
    Source code(tar.gz)
    Source code(zip)
Owner
Textualize
Because Terminals are here to stay
Textualize
Rich is a Python library for rich text and beautiful formatting in the terminal.

Rich δΈ­ζ–‡ readme β€’ lengua espaΓ±ola readme β€’ LΓ€s pΓ₯ svenska Rich is a Python library for rich text and beautiful formatting in the terminal. The Rich API

Will McGugan 41.4k Jan 2, 2023
Rich is a Python library for rich text and beautiful formatting in the terminal.

Rich δΈ­ζ–‡ readme β€’ lengua espaΓ±ola readme β€’ LΓ€s pΓ₯ svenska Rich is a Python library for rich text and beautiful formatting in the terminal. The Rich API

Will McGugan 41.5k Jan 7, 2023
Rich is a Python library for rich text and beautiful formatting in the terminal.

The Rich API makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more β€” out of the box.

Will McGugan 41.4k Jan 3, 2023
A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Stream your favorite shows straight from the command line.

A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Installation pip install -r requirements.txt It use

Jonardon Hazarika 17 Dec 11, 2022
Module for converting 2D Python lists to fancy ASCII tables. Table2Ascii lets you display pretty tables in the terminal and on Discord.

table2ascii Module for converting 2D Python lists to a fancy ASCII/Unicode tables table2ascii ?? Installation ??‍?? Usage Convert lists to ASCII table

Jonah Lawrence 40 Jan 3, 2023
Uses diff command to compare expected output with student's submission output

AUTOGRADER for GRADESCOPE using diff with partial grading Description: Uses diff command to compare expected output with student's submission output U

null 2 Jan 11, 2022
flora-dev-cli (fd-cli) is command line interface software to interact with flora blockchain.

Install git clone https://github.com/Flora-Network/fd-cli.git cd fd-cli python3 -m venv venv source venv/bin/activate pip install -e . --extra-index-u

null 14 Sep 11, 2022
Rich.tui is a TUI (Text User Interface) framework for Python using Rich as a renderer.

rich.tui Rich.tui is a TUI (Text User Interface) framework for Python using Rich as a renderer. The end goal is to be able to rapidly create rich term

Will McGugan 17.1k Jan 4, 2023
A Discord Rich Presence App to set your own custom rich presence.

discord-rich-presence A Discord Rich Presence App to set your own custom rich presence. #BUILDS Ready to use package are available inside "finalpackag

null 1 Nov 22, 2021
Pytest-rich - Pytest + rich integration (proof of concept)

pytest-rich Leverage rich for richer test session output. This plugin is not pub

Bruno Oliveira 170 Dec 2, 2022
frogtrade9000 - a command-line Rich client for the freqtrade REST API

frogtrade9000 - a command-line Rich client for the freqtrade REST API I found FreqUI too cumbersome and slow on my Raspberry Pi 400 when running multi

Robert Davey 79 Dec 2, 2022
Format click help output nicely with rich.

rich-click Format click help output nicely with Rich. Click is a "Python package for creating beautiful command line interfaces". Rich is a "Python li

Phil Ewels 333 Jan 2, 2023
Deskew is a command line tool for deskewing scanned text documents. It uses Hough transform to detect "text lines" in the image. As an output, you get an image rotated so that the lines are horizontal.

Deskew by Marek Mauder https://galfar.vevb.net/deskew https://github.com/galfar/deskew v1.30 2019-06-07 Overview Deskew is a command line tool for des

Marek Mauder 127 Dec 3, 2022
Khandakar Muhtasim Ferdous Ruhan 1 Dec 30, 2021
A fancy and practical functional tools

Funcy A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions. Keep reading to get an

Alexander Schepanovski 2.9k Dec 29, 2022
bpython - A fancy curses interface to the Python interactive interpreter

bpython: A fancy curses interface to the Python interactive interpreter bpython is a lightweight Python interpreter that adds several features common

bpython 2.2k Dec 27, 2022
A fancy and practical functional tools

Funcy A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions. Keep reading to get an

Alexander Schepanovski 2.9k Dec 29, 2022
A fancy and practical functional tools

Funcy A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions. Keep reading to get an

Alexander Schepanovski 2.9k Jan 7, 2023
Fancy data functions that will make your life as a data scientist easier.

WhiteBox Utilities Toolkit: Tools to make your life easier Fancy data functions that will make your life as a data scientist easier. Installing To ins

WhiteBox 3 Oct 3, 2022
pubmex.py - a script to get a fancy paper title based on given DOI or PMID

pubmex.py is a script to get a fancy paper title based on given DOI or PMID (can be also combined with macOS Finder)

Marcin Magnus 13 Nov 20, 2022