From 38337511e9b5896006f276c111265c985b2af70d Mon Sep 17 00:00:00 2001 From: Fernando Tarlá Cardoso Lemos Date: Tue, 29 Jun 2010 20:59:03 -0300 Subject: Support customized colors. --- i3status.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'i3status.c') diff --git a/i3status.c b/i3status.c index 64fac76..eabcd6c 100644 --- a/i3status.c +++ b/i3status.c @@ -65,12 +65,33 @@ static char *file_exists(char *path) { return full_path; } +/* + * Validates a color in "#RRGGBB" format + * + */ +static int valid_color(const char *value) +{ + if (strlen(value) != 7) return 0; + if (value[0] != '#') return 0; + for (int i = 1; i < 7; ++i) { + if (value[i] >= '0' && value[i] <= '9') continue; + if (value[i] >= 'a' && value[i] <= 'f') continue; + if (value[i] >= 'A' && value[i] <= 'F') continue; + return 0; + } + return 1; +} + int main(int argc, char *argv[]) { unsigned int j; cfg_opt_t general_opts[] = { CFG_STR("output_format", "dzen2", CFGF_NONE), CFG_BOOL("colors", 1, CFGF_NONE), + CFG_STR("color_good", "#00FF00", CFGF_NONE), + CFG_STR("color_degraded", "#FFFF00", CFGF_NONE), + CFG_STR("color_bad", "#FF0000", CFGF_NONE), + CFG_STR("color_separator", "#333333", CFGF_NONE), CFG_INT("interval", 1, CFGF_NONE), CFG_END() }; @@ -194,6 +215,12 @@ int main(int argc, char *argv[]) { output_format = O_NONE; else die("Unknown output format: \"%s\"\n", output_str); + if (!valid_color(cfg_getstr(cfg_general, "color_good")) + || !valid_color(cfg_getstr(cfg_general, "color_degraded")) + || !valid_color(cfg_getstr(cfg_general, "color_bad")) + || !valid_color(cfg_getstr(cfg_general, "color_separator"))) + die("Bad color format"); + if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) die("Could not create socket\n"); -- cgit v1.2.3