This is a continuation of the old thread Listing all color names in the Murga forum.
My problem back then:
Setting a color option for X applications usually requires to specify a color as RGB hex value (e.g. #FF0022) .
As an alternative to those cryptic hex values the user may use color names like "white" or "orange", which is fine, but more than 700 of such names exist,
Interesting stuff and interesting solutions,but it turned out that I use none of them. I now tend to avoid those names and use hex values instead, but not the 'cryptic' 6 digit types. Above mentioned value #FF0022 can be abbreviated as #F02. Shortened values are fairly easy to remember and type (I prefer to type lower case. E.g. #8b8 is easier to read than #8B8)
When I searched on the web for those short hand values I stumbled upon a list of "web safe" colors. Pretty retro stuff and technically not relevant anymore, but the 216 listed colors are nice and in most cases "good enough" for most purposes. Eventually I wrote a script to generate those and other simple colors and added sample text, which makes it easy to determine, whether the color is suitable as text background color. I then packed everything into a no-frills gtkdialog GUI. Uses pango markup, which makes it a bit slow.
The "256 Shades of Gray" require 6 digit hex values, but since the first 2 digits are repeated 2 times only the first 2 digits need to be remembered.
As a bonus I added the x11 color names (which I don't use ) and a color picker.
[EDIT]: x11 is expected not to work in all distros as the location for the rgb.txt file may be different (see posts at end of the linked Murga thread). Can be fixed by changing the X11_RGBTXTFILE variable in the code header.
Tested in Slacko 5.6 and Fossapup, may work in other distros:
Code: Select all
#!/bin/sh
export COLORS_TSAMPLE='text'
export COLORS_TXTSIZE=12
export SIMPLE_WEBSAFE='0 3 6 9 c f'
export SIMPLE_PASTELL='8 9 a b c d e f'
export SIMPLE_DARKPAT='0 1 2 3 4 5 6 7'
export SIMPLE_GRAYPAT='0 1 2 3 4 5 6 7 8 9 a b c d e f'
export X11_RGBTXTFILE=/usr/share/X11/rgb.txt
function x11_colors {
echo "<span fgcolor='#800' font='bold 12'>""X11 Colors""</span>"
awk -v fontsize=$COLORS_TXTSIZE -v text=$COLORS_TSAMPLE ' !/[Gg]rey/ && NF<5 {printf "<span font=\"22\" bgcolor=\"#%02X%02X%02X\"> <span font=\""fontsize"\" fgcolor=\"#000\">"text"</span><span font=\""fontsize"\" fgcolor=\"#fff\">"text"</span> </span><big><tt> #%02X%02X%02X </tt></big>%s\n",$1,$2,$3,$1,$2,$3,$4}' $X11_RGBTXTFILE 2>&1
};export -f x11_colors
function simple_colors {
function write_line {
case $@ in
*000)name=black;; f00)name=red;; 0f0)name=green;; 00f)name=blue;; ff0)name=yellow;; *fff)name=white ;; 0ff)name=cyan;; f0f)name=magenta;; *)name= ;;
esac
echo "<span font=\"24\" bgcolor=\"#$@\"> <span font=\"$COLORS_TXTSIZE\" fgcolor=\"#000\">$COLORS_TSAMPLE</span><span font=\"$COLORS_TXTSIZE\" fgcolor=\"#fff\">$COLORS_TSAMPLE</span> </span> <big><big><tt>#$@ $name</tt></big></big>"
}
case $1 in
websafe) TITLE='216 "Web Safe" Colors' P=$SIMPLE_WEBSAFE ;;
pastell) TITLE='512 Pastell Colors' P=$SIMPLE_PASTELL ;;
dark) TITLE='512 Dark Colors' P=$SIMPLE_DARKPAT ;;
gray16) TITLE='16 Shades of Gray' P=$SIMPLE_GRAYPAT ;;
gray256) TITLE='256 Shades of Gray' P=$SIMPLE_GRAYPAT ;;
esac
echo "<span fgcolor='#800' font='bold 12'>""$TITLE""</span>"
if [[ $1 = gray16 ]] ;then
for a in $P;do
write_line $a$a$a
done
elif [[ $1 = gray256 ]] ;then
for a in $P ;do for b in $P;do
write_line $a$b$a$b$a$b
done;done
else
for a in $P ;do for b in $P;do for c in $P;do
write_line $a$b$c
done;done;done
fi
};export -f simple_colors
function nearest_color {
[[ $1 ]] || return
PICKED=$1
if [[ ${PICKED:1:1} = ${PICKED:2:1} && ${PICKED:3:1} = ${PICKED:4:1} && ${PICKED:5:1} = ${PICKED:6:1} ]];then
LABEL='Same as'
else
LABEL='Nearest'
fi
RRGGBB=(${PICKED:1:2} ${PICKED:3:2} ${PICKED:5:2}) #e.g. #b4120a -> array b4 12 0a
for c in 0 1 2 ;do
printf -v DEC %i 0x${RRGGBB[c]} #e.g. b4 -> DEC 180
for ((i=0;i<=255;i+=17)); do #0 17 34 51 68 85 102 119 136 153 170 187 204 221 238 255
(( DEC>$((i+17)) )) && continue
(( DEC==i )) && DIGIT[c]=${RRGGBB[c]#?} && break
(( DEC>$((i+8)) )) && DEC=$((i+17)) || DEC=$i #DEC value changes here
printf -v HEX %02x $DEC #e.g. DEC 187 -> HEX bb
DIGIT[c]=${HEX#?} #e.g. DIGIT[0]=b
break
done
done
SIMPLE="#${DIGIT[0]}${DIGIT[1]}${DIGIT[2]}"
printf "<span font='bold 12' fgcolor='#800'>Picked Color vs. Nearest Simple Color</span>\n\n"
printf "<span font='124' bgcolor='$PICKED'> <span font='12' fgcolor='#000'>text</span><span font='12' fgcolor='#fff'>text</span> </span> <big><big><tt>Picked: $PICKED</tt></big></big>"
printf "\n<span font='2'> </span>\n"
printf "<span font='124' bgcolor='$SIMPLE'> <span font='12' fgcolor='#000'>text</span><span font='12' fgcolor='#fff'>text</span> </span> <big><big><tt>$LABEL: $SIMPLE</tt></big></big>"
}; export -f nearest_color
echo '<window title="Simple Colors" default-height="600" border-width="0">
<vbox>
<vbox scrollable="true" border-width="5">
<text use-markup="true" xalign="0" wrap="false" visible="true">
<variable export="false">vTXT1</variable>
<input>simple_colors websafe</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT2</variable>
<input>simple_colors pastell</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT3</variable>
<input>simple_colors dark</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT4</variable>
<input>simple_colors gray16</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT5</variable>
<input>simple_colors gray256</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT6</variable>
<input>x11_colors</input>
</text>
<text use-markup="true" xalign="0" wrap="false" visible="false">
<variable export="false">vTXT7</variable>
<input>nearest_color $vCLRBUT</input>
</text>
</vbox>
<hbox>
<button label="Web Safe">
<action>show:vTXT1</action>
<action>hide:vTXT2</action>
<action>hide:vTXT3</action>
<action>hide:vTXT4</action>
<action>hide:vTXT5</action>
<action>hide:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<button label="Pastell">
<action>hide:vTXT1</action>
<action>show:vTXT2</action>
<action>hide:vTXT3</action>
<action>hide:vTXT4</action>
<action>hide:vTXT5</action>
<action>hide:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<button label="Dark">
<action>hide:vTXT1</action>
<action>hide:vTXT2</action>
<action>show:vTXT3</action>
<action>hide:vTXT4</action>
<action>hide:vTXT5</action>
<action>hide:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<button label="Gray16">
<action>hide:vTXT1</action>
<action>hide:vTXT2</action>
<action>hide:vTXT3</action>
<action>show:vTXT4</action>
<action>hide:vTXT5</action>
<action>hide:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<button label="Gray256">
<action>hide:vTXT1</action>
<action>hide:vTXT2</action>
<action>hide:vTXT3</action>
<action>hide:vTXT4</action>
<action>show:vTXT5</action>
<action>hide:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<button label=" x11 ">
<action>hide:vTXT1</action>
<action>hide:vTXT2</action>
<action>hide:vTXT3</action>
<action>hide:vTXT4</action>
<action>hide:vTXT5</action>
<action>show:vTXT6</action>
<action>hide:vTXT7</action>
</button>
<colorbutton>
<variable>vCLRBUT</variable>
<action>hide:vTXT1</action>
<action>hide:vTXT2</action>
<action>hide:vTXT3</action>
<action>hide:vTXT4</action>
<action>hide:vTXT5</action>
<action>hide:vTXT6</action>
<action>show:vTXT7</action>
<action>refresh:vTXT7</action>
</colorbutton>
<button ok></button>
</hbox>
</vbox>
</window>'| gtkdialog -s
[EDIT 2022-8-6] Above code updated. It adds the possibility to change any 6-digit color value to it's most similar 3-digit value. Just open the color button and type or pick a color, then push OK button.