X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_run_watch.c;h=0887521f5b71c8cd5da0b78168595b72f1755ae3;hb=0b8aa86ecbec930ef0315bc4627c0f48966769d2;hp=807e322b07f4989f65dfbbb7bce31575834d0c85;hpb=8a66289702bb17c2874497319ea2a2921e7a3e0d;p=i3%2Fi3status diff --git a/src/print_run_watch.c b/src/print_run_watch.c index 807e322..0887521 100644 --- a/src/print_run_watch.c +++ b/src/print_run_watch.c @@ -1,27 +1,42 @@ +// vim:ts=4:sw=4:expandtab #include #include +#include +#include #include "i3status.h" -void print_run_watch(const char *title, const char *pidfile, const char *format) { - bool running = process_runs(pidfile); - const char *walk; - - printf("%s", (running ? color("#00FF00") : color("#FF0000"))); - - for (walk = format; *walk != '\0'; walk++) { - if (*walk != '%') { - putchar(*walk); - continue; - } - - if (strncmp(walk+1, "title", strlen("title")) == 0) { - printf("%s", title); - walk += strlen("title"); - } else if (strncmp(walk+1, "status", strlen("status")) == 0) { - printf("%s", (running ? "yes" : "no")); - walk += strlen("status"); - } +void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down) { + bool running = process_runs(pidfile); + const char *walk; + char *outwalk = buffer; + + if (running || format_down == NULL) { + walk = format; + } else { + walk = format_down; + } + + INSTANCE(pidfile); + + START_COLOR((running ? "color_good" : "color_bad")); + + for (; *walk != '\0'; walk++) { + if (*walk != '%') { + *(outwalk++) = *walk; + + } else if (BEGINS_WITH(walk + 1, "title")) { + outwalk += sprintf(outwalk, "%s", title); + walk += strlen("title"); + + } else if (BEGINS_WITH(walk + 1, "status")) { + outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no")); + walk += strlen("status"); + + } else { + *(outwalk++) = '%'; } + } - printf("%s", endcolor()); + END_COLOR; + OUTPUT_FULL_TEXT(buffer); }