]> git.sur5r.net Git - i3/i3status/blob - src/print_run_watch.c
able to print percentage
[i3/i3status] / src / print_run_watch.c
1 // vim:ts=4:sw=4:expandtab
2 #include <stdio.h>
3 #include <string.h>
4 #include <yajl/yajl_gen.h>
5 #include <yajl/yajl_version.h>
6 #include "i3status.h"
7
8 void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down) {
9     bool running = process_runs(pidfile);
10     const char *walk;
11     char *outwalk = buffer;
12
13     if (running || format_down == NULL) {
14         walk = format;
15     } else {
16         walk = format_down;
17     }
18
19     INSTANCE(pidfile);
20
21     START_COLOR((running ? "color_good" : "color_bad"));
22
23     for (; *walk != '\0'; walk++) {
24         if (*walk != '%') {
25             *(outwalk++) = *walk;
26
27         } else if (BEGINS_WITH(walk + 1, "title")) {
28             outwalk += sprintf(outwalk, "%s", title);
29             walk += strlen("title");
30
31         } else if (BEGINS_WITH(walk + 1, "status")) {
32             outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
33             walk += strlen("status");
34
35         } else {
36             *(outwalk++) = '%';
37         }
38     }
39
40     END_COLOR;
41     OUTPUT_FULL_TEXT(buffer);
42 }