rich

Utilities

终端样式

概述 rich

Rich 是一个用于将富文本写入终端的 Python 库。它支持 Markdown 渲染、语法突出显示、表格、进度条、漂亮打印的回溯以及各种其他格式选项 - 所有这些都具有简单、富有表现力的 API。

在PyRun的终端中,Rich 的样式以格式化输出的形式出现,使其成为构建精美的 CLI 输出的出色工具。无论您是要构建数据报告脚本还是只是想要更好的打印报表,Rich 都可以通过 micropip 开箱即用,无需安装。

代码和执行输出

使用丰富的库设计面板和表格。

Rich Terminal Tables在编辑器中运行
from rich.console import Console
from rich.table import Table
from rich.panel import Panel

console = Console()

console.print(Panel.fit("[bold green]Welcome to PyRun[/bold green]", border_style="green"))

table = Table(title="Top Programming Languages")
table.add_column("Rank", justify="center", style="cyan", no_wrap=True)
table.add_column("Language", style="magenta")
table.add_column("Type", style="green")
table.add_column("Popular For", style="yellow")

table.add_row("1", "Python",     "Dynamic", "Data Science, AI")
table.add_row("2", "JavaScript", "Dynamic", "Web, Node")
table.add_row("3", "TypeScript", "Static",  "Large-scale Web")
table.add_row("4", "Rust",       "Static",  "Systems, WASM")

console.print(table)

相关套餐

推荐的 Python 资源

通过相关的交互式教程、备忘单和代码比较来扩展您的知识。