OK, well, that was simple, no need to mess around with from_rgb, because of what styles support.
And, after reading Will's answer, I've modified my original solution to use saved themes. Thanks again for an awesome library, Will!
Alternatively you can use a CSS-like syntax to specify a color with a “#” followed by three pairs of hex characters, or in RGB form with three decimal integers. The following two lines both print “Hello” in the same color (purple):
console.print("Hello", style="#af00ff")
Found a 20-element list here (last 2 are black and white which I am skipping).
hivis.theme.ini
[styles]
; High constrast palette from
; https://sashamaps.net/docs/resources/20-colors/
hivis0 = #e6194b
hivis1 = #3cb44b
hivis2 = #ffe119
hivis3 = #4363d8
hivis4 = #f58231
hivis5 = #911eb4
hivis6 = #46f0f0
hivis7 = #f032e6
hivis8 = #bcf60c
hivis9 = #fabebe
hivis10 = #008080
hivis11 = #e6beff
hivis12 = #9a6324
hivis13 = #fffac8
hivis14 = #800000
hivis15 = #aaffc3
hivis16 = #808000
hivis17 = #ffd8b1
hivis18 = #000075
hivis19 = #808080
;hivis20 = #ffffff
;hivis21 = #000000
script.py
from rich.console import Console
from rich.theme import Theme
with open("hivis.theme.ini") as fi:
theme = Theme.from_file(fi)
palette = [name for name in theme.styles.keys() if name.startswith("hivis")]
console = Console(theme=theme)
console.print("[hivis1] First Hivis. [hivis2] Second Hivis.")
for ix, rgb in enumerate(palette):
console.print(f"[{palette[ix]}] {rgb}")
