mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix issue rendering strips with missing style
This commit is contained in:
@@ -659,9 +659,12 @@ class Strip:
|
||||
render = Style.render
|
||||
self._render_cache = "".join(
|
||||
[
|
||||
render(style, text, color_system=color_system)
|
||||
(
|
||||
text
|
||||
if style is None
|
||||
else render(style, text, color_system=color_system)
|
||||
)
|
||||
for text, style, _ in self._segments
|
||||
if style is not None
|
||||
]
|
||||
)
|
||||
return self._render_cache
|
||||
|
||||
@@ -29,6 +29,8 @@ from textual.pilot import Pilot
|
||||
from textual.reactive import var
|
||||
from textual.renderables.gradient import LinearGradient
|
||||
from textual.screen import ModalScreen, Screen
|
||||
from textual.strip import Strip
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import (
|
||||
Button,
|
||||
Collapsible,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
from rich.console import Console
|
||||
from rich.segment import Segment
|
||||
from rich.style import Style
|
||||
|
||||
@@ -196,3 +197,9 @@ def test_text():
|
||||
assert Strip([]).text == ""
|
||||
assert Strip([Segment("foo")]).text == "foo"
|
||||
assert Strip([Segment("foo"), Segment("bar")]).text == "foobar"
|
||||
|
||||
|
||||
def test_render_with_missing_style() -> None:
|
||||
"""Test that render with segments that omit a style still work."""
|
||||
strip = Strip([Segment("Hello")])
|
||||
assert strip.render(Console()) == "Hello"
|
||||
|
||||
Reference in New Issue
Block a user