55[ ![ Rich blog] ( https://img.shields.io/badge/blog-rich%20news-yellowgreen )] ( https://www.willmcgugan.com/tag/rich/ )
66[ ![ Twitter Follow] ( https://img.shields.io/twitter/follow/willmcgugan.svg?style=social )] ( https://twitter.com/willmcgugan )
77
8- ![ Logo] ( https://github.com/textualize/rich/raw/master /imgs/logo.svg )
9-
10- [ English readme] ( https://github.com/textualize/rich/blob/master /README.md )
11- • [ 简体中文 readme] ( https://github.com/textualize/rich/blob/master /README.cn.md )
12- • [ 正體中文 readme] ( https://github.com/textualize/rich/blob/master /README.zh-tw.md )
13- • [ Lengua española readme] ( https://github.com/textualize/rich/blob/master /README.es.md )
14- • [ Deutsche readme] ( https://github.com/textualize/rich/blob/master /README.de.md )
15- • [ Läs på svenska] ( https://github.com/textualize/rich/blob/master /README.sv.md )
16- • [ 日本語 readme] ( https://github.com/textualize/rich/blob/master /README.ja.md )
17- • [ 한국어 readme] ( https://github.com/textualize/rich/blob/master /README.kr.md )
18- • [ Français readme] ( https://github.com/textualize/rich/blob/master /README.fr.md )
19- • [ Schwizerdütsch readme] ( https://github.com/textualize/rich/blob/master /README.de-ch.md )
20- • [ हिन्दी readme] ( https://github.com/textualize/rich/blob/master /README.hi.md )
21- • [ Português brasileiro readme] ( https://github.com/textualize/rich/blob/master /README.pt-br.md )
22- • [ Italian readme] ( https://github.com/textualize/rich/blob/master /README.it.md )
23- • [ Русский readme] ( https://github.com/textualize/rich/blob/master /README.ru.md )
24- • [ فارسی readme] ( https://github.com/textualize/rich/blob/master /README.fa.md )
25- • [ Türkçe readme] ( https://github.com/textualize/rich/blob/master /README.tr.md )
26- • [ Polskie readme] ( https://github.com/textualize/rich/blob/master /README.pl.md )
8+ ![ Logo] ( https://github.com/textualize/rich/raw/main /imgs/logo.svg )
9+
10+ [ English readme] ( https://github.com/textualize/rich/blob/main /README.md )
11+ • [ 简体中文 readme] ( https://github.com/textualize/rich/blob/main /README.cn.md )
12+ • [ 正體中文 readme] ( https://github.com/textualize/rich/blob/main /README.zh-tw.md )
13+ • [ Lengua española readme] ( https://github.com/textualize/rich/blob/main /README.es.md )
14+ • [ Deutsche readme] ( https://github.com/textualize/rich/blob/main /README.de.md )
15+ • [ Läs på svenska] ( https://github.com/textualize/rich/blob/main /README.sv.md )
16+ • [ 日本語 readme] ( https://github.com/textualize/rich/blob/main /README.ja.md )
17+ • [ 한국어 readme] ( https://github.com/textualize/rich/blob/main /README.kr.md )
18+ • [ Français readme] ( https://github.com/textualize/rich/blob/main /README.fr.md )
19+ • [ Schwizerdütsch readme] ( https://github.com/textualize/rich/blob/main /README.de-ch.md )
20+ • [ हिन्दी readme] ( https://github.com/textualize/rich/blob/main /README.hi.md )
21+ • [ Português brasileiro readme] ( https://github.com/textualize/rich/blob/main /README.pt-br.md )
22+ • [ Italian readme] ( https://github.com/textualize/rich/blob/main /README.it.md )
23+ • [ Русский readme] ( https://github.com/textualize/rich/blob/main /README.ru.md )
24+ • [ فارسی readme] ( https://github.com/textualize/rich/blob/main /README.fa.md )
25+ • [ Türkçe readme] ( https://github.com/textualize/rich/blob/main /README.tr.md )
26+ • [ Polskie readme] ( https://github.com/textualize/rich/blob/main /README.pl.md )
2727
2828Rich 是一个 Python 库,可以为您在终端中提供富文本和精美格式。
2929
3030[ Rich 的 API] ( https://rich.readthedocs.io/en/latest/ ) 让在终端输出颜色和样式变得很简单。此外,Rich 还可以绘制漂亮的表格、进度条、markdown、语法高亮的源代码以及栈回溯信息(tracebacks)等——开箱即用。
3131
32- ![ 功能纵览] ( https://github.com/textualize/rich/raw/master /imgs/features.png )
32+ ![ 功能纵览] ( https://github.com/textualize/rich/raw/main /imgs/features.png )
3333
3434有关 Rich 的视频介绍,请参见
3535[ @fishnets88 ] ( https://twitter.com/fishnets88 ) 录制的
@@ -59,7 +59,7 @@ from rich import print
5959print (" Hello, [bold magenta]World[/bold magenta]!" , " :vampire:" , locals ())
6060```
6161
62- ![ Hello World] ( https://github.com/textualize/rich/raw/master /imgs/print.png )
62+ ![ Hello World] ( https://github.com/textualize/rich/raw/main /imgs/print.png )
6363
6464## 在交互式命令行(REPL)中使用 Rich
6565
@@ -70,7 +70,7 @@ Rich 可以被安装到 Python 交互式命令行中,那样做以后,任何
7070>> > pretty.install()
7171```
7272
73- ![ REPL] ( https://github.com/textualize/rich/raw/master /imgs/repl.png )
73+ ![ REPL] ( https://github.com/textualize/rich/raw/main /imgs/repl.png )
7474
7575## 使用控制台
7676
@@ -98,15 +98,15 @@ console.print("Hello", "World!", style="bold red")
9898
9999输出如下图:
100100
101- ![ Hello World] ( https://github.com/textualize/rich/raw/master /imgs/hello_world.png )
101+ ![ Hello World] ( https://github.com/textualize/rich/raw/main /imgs/hello_world.png )
102102
103103这个范例一次只设置了一行文字的样式。如果想获得更细腻更复杂的样式,Rich 可以渲染一个特殊的标记,其语法类似于[ bbcode] ( https://en.wikipedia.org/wiki/BBCode ) 。示例如下:
104104
105105``` python
106106console.print(" Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i]." )
107107```
108108
109- ![ 控制台标记] ( https://github.com/textualize/rich/raw/master /imgs/where_there_is_a_will.png )
109+ ![ 控制台标记] ( https://github.com/textualize/rich/raw/main /imgs/where_there_is_a_will.png )
110110
111111使用` Console ` 对象,你可以花最少的工夫生成复杂的输出。更详细的内容可查阅 [ Console API] ( https://rich.readthedocs.io/en/latest/console.html ) 文档。
112112
@@ -120,7 +120,7 @@ Rich 提供一个 [inspect](https://rich.readthedocs.io/en/latest/reference/init
120120>> > inspect(my_list, methods = True )
121121```
122122
123- ![ Log] ( https://github.com/textualize/rich/raw/master /imgs/inspect.png )
123+ ![ Log] ( https://github.com/textualize/rich/raw/main /imgs/inspect.png )
124124
125125查看 [ inspect 文档] ( https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect ) 详细了解。
126126
@@ -160,7 +160,7 @@ test_log()
160160
161161以上范例的输出如下:
162162
163- ![ 日志] ( https://github.com/textualize/rich/raw/master /imgs/log.png )
163+ ![ 日志] ( https://github.com/textualize/rich/raw/main /imgs/log.png )
164164
165165注意其中的` log_locals ` 参数会输出一个表格,该表格包含调用 log 方法的局部变量。
166166
@@ -172,7 +172,7 @@ log 方法既可用于将常驻进程(例如服务器进程)的日志打印
172172
173173您还可以使用内置的[ 处理器类] ( https://rich.readthedocs.io/en/latest/logging.html ) 来对 Python 的 logging 模块的输出进行格式化和着色。下面是输出示例:
174174
175- ![ 记录] ( https://github.com/textualize/rich/raw/master /imgs/logging.png )
175+ ![ 记录] ( https://github.com/textualize/rich/raw/main /imgs/logging.png )
176176
177177</details >
178178
@@ -227,13 +227,13 @@ console.print(table)
227227
228228该示例的输出如下:
229229
230- ![ 表格] ( https://github.com/textualize/rich/raw/master /imgs/table.png )
230+ ![ 表格] ( https://github.com/textualize/rich/raw/main /imgs/table.png )
231231
232232请注意,控制台标记的呈现方式与` print() ` 和` log() ` 相同。实际上,由 Rich 渲染的任何内容都可以添加到标题/行(甚至其他表格)中。
233233
234234` Table ` 类很聪明,可以调整列的大小以适合终端的可用宽度,并能根据需要对文字折行。下面是相同的示例,输出与比上表小的终端上:
235235
236- ![ 表格 2] ( https://github.com/textualize/rich/raw/master /imgs/table2.png )
236+ ![ 表格 2] ( https://github.com/textualize/rich/raw/main /imgs/table2.png )
237237
238238</details >
239239
@@ -253,13 +253,13 @@ for step in track(range(100)):
253253
254254添加多个进度条并不难。以下是从文档中获取的示例:
255255
256- ![ 进度] ( https://github.com/textualize/rich/raw/master /imgs/progress.gif )
256+ ![ 进度] ( https://github.com/textualize/rich/raw/main /imgs/progress.gif )
257257
258258这些列可以配置为显示您所需的任何详细信息。内置列包括完成百分比,文件大小,文件速度和剩余时间。下面是显示正在进行的下载的示例:
259259
260- ![ 进度] ( https://github.com/textualize/rich/raw/master /imgs/downloader.gif )
260+ ![ 进度] ( https://github.com/textualize/rich/raw/main /imgs/downloader.gif )
261261
262- 要自己尝试一下,请参阅[ examples/downloader.py] ( https://github.com/textualize/rich/blob/master /examples/downloader.py ) ,它可以在显示进度的同时下载多个 URL。
262+ 要自己尝试一下,请参阅[ examples/downloader.py] ( https://github.com/textualize/rich/blob/main /examples/downloader.py ) ,它可以在显示进度的同时下载多个 URL。
263263
264264</details >
265265
@@ -284,7 +284,7 @@ with console.status("[bold green]Working on tasks...") as status:
284284
285285这会往终端生成以下输出:
286286
287- ![ status] ( https://github.com/textualize/rich/raw/master /imgs/status.gif )
287+ ![ status] ( https://github.com/textualize/rich/raw/main /imgs/status.gif )
288288
289289这个旋转动画借鉴自 [ cli-spinners] ( https://www.npmjs.com/package/cli-spinners ) 项目。你可以通过` spinner ` 参数指定一种动画效果。执行以下命令来查看所有可选值:
290290
@@ -294,7 +294,7 @@ python -m rich.spinner
294294
295295这会往终端输出以下内容:
296296
297- ![ spinners] ( https://github.com/textualize/rich/raw/master /imgs/spinners.gif )
297+ ![ spinners] ( https://github.com/textualize/rich/raw/main /imgs/spinners.gif )
298298
299299</details >
300300
@@ -311,9 +311,9 @@ python -m rich.tree
311311
312312这会产生以下输出:
313313
314- ![ markdown] ( https://github.com/textualize/rich/raw/master /imgs/tree.png )
314+ ![ markdown] ( https://github.com/textualize/rich/raw/main /imgs/tree.png )
315315
316- [ tree.py] ( https://github.com/textualize/rich/blob/master /examples/tree.py ) 是一个展示任意目录的文件树视图的样例文件,类似于 Linux 中的 ` tree ` 命令。
316+ [ tree.py] ( https://github.com/textualize/rich/blob/main /examples/tree.py ) 是一个展示任意目录的文件树视图的样例文件,类似于 Linux 中的 ` tree ` 命令。
317317
318318</details >
319319
@@ -333,9 +333,9 @@ directory = os.listdir(sys.argv[1])
333333print (Columns(directory))
334334```
335335
336- 以下屏幕截图是[ 列示例] ( https://github.com/textualize/rich/blob/master /examples/columns.py ) 的输出,该列显示了从 API 提取的数据:
336+ 以下屏幕截图是[ 列示例] ( https://github.com/textualize/rich/blob/main /examples/columns.py ) 的输出,该列显示了从 API 提取的数据:
337337
338- ![ 列] ( https://github.com/textualize/rich/raw/master /imgs/columns.png )
338+ ![ 列] ( https://github.com/textualize/rich/raw/main /imgs/columns.png )
339339
340340</details >
341341
@@ -358,7 +358,7 @@ console.print(markdown)
358358
359359该例子的输出如下图:
360360
361- ![ markdown] ( https://github.com/textualize/rich/raw/master /imgs/markdown.png )
361+ ![ markdown] ( https://github.com/textualize/rich/raw/main /imgs/markdown.png )
362362
363363</details >
364364
@@ -393,7 +393,7 @@ console.print(syntax)
393393
394394输出如下:
395395
396- ![ 语法] ( https://github.com/textualize/rich/raw/master /imgs/syntax.png )
396+ ![ 语法] ( https://github.com/textualize/rich/raw/main /imgs/syntax.png )
397397
398398</details >
399399
@@ -404,7 +404,7 @@ Rich 可以渲染出漂亮的[栈回溯信息](https://rich.readthedocs.io/en/la
404404
405405下面是在 OSX(在 Linux 上也类似)系统的效果:
406406
407- ![ 回溯] ( https://github.com/textualize/rich/raw/master /imgs/traceback.png )
407+ ![ 回溯] ( https://github.com/textualize/rich/raw/main /imgs/traceback.png )
408408
409409</details >
410410
0 commit comments