#define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
+#define CFG_COLOR_OPTS(good, degraded, bad) \
+ CFG_STR("color_good", good, CFGF_NONE), \
+ CFG_STR("color_degraded", degraded, CFGF_NONE), \
+ CFG_STR("color_bad", bad, CFGF_NONE)
+
+#define CFG_CUSTOM_COLOR_OPTS CFG_COLOR_OPTS(NULL, NULL, NULL)
+
/* socket file descriptor for general purposes */
int general_socket;
-cfg_t *cfg, *cfg_general;
+cfg_t *cfg, *cfg_general, *cfg_section;
/*
* Exit upon SIGPIPE because when we have nowhere to write to, gathering
cfg_opt_t general_opts[] = {
CFG_STR("output_format", "auto", CFGF_NONE),
CFG_BOOL("colors", 1, CFGF_NONE),
- CFG_STR("color_good", "#00FF00", CFGF_NONE),
- CFG_STR("color_degraded", "#FFFF00", CFGF_NONE),
- CFG_STR("color_bad", "#FF0000", CFGF_NONE),
CFG_STR("color_separator", "#333333", CFGF_NONE),
CFG_INT("interval", 1, CFGF_NONE),
+ CFG_COLOR_OPTS("#00FF00", "#FFFF00", "#FF0000"),
CFG_END()
};
cfg_opt_t run_watch_opts[] = {
CFG_STR("pidfile", NULL, CFGF_NONE),
CFG_STR("format", "%title: %status", CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
cfg_opt_t wireless_opts[] = {
CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
CFG_STR("format_down", "W: down", CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
cfg_opt_t ethernet_opts[] = {
CFG_STR("format_up", "E: %ip (%speed)", CFGF_NONE),
CFG_STR("format_down", "E: down", CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
cfg_opt_t ipv6_opts[] = {
CFG_STR("format_up", "%ip", CFGF_NONE),
CFG_STR("format_down", "no IPv6", CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
CFG_STR("device", "default", CFGF_NONE),
CFG_STR("mixer", "Master", CFGF_NONE),
CFG_INT("mixer_idx", 0, CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
CFG_SEC("ddate", ddate_opts, CFGF_NONE),
CFG_SEC("load", load_opts, CFGF_NONE),
CFG_SEC("cpu_usage", usage_opts, CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
CFG_END()
};
#define CASE_SEC(name) \
if (BEGINS_WITH(current, name)) \
- with(cfg_t *, sec, cfg_getsec(cfg, name)) \
+ with(cfg_t *, sec, cfg_section = cfg_getsec(cfg, name)) \
if (sec != NULL)
#define CASE_SEC_TITLE(name) \
if (BEGINS_WITH(current, name)) \
with(const char *, title, current + strlen(name) + 1) \
- with(cfg_t *, sec, cfg_gettsec(cfg, name, title)) \
+ with(cfg_t *, sec, cfg_section = cfg_gettsec(cfg, name, title)) \
if (sec != NULL)
/* Macro which any plugin can use to output the full_text part (when the output
#define START_COLOR(colorstr) \
do { \
if (cfg_getbool(cfg_general, "colors")) { \
- const char *_val = cfg_getstr(cfg_general, colorstr); \
+ const char *_val = NULL; \
+ if (cfg_section) \
+ _val = cfg_getstr(cfg_section, colorstr); \
+ if (!_val) \
+ _val = cfg_getstr(cfg_general, colorstr); \
if (output_format == O_I3BAR) { \
yajl_gen_string(json_gen, (const unsigned char *)"color", strlen("color")); \
yajl_gen_string(json_gen, (const unsigned char *)_val, strlen(_val)); \
/* socket file descriptor for general purposes */
extern int general_socket;
-extern cfg_t *cfg, *cfg_general;
+extern cfg_t *cfg, *cfg_general, *cfg_section;
#endif