mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Use fstrings instead, test 3 and 4 character css hex colours
This commit is contained in:
@@ -277,11 +277,14 @@ class Color(NamedTuple):
|
|||||||
|
|
||||||
if rgb_hex_triple is not None:
|
if rgb_hex_triple is not None:
|
||||||
r, g, b = rgb_hex_triple
|
r, g, b = rgb_hex_triple
|
||||||
color = cls(int(r + r, 16), int(g + g, 16), int(b + b, 16))
|
color = cls(int(f"{r}{r}", 16), int(f"{g}{g}", 16), int(f"{b}{b}", 16))
|
||||||
elif rgb_hex_quad is not None:
|
elif rgb_hex_quad is not None:
|
||||||
r, g, b, a = rgb_hex_quad
|
r, g, b, a = rgb_hex_quad
|
||||||
color = cls(
|
color = cls(
|
||||||
int(r + r, 16), int(g + g, 16), int(b + b, 16), int(a + a, 16) / 255.0
|
int(f"{r}{r}", 16),
|
||||||
|
int(f"{g}{g}", 16),
|
||||||
|
int(f"{b}{b}", 16),
|
||||||
|
int(f"{a}{a}", 16) / 255.0,
|
||||||
)
|
)
|
||||||
elif rgb_hex is not None:
|
elif rgb_hex is not None:
|
||||||
r, g, b = [int(pair, 16) for pair in split_pairs3(rgb_hex)]
|
r, g, b = [int(pair, 16) for pair in split_pairs3(rgb_hex)]
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ def test_color_blend():
|
|||||||
("#000000", Color(0, 0, 0, 1.0)),
|
("#000000", Color(0, 0, 0, 1.0)),
|
||||||
("#ffffff", Color(255, 255, 255, 1.0)),
|
("#ffffff", Color(255, 255, 255, 1.0)),
|
||||||
("#FFFFFF", Color(255, 255, 255, 1.0)),
|
("#FFFFFF", Color(255, 255, 255, 1.0)),
|
||||||
|
("#fab", Color(255, 170, 187, 1.0)), # #ffaabb
|
||||||
|
("#fab0", Color(255, 170, 187, .0)), # #ffaabb00
|
||||||
("#020304ff", Color(2, 3, 4, 1.0)),
|
("#020304ff", Color(2, 3, 4, 1.0)),
|
||||||
("#02030400", Color(2, 3, 4, 0.0)),
|
("#02030400", Color(2, 3, 4, 0.0)),
|
||||||
("#0203040f", Color(2, 3, 4, 0.058823529411764705)),
|
("#0203040f", Color(2, 3, 4, 0.058823529411764705)),
|
||||||
|
|||||||
Reference in New Issue
Block a user