`text-wrap: nowrap` with `line-pad` filling the width raises `ValueError: range() arg 3 must not be zero`

Aperta Adatta ai principianti
#6,782 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Il crash deriva da get_height in textual/content.py (intorno alla riga 613), che passa width - line_pad * 2 a _wrap_and_format, dove il ramo nowrap + fold (intorno alla riga 670) lo usa come passo di range. Esegui l'app di riproduzione con Static { width: 2; line-pad: 1; text-wrap: nowrap; } per confermare il ValueError. È completato quando questo layout restituisce un'altezza senza sollevare eccezioni e il caso di larghezza zero viene gestito come già avviene per le larghezze negative. Il fatto che il percorso di a capo raggiunga divide_line di Rich con larghezza 0 (rich#4234) è un problema separato e deve restare fuori dall'ambito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi! I hit this while writing generated tests against Textual's widgets. When a widget's line-pad takes up its whole content width and text-wrap is nowrap, measuring its height crashes.

from textual.app import App, ComposeResult
from textual.widgets import Static

class LinePadApp(App):
    CSS = "Static { width: 2; line-pad: 1; text-wrap: nowrap; }"

    def compose(self) -> ComposeResult:
        yield Static("Hello")

if __name__ == "__main__":
    LinePadApp().run()

Expected: an (empty-looking) two-cell widget.

Actual (on Textual 8.2.7 with Rich 15.0.0, and on main at 5e5b7ef with Rich 14.2.0 and with Rich main):

  File "textual/content.py", line 613, in get_height
    lines = self.without_spans._wrap_and_format(
        width - line_pad, overflow=overflow, no_wrap=no_wrap
    )
  File "textual/content.py", line 670, in _wrap_and_format
    cuts = list(range(0, line.cell_length, width))[1:]
ValueError: range() arg 3 must not be zero

get_height passes width - line_pad * 2, which is 0 here, and the nowrap + fold branch uses it as a range step. A width less than 0 (for example width: 1) gives an empty range and doesn't raise.

With wrapping on (the default), the same layout reaches Rich's divide_line with width 0, which is rich#4234. A plain Button with width: 2; min-width: 0 hits that one, with Rich 15.

I'd suggest skipping the cuts when the width is 0 or less, which is what already happens for negative widths. I'm happy to send a PR.

Lingua principale
Python
Stelle
37.7k
Fork
1.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Textualize/textual

Tutte le issue di Textualize/textual

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.