From d5b4c8e368050cf1b84b03c1379bbbc3c817a713 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 16 Feb 2012 23:29:29 +0000 Subject: Implement the i3bar JSON protocol This hardcodes all the JSON parts. Strings are not properly escaped currently. The best/easiest way to fix this is by actually using libyajl. --- src/print_cpu_usage.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/print_cpu_usage.c') diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index 1d3bac8..d97a7fa 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -26,6 +26,9 @@ void print_cpu_usage(const char *format) { int curr_user = 0, curr_nice = 0, curr_system = 0, curr_idle = 0, curr_total; int diff_idle, diff_total, diff_usage; + if (output_format == O_I3BAR) + printf("{\"name\":\"cpu_usage\", \"full_text\":\""); + #if defined(LINUX) static char statpath[512]; strcpy(statpath, "/proc/stat"); @@ -70,6 +73,10 @@ void print_cpu_usage(const char *format) { walk += strlen("usage"); } } + + if (output_format == O_I3BAR) + printf("\"}"); + return; error: (void)fputs("Cannot read usage\n", stderr); -- cgit v1.2.3