avatarapril

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2229

Abstract

ps://cdn-images-1.readmedium.com/v2/resize:fit:800/0*anFJIP4AQ1UnudzT.png"><figcaption></figcaption></figure><h2 id="d302">Rules</h2><p id="38db">You can render a horizontal rule with <code>--rule</code> or <code>-u</code>. Specify a rule style with <code>--rule-style</code>. Set the character(s) to render the line with <code>--rule-char</code>.</p><figure id="7bc8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*GeiDqLPgBw7Km3ny.png"><figcaption></figcaption></figure><h2 id="8960">Pager</h2><p id="c975">Add <code>--pager</code> to display the content with a built in pager application.</p><p id="4440">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).</p><div id="6874"><pre>rich main<span class="hljs-selector-class">.py</span> -n -g <span class="hljs-attr">--theme</span> monokai <span class="hljs-attr">--pager</span></pre></div><figure id="923f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*gSZJwtKAQ5xaGGeN.png"><figcaption></figcaption></figure><h2 id="e92b">Network</h2><p id="8c74">The <code>rich</code> command can read files from the internet you give it a URL starting with <code>http://</code> or <a href="https://."><code>https</code>://.</a></p><figure id="0f6b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*LVFI-kNI-pVJ6KKn.png"><figcaption></figcaption></figure><h2 id="0d53">Rich Printing</h2><p id="2e0b">If you add the <code>--print</code> or <code>--p</code> option then Rich will treat the first argument as <a href="https://rich.readthedocs.io/en/latest/markup.html">console markup</a> which allows you to insert styles with a markup similar in design to bbcode.</p><figure id="a4e9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*-NS5RAfan5w9DHnd.png"><figcaption></figcaption></figure><h2 id="b9c3">Style</h2><p id="0f0b">You can set a style to apply to the output with <code>--style</code> or <code>-s</code>. The styles are specified with <a href="https://rich.readthedocs.io/en/latest/style.html">this syntax</a>.</p><figure id="637e"><img src="https://cdn-images-1.rea

Options

dmedium.com/v2/resize:fit:800/0*FHXxmdoCoN5k53CV.png"><figcaption></figcaption></figure><h2 id="3eba">Alignment</h2><p id="fe1d">You can align output to the left, center, or right with the <code>--left</code>, <code>--center</code>, or <code>--right</code> options, or their single letter counterparts: <code>-l</code>, <code>-c</code>, or <code>-r</code>.</p><figure id="a15c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*npVpWMQkjqwNWNKf.png"><figcaption></figcaption></figure><h2 id="53ce">Panel</h2><p id="7e0b">You can draw a <i>panel</i> around content with <code>--panel</code> or <code>-a</code>, which takes one of a number of <a href="https://rich.readthedocs.io/en/latest/appendix/box.html">styles</a>.</p><figure id="54cf"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*94T-iO2RpfXUkP35.png"><figcaption></figcaption></figure><h2 id="a2eb">Exporting</h2><p id="205c">In addition to rendering to the console, <code>rich</code> can write an HTML file. This works with any command. Add <code>--export-html</code> or <code>-o</code> followed by the output path.</p><div id="c5df"><pre>rich README.<span class="hljs-built_in">md</span> -o readme.html</pre></div><p id="cc93">After running this command you should find a “readme.html” in your current working directory.</p><h2 id="ecb0">Reading from Stdin</h2><p id="3caa">Where <code>rich</code> accepts a path, you can enter <code>-</code> which reads the content from stdin. You may want this if you are piping output from another process.</p><p id="8bce">Note that when rich isn’t writing directly to the terminal it will disable ansi color codes, so you may want to add <code>--force-terminal</code> or <code>-F</code> to tell <code>rich</code> you want to keep ansi codes in the output.</p><div id="bc23"><pre><span class="hljs-comment">cat README</span><span class="hljs-string">.</span><span class="hljs-comment">md | rich</span> <span class="hljs-literal">-</span> <span class="hljs-literal">--</span><span class="hljs-comment">markdown</span> <span class="hljs-literal">--</span><span class="hljs-comment">force</span><span class="hljs-literal">-</span><span class="hljs-comment">terminal</span></pre></div></article></body>

A Powerful Open Source CLI for Fancy Output

Rich CLI for a command line application powered by Rich.

Stars: 2.1k
License: MIT
Platforms: Windows, Linux and MacOS
Link: https://github.com/textualize/rich-cli

You can use Rich CLI to highlight a variety of file types in the terminal, with specialized rendering for Markdown, JSON and CSV files. Additionally you can markup and format text from the command line, read files from the internet, and output an HTML file, etc.

Syntax highlighting

To syntax highlight a file enter rich followed by a path. Many file formats are supported.

Markdown

You can request markdown rendering by adding the --markdown switch or -m. If the file ends with .md markdown will be auto-detected.

JSON

You can request JSON pretty formatting and highlighting with the --json or -j switches. If the file ends with .json then JSON will be auto-detected.

CSV

Rich can display the contents of a CSV (or TSV) as a table. If the file ends with .csv or .tsv then CSV will be auto-detected.

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.

Pager

Add --pager to 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 --pager

Network

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

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.

Style

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

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.

Panel

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

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.

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
Programming
Developer
Tools
Productivity
Software Engineering
Recommended from ReadMedium