Skip to content

Commit be59137

Browse files
authored
Merge pull request #5957 from Textualize/fix-truecolor-dim
Fix truecolor dim style
2 parents 3f121fc + 0edab92 commit be59137

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## Unreleased
1010

11-
### Added
12-
13-
- Added `compact` parameter to `MaskedInput` https://github.com/Textualize/textual/pull/5952
14-
1511
### Fixed
1612

1713
- Fixed `query_one` and `query_exactly_one` not raising documented `WrongType` exception.
1814
- Fixed logging to a file on Windows https://github.com/Textualize/textual/issues/5941
15+
- Fixed eight bit colors crashing when applying dim style https://github.com/Textualize/textual/pull/5957
1916

2017
### Changed
2118

@@ -25,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2522

2623
- Added `Markdown.append` https://github.com/Textualize/textual/pull/5950
2724
- Added `Widget.release_anchor` https://github.com/Textualize/textual/pull/5950
25+
- Added `compact` parameter to `MaskedInput` https://github.com/Textualize/textual/pull/5952
2826

2927
## [3.7.1] - 2025-07-09
3028

src/textual/filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ def truecolor_style(self, style: Style, background: RichColor) -> Style:
241241
"""
242242
terminal_theme = self._terminal_theme
243243
color = style.color
244-
if color is not None and color.is_system_defined:
244+
if color is not None and color.triplet is None:
245245
color = RichColor.from_rgb(
246246
*color.get_truecolor(terminal_theme, foreground=True)
247247
)
248248
bgcolor = style.bgcolor
249-
if bgcolor is not None and bgcolor.is_system_defined:
249+
if bgcolor is not None and bgcolor.triplet is None:
250250
bgcolor = RichColor.from_rgb(
251251
*bgcolor.get_truecolor(terminal_theme, foreground=False)
252252
)

tests/test_filters.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from rich.color import Color as RichColor
2+
from rich.color import ColorType
3+
from rich.segment import Segment
4+
from rich.style import Style
5+
from rich.terminal_theme import MONOKAI
6+
7+
from textual.color import Color
8+
from textual.filter import ANSIToTruecolor
9+
10+
11+
def test_ansi_to_truecolor_8_bit_dim():
12+
"""Test that converting an 8-bit color with dim doesn't crash.
13+
14+
Regression test for https://github.com/Textualize/textual/issues/5946
15+
16+
"""
17+
# Given
18+
ansi_filter = ANSIToTruecolor(MONOKAI)
19+
test_color = RichColor("color(253)", ColorType.EIGHT_BIT, number=253)
20+
test_style = Style(color=test_color, dim=True)
21+
segments = [Segment("This should not crash", style=test_style)]
22+
background_color = Color(0, 0, 0)
23+
24+
# When
25+
# This line will crash if the bug is present
26+
new_segments = ansi_filter.apply(segments, background_color)
27+
28+
# Then
29+
assert new_segments is not None

0 commit comments

Comments
 (0)