mcpField
R
rich

rich

github.com/jamie-bitflight開発37 回インストール
リポジトリ

rich について

Rich を使った Python のターミナル UI 開発向けリファレンススキルです。スタイル付き出力、レンダラブル、進捗表示、構文ハイライト、ログ、カスタム描画を扱います。

主な機能

  1. 01Console 出力とマークアップのガイド
  2. 02テーブル、パネル、ツリー、レイアウト
  3. 03プログレスバーとライブ表示
  4. 04構文ハイライトと整形表示
  5. 05ログとトレースバックの連携
  6. 06カスタムレンダラブルのパターン

活用シーン

  1. 01Python CLI にスタイル付き出力を追加
  2. 02構造化されたターミナルデータを表示
  3. 03長時間タスクの進捗を表示
  4. 04ターミナルのログと例外表示を改善

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jamie-bitflight/claude_skills --skill rich

インストール後、Claude Code で/richを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
advanced-patterns.md
console-and-markup.md
logging-and-tracebacks.md
progress-and-live.md
renderables.md
text-and-syntax.md

詳細

Rich ナレッジ

マークアップ、スタイル付き出力、テーブル、進捗状況の追跡、ライブ表示、ロギングとの統合、カスタムレンダラブルなど、正しい Rich ターミナル UI コードを記述できるようにします。

対象範囲

共通のアーキテクチャ、型付け、テスト、CLI のルールを適用する際は、../python3-development/references/python3-standards.md を参照してください。標準、グラフ、改訂プロセスの全容は、そちらに記載されています。

トリガー:rich からインポートする Python コードを記述するとき、または Python CLI にターミナル UI、カラー出力、プログレスバー、テーブル、構文ハイライト、整形出力を追加するよう求められたときに有効化します。

対象:

  • Console クラス、マークアップ構文、スタイル文字列、色の形式
  • すべてのレンダラブル型(Panel、Table、Tree、Columns、Layout)
  • プログレスバー(track()、Progress)と Live 表示
  • 標準ライブラリのロギング用 RichHandler とトレースバックのインストール
  • Text クラスとプログラムによるスタイルの構築
  • Syntax、Markdown、Pretty / pprint、JSON
  • カスタムオブジェクト用の __rich_console__ および __rich_repr__ プロトコル

対象外:

  • Textual(Rich の兄弟にあたる TUI フレームワーク。別ライブラリです)
  • Segment レベル以下の Rich 内部実装
  • Pygments のテーマ作成

ワークフロー

flowchart TD
    Start([Rich task]) --> Q1{Task type?}
    Q1 -->|Print styled output or markup| Markup[Load console-and-markup.md]
    Q1 -->|Build table, panel, tree, columns| Render[Load renderables.md]
    Q1 -->|Progress bar or live update| Prog[Load progress-and-live.md]
    Q1 -->|Syntax highlight or pretty-print code/data| TextSyn[Load text-and-syntax.md]
    Q1 -->|Logging or traceback display| LogTB[Load logging-and-tracebacks.md]
    Q1 -->|Custom renderable, layout, or highlighter| Adv[Load advanced-patterns.md]

リファレンスファイル

Console とマークアップ

Console クラスのインスタンス化とコンストラクターパラメーター、print() / log() / rule() / status() メソッド、マークアップ構文(BBCode 形式のタグ)、スタイル定義文字列、色の形式(名前付き / 256 色番号 / hex / rgb)、スタイル属性(太字/イタリック/下線など)、Style クラス、Theme クラス、環境変数、出力のキャプチャとエクスポート。

console.print() の記述、色やスタイルの適用、Rich マークアップタグの使用、Console の動作設定を行う際に読み込みます。

references/console-and-markup.md

レンダラブル

Panel、Table(add_column、add_row、コンストラクターオプション、列オプション)、Tree(add、style、guide_style)、Columns レイアウト、Padding、Rule、Align、Box スタイルを扱います。コンストラクターのシグネチャと主要なパラメーターを、ソースドキュメントの記載どおりにすべて含みます。

ボックス、テーブル、ツリービュー、複数列レイアウトを使って構造化された出力を作成する際に読み込みます。

references/renderables.md

進捗状況と Live 表示

track() 関数、Progress クラス(add_task、update、advance)、タスク管理(visible、indeterminate、transient)、すべての組み込み列クラス(BarColumn、TextColumn、TimeRemainingColumn、SpinnerColumn など)、Live クラス、console.status() のスピナーを扱います。

CLI に進捗状況の追跡、スピナー、ライブ更新出力を追加する際に読み込みます。

references/progress-and-live.md

Text と構文

Text クラス(append、stylize、highlight_regex、assemble、from_markup)、Syntax クラス(from_path、line_numbers、theme、line_range)、Markdown レンダラブル、pprint / Pretty、JSON レンダラブル、@rich.repr.auto デコレーターを使う __rich_repr__ プロトコルを扱います。

コードブロックのハイライト、Markdown のレンダリング、データ構造の整形出力、オブジェクトの repr 出力のカスタマイズを行う際に読み込みます。

references/text-and-syntax.md

ロギングとトレースバック

RichHandler のコンストラクターパラメーター(全項目の表)、extra={} によるメッセージごとのマークアップ/ハイライターの上書き、ログ出力中の例外に対する rich_tracebacks=True、フレームワークのフレーム用 tracebacks_suppress、グローバルハンドラー用 traceback.install()、console.print_exception() のパラメーター、max_frames の動作を扱います。

Rich と Python の logging モジュールを統合する、グローバルなトレースバックハンドラーをインストールする、例外表示を改善する際に読み込みます。

references/logging-and-tracebacks.md

高度なパターン

__rich__ プロトコル(オブジェクトからレンダラブルを返す)、__rich_console__ プロトコル(レンダラブルまたは Segment を生成するジェネレーター)、カスタム幅報告用の __rich_measure__、Layout クラス(split_column、split_row、update、名前付きペイン)、RegexHighlighter のサブクラス化、組み込みハイライター、inspect() 関数、REPL のインストールを扱います。

カスタムレンダラブルの記述、複数ペインの全画面レイアウトの構築、カスタム構文ハイライトの実装、Python オブジェクトのデバッグを行う際に読み込みます。

references/advanced-patterns.md

Quick Reference

# Install
pip install rich

# Drop-in print replacement
from rich import print
print("[bold red]Hello[/bold red] [green]world[/green]")

# Console (preferred for production code)
from rich.console import Console
console = Console()
console.print("[bold]Hello[/bold]", style="green")
console.rule("[bold red]Section")

# Style string formats
console.print("text", style="bold red underline on white")
console.print("text", style="#af00ff")
console.print("text", style="rgb(175,0,255)")

# Progress bar — simple
from rich.progress import track
for item in track(sequence, description="Processing..."):
    process(item)

# Progress bar — multiple tasks
from rich.progress import Progress
with Progress() as progress:
    task = progress.add_task("[cyan]Working...", total=100)
    progress.update(task, advance=10)

# Logging
import logging
from rich.logging import RichHandler
logging.basicConfig(
    level="NOTSET", format="%(message)s",
    datefmt="[%X]", handlers=[RichHandler()]
)

# Tracebacks
from rich.traceback import install
install(show_locals=True)

# Table
from rich.table import Table
table = Table("Name", "Value")
table.add_row("foo", "bar")
console.print(table)

# Panel
from rich.panel import Panel
console.print(Panel("content", title="Title"))

コメント