From 53266a8bdc96e5313a64fa4aec34c4b0bb61bd47 Mon Sep 17 00:00:00 2001 From: norly Date: Wed, 2 Oct 2013 15:43:13 +0200 Subject: [PATCH] Change output format from dzen2 to i3bar --- include/common.h | 1 + src/common/common.c | 24 +++++++++++++++++------- src/status/temp.c | 2 +- src/sysstatus.c | 5 ++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/common.h b/include/common.h index 04869bb..87f30ed 100644 --- a/include/common.h +++ b/include/common.h @@ -15,6 +15,7 @@ typedef struct GlobalData { char *line; size_t linelen; size_t linemax; /* Buffer size, including NUL */ + int firstItemDone; } GlobalData; diff --git a/src/common/common.c b/src/common/common.c index 9e62259..4133ca8 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -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); } diff --git a/src/status/temp.c b/src/status/temp.c index bcd189a..3d4ddd6 100644 --- a/src/status/temp.c +++ b/src/status/temp.c @@ -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); diff --git a/src/sysstatus.c b/src/sysstatus.c index cc11c11..06ea31d 100644 --- a/src/sysstatus.c +++ b/src/sysstatus.c @@ -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(); -- 2.30.2