Skip to content

Commit 71548ca

Browse files
committed
calculate dim RGB
1 parent 5ac6891 commit 71548ca

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/textual/filter.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def __init__(self, terminal_theme: TerminalTheme, enabled: bool = True):
227227
super().__init__(enabled=enabled)
228228

229229
@lru_cache(1024)
230-
def truecolor_style(self, style: Style) -> Style:
230+
def truecolor_style(self, style: Style, background: RichColor) -> Style:
231231
"""Replace system colors with truecolor equivalent.
232232
233233
Args:
@@ -247,8 +247,11 @@ def truecolor_style(self, style: Style) -> Style:
247247
bgcolor = RichColor.from_rgb(
248248
*bgcolor.get_truecolor(terminal_theme, foreground=False)
249249
)
250+
# Convert dim style to RGB
251+
if style.dim and color is not None:
252+
color = dim_color(background, color, 0.5)
250253

251-
return style + Style.from_color(color, bgcolor)
254+
return Style.from_color(color, bgcolor)
252255

253256
def apply(self, segments: list[Segment], background: Color) -> list[Segment]:
254257
"""Transform a list of segments.
@@ -263,10 +266,16 @@ def apply(self, segments: list[Segment], background: Color) -> list[Segment]:
263266
_Segment = Segment
264267
truecolor_style = self.truecolor_style
265268

269+
background_rich_color = background.rich_color
270+
266271
return [
267272
_Segment(
268273
text,
269-
None if style is None else truecolor_style(style),
274+
(
275+
None
276+
if style is None
277+
else truecolor_style(style, background_rich_color)
278+
),
270279
None,
271280
)
272281
for text, style, _ in segments

0 commit comments

Comments
 (0)