i3status/src/print_run_watch.c

35 lines
948 B
C
Raw Normal View History

// vim:ts=4:sw=4:expandtab
#include <stdio.h>
2009-10-16 18:31:20 +00:00
#include <string.h>
2012-03-25 18:55:55 +00:00
#include <yajl/yajl_gen.h>
2012-04-08 12:05:47 +00:00
#include <yajl/yajl_version.h>
#include "i3status.h"
2012-03-25 18:55:55 +00:00
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format) {
bool running = process_runs(pidfile);
const char *walk;
char *outwalk = buffer;
2009-10-16 18:31:20 +00:00
INSTANCE(pidfile);
START_COLOR((running ? "color_good" : "color_bad"));
for (walk = format; *walk != '\0'; walk++) {
if (*walk != '%') {
*(outwalk++) = *walk;
continue;
}
2009-10-16 18:31:20 +00:00
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");
2009-10-16 18:31:20 +00:00
}
}
2009-10-16 18:31:20 +00:00
END_COLOR;
OUTPUT_FULL_TEXT(buffer);
}