i3status/src/print_run_watch.c

34 lines
953 B
C
Raw Normal View History

#include <stdio.h>
2009-10-16 20:31:20 +02:00
#include <string.h>
2012-03-25 20:55:55 +02:00
#include <yajl/yajl_gen.h>
2012-04-08 14:05:47 +02:00
#include <yajl/yajl_version.h>
#include "i3status.h"
2012-03-25 20:55:55 +02: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);
2009-10-16 20:31:20 +02:00
const char *walk;
2012-03-25 20:55:55 +02:00
char *outwalk = buffer;
2009-10-16 20:31:20 +02:00
2012-03-25 20:55:55 +02:00
INSTANCE(pidfile);
2012-03-25 20:55:55 +02:00
START_COLOR((running ? "color_good" : "color_bad"));
2009-10-16 20:31:20 +02:00
for (walk = format; *walk != '\0'; walk++) {
if (*walk != '%') {
2012-03-25 20:55:55 +02:00
*(outwalk++) = *walk;
2009-10-16 20:31:20 +02:00
continue;
}
if (BEGINS_WITH(walk+1, "title")) {
2012-03-25 20:55:55 +02:00
outwalk += sprintf(outwalk, "%s", title);
2009-10-16 20:31:20 +02:00
walk += strlen("title");
} else if (BEGINS_WITH(walk+1, "status")) {
2012-03-25 20:55:55 +02:00
outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
2009-10-16 20:31:20 +02:00
walk += strlen("status");
}
}
2012-03-25 20:55:55 +02:00
END_COLOR;
OUTPUT_FULL_TEXT(buffer);
}