From 2302516182e087aaee1e682a0742b4e1a8ab884a Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 12 Jul 2025 10:02:24 +0100 Subject: [PATCH 1/3] Fix truecolor dim style --- src/textual/filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) ) From 15ce8f3d3638b920770131b431fee71c310b2e6b Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 12 Jul 2025 10:06:17 +0100 Subject: [PATCH 2/3] test filters --- tests/test_filters.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_filters.py 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 From 0edab9271ba616caa3d01c5ad50d591872ad0ace Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 12 Jul 2025 10:11:11 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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