]> git.sur5r.net Git - i3/i3status/blobdiff - src/output.c
Implement getting the wireless ESSID
[i3/i3status] / src / output.c
index 379710e3ab063067dc13dc3cedb9e9421d794e09..eee458bd9be878e75e04a68a35aa952456fea24e 100644 (file)
@@ -1,3 +1,4 @@
+// vim:ts=8:expandtab
 #include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
@@ -25,20 +26,38 @@ void write_error_to_statusbar(const char *message) {
  */
 char *color(const char *colorstr) {
         static char colorbuf[32];
+        if (!use_colors) {
+                colorbuf[0] = '\0';
+                return colorbuf;
+        }
 #ifdef DZEN
         (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
+#elif XMOBAR
+        (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
 #else
         (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors);
 #endif
         return colorbuf;
 }
 
+/*
+ * Some color formats (xmobar) require to terminate colors again
+ *
+ */
+char *endcolor() {
+#ifdef XMOBAR
+        return "</fc>";
+#else
+        return "";
+#endif
+}
+
 /*
  * Cleans wmii's /rbar directory by deleting all regular files
  *
  */
 void cleanup_rbar_dir() {
-#ifdef DZEN
+#if defined(DZEN) || defined(XMOBAR)
         return;
 #endif
         struct dirent *ent;
@@ -65,7 +84,7 @@ void cleanup_rbar_dir() {
  *
  */
 void create_file(const char *name) {
-#ifdef DZEN
+#if defined(DZEN) || defined(XMOBAR)
         return;
 #endif
         char pathbuf[strlen(wmii_path)+256+1];
@@ -98,24 +117,25 @@ void setup(void) {
         unsigned int i;
         char pathbuf[512];
 
-#ifndef DZEN
+#if !defined(DZEN) && !defined(XMOBAR)
         struct stat statbuf;
         /* Wait until wmii_path/rbar exists */
         for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
 #endif
+#define cf(orderidx, name) create_file(order_to_str(order[orderidx], name));
 
         cleanup_rbar_dir();
         if (wlan_interface)
-                create_file(concat(order[ORDER_WLAN],"wlan"));
+                cf(ORDER_WLAN, "wlan");
         if (eth_interface)
-                create_file(concat(order[ORDER_ETH],"eth"));
+                cf(ORDER_ETH, "eth");
         if (get_cpu_temperature)
-                create_file(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"));
-        create_file(concat(order[ORDER_LOAD],"load"));
+                cf(ORDER_CPU_TEMPERATURE, "cpu_temperature");
+        cf(ORDER_LOAD, "load");
         if (time_format)
-                create_file(concat(order[ORDER_TIME],"time"));
+                cf(ORDER_TIME, "time");
         for (i = 0; i < num_run_watches; i += 2) {
-                snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
+                snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
                 create_file(pathbuf);
         }
 }
@@ -140,6 +160,22 @@ void write_to_statusbar(const char *name, const char *message, bool final_entry)
                 exit(1);
         }
         return;
+#elif XMOBAR
+        if (final_entry) {
+                if (printf("%s\n", message) < 0) {
+                        perror("printf");
+                        exit(1);
+                }
+
+                fflush(stdout);
+                return;
+        }
+        if (printf("%s" BAR, message) < 0) {
+                perror("printf");
+                exit(1);
+        }
+        return;
+
 #endif
 
         char pathbuf[strlen(wmii_path)+256+1];