diff --git a/src/textual/color.py b/src/textual/color.py index 84cfc3502..4fa63c169 100644 --- a/src/textual/color.py +++ b/src/textual/color.py @@ -63,7 +63,7 @@ RE_COLOR = re.compile( rgb{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$| rgba{OPEN_BRACE}({DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}{COMMA}{DECIMAL}){CLOSE_BRACE}$| hsl{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}){CLOSE_BRACE}$| -hsla{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}{COMMA}{DECIMAL}){CLOSE_BRACE}$| +hsla{OPEN_BRACE}({DECIMAL}{COMMA}{PERCENT}{COMMA}{PERCENT}{COMMA}{DECIMAL}){CLOSE_BRACE}$ """, re.VERBOSE, ) @@ -289,7 +289,11 @@ class Color(NamedTuple): if color_match is None: error_message = f"failed to parse {color_text!r} as a color" suggested_color = None - if not color_text.startswith("#") and not color_text.startswith("rgb"): + if ( + not color_text.startswith("#") + and not color_text.startswith("rgb") + and not color_text.startswith("hsl") + ): # Seems like we tried to use a color name: let's try to find one that is close enough: suggested_color = get_suggestion(color_text, COLOR_NAME_TO_RGB.keys()) if suggested_color: diff --git a/tests/css/test_stylesheet.py b/tests/css/test_stylesheet.py index 25f557b9c..6cb2f01ac 100644 --- a/tests/css/test_stylesheet.py +++ b/tests/css/test_stylesheet.py @@ -32,9 +32,6 @@ from textual.css.tokenizer import TokenizeError ["red 4", pytest.raises(StylesheetParseError), None], # space in it ["1", pytest.raises(StylesheetParseError), None], # invalid value ["()", pytest.raises(TokenizeError), None], # invalid tokens - # TODO: allow spaces in rgb/rgba expressions? - ["rgb(200, 90, 30)", pytest.raises(TokenizeError), None], - ["rgba(200,90,30, 0.4)", pytest.raises(TokenizeError), None], ], ) def test_color_property_parsing(css_value, expectation, expected_color):