[BUG] Text and Syntax measure tabs as zero width, so tables and Panel.fit wrap or cut the text
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Empieza con Text.__rich_measure__ en rich/text.py y Syntax.__rich_measure__ en rich/syntax.py; compara cómo cada medición trata las tabulaciones con el tamaño de tabulación de su renderizador. Reproduce el problema con el ejemplo proporcionado de Measurement.get y los ejemplos de tablas o paneles. El trabajo estará terminado cuando los anchos medidos tengan en cuenta las tabulaciones expandidas y la salida afectada ya no ajuste ni corte el texto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
- 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).
- Lenguaje dominante
- Python
- Estrellas
- 57.8k
- Forks
- 2.6k
- Merge medio
- 20 min
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Textualize/rich#4269 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4268 ·
-
Needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4267 ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Textualize/rich#4265 ·
Todos los issues de Textualize/rich
Issues similares
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
sandbox-quantum/switch#2163 ·
Los mantenedores suelen responder en 1 día
-
bug pydanty:is-working
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
pydantic/pydantic-ai#13939 ·
Los mantenedores suelen responder en 1 día
-
priority: low python
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
LearningCircuit/local-deep-research#8849 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
francescopace/espectre#223 ·
Los mantenedores suelen responder en 3 días
-
good first issue Status: Triaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
canonical/imagecraft#538 · 1 comentario ·
Los mantenedores suelen responder en 2 días