Package: rich-cli
Rich CLIRich-cli is a command line toolbox for fancy output in the terminal, built withRich.Use therichcommand 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.InstallationThere are a few options for installing Rich-CLI.Windows / LinuxYou can install Rich-CLI withpipx.pipx install rich-cliMacOSYou can install Rich-CLI withHomebrew.brew install richUniversalRich-CLI may be installed as a Python package, either usingpip:python -m pip install rich-cliOr usingcondaormamba:mamba install -c conda-forge rich-cliRich commandOnce installed you should have therichcommand in your path. Run the following to see usage / help:rich --helpSyntax highlightingTo syntax highlight a file enterrichfollowed by a path. Many file formats are supported.rich loop.pyAdd the--line-numberor-nswitch to enable line numbers. Add--guidesor-gto enable indentation guides.rich loop.py -n -gYou can specify athemewith--theme.rich loop.py --theme draculaYou can set the default theme via theRICH_THEMEenvironment variable. So the following is equivalent to the above command:RICH_THEME=dracula rich loop.pyBy default,richwill wrap lines if they don't fit within the available width. You can disable this behavior with--no-wrap.Richwill try to deduce the format of the via from the filename. If you want to override the auto-detectedlexeryou can explicitly set it with the--lexeror-xswitch.MarkdownYou can request markdown rendering by adding the--markdownswitch or-m. If the file ends with.mdmarkdown will be auto-detected.rich README.mdIf your terminal supports hyperlinks, you can add--hyperlinksor-ywhich will output hyperlinks rather than full URLs.rich README.md --hyperlinksJupyter notebookYou can request Jupyter notebook rendering by adding the--ipynbswitch. If the file ends with.ipynbJupyter notebook will be auto-detected.rich notebook.ipynbAll options that apply to syntax highlighting can be applied to code cells, and all options that apply to Markdown can be
applied to Markdown cells.JSONYou can request JSON pretty formatting and highlighting with the--jsonor-jswitches. If the file ends with.jsonthen JSON will be auto-detected.rich cats.jsonCSVRich can display the contents of a CSV (or TSV) as a table. If the file ends with.csvor.tsvthen CSV will be auto-detected.rich deniro.csvRulesYou can render a horizontal rule with--ruleor-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 "="PagerAdd--pagerto display the content with a built in pager application.Scroll the pager with cursor keys, page up/down, home, end. Alternatively use the scrollbar which will be visible to the right of the terminal. Or use the vi navigation (j, k, ctrl_d, ctrl-u).rich __main__.py -n -g --theme monokai --pagerNetworkTherichcommand can read files from the internet you give it a URL starting withhttp://orhttps://.rich https://raw.githubusercontent.com/Textualize/rich-cli/main/README.md --markdownExportingIn addition to rendering to the console,richcan write an HTML file. This works with any command. Add--export-htmlor-ofollowed by the output path.rich README.md -o readme.htmlAfter running this command you should find a "readme.html" in your current working directory.Rich PrintingIf you add the--printor--poption then Rich will treat the first argument asconsole markupwhich allows you to insert styles with a markup similar in design to bbcode.rich "Hello, [bold magenta]World[/]!" --printSoft wrappingRich will word wrap your text by default by inserting newlines where appropriate. If you don't want this behavior you can enablesoftwrapping with--soft.Reading from StdinWhererichaccepts 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-terminalor-Fto tellrichyou want to keep ansi codes in the output.cat README.md | rich - --markdown --force-terminalGeneral OptionsThere 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.StyleYou can set a style to apply to the output with--styleor-s. The styles are specified withthis syntax.rich "Hello, [b]World[/b]!" --print --style "on blue"AlignmentYou can align output to the left, center, or right with the--left,--center, or--rightoptions, or their single letter counterparts:-l,-c, or-r.rich "Hello [b]World[/b]!" --print --centerWidthYou can set the width of the output with--widthor-wand 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 40Text JustifyYou can set howrichwill 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--leftand--text-leftmay not be obvious unless you specify the width of the output. The--left,--center, and--rightoptions will center the block of text within the terminal dimensions. Whereas, the--text-left,--text-center, and--text-rightoptions define how text is renderedwithinthat block.In the following examples, we specify a width of 40 (-w 40) which is center aligned with the-cswitch. Note how the-R,-Cand-Fapply 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 -FPaddingYou can applypaddingaround the output with--paddingor-d.rich "Hello [b]World[/b]!" -p -c --padding 3 --style "on blue"PanelYou can draw apanelaround content with--panelor-a, which takes one of a number ofstyles.rich "Hello, [b]World[/b]!" -p -a heavy