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

オープン 初心者向け
#6,782 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

クラッシュの原因は textual/content.py の get_height(613行付近)です。ここで width - line_pad * 2 を _wrap_and_format に渡しており、nowrap + fold の分岐(670行付近)がそれを range のステップとして使っています。再現アプリを Static { width: 2; line-pad: 1; text-wrap: nowrap; } で実行し、ValueError を確認してください。このレイアウトが例外を発生させずに高さを返し、幅ゼロの場合が既存の負の幅と同じように扱われれば完了です。折り返しの経路が幅0で Rich の divide_line に到達する件(rich#4234)は別の問題なので、今回の対象外のままにしてください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
37.7k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Textualize/textual のほかの issue

Textualize/textual の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。