Skip to content

Commit 4e0ff24

Browse files
authored
Merge pull request #6256 from Textualize/fix-fold
fix fold
2 parents 7a5bc20 + 730bffe commit 4e0ff24

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [6.7.1] - 2025-12-1
9+
10+
### Fixed
11+
12+
- Fixed `Content.fold` https://github.com/Textualize/textual/pull/6256
13+
814
## [6.7.0] - 2025-11-29
915

1016
### Added
@@ -3208,6 +3214,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
32083214
- New handler system for messages that doesn't require inheritance
32093215
- Improved traceback handling
32103216

3217+
[6.7.1]: https://github.com/Textualize/textual/compare/v6.7.0...v6.7.1
32113218
[6.7.0]: https://github.com/Textualize/textual/compare/v6.6.0...v6.7.0
32123219
[6.6.0]: https://github.com/Textualize/textual/compare/v6.5.0...v6.6.0
32133220
[6.5.0]: https://github.com/Textualize/textual/compare/v6.4.0...v6.5.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "6.7.0"
3+
version = "6.7.1"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/content.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,12 @@ def wrap(
967967
return content_lines
968968

969969
def fold(self, width: int) -> list[Content]:
970-
"""Fold this line into a list of lines which have a cell length no greater than `width`.
970+
"""Fold this line into a list of lines which have a cell length no less than 2 and no greater than `width`.
971971
972972
Folded lines may be 1 less than the width if it contains double width characters (which may
973973
not be subdivided).
974974
975-
Note that this method will not do any word wrappig. For that, see [wrap()][textual.content.Content.wrap].
975+
Note that this method will not do any word wrapping. For that, see [wrap()][textual.content.Content.wrap].
976976
977977
Args:
978978
width: Desired maximum width (in cells)
@@ -981,12 +981,12 @@ def fold(self, width: int) -> list[Content]:
981981
List of content instances.
982982
"""
983983
if not self:
984-
return []
984+
return [self]
985985
text = self.plain
986986
lines: list[Content] = []
987987
position = 0
988988
width = max(width, 2)
989-
while text:
989+
while True:
990990
snip = text[position : position + width]
991991
if not snip:
992992
break
@@ -998,7 +998,6 @@ def fold(self, width: int) -> list[Content]:
998998
if snip_cell_length == width:
999999
# Cell length is exactly width
10001000
lines.append(self[position : position + width])
1001-
text = text[len(snip) :]
10021001
position += len(snip)
10031002
continue
10041003
# TODO: Can this be more efficient?
@@ -1304,7 +1303,6 @@ def render(
13041303
An iterable of string and styles, which make up the content.
13051304
13061305
"""
1307-
13081306
if not self._spans:
13091307
yield (self._text, base_style)
13101308
if end:

src/textual/style.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def from_styles(cls, styles: StylesBase) -> Style:
409409
underline2=text_style.underline2,
410410
reverse=text_style.reverse,
411411
strike=text_style.strike,
412+
blink=text_style.blink,
412413
auto_color=styles.auto_color,
413414
)
414415

tests/test_content.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,25 @@ def test_wrap() -> None:
385385
@pytest.mark.parametrize(
386386
"content, width, expected",
387387
[
388+
(
389+
Content("111222333"),
390+
3,
391+
[
392+
Content("111"),
393+
Content("222"),
394+
Content("333"),
395+
],
396+
),
397+
(
398+
Content("1112223334"),
399+
3,
400+
[
401+
Content("111"),
402+
Content("222"),
403+
Content("333"),
404+
Content("4"),
405+
],
406+
),
388407
(
389408
Content(""),
390409
10,
@@ -445,16 +464,16 @@ def test_wrap() -> None:
445464
[
446465
Content("💩H"),
447466
Content.from_markup("[b]ell"),
448-
Content.from_markup("[b]o[/]"),
467+
Content.from_markup("o"),
449468
],
450469
),
451470
(
452-
Content.from_markup("💩H[b]ell[/]💩"),
471+
Content.from_markup("💩H[b]ell[/]o💩"),
453472
3,
454473
[
455474
Content("💩H"),
456475
Content.from_markup("[b]ell"),
457-
Content.from_markup("[b]o[/]💩"),
476+
Content.from_markup("o💩"),
458477
],
459478
),
460479
(
@@ -548,5 +567,6 @@ def test_fold(content: Content, width: int, expected: list[Content]) -> None:
548567
"""
549568
result = content.fold(width)
550569
assert isinstance(result, list)
570+
assert len(result) == len(expected)
551571
for line, expected_line in zip(result, expected):
552572
assert line.is_same(expected_line)

0 commit comments

Comments
 (0)