Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
10 changes: 4 additions & 6 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -1304,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:
Expand Down
1 change: 1 addition & 0 deletions src/textual/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
26 changes: 23 additions & 3 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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💩"),
],
),
(
Expand Down Expand Up @@ -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)
Loading