sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5.13k stars 105 forks source link

support all named colors from X11 rgb.txt #138

Open markus-oberhumer opened 3 years ago

markus-oberhumer commented 3 years ago

Just came across this nice program, only to realize that it is missing many named colors:

$ pastel color red3
[pastel error]: Could not parse color 'red3'

Please see https://en.wikipedia.org/wiki/X11_color_names and https://cgit.freedesktop.org/xorg/app/rgb/tree/rgb.txt .

The few clashing color names could be resolved by using a x11- prefix like in x11-gray.

sharkdp commented 3 years ago

Thank you for your feedback.

I'm okay with adding these color names. I'm not sure if they should show by default when calling pastel list though.

As for the name clashes: maybe we could prefix all of them with x11? But then there's the issue of discoverability.

See also: #32

markus-oberhumer commented 3 years ago

I agree that this might be an UI issue.

So prefixing all colors with x11- and (maybe) hiding them from pastel list would be fine.

markus-oberhumer commented 3 years ago

The following small Python program

#!/usr/bin/env python3
import re

# NOTE: wget https://cgit.freedesktop.org/xorg/app/rgb/plain/rgb.txt
lines = open("rgb.txt").read().splitlines()

colors = []
for l in lines:
    m = re.match(r"^(\d+)\s+(\d+)\s+(\d+)\s+(.*)", l.strip())
    if m:
        colors.append([m.group(4), m.group(1), m.group(2), m.group(3)])

print(f'// {len(colors)} X11 colors')
for name, r, g, b in sorted(colors):
    print(f'        named_color("x11-{name}", {r}, {g}, {b}),'

creates 782 entries in the form of

        named_color("x11-AliceBlue", 240, 248, 255),
        named_color("x11-AntiqueWhite", 250, 235, 215),
        ...

for inclusion into src/named.rs.

After compiling pastel list seems to work, but pastel color x11-red does not - probably some issue with the parser.

devhell commented 3 years ago

This would be awesome! I've been trying to create various colorschemes for programs that only have support for xterm-type colors, and would thoroughly enjoy having the ability to match colors to their nearest xterm equivalent. Thank you for such a thoughtful and amazing tool! Prost! :beers:

Vinegret43 commented 3 years ago

@sharkdp, maybe we could add something like '--all' option for list command that will display all colors, and without this option it will display only base colors, excluding X11, this will solve problem with discoverability. (i'm working on this issue right now and just want to know your opinion about adding this option, i already tested it on my machine)

Also, X11's rgb.txt has some color names which consist of multiple words (They are just synonyms for their single-worded alternatives, like 'royal blue' and 'royalblue'). The question is: should i delete these multi-worded synonyms from the list?