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
A Discord Bot for rendering Markdown

Markdown to PDF Bot A discord bot that accepts markdown files (or messages) and displays them as images. Prerequisite To install, you must have have :

1 Oct 21, 2021
A markdown lexer and parser which gives the programmer atomic control over markdown parsing to html.

A markdown lexer and parser which gives the programmer atomic control over markdown parsing to html.

stonepresto 4 Aug 13, 2022
Mdut: a tool for generating Markdown URL tags

mdut mdut (pronounced "em-doot") is a tool for generating Markdown URL tags. It

Nik Kantar 2 Feb 17, 2022
A minimal platform for Markdown-based blogs

madblog This project provides a minimal blogging platform based on Markdown files. Demos This project powers the following blogs: Platypush My persona

Fabio Manganiello 2 Aug 02, 2022
Provides syntax for Python-Markdown which allows for the inclusion of the contents of other Markdown documents.

Markdown-Include This is an extension to Python-Markdown which provides an "include" function, similar to that found in LaTeX (and also the C pre-proc

Chris MacMackin 85 Dec 30, 2022
markdown2: A fast and complete implementation of Markdown in Python

Markdown is a light text markup format and a processor to convert that to HTML. The originator describes it as follows: Markdown is a text-to-HTML con

Trent Mick 2.4k Dec 30, 2022
Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed. Now in Python!

markdown-it-py Markdown parser done right. Follows the CommonMark spec for baseline parsing Configurable syntax: you can add new rules and even replac

Executable Books 398 Dec 24, 2022
Pure-python-server - A blogging platform written in pure python for developer to share their coding knowledge

Pure Python web server - PyProject A blogging platform written in pure python (n

Srikar Koushik Satya Viswanadha 10 Nov 07, 2022
Extensions for Python Markdown

PyMdown Extensions Extensions for Python Markdown. Documentation Extension documentation is found here: https://facelessuser.github.io/pymdown-extensi

Isaac Muse 685 Jan 01, 2023
A markdown extension for converting Leiden+ epigraphic text to TEI XML/HTML

LeidenMark $ pip install leidenmark A Python Markdown extension for converting Leiden+ epigraphic text to TEI XML/HTML. Inspired by the Brill plain te

Andrรฉ van Delft 2 Aug 04, 2021
A markdown generation library for Python.

Welcome to SnakeMD SnakeMD is your ticket to generating Markdown in Python. To prove it to you, we've generated this entire README using SnakeMD. See

The Renegade Coder 22 Dec 08, 2022
A Straightforward Markdown Journal

Introducing Pepys: A straightforward markdown journal "It is rightly made for those who love to document their daily life events" - FOSSBytes Pepys is

Luke Briggs 23 Nov 12, 2022
Lightweight Markdown dialect for Python desktop apps

Litemark is a lightweight Markdown dialect originally created to be the markup language for the Codegame Platform project. When you run litemark from the command line interface without any arguments,

10 Apr 23, 2022
Yuque2md - Offline download the markdown file and image from yuque

yuque2md ๆŒ‰็…ง่ฏญ้›€็Ÿฅ่ฏ†ๅบ“้‡Œ็š„็›ฎๅฝ•๏ผŒๅฏผๅ‡บ่ฏญ้›€็Ÿฅ่ฏ†ๅบ“ไธญๆ‰€ๆœ‰็š„markdownๆ–‡ๆกฃ๏ผŒๅนถ็ฆป็บฟๅ›พ็‰‡ๅˆฐๆœฌๅœฐ ไฝฟ็”จ ๅฎ‰่ฃ… Python3.x clone ้กน็›ฎ ไธ‹่ฝฝไพ

JiaJianHuang 4 Oct 30, 2022
Notedown - Markdown <=> IPython Notebook

Python 2/3 and IPython 4 / Jupyter compatible! Convert IPython Notebooks to markdown (and back) notedown is a simple tool to create IPython notebooks

Aaron O'Leary 840 Jan 04, 2023
Static site generator that supports Markdown and reST syntax. Powered by Python.

Pelican Pelican is a static site generator, written in Python. Write content in reStructuredText or Markdown using your editor of choice Includes a si

Pelican dev team 11.3k Jan 05, 2023
Toci is a markdown tool to generate an outline from a given Jupyter notebook.

Toci is a markdown tool to generate an outline from a given Jupyter notebook. It traverses the markdown cells of a given ipynb file to form a toc for you.

Hakan ร–zler 7 Jan 22, 2022
Preview GitHub README.md files locally before committing them.

Grip -- GitHub Readme Instant Preview Render local readme files before sending off to GitHub. Grip is a command-line server application written in Pyt

Joe Esposito 5.9k Jan 08, 2023
Comprehensive Markdown plugin built for Django

Django MarkdownX Django MarkdownX is a comprehensive Markdown plugin built for Django, the renowned high-level Python web framework, with flexibility,

neutronX 740 Jan 08, 2023
Markdown journal template.

Markdown Journal Template Description This project contains a script which creates a markdown journal template for the current year by creating a mark

Stephen McAleese 2 Mar 06, 2022