Change output format from dzen2 to i3bar
authornorly <ny-git@enpas.org>
Wed, 2 Oct 2013 13:43:13 +0000 (15:43 +0200)
committernorly <ny-git@enpas.org>
Wed, 2 Oct 2013 16:10:51 +0000 (18:10 +0200)
include/common.h
src/common/common.c
src/status/temp.c
src/sysstatus.c

index 04869bbec3b00842b2ac6a81584c32ee484a09f3..87f30ed27fb99c71a22c3e84bc8f397dd2da9a12 100644 (file)
@@ -15,6 +15,7 @@ typedef struct GlobalData {
   char *line;
   size_t linelen;
   size_t linemax; /* Buffer size, including NUL */
+  int firstItemDone;
 } GlobalData;
 
 
index 9e62259ea2b96374fb38089ee7d1b555a5fa7d79..4133ca858bb7edf4407e06bf8ceaecf838be24fe 100644 (file)
@@ -18,6 +18,9 @@ void line_clear(GlobalData *g)
 
   g->line[0] = '\0';
   g->linelen = 0;
+  g->firstItemDone = 0;
+
+  line_append_str(g, "[");
 }
 
 
@@ -45,24 +48,31 @@ void line_append_str(GlobalData *g, char *string)
 
 void line_append_item(GlobalData *g, StatusItem *s)
 {
-  line_append_str(g, " ");
+  if (g->firstItemDone) {
+    line_append_str(g, ",");
+  }
+  g->firstItemDone = 1;
+
+  line_append_str(g, "{");
 
   if (s->color) {
-    line_append_str(g, "^fg(");
+    line_append_str(g, "\"color\":\"");
     line_append_str(g, s->color);
-    line_append_str(g, ")");
+    line_append_str(g, "\",");
   }
 
-  if (s->text) {
-    line_append_str(g, s->text);
-  }
+  line_append_str(g, "\"full_text\":\"");
+  assert(s->text);
+  line_append_str(g, s->text);
+  line_append_str(g, "\"");
 
-  line_append_str(g, " ");
+  line_append_str(g, "}");
 }
 
 
 void line_print(GlobalData *g)
 {
+  line_append_str(g, "],");
   puts(g->line);
 }
 
index bcd189a54ad09dc0e2470cca4c5d8727b660bce3..3d4ddd6530c92111b2be16915f910befd8697be3 100644 (file)
@@ -34,7 +34,7 @@ void status_temp(GlobalData *g, char *title, char *sysfile)
     stline[stlen - 4] = '\0';
 
     s.color = "#FF33FF";
-    snprintf(text, sizeof(text), "%s%s°C", title, stline);
+    snprintf(text, sizeof(text), "%s%s C", title, stline);
   }
 
   line_append_item(g, &s);
index cc11c1187cd3af5c609f72c15f8c57863e0f651a..06ea31d36c89fabd768377a89b0c468d29a60db2 100644 (file)
@@ -6,7 +6,7 @@
 #include "statuses.h"
 
 
-static char outline[1024];
+static char outline[4096];
 
 static GlobalData gd = {
   .line = outline,
@@ -58,6 +58,9 @@ int main()
 {
   struct timeval tv;
 
+  /* Initial JSON header for i3bar */
+  printf("{\"version\":1}\n[\n");
+
   for(;;)
   {
     updatestatus();