diff --git a/CHANGELOG.md b/CHANGELOG.md index ff630ffd..2151aabc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added Text.extend_style method. +- Added Span.extend method. ## [13.4.2] - 2023-06-12 diff --git a/rich/text.py b/rich/text.py index 946485a6..1f9c4f7c 100644 --- a/rich/text.py +++ b/rich/text.py @@ -97,18 +97,18 @@ class Span(NamedTuple): return self return Span(start, min(offset, end), style) - def add_padding(self, padding: int) -> "Span": - """Add spaces the the end of a span. + def extend(self, cells: int) -> "Span": + """Extend the span by the given number of cells. Args: - padding (int): Number of additional spaces. + cells (int): Additional space to add to end of span. Returns: Span: A span. """ - if padding: + if cells: start, end, style = self - return Span(start, end + padding, style) + return Span(start, end + cells, style) else: return self @@ -577,7 +577,7 @@ class Text(JupyterMixin): if spans: end_offset = len(self) self._spans[:] = [ - span.add_padding(spaces) if span.end >= end_offset else span + span.extend(spaces) if span.end >= end_offset else span for span in spans ] self._text.append(new_spaces)