2222from rich .terminal_theme import TerminalTheme
2323
2424from textual .color import Color
25+ from textual .constants import DIM_FACTOR
2526
2627
2728class LineFilter (ABC ):
@@ -125,7 +126,9 @@ def apply(self, segments: list[Segment], background: Color) -> list[Segment]:
125126
126127
127128@lru_cache (1024 )
128- def dim_color (background : RichColor , color : RichColor , factor : float ) -> RichColor :
129+ def dim_color (
130+ background : RichColor , color : RichColor , factor : float = DIM_FACTOR
131+ ) -> RichColor :
129132 """Dim a color by blending towards the background
130133
131134 Args:
@@ -227,7 +230,7 @@ def __init__(self, terminal_theme: TerminalTheme, enabled: bool = True):
227230 super ().__init__ (enabled = enabled )
228231
229232 @lru_cache (1024 )
230- def truecolor_style (self , style : Style ) -> Style :
233+ def truecolor_style (self , style : Style , background : RichColor ) -> Style :
231234 """Replace system colors with truecolor equivalent.
232235
233236 Args:
@@ -247,6 +250,10 @@ def truecolor_style(self, style: Style) -> Style:
247250 bgcolor = RichColor .from_rgb (
248251 * bgcolor .get_truecolor (terminal_theme , foreground = False )
249252 )
253+ # Convert dim style to RGB
254+ if style .dim and color is not None :
255+ color = dim_color (background , color )
256+ style += NO_DIM
250257
251258 return style + Style .from_color (color , bgcolor )
252259
@@ -263,10 +270,16 @@ def apply(self, segments: list[Segment], background: Color) -> list[Segment]:
263270 _Segment = Segment
264271 truecolor_style = self .truecolor_style
265272
273+ background_rich_color = background .rich_color
274+
266275 return [
267276 _Segment (
268277 text ,
269- None if style is None else truecolor_style (style ),
278+ (
279+ None
280+ if style is None
281+ else truecolor_style (style , background_rich_color )
282+ ),
270283 None ,
271284 )
272285 for text , style , _ in segments
0 commit comments