| 18 | return ColorTriplet(*self._colors[number]) |
| 19 | |
| 20 | def __rich__(self) -> "Table": |
| 21 | from rich.color import Color |
| 22 | from rich.style import Style |
| 23 | from rich.text import Text |
| 24 | from rich.table import Table |
| 25 | |
| 26 | table = Table( |
| 27 | "index", |
| 28 | "RGB", |
| 29 | "Color", |
| 30 | title="Palette", |
| 31 | caption=f"{len(self._colors)} colors", |
| 32 | highlight=True, |
| 33 | caption_justify="right", |
| 34 | ) |
| 35 | for index, color in enumerate(self._colors): |
| 36 | table.add_row( |
| 37 | str(index), |
| 38 | repr(color), |
| 39 | Text(" " * 16, style=Style(bgcolor=Color.from_rgb(*color))), |
| 40 | ) |
| 41 | return table |
| 42 | |
| 43 | # This is somewhat inefficient and needs caching |
| 44 | @lru_cache(maxsize=1024) |