[BUG] Text and Syntax measure tabs as zero width, so tables and Panel.fit wrap or cut the text
まだ誰も着手していません。
評価
調査の方向性
rich/text.py の Text.__rich_measure__ と rich/syntax.py の Syntax.__rich_measure__ から始め、それぞれの測定がレンダラーのタブサイズに応じてタブをどのように扱うかを比較します。提供された Measurement.get の例と、テーブルまたはパネルの例を使って問題を再現します。測定幅が展開後のタブを考慮し、影響を受ける出力でテキストが折り返されたり切れたりしなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
- I've checked docs and closed issues for possible solutions.
- I can't find my issue in the FAQ.
Describe the bug
Tabs are expanded when text is rendered, but not when it is measured, so containers that size to their content come out too narrow:
from rich.console import Console
from rich.panel import Panel
from rich.syntax import Syntax
from rich.table import Table
console = Console(width=80)
table = Table("name", "value")
table.add_row("path\t/usr/bin", "1")
console.print(table)
console.print(Panel.fit(Syntax('func main() {\n\tfmt.Println("hello")\n}', "go")))
┏━━━━━━━━━━━━━━┳━━━━━━━┓
┃ name ┃ value ┃
┡━━━━━━━━━━━━━━╇━━━━━━━┩
│ path │ 1 │
│ /usr/bin │ │
└──────────────┴───────┘
╭──────────────────────╮
│ func main() { │
│ fmt.Println("hel │
│ } │
╰──────────────────────╯
There are 80 columns available, but the cell wraps and the Go line is cut. In a no_wrap=True column, "x\ty" becomes x ….
Measurement.get(console, console.options, Text("ab\tcd")) returns a maximum of 4, but the text renders 10 cells wide. Text.__rich_measure__ (rich/text.py) uses cell_len on the raw plain text, and Syntax.__rich_measure__ (rich/syntax.py) does the same on the raw code lines. Both renderers expand tabs (tab_size 8 for Text, 4 for Syntax).
Platform
Click to expand
Linux. Reproduced with rich 14.1.0 and master (3a109ccd), output to a plain Console(width=80).
- 主要言語
- Python
- スター
- 57.8k
- フォーク
- 2.6k
- 平均マージ
- 20分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/rich のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
Textualize/rich#4269 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4268 ·
-
Needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4267 ·
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Textualize/rich#4265 ·
Textualize/rich の issue をすべて見る
似ている issue
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信
-
bug pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pydantic/pydantic-ai#13939 ·
メンテナーはふだん 1 日以内に返信
-
priority: low python
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
LearningCircuit/local-deep-research#8849 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
francescopace/espectre#223 ·
メンテナーはふだん 3 日以内に返信
-
good first issue Status: Triaged
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
canonical/imagecraft#538 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信