[BUG] Text and Syntax measure tabs as zero width, so tables and Panel.fit wrap or cut the text
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu với Text.__rich_measure__ trong rich/text.py và Syntax.__rich_measure__ trong rich/syntax.py; so sánh cách mỗi phép đo xử lý tab theo kích thước tab của bộ kết xuất tương ứng. Tái hiện sự cố bằng ví dụ Measurement.get được cung cấp và các ví dụ bảng hoặc panel. Hoàn tất khi độ rộng được đo tính đến các tab đã mở rộng và đầu ra bị ảnh hưởng không còn ngắt dòng hoặc cắt mất văn bản.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- 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).
- Ngôn ngữ chính
- Python
- Star
- 57.8k
- Fork
- 2.6k
- Merge trung bình
- 20 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Textualize/rich#4269 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Textualize/rich#4268 ·
-
Needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Textualize/rich#4267 ·
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Textualize/rich#4265 ·
Tất cả issue của Textualize/rich
Issue tương tự
-
Internal ErrorĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
frappe/frappe_docker#2071 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Đang mởcomp/desktop P2 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#157702 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenCó thể đã có người làm @BahaaMattar đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Maintainer thường phản hồi trong vòng 1 ngày