Hex utils
Helpers for handling hex color codes.
expand_3digit_hex(hex3)
¶
Expand a 3-digit hex string (e.g. '#ABC' or 'ABC') into a 6-digit with leading '#', e.g. '#AABBCC'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex3
|
str
|
The 3-digit hex string including or excluding the '#'. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string of format '#RRGGBB'. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input is not a valid 3-digit hex representation. |
Source code in src/rich_color_ext/hex_utils.py
is_3digit_hex(string)
¶
Test whether a string is a 3-digit hex colour code (#ABC or ABC) case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
input string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if matches 3-digit hex format. |
Source code in src/rich_color_ext/hex_utils.py
is_dark(hex_str)
¶
Determine if a hex colour is 'dark' based on its luminance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_str
|
str
|
A hex colour string of format '#RRGGBB'. |
required |
Returns: True if the colour is dark, False otherwise.
Source code in src/rich_color_ext/hex_utils.py
is_light(hex_str)
¶
Determine if a hex colour is 'light' based on its luminance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hex_str
|
str
|
A hex colour string of format '#RRGGBB'. |
required |
Returns: True if the colour is light, False otherwise.