run_watch: fix colors (+param struct)
This commit is contained in:
parent
4722198875
commit
7d613fbe95
11
i3status.c
11
i3status.c
@ -754,7 +754,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
CASE_SEC_TITLE("run_watch") {
|
||||
SEC_OPEN_MAP("run_watch");
|
||||
print_run_watch(json_gen, buffer, title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format"), cfg_getstr(sec, "format_down"));
|
||||
run_watch_ctx_t ctx = {
|
||||
.json_gen = json_gen,
|
||||
.buf = buffer,
|
||||
.buflen = sizeof(buffer),
|
||||
.title = title,
|
||||
.pidfile = cfg_getstr(sec, "pidfile"),
|
||||
.format = cfg_getstr(sec, "format"),
|
||||
.format_down = cfg_getstr(sec, "format_down"),
|
||||
};
|
||||
print_run_watch(&ctx);
|
||||
SEC_CLOSE_MAP;
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,18 @@ typedef struct {
|
||||
|
||||
void print_wireless_info(wireless_info_ctx_t *ctx);
|
||||
|
||||
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down);
|
||||
typedef struct {
|
||||
yajl_gen json_gen;
|
||||
char *buf;
|
||||
const size_t buflen;
|
||||
const char *title;
|
||||
const char *pidfile;
|
||||
const char *format;
|
||||
const char *format_down;
|
||||
} run_watch_ctx_t;
|
||||
|
||||
void print_run_watch(run_watch_ctx_t *ctx);
|
||||
|
||||
void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_down);
|
||||
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int);
|
||||
void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const char *format_above_degraded_threshold, const char *path, const float max_threshold, const float degraded_threshold);
|
||||
|
@ -9,18 +9,19 @@
|
||||
|
||||
#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);
|
||||
void print_run_watch(run_watch_ctx_t *ctx) {
|
||||
bool running = process_runs(ctx->pidfile);
|
||||
const char *walk;
|
||||
char *outwalk = buffer;
|
||||
char *outwalk = ctx->buf;
|
||||
#define json_gen ctx->json_gen
|
||||
|
||||
if (running || format_down == NULL) {
|
||||
walk = format;
|
||||
if (running || ctx->format_down == NULL) {
|
||||
walk = ctx->format;
|
||||
} else {
|
||||
walk = format_down;
|
||||
walk = ctx->format_down;
|
||||
}
|
||||
|
||||
INSTANCE(pidfile);
|
||||
INSTANCE(ctx->pidfile);
|
||||
|
||||
START_COLOR((running ? "color_good" : "color_bad"));
|
||||
|
||||
@ -28,13 +29,12 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c
|
||||
snprintf(string_status, STRING_SIZE, "%s", (running ? "yes" : "no"));
|
||||
|
||||
placeholder_t placeholders[] = {
|
||||
{.name = "%title", .value = title},
|
||||
{.name = "%title", .value = ctx->title},
|
||||
{.name = "%status", .value = string_status}};
|
||||
|
||||
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
||||
buffer = format_placeholders(walk, &placeholders[0], num);
|
||||
|
||||
char *formatted = format_placeholders(walk, &placeholders[0], num);
|
||||
OUTPUT_FORMATTED;
|
||||
END_COLOR;
|
||||
OUTPUT_FULL_TEXT(buffer);
|
||||
free(buffer);
|
||||
OUTPUT_FULL_TEXT(ctx->buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user