color
chromatic.color
ANSI_4BIT_RGB = ((0, 0, 0), (170, 0, 0), (0, 170, 0), (170, 85, 0), (0, 0, 170), (170, 0, 170), (0, 170, 170), (170, 170, 170), (85, 85, 85), (255, 85, 85), (85, 255, 85), (255, 255, 85), (85, 85, 255), (255, 85, 255), (85, 255, 255), (255, 255, 255))
module-attribute
CSI = b'\x1b['
module-attribute
DEFAULT_ANSI = ansicolor8Bit if is_vt_enabled() else ansicolor4Bit
module-attribute
SGR_RESET = b'\x1b[0m'
module-attribute
Back
module-attribute
Fore
module-attribute
Style
module-attribute
named_color
module-attribute
Color
Bases: int
Color([x]) -> color
Color(x, base=10) -> color
Convert a number or string into a color, or return Color(0) if no arguments are given.
Accepts the same arguments as int, but the value must be in range 0,0xFFFFFF (incl).
Source code in chromatic/color/core.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
rgb
property
__new__(*args, **kwargs)
__new__(x: ConvertibleToInt = ...) -> tp.Self
__new__(x: str | bytes | bytearray, /, base: tp.SupportsIndex = 10) -> tp.Self
Source code in chromatic/color/core.py
579 580 581 582 583 | |
__repr__()
Source code in chromatic/color/core.py
585 586 | |
__invert__()
Source code in chromatic/color/core.py
588 589 | |
from_rgb(rgb)
classmethod
Source code in chromatic/color/core.py
591 592 593 | |
ColorStr
Bases: str, _IntFloatMixin
Source code in chromatic/color/core.py
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 | |
__rmul__ = __mul__
class-attribute
instance-attribute
ansi
property
ansi_type
property
base_str
property
The non-ANSI part of the string
bg
property
Background color
fg
property
Foreground color
reset
property
rgb_dict
property
ansi_partition()
Returns a 3-tuple of parts of the string (sgr, base string, '\x1B[0m' or '')
Source code in chromatic/color/core.py
1230 1231 1232 1233 1234 1235 | |
as_ansi_type(ansi_type)
Convert all ANSI colors in the ColorStr to a single ANSI type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ansi_type
|
('4b', '8b', '24b')
|
ANSI format to which all SGR parameters of type |
'4b'
|
Returns:
| Type | Description |
|---|---|
ColorStr
|
Return |
Source code in chromatic/color/core.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 | |
recolor(*args, **kwargs)
recolor(value: ColorStr, /, *, absolute: bool = ...) -> tp.Self
recolor(**kwargs: tp.Unpack[_RecolorKwargs]) -> tp.Self
Return a copy of self with a new color spec.
ColorStr.recolor(self, value, /, *, absolute=False) -> ColorStr
ColorStr.recolor(self, *, fg=None, bg=None, absolute=False) -> ColorStr
If no arguments are given, returns self unchanged.
If 'value' is given and a ColorStr, return self with the colors of 'value'.
Else, use keyword arguments {'fg', 'bg'} for colors.
Any other mix of arguments will fail outright, since 'value' along with { fg=... | bg=... } is ambiguous which to use for colors.
The 'absolute' keyword can be used with either signature.
Keyword Args
fg : SupportsInt, optional New foreground color.
bg : SupportsInt, optional New background color.
absolute : bool, optional If True, clear all colors of the copied string before substitution. Otherwise, replace colors only where specified (default is False).
Returns:
| Name | Type | Description |
|---|---|---|
recolored |
ColorStr
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input arguments do not match any of the expected signatures. |
Examples:
>>> from chromatic import ColorStr, Color, randcolor
>>> cs1 = ColorStr('foo', randcolor())
>>> cs2 = ColorStr('bar', fg=Color(0xFF5555), bg=Color(0xFF00FF))
>>> new_cs = cs2.recolor(bg=cs1.fg)
>>> int(new_cs.fg) == 0xFF5555, new_cs.bg == cs1.fg
(True, True)
>>> cs = ColorStr("Red text", fg=0xFF0000)
>>> recolored = cs.recolor(fg=Color(0x00FF00))
>>> recolored.base_str, f"0x{recolored.fg:06X}"
('Red text', '0x00FF00')
Source code in chromatic/color/core.py
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 | |
strip_style()
Source code in chromatic/color/core.py
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
add_reset()
Source code in chromatic/color/core.py
1365 1366 1367 1368 | |
remove_reset()
Source code in chromatic/color/core.py
1370 1371 1372 1373 | |
swap_reset()
Source code in chromatic/color/core.py
1375 1376 | |
add_sgr_param(x)
Source code in chromatic/color/core.py
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 | |
remove_sgr_param(x)
Source code in chromatic/color/core.py
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 | |
blink()
Source code in chromatic/color/core.py
1404 1405 | |
blink_stop()
Source code in chromatic/color/core.py
1407 1408 | |
bold()
Source code in chromatic/color/core.py
1410 1411 | |
faint()
Source code in chromatic/color/core.py
1413 1414 | |
crossed_out()
Source code in chromatic/color/core.py
1416 1417 | |
encircle()
Source code in chromatic/color/core.py
1419 1420 | |
italicize()
Source code in chromatic/color/core.py
1422 1423 | |
negative()
Source code in chromatic/color/core.py
1425 1426 | |
underline()
Source code in chromatic/color/core.py
1428 1429 | |
double_underline()
Source code in chromatic/color/core.py
1431 1432 | |
capitalize()
Source code in chromatic/color/core.py
1434 1435 | |
casefold()
Source code in chromatic/color/core.py
1437 1438 | |
center(width, fillchar=' ')
Source code in chromatic/color/core.py
1440 1441 | |
count(x, /, *args)
Source code in chromatic/color/core.py
1443 1444 | |
endswith(suffix, /, *args)
Source code in chromatic/color/core.py
1446 1447 | |
expandtabs(tabsize=8)
Source code in chromatic/color/core.py
1449 1450 | |
find(sub, /, *args)
Source code in chromatic/color/core.py
1452 1453 | |
format(*args, **kwargs)
Source code in chromatic/color/core.py
1455 1456 | |
format_map(mapping)
Source code in chromatic/color/core.py
1458 1459 | |
index(sub, /, *args)
Source code in chromatic/color/core.py
1461 1462 | |
isalnum()
Source code in chromatic/color/core.py
1464 1465 | |
isalpha()
Source code in chromatic/color/core.py
1467 1468 | |
isascii()
Source code in chromatic/color/core.py
1470 1471 | |
isdecimal()
Source code in chromatic/color/core.py
1473 1474 | |
isdigit()
Source code in chromatic/color/core.py
1476 1477 | |
isidentifier()
Source code in chromatic/color/core.py
1479 1480 | |
islower()
Source code in chromatic/color/core.py
1482 1483 | |
isnumeric()
Source code in chromatic/color/core.py
1485 1486 | |
isprintable()
Source code in chromatic/color/core.py
1488 1489 | |
isspace()
Source code in chromatic/color/core.py
1491 1492 | |
istitle()
Source code in chromatic/color/core.py
1494 1495 | |
isupper()
Source code in chromatic/color/core.py
1497 1498 | |
join(iterable)
Source code in chromatic/color/core.py
1500 1501 1502 1503 1504 1505 | |
ljust(width, fillchar=' ')
Source code in chromatic/color/core.py
1507 1508 | |
lower()
Source code in chromatic/color/core.py
1510 1511 | |
lstrip(chars=None)
Source code in chromatic/color/core.py
1513 1514 | |
partition(sep)
Source code in chromatic/color/core.py
1516 1517 1518 1519 1520 | |
removeprefix(prefix)
Source code in chromatic/color/core.py
1522 1523 | |
removesuffix(prefix)
Source code in chromatic/color/core.py
1525 1526 | |
replace(old, new, /, count=-1)
Source code in chromatic/color/core.py
1528 1529 | |
rfind(sub, /, *args)
Source code in chromatic/color/core.py
1531 1532 | |
rindex(sub, /, *args)
Source code in chromatic/color/core.py
1534 1535 | |
rjust(width, fillchar=' ')
Source code in chromatic/color/core.py
1537 1538 | |
rstrip(chars=None)
Source code in chromatic/color/core.py
1540 1541 | |
rpartition(sep)
Source code in chromatic/color/core.py
1543 1544 1545 1546 1547 | |
rsplit(sep=None, maxsplit=-1)
Source code in chromatic/color/core.py
1549 1550 1551 1552 1553 | |
split(sep=None, maxsplit=-1)
Source code in chromatic/color/core.py
1555 1556 1557 1558 1559 | |
splitlines(keepends=False)
Source code in chromatic/color/core.py
1561 1562 1563 1564 1565 | |
startswith(prefix, /, *args)
Source code in chromatic/color/core.py
1567 1568 | |
strip(chars=None)
Source code in chromatic/color/core.py
1570 1571 | |
swapcase()
Source code in chromatic/color/core.py
1573 1574 | |
title()
Source code in chromatic/color/core.py
1576 1577 | |
translate(table)
Source code in chromatic/color/core.py
1579 1580 | |
upper()
Source code in chromatic/color/core.py
1582 1583 | |
zfill(width)
Source code in chromatic/color/core.py
1585 1586 | |
__add__(other)
Source code in chromatic/color/core.py
1588 1589 1590 1591 1592 1593 1594 1595 | |
__contains__(key)
Source code in chromatic/color/core.py
1597 1598 | |
__eq__(other)
Source code in chromatic/color/core.py
1600 1601 1602 1603 | |
__format__(format_spec='')
Return a formatted version of the ColorStr as described by format_spec.
A colorbytes subclass alias (ie., '24b', '8b', '4b') can be prepended to
a str format_spec to convert ansi types before applying the format_spec
to the base string.
Notes
This method returns type Self instead of str, which can lead to
surprising behavior when dealing with f-strings.
Consider the following example:
>>> from chromatic import ColorStr
>>> cs = ColorStr("hello", fg=0xFF0000, ansi_type="24b")
>>> cs._ansi_type
<class 'chromatic.color.core.ansicolor24Bit'>
>>> fstring = f"{cs:4b#<20}"
>>> fstring.__class__
<class 'chromatic.color.core.ColorStr'>
>>> fstring._ansi_type
<class 'chromatic.color.core.ansicolor4Bit'>
>>> fstring.base_str
'hello###############'
In that case, the f-string eval returned a ColorStr object,
because the whole f-string only consists of a single {...} span.
In such cases, the underlying format(...) -> ColorStr has nothing
to be concatenated with, so it is returned directly.
In any case other than the single span f-string, the internals delegate
to normal str concatentation, and we get a str result:
>>> from chromatic import ColorStr
>>> cs = ColorStr("hello", fg=0xFF0000, ansi_type="24b")
>>> f"foo {cs} bar".__class__
<class 'str'>
>>> cs2 = ColorStr("world", bg=0x00FFFF, ansi_type="8b")
>>> fstring_concat = f"{cs: >10}{cs2: <10}"
>>> fstring_concat
'\x1b[38;2;255;0;0m hello\x1b[0m\x1b[48;5;51mworld \x1b[0m'
>>> fstring_concat.__class__
<class 'str'>
Source code in chromatic/color/core.py
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 | |
__ge__(other)
Source code in chromatic/color/core.py
1661 1662 | |
__getitem__(key)
__getitem__(key: tp.SupportsIndex) -> tp.Self
__getitem__(key: slice) -> tp.Self
Source code in chromatic/color/core.py
1664 1665 | |
__gt__(other)
Source code in chromatic/color/core.py
1667 1668 | |
__hash__()
Source code in chromatic/color/core.py
1670 1671 | |
__invert__()
Return a copy of self with inverted colors (color ^= 0xFFFFFF)
Source code in chromatic/color/core.py
1673 1674 1675 1676 1677 1678 1679 1680 | |
__iter__()
Source code in chromatic/color/core.py
1682 1683 1684 | |
__le__(other)
Source code in chromatic/color/core.py
1686 1687 | |
__len__()
Source code in chromatic/color/core.py
1689 1690 | |
__lt__(other)
Source code in chromatic/color/core.py
1692 1693 | |
__matmul__(other)
Return a new ColorStr with the base string of self and colors of other
Source code in chromatic/color/core.py
1695 1696 1697 1698 1699 | |
__mod__(value)
Source code in chromatic/color/core.py
1701 1702 | |
__mul__(value)
Source code in chromatic/color/core.py
1704 1705 | |
__new__(obj=_unset, /, *args, **kwargs)
__new__(obj: object = ..., /, fg: tp.SupportsInt | _RGBVectorLike | None = None, bg: tp.SupportsInt | _RGBVectorLike | None = None, *, ansi_type: AnsiColorParam = ..., reset: bool = ...) -> tp.Self
__new__(obj: abc.Buffer, /, fg: tp.SupportsInt | _RGBVectorLike | None = None, bg: tp.SupportsInt | _RGBVectorLike | None = None, *, encoding: str = ..., errors: str = ..., ansi_type: AnsiColorParam = ..., reset: bool = ...) -> tp.Self
Source code in chromatic/color/core.py
1709 1710 | |
__radd__(other)
Source code in chromatic/color/core.py
1712 1713 1714 1715 | |
__repr__()
Source code in chromatic/color/core.py
1717 1718 | |
__xor__(other)
Return copy of self with colors ^ other colors
Source code in chromatic/color/core.py
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 | |
SgrFlag
Bases: IntFlag
Source code in chromatic/color/core.py
141 142 143 | |
parameters
property
RESET = 1
class-attribute
instance-attribute
BOLD = 2
class-attribute
instance-attribute
FAINT = 4
class-attribute
instance-attribute
ITALICS = 8
class-attribute
instance-attribute
SINGLE_UNDERLINE = 16
class-attribute
instance-attribute
SLOW_BLINK = 32
class-attribute
instance-attribute
RAPID_BLINK = 64
class-attribute
instance-attribute
NEGATIVE = 128
class-attribute
instance-attribute
CONCEALED_CHARS = 256
class-attribute
instance-attribute
CROSSED_OUT = 512
class-attribute
instance-attribute
PRIMARY = 1024
class-attribute
instance-attribute
FIRST_ALT = 2048
class-attribute
instance-attribute
SECOND_ALT = 4096
class-attribute
instance-attribute
THIRD_ALT = 8192
class-attribute
instance-attribute
FOURTH_ALT = 16384
class-attribute
instance-attribute
FIFTH_ALT = 32768
class-attribute
instance-attribute
SIXTH_ALT = 65536
class-attribute
instance-attribute
SEVENTH_ALT = 131072
class-attribute
instance-attribute
EIGHTH_ALT = 262144
class-attribute
instance-attribute
NINTH_ALT = 524288
class-attribute
instance-attribute
GOTHIC = 1048576
class-attribute
instance-attribute
DOUBLE_UNDERLINE = 2097152
class-attribute
instance-attribute
RESET_BOLD_AND_FAINT = 4194304
class-attribute
instance-attribute
RESET_ITALIC_AND_GOTHIC = 8388608
class-attribute
instance-attribute
RESET_UNDERLINES = 16777216
class-attribute
instance-attribute
RESET_BLINKING = 33554432
class-attribute
instance-attribute
POSITIVE = 67108864
class-attribute
instance-attribute
REVEALED_CHARS = 134217728
class-attribute
instance-attribute
RESET_CROSSED_OUT = 268435456
class-attribute
instance-attribute
DEFAULT_FG_COLOR = 536870912
class-attribute
instance-attribute
DEFAULT_BG_COLOR = 1073741824
class-attribute
instance-attribute
FRAMED = 2147483648
class-attribute
instance-attribute
ENCIRCLED = 4294967296
class-attribute
instance-attribute
OVERLINED = 8589934592
class-attribute
instance-attribute
NOT_FRAMED_OR_CIRCLED = 17179869184
class-attribute
instance-attribute
IDEOGRAM_UNDER_OR_RIGHT = 34359738368
class-attribute
instance-attribute
IDEOGRAM_2UNDER_OR_2RIGHT = 68719476736
class-attribute
instance-attribute
IDEOGRAM_OVER_OR_LEFT = 137438953472
class-attribute
instance-attribute
IDEOGRAM_2OVER_OR_2LEFT = 274877906944
class-attribute
instance-attribute
CANCEL = 549755813888
class-attribute
instance-attribute
SgrParameter
Bases: IntEnum
Source code in chromatic/color/core.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
RESET = 0
class-attribute
instance-attribute
BOLD = 1
class-attribute
instance-attribute
FAINT = 2
class-attribute
instance-attribute
ITALICS = 3
class-attribute
instance-attribute
SINGLE_UNDERLINE = 4
class-attribute
instance-attribute
SLOW_BLINK = 5
class-attribute
instance-attribute
RAPID_BLINK = 6
class-attribute
instance-attribute
NEGATIVE = 7
class-attribute
instance-attribute
CONCEALED_CHARS = 8
class-attribute
instance-attribute
CROSSED_OUT = 9
class-attribute
instance-attribute
PRIMARY = 10
class-attribute
instance-attribute
FIRST_ALT = 11
class-attribute
instance-attribute
SECOND_ALT = 12
class-attribute
instance-attribute
THIRD_ALT = 13
class-attribute
instance-attribute
FOURTH_ALT = 14
class-attribute
instance-attribute
FIFTH_ALT = 15
class-attribute
instance-attribute
SIXTH_ALT = 16
class-attribute
instance-attribute
SEVENTH_ALT = 17
class-attribute
instance-attribute
EIGHTH_ALT = 18
class-attribute
instance-attribute
NINTH_ALT = 19
class-attribute
instance-attribute
GOTHIC = 20
class-attribute
instance-attribute
DOUBLE_UNDERLINE = 21
class-attribute
instance-attribute
RESET_BOLD_AND_FAINT = 22
class-attribute
instance-attribute
RESET_ITALIC_AND_GOTHIC = 23
class-attribute
instance-attribute
RESET_UNDERLINES = 24
class-attribute
instance-attribute
RESET_BLINKING = 25
class-attribute
instance-attribute
POSITIVE = 26
class-attribute
instance-attribute
REVEALED_CHARS = 28
class-attribute
instance-attribute
RESET_CROSSED_OUT = 29
class-attribute
instance-attribute
BLACK_FG = 30
class-attribute
instance-attribute
RED_FG = 31
class-attribute
instance-attribute
GREEN_FG = 32
class-attribute
instance-attribute
YELLOW_FG = 33
class-attribute
instance-attribute
BLUE_FG = 34
class-attribute
instance-attribute
MAGENTA_FG = 35
class-attribute
instance-attribute
CYAN_FG = 36
class-attribute
instance-attribute
WHITE_FG = 37
class-attribute
instance-attribute
ANSI_256_SET_FG = 38
class-attribute
instance-attribute
DEFAULT_FG_COLOR = 39
class-attribute
instance-attribute
BLACK_BG = 40
class-attribute
instance-attribute
RED_BG = 41
class-attribute
instance-attribute
GREEN_BG = 42
class-attribute
instance-attribute
YELLOW_BG = 43
class-attribute
instance-attribute
BLUE_BG = 44
class-attribute
instance-attribute
MAGENTA_BG = 45
class-attribute
instance-attribute
CYAN_BG = 46
class-attribute
instance-attribute
WHITE_BG = 47
class-attribute
instance-attribute
ANSI_256_SET_BG = 48
class-attribute
instance-attribute
DEFAULT_BG_COLOR = 49
class-attribute
instance-attribute
FRAMED = 50
class-attribute
instance-attribute
ENCIRCLED = 52
class-attribute
instance-attribute
OVERLINED = 53
class-attribute
instance-attribute
NOT_FRAMED_OR_CIRCLED = 54
class-attribute
instance-attribute
IDEOGRAM_UNDER_OR_RIGHT = 55
class-attribute
instance-attribute
IDEOGRAM_2UNDER_OR_2RIGHT = 60
class-attribute
instance-attribute
IDEOGRAM_OVER_OR_LEFT = 61
class-attribute
instance-attribute
IDEOGRAM_2OVER_OR_2LEFT = 62
class-attribute
instance-attribute
CANCEL = 63
class-attribute
instance-attribute
BLACK_BRIGHT_FG = 90
class-attribute
instance-attribute
RED_BRIGHT_FG = 91
class-attribute
instance-attribute
GREEN_BRIGHT_FG = 92
class-attribute
instance-attribute
YELLOW_BRIGHT_FG = 93
class-attribute
instance-attribute
BLUE_BRIGHT_FG = 94
class-attribute
instance-attribute
MAGENTA_BRIGHT_FG = 95
class-attribute
instance-attribute
CYAN_BRIGHT_FG = 96
class-attribute
instance-attribute
WHITE_BRIGHT_FG = 97
class-attribute
instance-attribute
BLACK_BRIGHT_BG = 100
class-attribute
instance-attribute
RED_BRIGHT_BG = 101
class-attribute
instance-attribute
GREEN_BRIGHT_BG = 102
class-attribute
instance-attribute
YELLOW_BRIGHT_BG = 103
class-attribute
instance-attribute
BLUE_BRIGHT_BG = 104
class-attribute
instance-attribute
MAGENTA_BRIGHT_BG = 105
class-attribute
instance-attribute
CYAN_BRIGHT_BG = 106
class-attribute
instance-attribute
WHITE_BRIGHT_BG = 107
class-attribute
instance-attribute
flag
cached
property
SgrSequence
Bases: MutableSequence[SgrParamBuffer]
Construct a mutable sequence of SGR code bytes.
Source code in chromatic/color/core.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | |
__match_args__ = ('_sgr_params',)
class-attribute
instance-attribute
__slots__ = ('_sgr_params', '_fg_idx', '_bg_idx')
class-attribute
instance-attribute
fg = _color_descriptor()
class-attribute
instance-attribute
bg = _color_descriptor()
class-attribute
instance-attribute
copy = __copy__
class-attribute
instance-attribute
__hash__ = None
class-attribute
instance-attribute
rgb_dict = property(_rgb_dict_get, set_colors, clear_colors)
class-attribute
instance-attribute
insert(index, value)
Source code in chromatic/color/core.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | |
extend(iterable)
Source code in chromatic/color/core.py
910 911 | |
is_color()
Source code in chromatic/color/core.py
913 914 | |
is_reset()
Source code in chromatic/color/core.py
916 917 | |
values()
Source code in chromatic/color/core.py
919 920 921 | |
ansi_type()
Source code in chromatic/color/core.py
923 924 925 926 927 928 929 | |
shrink()
Mutate self in-place by removing redundant codes from the sequence.
Specifically what is removed:
- codes that occur before a
b"0" - fg / bg colors occurring before a respective reset code and vice-versa, or a subsequent color of the same kind
- duplicate codes (the highest-index occurrence is kept)
Source code in chromatic/color/core.py
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | |
__add__(other)
Source code in chromatic/color/core.py
965 966 967 968 | |
__bool__()
Source code in chromatic/color/core.py
970 971 | |
__bytes__()
Source code in chromatic/color/core.py
973 974 | |
__copy__()
Source code in chromatic/color/core.py
976 977 978 979 980 981 982 983 984 985 | |
__deepcopy__(memo)
Source code in chromatic/color/core.py
989 990 991 992 993 994 995 996 997 998 | |
__delitem__(index)
__delitem__(index: tp.SupportsIndex) -> None
__delitem__(index: slice) -> None
Source code in chromatic/color/core.py
1000 1001 1002 | |
__eq__(other)
Source code in chromatic/color/core.py
1004 1005 1006 1007 | |
__getitem__(index)
__getitem__(index: tp.SupportsIndex) -> SgrParamBuffer
__getitem__(index: slice) -> list[SgrParamBuffer]
Source code in chromatic/color/core.py
1009 1010 | |
__init__(iterable=None)
Source code in chromatic/color/core.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
__iter__()
Source code in chromatic/color/core.py
1026 1027 | |
__len__()
Source code in chromatic/color/core.py
1029 1030 | |
__repr__()
Source code in chromatic/color/core.py
1032 1033 | |
__setitem__(index, value)
__setitem__(index: tp.SupportsIndex, value: bytes | SgrParamBuffer) -> None
__setitem__(index: slice, value: abc.Iterable[bytes | SgrParamBuffer]) -> None
Source code in chromatic/color/core.py
1035 1036 1037 1038 1039 1040 1041 1042 | |
__str__()
Source code in chromatic/color/core.py
1044 1045 | |
clear_colors()
Remove all colorbytes values from self
Source code in chromatic/color/core.py
1049 1050 1051 1052 | |
set_colors(iterable, /, ansi_type=None)
set_colors(mapping: SupportsKeysAndGetItem[ColorDictKeys, Int3Tuple | None], /, ansi_type: AnsiColorParam | None = None) -> None
set_colors(iterable: abc.Iterable[tuple[ColorDictKeys, Int3Tuple | None]], /, ansi_type: AnsiColorParam | None = None) -> None
Set the active colors to the given dict or dict items, and remove the previous active colors from the sequence if they existed.
Values of None mean 'clear color', so
sgr.set_colors({"fg": None, "bg": None}) is the same as
sgr.clear_colors().
Source code in chromatic/color/core.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | |
ansicolor4Bit
Bases: colorbytes
ANSI 4-bit color format.
Notes
Supports 16 colors.
+-------+---------+
| index | color |
+-------+---------+
| 0 | black |
| 1 | red |
| 2 | green |
| 3 | yellow |
| 4 | blue |
| 5 | magenta |
| 6 | cyan |
| 7 | white |
+-------+---------+
Each color has a bright variant at index + 60.
Color codes use escape sequences of the form:
CSI 30–37 mfor foreground colors.CSI 40–47 mfor background colors.CSI 90–97 mfor foreground colors (bright).CSI 100–107 mfor background colors (bright).
Where CSI (Control Sequence Introducer) is ESC[.
Examples:
- bright red fg:
ESC[91m - standard green bg:
ESC[42m - bright white bg, black fg:
ESC[107;30m
Source code in chromatic/color/core.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
alias = '4b'
class-attribute
instance-attribute
typecode = 1
class-attribute
instance-attribute
ansicolor8Bit
Bases: colorbytes
ANSI 8-Bit color format.
Notes
Supports 256 colors, mapped to the following value ranges:
(0, 15): Corresponds to ANSI 4-bit colors.(16, 231): Represents a 6x6x6 RGB color cube.(232, 255): Greyscale colors, from black to white.
Color codes use escape sequences of the form:
CSI 38;5;(n) mfor foreground colors.CSI 48;5;(n) mfor background colors.
Where CSI (Control Sequence Introducer) is ESC[ and n is an unsigned 8-bit integer.
Examples:
- white bg:
ESC[48;5;255m - bright red fg (ANSI 4-bit):
ESC[38;5;9m - bright red fg (color cube):
ESC[38;5;196m
Source code in chromatic/color/core.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
alias = '8b'
class-attribute
instance-attribute
typecode = 2
class-attribute
instance-attribute
ansicolor24Bit
Bases: colorbytes
ANSI 24-Bit color format.
Notes
Supports all colors in the RGB color space (16,777,216 total).
Color codes use escape sequences of the form:
CSI 38;2;(r);(g);(b) mfor foreground colors.CSI 48;2;(r);(g);(b) mfor background colors.
Where CSI (Control Sequence Introducer) is ESC[ and r,g,b are unsigned 8-bit integers.
Examples:
- red fg:
ESC[38;2;255;85;85m - black bg:
ESC[48;2;0;0;0m - white fg, green bg:
ESC[38;2;255;255;255;48;2;0;170;0m
Source code in chromatic/color/core.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
alias = '24b'
class-attribute
instance-attribute
typecode = 3
class-attribute
instance-attribute
color_chain
Bases: MutableSequence[tuple[SgrSequence, str]]
Source code in chromatic/color/core.py
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 | |
__slots__ = ('_ansi_type', '_items')
class-attribute
instance-attribute
__match_args__ = ('_items',)
class-attribute
instance-attribute
dtype = ColorChainDType
class-attribute
instance-attribute
__array__(dtype=None, copy=None)
Source code in chromatic/color/core.py
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 | |
fromarray(arr, /, *, ansi_type=None)
classmethod
Source code in chromatic/color/core.py
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 | |
insert(index, value)
Source code in chromatic/color/core.py
1951 1952 1953 | |
shrink()
Mutate self in-place by joining SGR sequences for spans of empty string parts and vice-versa.
This operation removes items from the sequence, so prior length assumptions should be considered invalidated by calling this method.
Source code in chromatic/color/core.py
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 | |
splitlines()
Source code in chromatic/color/core.py
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 | |
term_array(shape=None, fillchar='')
term_array(shape: _Shape, fillchar='') -> ShapedNDArray[_Shape, np.void]
term_array(shape: tp.Any | None = None, fillchar='') -> ShapedNDArray[tuple[int, int], np.void]
Source code in chromatic/color/core.py
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 | |
__add__(other)
Source code in chromatic/color/core.py
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 | |
__bool__()
Source code in chromatic/color/core.py
2080 2081 | |
__call__(obj='')
Source code in chromatic/color/core.py
2083 2084 | |
__delitem__(index)
__delitem__(index: tp.SupportsIndex) -> None
__delitem__(index: slice) -> None
Source code in chromatic/color/core.py
2086 2087 | |
__eq__(other)
Source code in chromatic/color/core.py
2089 2090 2091 2092 | |
__getitem__(index)
__getitem__(index: tp.SupportsIndex) -> tuple[SgrSequence, str]
__getitem__(index: slice) -> list[tuple[SgrSequence, str]]
Source code in chromatic/color/core.py
2094 2095 | |
__init__(iterable=None, /, *, ansi_type=None)
__init__(iterable: None = None, /, *, ansi_type: AnsiColorParam | None = None) -> None
__init__(iterable: str, /, *, ansi_type: AnsiColorParam | None = None) -> None
__init__(iterable: abc.Iterable[tuple[SgrSequence, str] | SgrSequence | str], /, *, ansi_type: AnsiColorParam | None = None) -> None
Source code in chromatic/color/core.py
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 | |
__len__()
Source code in chromatic/color/core.py
2120 2121 | |
__radd__(other)
Source code in chromatic/color/core.py
2123 2124 2125 2126 2127 2128 2129 2130 | |
__repr__()
Source code in chromatic/color/core.py
2132 2133 2134 2135 2136 | |
__setitem__(index, value)
__setitem__(index: tp.SupportsIndex, value: tuple[SgrSequence, str]) -> None
__setitem__(index: slice, value: abc.Iterable[tuple[SgrSequence, str]]) -> None
Source code in chromatic/color/core.py
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 | |
__str__()
Source code in chromatic/color/core.py
2155 2156 | |
colorbytes
Bases: bytes
colorbytes(bytes_or_buffer) -> ansicolor4Bit | ansicolor8Bit | ansicolor24Bit
Construct an immutable array of bytes representing a valid ANSI SGR color code span.
When called from the base colorbytes class form, if the input is already
an instance of a colorbytes subclass, the constructor returns it as-is.
Otherwise, the bytes will be parsed and the constructor returns an instance
of the appropriate subclass. The constructor will never return an instance
of colorbytes, only a covariant type.
When called from a subclass, if the input is not a colorbytes subclass
instance, it will be parsed. If the input colorbytes is the same type as
this subclass, the constructor returns it as-is. Otherwise, the input rgb
colors are mapped to the nearest color code in this subclass' color-space.
Note
colorbytes is only to be subclassed by the internal implementation.
The programmer must override all constructors for it to behave properly as
a standalone subclass.
Source code in chromatic/color/core.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
rgb_dict
instance-attribute
from_rgb(rgb)
classmethod
from_rgb(rgb: tuple[ColorDictKeys, _VT] | abc.Mapping[_KT, _VT]) -> _T
from_rgb(rgb: tuple[str, _VT] | abc.Mapping[str, _VT]) -> _T
Construct a colorbytes object from an RGB key-value pair.
Returns:
| Type | Description |
|---|---|
cb
|
colorbytes object |
Raises:
| Type | Description |
|---|---|
ValueError
|
If key-value pair does not match expected structure. |
Examples:
>>> from chromatic.color.core import ansicolor4Bit, ansicolor8Bit
>>> rgb_dict = {'fg': (255, 85, 85)}
>>> old_ansi = ansicolor4Bit.from_rgb(rgb_dict)
>>> repr(old_ansi)
"ansicolor4Bit(b'91')"
>>> new_ansi = ansicolor24Bit.from_rgb(rgb_dict)
>>> repr(new_ansi)
"ansicolor24Bit(b'38;2;255;85;85')"
Source code in chromatic/color/core.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
__new__(ansi)
__new__(ansi: bytes | AnsiColorFormat) -> _T
__new__(ansi: bytes) -> AnsiColorFormat
Source code in chromatic/color/core.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
__repr__()
Source code in chromatic/color/core.py
303 304 | |
kind()
Source code in chromatic/color/core.py
306 307 308 | |
to_param_buffer()
Source code in chromatic/color/core.py
310 311 312 313 314 | |
ColorNamespace
Bases: DynamicNamespace
Source code in chromatic/color/palette.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
BLACK = 0
class-attribute
instance-attribute
DIM_GREY = 6908265
class-attribute
instance-attribute
GREY = 8421504
class-attribute
instance-attribute
DARK_GREY = 11119017
class-attribute
instance-attribute
SILVER = 12632256
class-attribute
instance-attribute
LIGHT_GREY = 13882323
class-attribute
instance-attribute
WHITE_SMOKE = 16119285
class-attribute
instance-attribute
WHITE = 16777215
class-attribute
instance-attribute
MAROON = 8388608
class-attribute
instance-attribute
DARK_RED = 9109504
class-attribute
instance-attribute
RED = 16711680
class-attribute
instance-attribute
FIREBRICK = 11674146
class-attribute
instance-attribute
BROWN = 10824234
class-attribute
instance-attribute
INDIAN_RED = 13458524
class-attribute
instance-attribute
LIGHT_CORAL = 15761536
class-attribute
instance-attribute
ROSY_BROWN = 12357519
class-attribute
instance-attribute
MISTY_ROSE = 16770273
class-attribute
instance-attribute
SNOW = 16775930
class-attribute
instance-attribute
SIENNA = 10506797
class-attribute
instance-attribute
ORANGE_RED = 16729344
class-attribute
instance-attribute
TOMATO = 16737095
class-attribute
instance-attribute
BURNT_SIENNA = 15367773
class-attribute
instance-attribute
CORAL = 16744272
class-attribute
instance-attribute
SALMON = 16416882
class-attribute
instance-attribute
DARK_SALMON = 15308410
class-attribute
instance-attribute
LIGHT_SALMON = 16752762
class-attribute
instance-attribute
SEASHELL = 16774638
class-attribute
instance-attribute
SADDLE_BROWN = 9127187
class-attribute
instance-attribute
CHOCOLATE = 13789470
class-attribute
instance-attribute
PERU = 13468991
class-attribute
instance-attribute
SANDY_BROWN = 16032864
class-attribute
instance-attribute
PEACH_PUFF = 16767673
class-attribute
instance-attribute
LINEN = 16445670
class-attribute
instance-attribute
DARK_ORANGE = 16747520
class-attribute
instance-attribute
BURLY_WOOD = 14596231
class-attribute
instance-attribute
BISQUE = 16770244
class-attribute
instance-attribute
ANTIQUE_WHITE = 16444375
class-attribute
instance-attribute
ORANGE = 16753920
class-attribute
instance-attribute
TAN = 13808780
class-attribute
instance-attribute
WHEAT = 16113331
class-attribute
instance-attribute
NAVAJO_WHITE = 16768685
class-attribute
instance-attribute
MOCCASIN = 16770229
class-attribute
instance-attribute
BLANCHED_ALMOND = 16772045
class-attribute
instance-attribute
PAPAYA_WHIP = 16773077
class-attribute
instance-attribute
OLD_LACE = 16643558
class-attribute
instance-attribute
FLORAL_WHITE = 16775920
class-attribute
instance-attribute
DARK_GOLDENROD = 12092939
class-attribute
instance-attribute
GOLDENROD = 14329120
class-attribute
instance-attribute
CORNSILK = 16775388
class-attribute
instance-attribute
DARK_KHAKI = 12433259
class-attribute
instance-attribute
GOLD = 16766720
class-attribute
instance-attribute
KHAKI = 15787660
class-attribute
instance-attribute
PALE_GOLDENROD = 15657130
class-attribute
instance-attribute
BEIGE = 16119260
class-attribute
instance-attribute
LIGHT_GOLDENROD_YELLOW = 16448210
class-attribute
instance-attribute
LEMON_CHIFFON = 16775885
class-attribute
instance-attribute
OLIVE = 8421376
class-attribute
instance-attribute
YELLOW = 16776960
class-attribute
instance-attribute
LIGHT_YELLOW = 16777184
class-attribute
instance-attribute
IVORY = 16777200
class-attribute
instance-attribute
DARK_GREEN = 25600
class-attribute
instance-attribute
GREEN = 32768
class-attribute
instance-attribute
DARK_OLIVE_GREEN = 5597999
class-attribute
instance-attribute
FOREST_GREEN = 2263842
class-attribute
instance-attribute
OLIVE_DRAB = 7048739
class-attribute
instance-attribute
LIME_GREEN = 3329330
class-attribute
instance-attribute
DARK_SEA_GREEN = 9419919
class-attribute
instance-attribute
LIME = 65280
class-attribute
instance-attribute
YELLOW_GREEN = 10145074
class-attribute
instance-attribute
LAWN_GREEN = 8190976
class-attribute
instance-attribute
CHARTREUSE = 8388352
class-attribute
instance-attribute
LIGHT_GREEN = 9498256
class-attribute
instance-attribute
GREEN_YELLOW = 11403055
class-attribute
instance-attribute
PALE_GREEN = 10025880
class-attribute
instance-attribute
HONEYDEW = 15794160
class-attribute
instance-attribute
SEA_GREEN = 3050327
class-attribute
instance-attribute
MEDIUM_SEA_GREEN = 3978097
class-attribute
instance-attribute
SPRING_GREEN = 65407
class-attribute
instance-attribute
MINT_CREAM = 16121850
class-attribute
instance-attribute
DARK_SLATE_GREY = 3100495
class-attribute
instance-attribute
TEAL = 32896
class-attribute
instance-attribute
DARK_CYAN = 35723
class-attribute
instance-attribute
LIGHT_SEA_GREEN = 2142890
class-attribute
instance-attribute
MEDIUM_TURQUOISE = 4772300
class-attribute
instance-attribute
MEDIUM_AQUAMARINE = 6737322
class-attribute
instance-attribute
TURQUOISE = 4251856
class-attribute
instance-attribute
MEDIUM_SPRING_GREEN = 64154
class-attribute
instance-attribute
CYAN = 65535
class-attribute
instance-attribute
PALE_TURQUOISE = 11529966
class-attribute
instance-attribute
AQUAMARINE = 8388564
class-attribute
instance-attribute
LIGHT_CYAN = 14745599
class-attribute
instance-attribute
AZURE = 15794175
class-attribute
instance-attribute
STEEL_BLUE = 4620980
class-attribute
instance-attribute
CADET_BLUE = 6266528
class-attribute
instance-attribute
DEEP_SKY_BLUE = 49151
class-attribute
instance-attribute
DARK_TURQUOISE = 52945
class-attribute
instance-attribute
SKY_BLUE = 8900331
class-attribute
instance-attribute
LIGHT_SKY_BLUE = 8900346
class-attribute
instance-attribute
LIGHT_BLUE = 11393254
class-attribute
instance-attribute
POWDER_BLUE = 11591910
class-attribute
instance-attribute
ALICE_BLUE = 15792383
class-attribute
instance-attribute
MIDNIGHT_BLUE = 1644912
class-attribute
instance-attribute
ROYAL_BLUE = 4286945
class-attribute
instance-attribute
SLATE_GREY = 7372944
class-attribute
instance-attribute
DODGER_BLUE = 2003199
class-attribute
instance-attribute
LIGHT_SLATE_GREY = 7833753
class-attribute
instance-attribute
CORNFLOWER_BLUE = 6591981
class-attribute
instance-attribute
LIGHT_STEEL_BLUE = 11584734
class-attribute
instance-attribute
LAVENDER = 15132410
class-attribute
instance-attribute
NAVY = 128
class-attribute
instance-attribute
DARK_BLUE = 139
class-attribute
instance-attribute
MEDIUM_BLUE = 205
class-attribute
instance-attribute
BLUE = 255
class-attribute
instance-attribute
GHOST_WHITE = 16316671
class-attribute
instance-attribute
INDIGO = 4915330
class-attribute
instance-attribute
DARK_VIOLET = 9699539
class-attribute
instance-attribute
DARK_SLATE_BLUE = 4734347
class-attribute
instance-attribute
REBECCA_PURPLE = 6697881
class-attribute
instance-attribute
BLUE_VIOLET = 9055202
class-attribute
instance-attribute
DARK_ORCHID = 10040012
class-attribute
instance-attribute
SLATE_BLUE = 6970061
class-attribute
instance-attribute
MEDIUM_ORCHID = 12211667
class-attribute
instance-attribute
MEDIUM_SLATE_BLUE = 8087790
class-attribute
instance-attribute
MEDIUM_PURPLE = 9662683
class-attribute
instance-attribute
THISTLE = 14204888
class-attribute
instance-attribute
PURPLE = 8388736
class-attribute
instance-attribute
DARK_MAGENTA = 9109643
class-attribute
instance-attribute
MEDIUM_VIOLET_RED = 13047173
class-attribute
instance-attribute
FUCHSIA = 16711935
class-attribute
instance-attribute
DEEP_PINK = 16716947
class-attribute
instance-attribute
ORCHID = 14315734
class-attribute
instance-attribute
HOT_PINK = 16738740
class-attribute
instance-attribute
VIOLET = 15631086
class-attribute
instance-attribute
PLUM = 14524637
class-attribute
instance-attribute
LAVENDER_BLUSH = 16773365
class-attribute
instance-attribute
CRIMSON = 14423100
class-attribute
instance-attribute
PALE_VIOLET_RED = 14381203
class-attribute
instance-attribute
LIGHT_PINK = 16758465
class-attribute
instance-attribute
PINK = 16761035
class-attribute
instance-attribute
ansi_4bit_to_rgb(value)
Source code in chromatic/color/colorconv.py
314 315 316 317 318 319 320 321 322 323 324 325 | |
ansi_8bit_to_rgb(value)
ansi_8bit_to_rgb(value: int) -> Int3Tuple
ansi_8bit_to_rgb(value: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[tuple[*_Shape, L[3]], np.uint8]
Source code in chromatic/color/colorconv.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
hexstr2rgb(s)
Source code in chromatic/color/colorconv.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
hsl2rgb(hsl)
hsl2rgb(hsl: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.uint8]
hsl2rgb(hsl: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
hsv2rgb(hsv)
hsv2rgb(hsv: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.uint8]
hsv2rgb(hsv: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
int2rgb(x)
Source code in chromatic/color/colorconv.py
90 91 92 | |
is_u24(value, *, strict=False)
Check if value is an unsigned 24-bit integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Input number |
required | |
strict
|
bool
|
Whether to return False or raise ValueError on failure |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when |
Source code in chromatic/color/colorconv.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
lab2lch(lab)
lab2lch(lab: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
lab2lch(lab: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
247 248 249 250 251 252 | |
lab2rgb(lab)
lab2rgb(lab: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.uint8]
lab2rgb(lab: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
239 240 | |
lab2xyz(lab)
lab2xyz(lab: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
lab2xyz(lab: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
138 139 140 141 142 143 144 145 146 147 148 | |
lch2lab(lch)
lch2lab(lch: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
lch2lab(lch: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
255 256 257 258 259 | |
lch2rgb(lch)
lch2rgb(lch: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.uint8]
lch2rgb(lch: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
262 263 | |
lerp_lch(lch1, lch2, /, num=8)
lerp_lch(lch1: Float3Tuple | ShapedNDArray[tuple[L[3]], np.floating], lch2: Float3Tuple | ShapedNDArray[tuple[L[3]], np.floating], /, num: _N = 8) -> ShapedNDArray[tuple[_N, L[3]], np.float64]
lerp_lch(lch1: ShapedNDArray[tuple[_D1, L[3]], np.floating], lch2: ShapedNDArray[tuple[_D1, L[3]], np.floating], /, num: _N = 8) -> ShapedNDArray[tuple[_D1, _N, L[3]], np.float64]
lerp_lch(lch1: ShapedNDArray[tuple[_D1, _D2, L[3]], np.floating], lch2: ShapedNDArray[tuple[_D1, _D2, L[3]], np.floating], /, num: _N = 8) -> ShapedNDArray[tuple[_D1, _D2, _N, L[3]], np.float64]
lerp_lch(lch1: np.typing.NDArray[np.floating], lch2: np.typing.NDArray[np.floating], /, num=8) -> np.typing.NDArray[np.float64]
Return a linear interpolation of the given LCh arrays.
Where lch1 and lch2 have dims ([D0[,...D-1],] 3) and num is N,
the returned array will have dims ([D0[,...D-1],] N, 3).
Source code in chromatic/color/colorconv.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
nearest_ansi_4bit_rgb(rgb)
nearest_ansi_4bit_rgb(rgb: Int3Tuple) -> Int3Tuple
nearest_ansi_4bit_rgb(rgb: tp.Sequence[ConvertibleToInt]) -> Int3Tuple
nearest_ansi_4bit_rgb(rgb: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
348 349 350 351 352 | |
nearest_ansi_8bit_rgb(value)
nearest_ansi_8bit_rgb(rgb: Int3Tuple) -> Int3Tuple
nearest_ansi_8bit_rgb(rgb: tp.Sequence[ConvertibleToInt]) -> Int3Tuple
nearest_ansi_8bit_rgb(rgb: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
355 356 | |
rgb2hexstr(rgb)
Source code in chromatic/color/colorconv.py
81 82 | |
rgb2hsl(rgb)
rgb2hsl(rgb: Int3Tuple) -> ShapedNDArray[tuple[L[3]], np.float32]
rgb2hsl(rgb: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[_Shape, np.float32]
Source code in chromatic/color/colorconv.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
rgb2hsv(rgb)
rgb2hsv(rgb: Int3Tuple) -> ShapedNDArray[tuple[L[3]], np.float32]
rgb2hsv(rgb: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[_Shape, np.float32]
Source code in chromatic/color/colorconv.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
rgb2int(rgb)
Source code in chromatic/color/colorconv.py
85 86 87 | |
rgb2lab(rgb)
rgb2lab(rgb: Int3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
rgb2lab(rgb: ShapedNDArray[_Shape, np.uint8]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
243 244 | |
rgb2lch(rgb)
rgb2lch(rgb: Int3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
rgb2lch(rgb: ShapedNDArray[_Shape, np.uint8]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
266 267 | |
rgb2xyz(rgb)
Source code in chromatic/color/colorconv.py
122 123 | |
rgb_diff(rgb1, rgb2)
rgb_diff(rgb1: Int3Tuple, rgb2: Int3Tuple) -> ShapedNDArray[tuple[L[3]], np.uint8]
rgb_diff(rgb1: ShapedNDArray[_Shape, np.number], rgb2: ShapedNDArray[_Shape, np.number]) -> ShapedNDArray[_Shape, np.uint8]
Source code in chromatic/color/colorconv.py
290 291 | |
rgb_to_ansi_8bit(rgb)
rgb_to_ansi_8bit(rgb: Int3Tuple) -> int
rgb_to_ansi_8bit(rgb: tp.Sequence[ConvertibleToInt]) -> int
rgb_to_ansi_8bit(rgb: ShapedNDArray[tuple[_D1, L[3]], np.number]) -> ShapedNDArray[tuple[_D1], np.uint8]
rgb_to_ansi_8bit(rgb: ShapedNDArray[tuple[_D1, _D2, L[3]], np.number]) -> ShapedNDArray[tuple[_D1, _D2], np.uint8]
rgb_to_ansi_8bit(rgb: np.typing.NDArray[np.number]) -> np.typing.NDArray[np.uint8]
Source code in chromatic/color/colorconv.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
xyz2lab(xyz)
xyz2lab(xyz: Float3Tuple) -> ShapedNDArray[tuple[L[3]], np.float64]
xyz2lab(xyz: ShapedNDArray[_Shape, np.floating]) -> ShapedNDArray[_Shape, np.float64]
Source code in chromatic/color/colorconv.py
126 127 128 129 130 131 132 133 134 135 | |
xyz2rgb(xyz)
Source code in chromatic/color/colorconv.py
117 118 119 | |
get_ansi_type(typ=None)
get_ansi_type(typ: None = None) -> type[ansicolor8Bit | ansicolor4Bit]
get_ansi_type(typ: _T) -> _T
get_ansi_type(typ: Ansi4BitAlias) -> type[ansicolor4Bit]
get_ansi_type(typ: Ansi8BitAlias) -> type[ansicolor8Bit]
get_ansi_type(typ: Ansi24BitAlias) -> type[ansicolor24Bit]
Source code in chromatic/color/core.py
507 508 509 510 | |
randcolor()
Return a random color as a Color object
Source code in chromatic/color/core.py
600 601 602 | |
rgb2ansi_escape(fmt, /, mode, rgb)
Source code in chromatic/color/core.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
set_default_ansi(typ)
Sets the global DEFAULT_ANSI variable to the specified ANSI color format
Source code in chromatic/color/core.py
513 514 515 516 517 | |
rgb_dispatch(*names, replace_defaults=True)
Returns a decorator which intercepts input arguments that are color name strings, and replaces those arguments with their RGB tuple counterparts before passing them to the wrapped function.
In the bare form, ie. @rgb_dispatch, the decorator treats all
positional-only and variadic positional parameters as assignable.
In the named form, ie. @rgb_dispatch("a", "b", "c"), the decorator
will only attempt to match and replace those parameter names, regardless
of their parameter kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Parameter names to target for color name to RGB tuple replacement. |
()
|
replace_defaults
|
bool
|
Whether to replace default argument values of the returned callable. |
True
|
Examples:
>>> from chromatic.color.palette import rgb_dispatch
>>> @rgb_dispatch
... def func(r="red", b="blue", g="green", x="not a color", /):
... return r, g, b, x
...
>>> func()
((255, 0, 0), (0, 128, 0), (0, 0, 255), 'not a color')
>>> func(None, None, None, "Hot Pink")
(None, None, None, (255, 105, 180))
>>> @rgb_dispatch
... def func(a, b, c, /, *args):
... return a, b, c, *args
...
>>> func("red", "yellow", "pink", "dark magenta", "alice blue")
((255, 0, 0), (255, 255, 0), (255, 192, 203), (139, 0, 139), (240, 248, 255))
>>> @rgb_dispatch("c")
... def func(a, b, c, /, *args):
... return a, b, c, *args
...
>>> func("red", "yellow", "pink", "dark magenta", "alice blue")
('red', 'yellow', (255, 192, 203), 'dark magenta', 'alice blue')
>>> @rgb_dispatch("color")
... def func(**kwargs):
... return kwargs
...
>>> func(color="red")
{'color': (255, 0, 0)}
>>> @rgb_dispatch("kwargs")
... def func(**kwargs):
... return kwargs
...
>>> func(color1="red", color2="yellow", color3="orange")
{'color1': (255, 0, 0), 'color2': (255, 255, 0), 'color3': (255, 165, 0)}
>>> @rgb_dispatch("kwargs")
... def func(a=None, /, **kwargs):
... return a, kwargs
...
>>> func(a="green")
(None, {'a': (0, 128, 0)})
>>> @rgb_dispatch(replace_defaults=False)
... def func(fruit_or_color="orange", /):
... res = "fruit" if isinstance(fruit_or_color, str) else "color"
... return f"{fruit_or_color} is a {res}"
...
>>> func()
'orange is a fruit'
>>> func("orange")
'(255, 165, 0) is a color'
Source code in chromatic/color/palette.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |