diff --git a/CHANGELOG.md b/CHANGELOG.md index 405f4fab16..298d8ba06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,14 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -### Added - -- Added `compact` parameter to `MaskedInput` https://github.com/Textualize/textual/pull/5952 - ### Fixed - Fixed `query_one` and `query_exactly_one` not raising documented `WrongType` exception. - Fixed logging to a file on Windows https://github.com/Textualize/textual/issues/5941 +- Fixed eight bit colors crashing when applying dim style https://github.com/Textualize/textual/pull/5957 ### Changed @@ -25,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `Markdown.append` https://github.com/Textualize/textual/pull/5950 - Added `Widget.release_anchor` https://github.com/Textualize/textual/pull/5950 +- Added `compact` parameter to `MaskedInput` https://github.com/Textualize/textual/pull/5952 ## [3.7.1] - 2025-07-09 diff --git a/src/textual/filter.py b/src/textual/filter.py index 5a2984f381..9b37fb7e80 100644 --- a/src/textual/filter.py +++ b/src/textual/filter.py @@ -241,12 +241,12 @@ def truecolor_style(self, style: Style, background: RichColor) -> Style: """ terminal_theme = self._terminal_theme color = style.color - if color is not None and color.is_system_defined: + if color is not None and color.triplet is None: color = RichColor.from_rgb( *color.get_truecolor(terminal_theme, foreground=True) ) bgcolor = style.bgcolor - if bgcolor is not None and bgcolor.is_system_defined: + if bgcolor is not None and bgcolor.triplet is None: bgcolor = RichColor.from_rgb( *bgcolor.get_truecolor(terminal_theme, foreground=False) ) diff --git a/tests/test_filters.py b/tests/test_filters.py new file mode 100644 index 0000000000..40b382b814 --- /dev/null +++ b/tests/test_filters.py @@ -0,0 +1,29 @@ +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. + + Regression test for https://github.com/Textualize/textual/issues/5946 + + """ + # 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