From 555fa628570a060f147a0606bf1ee09d9c8c2c09 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 1 Jan 2025 10:50:39 +0000 Subject: [PATCH] fix padding style --- src/textual/content.py | 9 ++++++--- src/textual/visual.py | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/textual/content.py b/src/textual/content.py index 09afad8726..01b80824bc 100644 --- a/src/textual/content.py +++ b/src/textual/content.py @@ -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: @@ -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=""): @@ -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 diff --git a/src/textual/visual.py b/src/textual/visual.py index da83a7c18d..133f8cd7b1 100644 --- a/src/textual/visual.py +++ b/src/textual/visual.py @@ -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 @@ -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."""