From 6640057e1c06202b33b8bd57357d2dfcaf9e3c69 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 30 Nov 2025 18:02:51 +0000 Subject: [PATCH 1/2] fix fold --- src/textual/content.py | 5 ++--- tests/test_content.py | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/textual/content.py b/src/textual/content.py index e2a29ef704..488543a118 100644 --- a/src/textual/content.py +++ b/src/textual/content.py @@ -981,12 +981,12 @@ def fold(self, width: int) -> list[Content]: List of content instances. """ if not self: - return [] + return [self] text = self.plain lines: list[Content] = [] position = 0 width = max(width, 2) - while text: + while True: snip = text[position : position + width] if not snip: break @@ -998,7 +998,6 @@ def fold(self, width: int) -> list[Content]: if snip_cell_length == width: # Cell length is exactly width lines.append(self[position : position + width]) - text = text[len(snip) :] position += len(snip) continue # TODO: Can this be more efficient? diff --git a/tests/test_content.py b/tests/test_content.py index 57f2996cb3..8e60755f1e 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -385,6 +385,25 @@ def test_wrap() -> None: @pytest.mark.parametrize( "content, width, expected", [ + ( + Content("111222333"), + 3, + [ + Content("111"), + Content("222"), + Content("333"), + ], + ), + ( + Content("1112223334"), + 3, + [ + Content("111"), + Content("222"), + Content("333"), + Content("4"), + ], + ), ( Content(""), 10, @@ -445,16 +464,16 @@ def test_wrap() -> None: [ Content("💩H"), Content.from_markup("[b]ell"), - Content.from_markup("[b]o[/]"), + Content.from_markup("o"), ], ), ( - Content.from_markup("💩H[b]ell[/]💩"), + Content.from_markup("💩H[b]ell[/]o💩"), 3, [ Content("💩H"), Content.from_markup("[b]ell"), - Content.from_markup("[b]o[/]💩"), + Content.from_markup("o💩"), ], ), ( @@ -548,5 +567,6 @@ def test_fold(content: Content, width: int, expected: list[Content]) -> None: """ result = content.fold(width) assert isinstance(result, list) + assert len(result) == len(expected) for line, expected_line in zip(result, expected): assert line.is_same(expected_line) From 730bffe06e93a613a9fd435076409515ce243de1 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 1 Dec 2025 17:59:08 +0000 Subject: [PATCH 2/2] version bump --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- src/textual/content.py | 5 ++--- src/textual/style.py | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeb9bba75f..e0e387bb74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [6.7.1] - 2025-12-1 + +### Fixed + +- Fixed `Content.fold` https://github.com/Textualize/textual/pull/6256 + ## [6.7.0] - 2025-11-29 ### Added @@ -3208,6 +3214,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040 - New handler system for messages that doesn't require inheritance - Improved traceback handling +[6.7.1]: https://github.com/Textualize/textual/compare/v6.7.0...v6.7.1 [6.7.0]: https://github.com/Textualize/textual/compare/v6.6.0...v6.7.0 [6.6.0]: https://github.com/Textualize/textual/compare/v6.5.0...v6.6.0 [6.5.0]: https://github.com/Textualize/textual/compare/v6.4.0...v6.5.0 diff --git a/pyproject.toml b/pyproject.toml index c082cb84fd..6a04b4bd35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual" -version = "6.7.0" +version = "6.7.1" homepage = "https://github.com/Textualize/textual" repository = "https://github.com/Textualize/textual" documentation = "https://textual.textualize.io/" diff --git a/src/textual/content.py b/src/textual/content.py index 488543a118..968d36e521 100644 --- a/src/textual/content.py +++ b/src/textual/content.py @@ -967,12 +967,12 @@ def wrap( return content_lines def fold(self, width: int) -> list[Content]: - """Fold this line into a list of lines which have a cell length no greater than `width`. + """Fold this line into a list of lines which have a cell length no less than 2 and no greater than `width`. Folded lines may be 1 less than the width if it contains double width characters (which may not be subdivided). - Note that this method will not do any word wrappig. For that, see [wrap()][textual.content.Content.wrap]. + Note that this method will not do any word wrapping. For that, see [wrap()][textual.content.Content.wrap]. Args: width: Desired maximum width (in cells) @@ -1303,7 +1303,6 @@ def render( An iterable of string and styles, which make up the content. """ - if not self._spans: yield (self._text, base_style) if end: diff --git a/src/textual/style.py b/src/textual/style.py index 26bfa49690..30de58cd4c 100644 --- a/src/textual/style.py +++ b/src/textual/style.py @@ -409,6 +409,7 @@ def from_styles(cls, styles: StylesBase) -> Style: underline2=text_style.underline2, reverse=text_style.reverse, strike=text_style.strike, + blink=text_style.blink, auto_color=styles.auto_color, )