Skip to content

Commit

Permalink
Merge pull request #1621 from Textualize/strip-text
Browse files Browse the repository at this point in the history
Strip text
  • Loading branch information
willmcgugan authored Jan 19, 2023
2 parents 6b51f00 + 14c7eea commit c9b84f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ 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/).

## [0.11.0] - Unreleased
## Unreleased

### Added

- Added Strip.text property https://github.com/Textualize/textual/issues/1620

### Changed

- The default filename for screenshots uses a datetime format similar to ISO8601, but with reserved characters replaced by underscores https://github.com/Textualize/textual/pull/1518


## [0.10.0] - 2023-01-19

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/textual/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def __rich_repr__(self) -> rich.repr.Result:
yield self._segments
yield self.cell_length

@property
def text(self) -> str:
"""Segment text."""
return "".join(segment.text for segment in self._segments)

@classmethod
def blank(cls, cell_length: int, style: Style | None) -> Strip:
"""Create a blank strip.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ def test_index_cell_position_index_too_large():
strip = Strip([Segment("abcdef"), Segment("ghi")])
with pytest.raises(NoCellPositionForIndex):
strip.index_to_cell_position(100)


def test_text():
assert Strip([]).text == ""
assert Strip([Segment("foo")]).text == "foo"
assert Strip([Segment("foo"), Segment("bar")]).text == "foobar"

0 comments on commit c9b84f5

Please sign in to comment.