summaryrefslogtreecommitdiff
path: root/src/print_eth_info.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2012-02-16 23:29:29 +0000
committerMichael Stapelberg <michael@stapelberg.de>2012-02-16 23:30:54 +0000
commitd5b4c8e368050cf1b84b03c1379bbbc3c817a713 (patch)
tree2f918d4c5b95a05ebec68bceec35f7d4fa9a0c4e /src/print_eth_info.c
parent7149f6f78e0d105f02d54e1db60db8b191a98acb (diff)
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.
Diffstat (limited to 'src/print_eth_info.c')
-rw-r--r--src/print_eth_info.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/print_eth_info.c b/src/print_eth_info.c
index 28ba6c1..4fae191 100644
--- a/src/print_eth_info.c
+++ b/src/print_eth_info.c
@@ -78,6 +78,9 @@ void print_eth_info(const char *interface, const char *format_up, const char *fo
const char *walk;
const char *ip_address = get_ip_addr(interface);
+ if (output_format == O_I3BAR)
+ printf("{\"name\":\"ethernet\", \"instance\": \"%s\", ", interface);
+
if (ip_address == NULL) {
printf("%s", color("color_bad"));
printf("%s", format_down);
@@ -87,6 +90,9 @@ void print_eth_info(const char *interface, const char *format_up, const char *fo
printf("%s", color("color_good"));
}
+ if (output_format == O_I3BAR)
+ printf("\"full_text\":\"");
+
for (walk = format_up; *walk != '\0'; walk++) {
if (*walk != '%') {
putchar(*walk);
@@ -103,4 +109,7 @@ void print_eth_info(const char *interface, const char *format_up, const char *fo
}
(void)printf("%s", endcolor());
+
+ if (output_format == O_I3BAR)
+ printf("\"}");
}