Skip to content

Commit 8e67ce2

Browse files
committed
fix issue rendering strips with missing style
1 parent 43485ed commit 8e67ce2

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/textual/strip.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,12 @@ def render(self, console: Console) -> str:
659659
render = Style.render
660660
self._render_cache = "".join(
661661
[
662-
render(style, text, color_system=color_system)
662+
(
663+
text
664+
if style is None
665+
else render(style, text, color_system=color_system)
666+
)
663667
for text, style, _ in self._segments
664-
if style is not None
665668
]
666669
)
667670
return self._render_cache

tests/snapshot_tests/test_snapshots.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from textual.reactive import var
3030
from textual.renderables.gradient import LinearGradient
3131
from textual.screen import ModalScreen, Screen
32+
from textual.strip import Strip
33+
from textual.widget import Widget
3234
from textual.widgets import (
3335
Button,
3436
Collapsible,

tests/test_strip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from rich.console import Console
23
from rich.segment import Segment
34
from rich.style import Style
45

@@ -196,3 +197,9 @@ def test_text():
196197
assert Strip([]).text == ""
197198
assert Strip([Segment("foo")]).text == "foo"
198199
assert Strip([Segment("foo"), Segment("bar")]).text == "foobar"
200+
201+
202+
def test_render_with_missing_style() -> None:
203+
"""Test that render with segments that omit a style still work."""
204+
strip = Strip([Segment("Hello")])
205+
assert strip.render(Console()) == "Hello"

0 commit comments

Comments
 (0)