Reference - rich-color-ext
Author: Max Ludden
Description: Extend Rich with CSS color names and 3-digit hex parsing

Skip to content

# API Reference

Below are auto-generated API docs for the primary modules in this package.

Rich Color Extensions Package.

This package extends the Rich library's color parsing capabilities by adding support for: - 3-digit hexadecimal color codes (e.g., `#abc`). - CSS color names (e.g., `rebeccapurple`, `mediumslateblue`). It achieves this by patching the `Color.parse` method in Rich with an extended parser.

## `CSSColor`

Class to handle CSS color names and their corresponding hex values.

Source code in `src/rich_color_ext/css.py`

    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
    317
    318
    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
    361
    362
    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
    392
    393
    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
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    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
    class CSSColor:
        """Class to handle CSS color names and their corresponding hex values."""

        def __init__(
            self,
            name: Optional[str] = None,
            hex: Optional[str] = None,  # pylint:disable=W0622
            red: Optional[int] = None,
            green: Optional[int] = None,
            blue: Optional[int] = None,
        ) -> None:
            """Create a CSSColor.

            You may provide any combination of name/hex/RGB sufficient to derive the
            remaining attributes. Values are normalised and validated.
            """
            log.debug(f"Creating CSSColor({name=}, {hex=}, {red=}, {green=}, {blue=})")

            self._name = ""
            self._hex = ""
            self._red = -1
            self._green = -1
            self._blue = -1

            # Apply provided values through property setters to keep invariants.
            if name is not None:
                self.name = name
            if hex is not None:
                self.hex = hex
            # Only set numeric channels if caller provided them (None means omitted)
            if red is not None:
                self.red = red
            if green is not None:
                self.green = green
            if blue is not None:
                self.blue = blue

            # Fill missing values when possible
            if self._name and not self._hex and self._name in get_css_map():
                self.hex = get_css_map()[self._name]

            if self._hex and (self._red < 0 or self._green < 0 or self._blue < 0):
                r, g, b = self.hex_to_rgb(self._hex)
                self._red, self._green, self._blue = r, g, b

            if not self._name and self._hex:
                css_map = get_css_map() or get_css_map()
                derived = _find_name_by_hex(self._hex, css_map)
                if derived:
                    self._name = derived

            # Final validation
            if (
                not self._name
                or not self._hex
                or any(v < 0 or v > 255 for v in (self._red, self._green, self._blue))
            ):
                raise ValueError("Unable to determine color.")

        @classmethod
        def from_name(
            cls, name: str, css_map: Optional[dict[str, str]] = None
        ) -> "CSSColor":
            """Create a CSSColor instance from a color name."""
            if not name:
                raise ValueError("Name must be a non-empty string.")
            css_map = css_map or get_css_map()
            norm = _normalize_name(name)
            log.debug(f"Creating CSSColor from name: name={norm!r}")
            hex_value = css_map.get(norm)
            if not hex_value:
                raise ValueError(f"Unknown color name: {name}")
            red, green, blue = cls.hex_to_rgb(hex_value)
            return cls(name=norm, hex=hex_value, red=red, green=green, blue=blue)

        @classmethod
        def from_hex(cls, hex: str, css_map: Optional[dict[str, str]] = None) -> "CSSColor":  # pylint:disable=W0622
            """Create a CSSColor instance from a hex value."""
            if not hex:
                raise ValueError("Hex value must be a non-empty string.")
            css_map = css_map or get_css_map() or get_css_map()
            norm_hex = _normalize_hex(hex)
            name = _find_name_by_hex(norm_hex, css_map)
            if name is None:
                raise ValueError(f"Unknown hex value: {hex}")
            red, green, blue = cls.hex_to_rgb(norm_hex)
            return cls(name=name, hex=norm_hex, red=red, green=green, blue=blue)

        @classmethod
        def from_rgb(
            cls,
            red: int,
            green: int,
            blue: int,
            css_map: Optional[dict[str, str]] = None,
        ) -> "CSSColor":
            """Create a CSSColor instance from RGB values."""
            for channel, label in ((red, "red"), (green, "green"), (blue, "blue")):
                if not 0 <= channel <= 255:
                    raise ValueError(
                        f"{label.capitalize()} value must be between 0 and 255."
                    )
            css_map = css_map or get_css_map() or get_css_map()
            hex_str = _hex_from_rgb(red, green, blue)
            name = _find_name_by_hex(hex_str, css_map)
            if name is None:
                raise ValueError(f"Unknown RGB values: ({red}, {green}, {blue})")
            return cls(name=name, hex=hex_str, red=red, green=green, blue=blue)

        def __str__(self) -> str:
            """Return the name of the color.
            Returns:
                str: The name of the color."""
            return f"{self.name}"

        def __repr__(self) -> str:
            return (
                f"CSSColor(name={self.name}, hex={self.hex}, "
                f"rgb=({self.red}, {self.green}, {self.blue}))"
            )

        @staticmethod
        def hex_to_rgb(hex_str: str) -> Tuple[int, int, int]:
            """Return the RGB components as a tuple.
            Returns:
                Tuple[int, int, int]: The RGB components.
            """
            log.debug(f"Converting hex to RGB: hex_str={hex_str!r}")
            norm = _normalize_hex(hex_str)
            val = norm.lstrip("#")
            red, green, blue = (int(val[i : i + 2], 16) for i in (0, 2, 4))
            log.debug(f"Converted hex {norm} to RGB: red={red}, green={green}, blue={blue}")
            return (red, green, blue)

        @property
        def name(self) -> str:
            """Return the name of the color."""
            return self._name

        @name.setter
        def name(self, value: str) -> None:
            """Set the name of the color."""
            log.debug(f"Setting name to: {value!r}")
            self._name = _normalize_name(value)
            if self._name in get_css_map() and not self._hex:
                self.hex = get_css_map()[self._name]
                log.debug(f"Set hex from name: {self.hex=}")
            if self._hex and any(v < 0 for v in (self._red, self._green, self._blue)):
                red, green, blue = self.hex_to_rgb(self._hex)
                self._red, self._green, self._blue = red, green, blue
                log.debug(f"Set RGB from hex: {self._red=}, {self._green=}, {self._blue=}")

        @property
        def hex(self) -> str:
            """Return the hex representation of the color."""
            log.debug(f"Getting hex: {self._hex=}")
            return self._hex

        @hex.setter
        def hex(self, value: str) -> None:
            """Set the hex representation of the color."""
            log.debug(f"Setting hex to: {value!r}")
            self._hex = _normalize_hex(value)
            if any(v < 0 for v in (self._red, self._green, self._blue)):
                red, green, blue = self.hex_to_rgb(self._hex)
                self._red, self._green, self._blue = red, green, blue
            if not self._name:
                css_map = get_css_map() or get_css_map()
                name = _find_name_by_hex(self._hex, css_map)
                if name:
                    self._name = name

        @property
        def red(self) -> int:
            """Return the red component of the color."""
            log.debug(f"Getting red: {self._red=}")
            return self._red

        @red.setter
        def red(self, value: int) -> None:
            """Set the red component of the color."""
            log.debug(f"Setting red to: {value}")
            if 0 <= value <= 255:
                self._red = value
            else:
                raise ValueError("Red value must be between 0 and 255.")
            if self._green >= 0 and self._blue >= 0:
                hex_str = _hex_from_rgb(self._red, self._green, self._blue)
                self.hex = hex_str
                if not self._name:
                    css_map = get_css_map() or get_css_map()
                    name = _find_name_by_hex(self._hex, css_map)
                    if name:
                        self._name = name

        @property
        def green(self) -> int:
            """Return the green component of the color."""
            log.debug(f"Getting green: {self._green=}")
            return self._green

        @green.setter
        def green(self, value: int) -> None:
            """Set the green component of the color."""
            log.debug(f"Setting green to: {value}")
            if 0 <= value <= 255:
                self._green = value
            else:
                raise ValueError("Green value must be between 0 and 255.")
            if self._red >= 0 and self._blue >= 0:
                hex_str = _hex_from_rgb(self._red, self._green, self._blue)
                self.hex = hex_str
                if not self._name:
                    css_map = get_css_map() or get_css_map()
                    name = _find_name_by_hex(self._hex, css_map)
                    if name:
                        self._name = name

        @property
        def blue(self) -> int:
            """Return the blue component of the color."""
            log.debug(f"Getting blue: {self._blue=}")
            return self._blue

        @blue.setter
        def blue(self, value: int) -> None:
            """Set the blue component of the color."""
            log.debug(f"Setting blue to: {value}")
            if 0 <= value <= 255:
                self._blue = value
            else:
                raise ValueError("Blue value must be between 0 and 255.")
            if self._red >= 0 and self._green >= 0:
                hex_str = _hex_from_rgb(self._red, self._green, self._blue)
                self.hex = hex_str
                if not self._name:
                    css_map = get_css_map() or get_css_map()
                    name = _find_name_by_hex(self._hex, css_map)
                    if name:
                        self._name = name

        def rich(self, reverse: bool = False) -> Text:
            """Return a Rich Text representation of the color."""
            class_style = f"bold {self.hex}" if not reverse else f"bold on {self.hex}"
            color_style = f"bold on {self.hex}" if reverse else f"bold {self.hex}"
            label_style = f"bold black on {self.hex}" if reverse else "bold white"
            return Text.assemble(*[
                Text("CSSColor", style=class_style),
                Text("<", style=color_style),
                Text("hex=", style=label_style),
                Text(f"'{self.hex}'", style=color_style),
                Text(", rgb='", style=label_style),
                self.rgb(reverse),
                Text(", name=", style=label_style),
                Text(f"{self.name!r}'", style=color_style),
                Text(">", style=color_style),
            ])

        def __rich__(self) -> Text:
            """Return a Rich Text representation of the color."""
            return self.rich()

        def rgb(self, reverse: bool = False) -> Text:
            """Return a Rich Text representation of the RGB values."""
            style = f"bold {self.hex}" if not reverse else f"bold on {self.hex}"
            red_style = "bold #AA0000" if not reverse else f"bold #AA0000 on {self.hex}"
            green_style = "bold #00AA00" if not reverse else f"bold #00AA00 on {self.hex}"
            blue_style = "bold #00AAFF" if not reverse else f"bold #00AAFF on {self.hex}"

            rgb = Text.assemble(*[
                Text("rgb(", style=style),
                Text(f"{self.red}", style=red_style),
                Text(",", style=style),
                Text(f"{self.green}", style=green_style),
                Text(",", style=style),
                Text(f"{self.blue}", style=blue_style),
                Text(")", style=style),
            ])
            return rgb

        def panel(self) -> Panel:
            """Return a Rich Table representation of the color."""
            table = Table(
                show_header=False,
                show_edge=False,
                show_lines=False,
                pad_edge=True,
                collapse_padding=False,
                border_style=f"bold {self.hex}",
            )

            table.add_column("Hex")
            table.add_column("RGB")
            table.add_row(
                Text(self.hex, style=f"bold {self.hex}"), Align(self.rgb(), align="center")
            )
            return Panel(
                table,
                title=f"[bold on {self.hex}] {self.name.capitalize()} [/bold on {self.hex}]",
                border_style=f"bold {self.hex}",
                expand=False,
                padding=(1, 4),
            )

        @property
        def triplet(self) -> ColorTriplet:
            """Return the RGB triplet for this color."""
            return ColorTriplet(self.red, self.green, self.blue)

### `blue` `property` `writable`

Return the blue component of the color.

### `green` `property` `writable`

Return the green component of the color.

### `hex` `property` `writable`

Return the hex representation of the color.

### `name` `property` `writable`

Return the name of the color.

### `red` `property` `writable`

Return the red component of the color.

### `triplet` `property`

Return the RGB triplet for this color.

### `__init__(name=None, hex=None, red=None, green=None, blue=None)`

Create a CSSColor.

You may provide any combination of name/hex/RGB sufficient to derive the remaining attributes. Values are normalised and validated.

Source code in `src/rich_color_ext/css.py`

    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
    def __init__(
        self,
        name: Optional[str] = None,
        hex: Optional[str] = None,  # pylint:disable=W0622
        red: Optional[int] = None,
        green: Optional[int] = None,
        blue: Optional[int] = None,
    ) -> None:
        """Create a CSSColor.

        You may provide any combination of name/hex/RGB sufficient to derive the
        remaining attributes. Values are normalised and validated.
        """
        log.debug(f"Creating CSSColor({name=}, {hex=}, {red=}, {green=}, {blue=})")

        self._name = ""
        self._hex = ""
        self._red = -1
        self._green = -1
        self._blue = -1

        # Apply provided values through property setters to keep invariants.
        if name is not None:
            self.name = name
        if hex is not None:
            self.hex = hex
        # Only set numeric channels if caller provided them (None means omitted)
        if red is not None:
            self.red = red
        if green is not None:
            self.green = green
        if blue is not None:
            self.blue = blue

        # Fill missing values when possible
        if self._name and not self._hex and self._name in get_css_map():
            self.hex = get_css_map()[self._name]

        if self._hex and (self._red < 0 or self._green < 0 or self._blue < 0):
            r, g, b = self.hex_to_rgb(self._hex)
            self._red, self._green, self._blue = r, g, b

        if not self._name and self._hex:
            css_map = get_css_map() or get_css_map()
            derived = _find_name_by_hex(self._hex, css_map)
            if derived:
                self._name = derived

        # Final validation
        if (
            not self._name
            or not self._hex
            or any(v < 0 or v > 255 for v in (self._red, self._green, self._blue))
        ):
            raise ValueError("Unable to determine color.")

### `__rich__()`

Return a Rich Text representation of the color.

Source code in `src/rich_color_ext/css.py`

    489
    490
    491
    def __rich__(self) -> Text:
        """Return a Rich Text representation of the color."""
        return self.rich()

### `__str__()`

Return the name of the color. Returns: str: The name of the color.

Source code in `src/rich_color_ext/css.py`

    340
    341
    342
    343
    344
    def __str__(self) -> str:
        """Return the name of the color.
        Returns:
            str: The name of the color."""
        return f"{self.name}"

### `from_hex(hex, css_map=None)` `classmethod`

Create a CSSColor instance from a hex value.

Source code in `src/rich_color_ext/css.py`

    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    @classmethod
    def from_hex(cls, hex: str, css_map: Optional[dict[str, str]] = None) -> "CSSColor":  # pylint:disable=W0622
        """Create a CSSColor instance from a hex value."""
        if not hex:
            raise ValueError("Hex value must be a non-empty string.")
        css_map = css_map or get_css_map() or get_css_map()
        norm_hex = _normalize_hex(hex)
        name = _find_name_by_hex(norm_hex, css_map)
        if name is None:
            raise ValueError(f"Unknown hex value: {hex}")
        red, green, blue = cls.hex_to_rgb(norm_hex)
        return cls(name=name, hex=norm_hex, red=red, green=green, blue=blue)

### `from_name(name, css_map=None)` `classmethod`

Create a CSSColor instance from a color name.

Source code in `src/rich_color_ext/css.py`

    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    @classmethod
    def from_name(
        cls, name: str, css_map: Optional[dict[str, str]] = None
    ) -> "CSSColor":
        """Create a CSSColor instance from a color name."""
        if not name:
            raise ValueError("Name must be a non-empty string.")
        css_map = css_map or get_css_map()
        norm = _normalize_name(name)
        log.debug(f"Creating CSSColor from name: name={norm!r}")
        hex_value = css_map.get(norm)
        if not hex_value:
            raise ValueError(f"Unknown color name: {name}")
        red, green, blue = cls.hex_to_rgb(hex_value)
        return cls(name=norm, hex=hex_value, red=red, green=green, blue=blue)

### `from_rgb(red, green, blue, css_map=None)` `classmethod`

Create a CSSColor instance from RGB values.

Source code in `src/rich_color_ext/css.py`

    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    @classmethod
    def from_rgb(
        cls,
        red: int,
        green: int,
        blue: int,
        css_map: Optional[dict[str, str]] = None,
    ) -> "CSSColor":
        """Create a CSSColor instance from RGB values."""
        for channel, label in ((red, "red"), (green, "green"), (blue, "blue")):
            if not 0 <= channel <= 255:
                raise ValueError(
                    f"{label.capitalize()} value must be between 0 and 255."
                )
        css_map = css_map or get_css_map() or get_css_map()
        hex_str = _hex_from_rgb(red, green, blue)
        name = _find_name_by_hex(hex_str, css_map)
        if name is None:
            raise ValueError(f"Unknown RGB values: ({red}, {green}, {blue})")
        return cls(name=name, hex=hex_str, red=red, green=green, blue=blue)

### `hex_to_rgb(hex_str)` `staticmethod`

Return the RGB components as a tuple. Returns: Tuple[int, int, int]: The RGB components.

Source code in `src/rich_color_ext/css.py`

    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    @staticmethod
    def hex_to_rgb(hex_str: str) -> Tuple[int, int, int]:
        """Return the RGB components as a tuple.
        Returns:
            Tuple[int, int, int]: The RGB components.
        """
        log.debug(f"Converting hex to RGB: hex_str={hex_str!r}")
        norm = _normalize_hex(hex_str)
        val = norm.lstrip("#")
        red, green, blue = (int(val[i : i + 2], 16) for i in (0, 2, 4))
        log.debug(f"Converted hex {norm} to RGB: red={red}, green={green}, blue={blue}")
        return (red, green, blue)

### `panel()`

Return a Rich Table representation of the color.

Source code in `src/rich_color_ext/css.py`

    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    def panel(self) -> Panel:
        """Return a Rich Table representation of the color."""
        table = Table(
            show_header=False,
            show_edge=False,
            show_lines=False,
            pad_edge=True,
            collapse_padding=False,
            border_style=f"bold {self.hex}",
        )

        table.add_column("Hex")
        table.add_column("RGB")
        table.add_row(
            Text(self.hex, style=f"bold {self.hex}"), Align(self.rgb(), align="center")
        )
        return Panel(
            table,
            title=f"[bold on {self.hex}] {self.name.capitalize()} [/bold on {self.hex}]",
            border_style=f"bold {self.hex}",
            expand=False,
            padding=(1, 4),
        )

### `rgb(reverse=False)`

Return a Rich Text representation of the RGB values.

Source code in `src/rich_color_ext/css.py`

    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    def rgb(self, reverse: bool = False) -> Text:
        """Return a Rich Text representation of the RGB values."""
        style = f"bold {self.hex}" if not reverse else f"bold on {self.hex}"
        red_style = "bold #AA0000" if not reverse else f"bold #AA0000 on {self.hex}"
        green_style = "bold #00AA00" if not reverse else f"bold #00AA00 on {self.hex}"
        blue_style = "bold #00AAFF" if not reverse else f"bold #00AAFF on {self.hex}"

        rgb = Text.assemble(*[
            Text("rgb(", style=style),
            Text(f"{self.red}", style=red_style),
            Text(",", style=style),
            Text(f"{self.green}", style=green_style),
            Text(",", style=style),
            Text(f"{self.blue}", style=blue_style),
            Text(")", style=style),
        ])
        return rgb

### `rich(reverse=False)`

Return a Rich Text representation of the color.

Source code in `src/rich_color_ext/css.py`

    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    def rich(self, reverse: bool = False) -> Text:
        """Return a Rich Text representation of the color."""
        class_style = f"bold {self.hex}" if not reverse else f"bold on {self.hex}"
        color_style = f"bold on {self.hex}" if reverse else f"bold {self.hex}"
        label_style = f"bold black on {self.hex}" if reverse else "bold white"
        return Text.assemble(*[
            Text("CSSColor", style=class_style),
            Text("<", style=color_style),
            Text("hex=", style=label_style),
            Text(f"'{self.hex}'", style=color_style),
            Text(", rgb='", style=label_style),
            self.rgb(reverse),
            Text(", name=", style=label_style),
            Text(f"{self.name!r}'", style=color_style),
            Text(">", style=color_style),
        ])

## `get_css_map()` `cached`

Return the mapping of CSS colour name (lowercase) → hex string (‘#RRGGBB’). Loads the data on first call.

Returns:

Type | Description
--- | ---
`dict[str, str]` | Dict mapping colour name to hex.

Source code in `src/rich_color_ext/css.py`

     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     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
    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
    @lru_cache(maxsize=1024)
    def get_css_map() -> dict[str, str]:
        """
        Return the mapping of CSS colour name (lowercase) → hex string (‘#RRGGBB’).
        Loads the data on first call.

        Returns:
            Dict mapping colour name to hex.
        """
        css_map = {
            "aliceblue": "#f0f8ff",
            "antiquewhite": "#faebd7",
            "aqua": "#00ffff",
            "aquamarine": "#7fffd4",
            "azure": "#f0ffff",
            "beige": "#f5f5dc",
            "bisque": "#ffe4c4",
            "black": "#000000",
            "blanchedalmond": "#ffebcd",
            "blue": "#0000ff",
            "blueviolet": "#8a2be2",
            "brown": "#a52a2a",
            "burlywood": "#deb887",
            "cadetblue": "#5f9ea0",
            "chartreuse": "#7fff00",
            "chocolate": "#d2691e",
            "coral": "#ff7f50",
            "cornflowerblue": "#6495ed",
            "cornsilk": "#fff8dc",
            "crimson": "#dc143c",
            "cyan": "#00ffff",
            "darkblue": "#00008b",
            "darkcyan": "#008b8b",
            "darkgoldenrod": "#b8860b",
            "darkgray": "#a9a9a9",
            "darkgreen": "#006400",
            "darkgrey": "#a9a9a9",
            "darkkhaki": "#bdb76b",
            "darkmagenta": "#8b008b",
            "darkolivegreen": "#556b2f",
            "darkorange": "#ff8c00",
            "darkorchid": "#9932cc",
            "darkred": "#8b0000",
            "darksalmon": "#e9967a",
            "darkseagreen": "#8fbc8f",
            "darkslateblue": "#483d8b",
            "darkslategray": "#2f4f4f",
            "darkslategrey": "#2f4f4f",
            "darkturquoise": "#00ced1",
            "darkviolet": "#9400d3",
            "deeppink": "#ff1493",
            "deepskyblue": "#00bfff",
            "dimgray": "#696969",
            "dimgrey": "#696969",
            "dodgerblue": "#1e90ff",
            "firebrick": "#b22222",
            "floralwhite": "#fffaf0",
            "forestgreen": "#228b22",
            "fuchsia": "#ff00ff",
            "gainsboro": "#dcdcdc",
            "ghostwhite": "#f8f8ff",
            "gold": "#ffd700",
            "goldenrod": "#daa520",
            "gray": "#808080",
            "green": "#008000",
            "greenyellow": "#adff2f",
            "grey": "#808080",
            "honeydew": "#f0fff0",
            "hotpink": "#ff69b4",
            "indianred": "#cd5c5c",
            "indigo": "#4b0082",
            "ivory": "#fffff0",
            "khaki": "#f0e68c",
            "lavender": "#e6e6fa",
            "lavenderblush": "#fff0f5",
            "lawngreen": "#7cfc00",
            "lemonchiffon": "#fffacd",
            "lightblue": "#add8e6",
            "lightcoral": "#f08080",
            "lightcyan": "#e0ffff",
            "lightgoldenrodyellow": "#fafad2",
            "lightgray": "#d3d3d3",
            "lightgreen": "#90ee90",
            "lightgrey": "#d3d3d3",
            "lightpink": "#ffb6c1",
            "lightsalmon": "#ffa07a",
            "lightseagreen": "#20b2aa",
            "lightskyblue": "#87cefa",
            "lightslategray": "#778899",
            "lightslategrey": "#778899",
            "lightsteelblue": "#b0c4de",
            "lightyellow": "#ffffe0",
            "lime": "#00ff00",
            "limegreen": "#32cd32",
            "linen": "#faf0e6",
            "magenta": "#ff00ff",
            "maroon": "#800000",
            "mediumaquamarine": "#66cdaa",
            "mediumblue": "#0000cd",
            "mediumorchid": "#ba55d3",
            "mediumpurple": "#9370db",
            "mediumseagreen": "#3cb371",
            "mediumslateblue": "#7b68ee",
            "mediumspringgreen": "#00fa9a",
            "mediumturquoise": "#48d1cc",
            "mediumvioletred": "#c71585",
            "midnightblue": "#191970",
            "mintcream": "#f5fffa",
            "mistyrose": "#ffe4e1",
            "moccasin": "#ffe4b5",
            "navajowhite": "#ffdead",
            "navy": "#000080",
            "oldlace": "#fdf5e6",
            "olive": "#808000",
            "olivedrab": "#6b8e23",
            "orange": "#ffa500",
            "orangered": "#ff4500",
            "orchid": "#da70d6",
            "palegoldenrod": "#eee8aa",
            "palegreen": "#98fb98",
            "paleturquoise": "#afeeee",
            "palevioletred": "#db7093",
            "papayawhip": "#ffefd5",
            "peachpuff": "#ffdab9",
            "peru": "#cd853f",
            "pink": "#ffc0cb",
            "plum": "#dda0dd",
            "powderblue": "#b0e0e6",
            "purple": "#800080",
            "rebeccapurple": "#663399",
            "red": "#ff0000",
            "rosybrown": "#bc8f8f",
            "royalblue": "#4169e1",
            "saddlebrown": "#8b4513",
            "salmon": "#fa8072",
            "sandybrown": "#f4a460",
            "seagreen": "#2e8b57",
            "seashell": "#fff5ee",
            "sienna": "#a0522d",
            "silver": "#c0c0c0",
            "skyblue": "#87ceeb",
            "slateblue": "#6a5acd",
            "slategray": "#708090",
            "slategrey": "#708090",
            "snow": "#fffafa",
            "springgreen": "#00ff7f",
            "steelblue": "#4682b4",
            "tan": "#d2b48c",
            "teal": "#008080",
            "thistle": "#d8bfd8",
            "tomato": "#ff6347",
            "turquoise": "#40e0d0",
            "violet": "#ee82ee",
            "wheat": "#f5deb3",
            "white": "#ffffff",
            "whitesmoke": "#f5f5f5",
            "yellow": "#ffff00",
            "yellowgreen": "#9acd32",
        }
        return css_map

## `install()`

Install the monkey patch. After this call, rich.color.Color.parse will support 3‐digit hex and CSS colour names. Safe to call multiple times.

Source code in `src/rich_color_ext/patch.py`

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    def install() -> None:
        """
        Install the monkey patch. After this call, rich.color.Color.parse will
        support 3‐digit hex and CSS colour names. Safe to call multiple times.
        """
        global INSTALLED  # pylint: disable=global-statement
        if INSTALLED:
            return
        Color.parse = _patched_parse  # type: ignore[assignment]
        INSTALLED = True

## `is_installed()`

Return True if the monkey patch is currently installed.

Source code in `src/rich_color_ext/patch.py`

    68
    69
    70
    71
    72
    def is_installed() -> bool:
        """
        Return True if the monkey patch is currently installed.
        """
        return INSTALLED

## `rce_install()`

Backward-compatible wrapper for install().

Source code in `src/rich_color_ext/__init__.py`

    38
    39
    40
    def rce_install() -> None:
        """Backward-compatible wrapper for install()."""
        install()

## `rce_uninstall()`

Backward-compatible wrapper for uninstall().

Source code in `src/rich_color_ext/__init__.py`

    43
    44
    45
    46
    def rce_uninstall() -> None:
        """Backward-compatible wrapper for uninstall()."""
        # Call uninstall once. Previous versions mistakenly called it twice.
        uninstall()

## `uninstall()`

Uninstall the monkey patch, restoring the original rich.color.Color.parse. Safe to call multiple times.

Source code in `src/rich_color_ext/patch.py`

    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    def uninstall() -> None:
        """
        Uninstall the monkey patch, restoring the original rich.color.Color.parse.
        Safe to call multiple times.
        """
        global INSTALLED  # pylint: disable=global-statement
        if not INSTALLED:
            return
        Color.parse = _ORIGINAL_PARSE  # type: ignore[assignment]
        INSTALLED = False