Skip to content

Commit

Permalink
fix padding style
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 1, 2025
1 parent 617f1bd commit 555fa62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/textual/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def wrap(
selection: Selection | None = None,
selection_style: Style | None = None,
) -> list[ContentLine]:
# lines: list[Content] = []
output_lines: list[ContentLine] = []

if selection is not None:
Expand Down Expand Up @@ -1065,7 +1064,9 @@ def to_strip(self, style: Style) -> Strip:
return strip

segments: list[Segment] = (
[Segment(" " * pad_left, base_rich_style)] if pad_left else []
[Segment(" " * pad_left, style.background_style.rich_style)]
if pad_left
else []
)
add_segment = segments.append
for text, text_style in content.render(style, end=""):
Expand All @@ -1075,7 +1076,9 @@ def to_strip(self, style: Style) -> Strip:
x += len(text)

if pad_right:
segments.append(_Segment(" " * pad_right, base_rich_style))
segments.append(
_Segment(" " * pad_right, style.background_style.rich_style)
)
strip = Strip(segments, content.cell_length + pad_left + pad_right)
return strip

Expand Down
7 changes: 6 additions & 1 deletion src/textual/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def visualize(widget: Widget, obj: object) -> Visual:

if isinstance(obj, Text) and widget.allow_select:
return Content.from_rich_text(
obj, align=obj.align or widget.styles.text_align
obj, align=obj.justify or widget.styles.text_align
)

# If its is a Rich renderable, wrap it with a RichVisual
Expand Down Expand Up @@ -268,6 +268,11 @@ def without_color(self) -> Style:
_meta=self._meta,
)

@cached_property
def background_style(self) -> Style:
"""Just the background color, with no other attributes."""
return Style(self.background)

@classmethod
def combine(cls, styles: Iterable[Style]) -> Style:
"""Add a number of styles and get the result."""
Expand Down

0 comments on commit 555fa62

Please sign in to comment.