From 8f8ffb09de189a7a56322dc355726114fb0d07c6 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Tue, 31 Jul 2018 14:17:07 +0100 Subject: [PATCH] add support for named colors Signed-off-by: Eric Engestrom --- common/util.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/common/util.c b/common/util.c index 40c642305..f50333178 100644 --- a/common/util.c +++ b/common/util.c @@ -110,6 +110,30 @@ pid_t get_parent_pid(pid_t child) { } uint32_t parse_color(const char *color) { + static const struct { + uint32_t color; + char* name; + } color_names[] = { + { 0x000000, "black" }, + { 0x888888, "grey" }, + { 0xFFFFFF, "white" }, + { 0xFF0000, "red" }, + { 0x00FF00, "green" }, + { 0x0000FF, "blue" }, + { 0xFFFF00, "yellow" }, + { 0xFF00FF, "purple" }, + { 0x00FFFF, "cyan" }, + { 0xFF8800, "orange" }, + { 0xFF0088, "pink" }, + }; + + for (size_t i = 0; i < sizeof(color_names) / sizeof(color_names[0]); i++) { + if (strcasecmp(color, color_names[i].name) == 0) { + // Alpha is always 100% + return (color_names[i].color << 8) | 0xff; + } + } + if (color[0] == '#') { ++color; }