MIT License

项目介绍

Textualize/rich-cli 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 3.8k 个 Star、127 次 Fork。

仓库全名
Textualize/rich-cli
开源许可证
MIT License
Star 数
3.8k
Fork 数
127
未关闭 Issue
59

README 摘要

Rich-CLI Rich-CLI is a command line toolbox for fancy output in the terminal, built with Rich. Use the 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. Installation There are a few options for installing Rich-CLI. Windows / Linux You can install Rich-CLI with pipx. MacOS You…

完整内容见 GitHub 原始 README 或本页 。

常见问题

rich-cli 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 3.8k 个 Star。

rich-cli 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 rich-cli 的源码?

可以直接克隆仓库:git clone https://github.com/Textualize/rich-cli.git;安装与运行步骤见仓库 README。

rich-cli 最近还在维护吗?

仓库最近一次更新为 1 周前,当前有 59 个未关闭 Issue;Star 数为 3.8k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

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

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
4057
价值分
2303
活跃状态
活跃

语言占比

Jupyter Notebook
Python

Release

README

Rich-CLI

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

Use the 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.

splash image

Installation

There are a few options for installing Rich-CLI.

Windows / Linux

You can install Rich-CLI with pipx.

pipx install rich-cli

MacOS

You can install Rich-CLI with Homebrew.

brew install rich

Universal

Rich-CLI may be installed as a Python package, either using pip:

python -m pip install rich-cli

Or using conda or mamba:

mamba install -c conda-forge rich-cli

Rich command

Once installed you should have the rich command in your path. Run the following to see usage / help:

rich --help

Syntax highlighting

To syntax highlight a file enter rich followed by a path. 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.

rich loop.py --theme dracula

You can set the default theme via the RICH_THEME environment variable. So the following is equivalent to the above command:

RICH_THEME=dracula rich loop.py

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. If the file ends with .md markdown will be auto-detected.

rich README.md

markdown1

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

rich README.md --hyperlinks

Jupyter notebook

You can request Jupyter notebook rendering by adding the --ipynb switch. If the file ends with .ipynb Jupyter notebook will be auto-detected.

rich notebook.ipynb

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

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.

rich cats.json

json1

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.

rich deniro.csv

csv1

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

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

pager

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

评论

暂无评论