]> git.sur5r.net Git - i3/i3status/blobdiff - i3status.c
Support customized colors.
[i3/i3status] / i3status.c
index 9087d0cb1a4fa51be9dcc1dba80ef485ce5099a4..eabcd6c68cbf79469ca105e0013673da42ad3718 100644 (file)
@@ -6,6 +6,7 @@
  * Copyright © 2008-2009 Michael Stapelberg and contributors
  * Copyright © 2009 Thorsten Toepper <atsutane at freethoughts dot de>
  * Copyright © 2010 Axel Wagner <mail at merovius dot de>
+ * Copyright © 2010 Fernando Tarlá Cardoso Lemos <fernandotcl at gmail dot com>
  *
  * See file LICENSE for license information.
  *
@@ -64,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()
         };
@@ -193,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");