From 8e67ce25d47031eb5d7232d38bb4463cd24f2423 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 7 Sep 2025 10:58:56 +0100 Subject: [PATCH 1/2] fix issue rendering strips with missing style --- src/textual/strip.py | 7 +++++-- tests/snapshot_tests/test_snapshots.py | 2 ++ tests/test_strip.py | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/textual/strip.py b/src/textual/strip.py index b608a92f78..90bbc4df36 100644 --- a/src/textual/strip.py +++ b/src/textual/strip.py @@ -659,9 +659,12 @@ def render(self, console: Console) -> str: 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 diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 2b3eade06c..5781ef614f 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -29,6 +29,8 @@ 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, diff --git a/tests/test_strip.py b/tests/test_strip.py index b88c68ecc5..d3cbf61982 100644 --- a/tests/test_strip.py +++ b/tests/test_strip.py @@ -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" From 17cd7e66a5e1ed5d78f09a96c58752d22fa61d8d Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 7 Sep 2025 11:00:58 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ tests/snapshot_tests/test_snapshots.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa947c651b..76f269007d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `App.viewport_size` https://github.com/Textualize/textual/pull/6105 - Added `Screen.size` https://github.com/Textualize/textual/pull/6105 +### Fixed + +- Fixed issue where Segments with a style of `None` aren't rendered https://github.com/Textualize/textual/pull/6109 + ## [6.1.0] - 2025-08-01 ### Added diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 5781ef614f..2b3eade06c 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -29,8 +29,6 @@ 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,