`text-wrap: nowrap` with `line-pad` filling the width raises `ValueError: range() arg 3 must not be zero`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The crash comes from get_height in textual/content.py (around line 613), which passes width - line_pad * 2 into _wrap_and_format, where the nowrap + fold branch (around line 670) uses it as a range step. Run the reproduction app with Static { width: 2; line-pad: 1; text-wrap: nowrap; } to confirm the ValueError. Done when that layout returns a height without raising, and the zero-width case is handled the same way negative widths already are. The wrapping path reaching Rich's divide_line with width 0 (rich#4234) is a separate issue and should stay out of scope.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Textualize/textual#6777 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day