This plugin validates hex-formatted rgb color strings and normalizes them to decimal rgba format. It also accepts named colors and normalizes them.
1 # Mount a config file with the rgbcolor plugin
2 sudo kdb mount color.ecf user:/tests/color dump rgbcolor
4 # Suceeds, since the value is a valid rgbcolor. Quotes are important!
5 kdb set user:/tests/color/hex "#a1C2b3"
7 # Tell the plugin to validate the key and normalize if necessary
8 kdb meta-set user:/tests/color/hex check/rgbcolor ""
10 # Colors are normalized to 32-bit unsigned integers
11 # This one is normalized to 0xa1C2b3ff
12 kdb get user:/tests/color/hex
15 # Color names are supported (https://www.w3.org/TR/css-color-3/#svg-color)
16 kdb set user:/tests/color/hex "yellowgreen"
18 # yellowgreen is 0x9acd32ff
19 kdb get user:/tests/color/hex
22 kdb set user:/tests/color/hex/subcolor "#abc"
23 kdb meta-set user:/tests/color/hex/subcolor check/rgbcolor ""
25 # Expanded to rgba: #aabbccff
26 kdb get user:/tests/color/hex/subcolor
29 kdb set user:/tests/color/hex/subcolor "#abcd"
31 # Expanded to rgba: #aabbccdd
32 kdb get user:/tests/color/hex/subcolor
35 kdb set user:/tests/color/hex/subcolor "#aabbcc"
37 # Expanded to rgba: #aabbccff
38 kdb get user:/tests/color/hex/subcolor
41 # Try to set incorrect value
42 kdb set user:/tests/color/hex fff
45 # Try to set incorrect value
46 kdb set user:/tests/color/hex/subcolor "not a named color"
49 # Try to set incorrect value
50 kdb set user:/tests/color/hex "fff"
53 # Try to set incorrect value
54 kdb set user:/tests/color/hex "#12345"
57 # Old values are still there
58 kdb get user:/tests/color/hex
61 # Undo modifications to the key database
62 kdb rm -r user:/tests/color
63 sudo kdb umount user:/tests/color