$darkmode
Elektra 0.11.0
Plugin: rgbcolor

This plugin validates hex-formatted rgb color strings and normalizes them to decimal rgba format. It also accepts named colors and normalizes them.

Usage

Add the metakey check/rgbcolor with an arbitrary value (e.g. "") to the key that you want to check and normalize.

Installation

See installation. The package is called libelektra5-extra.

Examples

1 # Mount a config file with the rgbcolor plugin
2 sudo kdb mount color.ecf user:/tests/color dump rgbcolor
3 
4 # Suceeds, since the value is a valid rgbcolor. Quotes are important!
5 kdb set user:/tests/color/hex "#a1C2b3"
6 
7 # Tell the plugin to validate the key and normalize if necessary
8 kdb meta-set user:/tests/color/hex check/rgbcolor ""
9 
10 # Colors are normalized to 32-bit unsigned integers
11 # This one is normalized to 0xa1C2b3ff
12 kdb get user:/tests/color/hex
13 #> 2713891839
14 
15 # Color names are supported (https://www.w3.org/TR/css-color-3/#svg-color)
16 kdb set user:/tests/color/hex "yellowgreen"
17 
18 # yellowgreen is 0x9acd32ff
19 kdb get user:/tests/color/hex
20 #> 2597139199
21 
22 kdb set user:/tests/color/hex/subcolor "#abc"
23 kdb meta-set user:/tests/color/hex/subcolor check/rgbcolor ""
24 
25 # Expanded to rgba: #aabbccff
26 kdb get user:/tests/color/hex/subcolor
27 #> 2864434431
28 
29 kdb set user:/tests/color/hex/subcolor "#abcd"
30 
31 # Expanded to rgba: #aabbccdd
32 kdb get user:/tests/color/hex/subcolor
33 #> 2864434397
34 
35 kdb set user:/tests/color/hex/subcolor "#aabbcc"
36 
37 # Expanded to rgba: #aabbccff
38 kdb get user:/tests/color/hex/subcolor
39 #> 2864434431
40 
41 # Try to set incorrect value
42 kdb set user:/tests/color/hex fff
43 # RET: 5
44 
45 # Try to set incorrect value
46 kdb set user:/tests/color/hex/subcolor "not a named color"
47 # RET: 5
48 
49 # Try to set incorrect value
50 kdb set user:/tests/color/hex "fff"
51 # RET: 5
52 
53 # Try to set incorrect value
54 kdb set user:/tests/color/hex "#12345"
55 # RET: 5
56 
57 # Old values are still there
58 kdb get user:/tests/color/hex
59 #> 2597139199
60 
61 # Undo modifications to the key database
62 kdb rm -r user:/tests/color
63 sudo kdb umount user:/tests/color