i3status/src/print_run_watch.c

40 lines
1.0 KiB
C
Raw Permalink Normal View History

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