]> git.sur5r.net Git - i3/i3status/blob - src/print_run_watch.c
Implement the i3bar JSON protocol
[i3/i3status] / src / print_run_watch.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "i3status.h"
4
5 void print_run_watch(const char *title, const char *pidfile, const char *format) {
6         bool running = process_runs(pidfile);
7         const char *walk;
8
9         if (output_format == O_I3BAR)
10                 printf("{\"name\":\"run_watch\", \"instance\": \"%s\", ", pidfile);
11
12         printf("%s", (running ? color("color_good") : color("color_bad")));
13
14         if (output_format == O_I3BAR)
15                 printf("\"full_text\":\"");
16
17         for (walk = format; *walk != '\0'; walk++) {
18                 if (*walk != '%') {
19                         putchar(*walk);
20                         continue;
21                 }
22
23                 if (strncmp(walk+1, "title", strlen("title")) == 0) {
24                         printf("%s", title);
25                         walk += strlen("title");
26                 } else if (strncmp(walk+1, "status", strlen("status")) == 0) {
27                         printf("%s", (running ? "yes" : "no"));
28                         walk += strlen("status");
29                 }
30         }
31
32         printf("%s", endcolor());
33
34         if (output_format == O_I3BAR)
35                 printf("\"}");
36 }