2015-03-16 10:00:32 +01:00
|
|
|
// vim:ts=4:sw=4:expandtab
|
2019-01-23 08:56:40 +01:00
|
|
|
#include <config.h>
|
2009-10-11 22:11:09 +02:00
|
|
|
#include <stdio.h>
|
2020-05-01 10:04:33 +02:00
|
|
|
#include <stdlib.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>
|
2009-10-11 22:11:09 +02:00
|
|
|
#include "i3status.h"
|
|
|
|
|
2020-03-31 16:08:07 +02:00
|
|
|
#define STRING_SIZE 5
|
|
|
|
|
2021-11-02 20:53:06 +01:00
|
|
|
void print_run_watch(run_watch_ctx_t *ctx) {
|
|
|
|
bool running = process_runs(ctx->pidfile);
|
2015-03-16 10:00:32 +01:00
|
|
|
const char *walk;
|
2021-11-02 20:53:06 +01:00
|
|
|
char *outwalk = ctx->buf;
|
|
|
|
#define json_gen ctx->json_gen
|
2009-10-16 20:31:20 +02:00
|
|
|
|
2021-11-02 20:53:06 +01:00
|
|
|
if (running || ctx->format_down == NULL) {
|
|
|
|
walk = ctx->format;
|
2015-04-02 22:31:06 +02:00
|
|
|
} else {
|
2021-11-02 20:53:06 +01:00
|
|
|
walk = ctx->format_down;
|
2015-04-02 22:31:06 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 20:53:06 +01:00
|
|
|
INSTANCE(ctx->pidfile);
|
2012-02-16 23:29:29 +00:00
|
|
|
|
2015-03-16 10:00:32 +01:00
|
|
|
START_COLOR((running ? "color_good" : "color_bad"));
|
2012-02-16 23:29:29 +00:00
|
|
|
|
2020-03-31 16:08:07 +02:00
|
|
|
char string_status[STRING_SIZE];
|
|
|
|
snprintf(string_status, STRING_SIZE, "%s", (running ? "yes" : "no"));
|
2018-06-02 02:32:25 +02:00
|
|
|
|
2020-03-31 16:08:07 +02:00
|
|
|
placeholder_t placeholders[] = {
|
2021-11-02 20:53:06 +01:00
|
|
|
{.name = "%title", .value = ctx->title},
|
2020-03-31 16:08:07 +02:00
|
|
|
{.name = "%status", .value = string_status}};
|
2018-06-02 02:32:25 +02:00
|
|
|
|
2020-03-31 16:08:07 +02:00
|
|
|
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
2021-11-02 20:53:06 +01:00
|
|
|
char *formatted = format_placeholders(walk, &placeholders[0], num);
|
|
|
|
OUTPUT_FORMATTED;
|
2015-03-16 10:00:32 +01:00
|
|
|
END_COLOR;
|
2021-11-02 20:53:06 +01:00
|
|
|
OUTPUT_FULL_TEXT(ctx->buf);
|
2009-10-11 22:11:09 +02:00
|
|
|
}
|