Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/textual/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ def truecolor_style(self, style: Style, background: RichColor) -> Style:
)
# Convert dim style to RGB
if style.dim and color is not None:
if color.triplet is None:
color = RichColor.from_rgb(
*color.get_truecolor(terminal_theme, foreground=True)
)
if background.triplet is None:
background = RichColor.from_rgb(
*background.get_truecolor(terminal_theme, foreground=False)
)
color = dim_color(background, color)
style += NO_DIM

Expand Down
25 changes: 25 additions & 0 deletions tests/test_ansi_truecolor_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from rich.color import Color as RichColor
from rich.color import ColorType
from rich.segment import Segment
from rich.style import Style
from rich.terminal_theme import MONOKAI

from textual.color import Color
from textual.filter import ANSIToTruecolor


def test_ansi_to_truecolor_8_bit_dim():
"""Test that converting an 8-bit color with dim doesn't crash."""
# Given
ansi_filter = ANSIToTruecolor(MONOKAI)
test_color = RichColor("color(253)", ColorType.EIGHT_BIT, number=253)
test_style = Style(color=test_color, dim=True)
segments = [Segment("This should not crash", style=test_style)]
background_color = Color(0, 0, 0)

# When
# This line will crash if the bug is present
new_segments = ansi_filter.apply(segments, background_color)

# Then
assert new_segments is not None