Merge pull request #400 from Stunkymonkey/format_placeholder-run_watch

use format_placeholder for run_watch
This commit is contained in:
Ingo Bürk 2020-04-03 08:38:04 +02:00 committed by GitHub
commit 4980193dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,8 @@
#include <yajl/yajl_version.h>
#include "i3status.h"
#define STRING_SIZE 5
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;
@ -21,22 +23,15 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c
START_COLOR((running ? "color_good" : "color_bad"));
for (; *walk != '\0'; walk++) {
if (*walk != '%') {
*(outwalk++) = *walk;
char string_status[STRING_SIZE];
snprintf(string_status, STRING_SIZE, "%s", (running ? "yes" : "no"));
} else if (BEGINS_WITH(walk + 1, "title")) {
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
placeholder_t placeholders[] = {
{.name = "%title", .value = title},
{.name = "%status", .value = string_status}};
} else if (BEGINS_WITH(walk + 1, "status")) {
outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
walk += strlen("status");
} else {
*(outwalk++) = '%';
}
}
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
buffer = format_placeholders(walk, &placeholders[0], num);
END_COLOR;
OUTPUT_FULL_TEXT(buffer);