ipv6: fix colors (+ param struct)
This commit is contained in:
parent
11d5c9863e
commit
48d817a653
|
@ -675,7 +675,14 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
CASE_SEC("ipv6") {
|
||||
SEC_OPEN_MAP("ipv6");
|
||||
print_ipv6_info(json_gen, buffer, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
|
||||
ipv6_info_ctx_t ctx = {
|
||||
.json_gen = json_gen,
|
||||
.buf = buffer,
|
||||
.buflen = sizeof(buffer),
|
||||
.format_up = cfg_getstr(sec, "format_up"),
|
||||
.format_down = cfg_getstr(sec, "format_down"),
|
||||
};
|
||||
print_ipv6_info(&ctx);
|
||||
SEC_CLOSE_MAP;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,16 @@ typedef enum {
|
|||
} net_type_t;
|
||||
const char *first_eth_interface(const net_type_t type);
|
||||
|
||||
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
|
||||
typedef struct {
|
||||
yajl_gen json_gen;
|
||||
char *buf;
|
||||
const size_t buflen;
|
||||
const char *format_up;
|
||||
const char *format_down;
|
||||
} ipv6_info_ctx_t;
|
||||
|
||||
void print_ipv6_info(ipv6_info_ctx_t *ctx);
|
||||
|
||||
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_below_threshold, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold);
|
||||
void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, const char *format_percentage, bool hide_seconds);
|
||||
void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *format, const char *tz, const char *locale, const char *format_time, bool hide_if_equals_localtime, time_t t);
|
||||
|
@ -257,7 +266,7 @@ bool pulse_initialize(void);
|
|||
typedef struct {
|
||||
yajl_gen json_gen;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
const size_t buflen;
|
||||
const char *title;
|
||||
const char *path;
|
||||
const char *format;
|
||||
|
|
|
@ -117,15 +117,16 @@ static char *get_ipv6_addr(void) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down) {
|
||||
void print_ipv6_info(ipv6_info_ctx_t *ctx) {
|
||||
char *addr_string = get_ipv6_addr();
|
||||
char *outwalk = buffer;
|
||||
char *outwalk = ctx->buf;
|
||||
|
||||
#define json_gen ctx->json_gen
|
||||
if (addr_string == NULL) {
|
||||
START_COLOR("color_bad");
|
||||
outwalk += sprintf(outwalk, "%s", format_down);
|
||||
outwalk += sprintf(outwalk, "%s", ctx->format_down);
|
||||
END_COLOR;
|
||||
OUTPUT_FULL_TEXT(buffer);
|
||||
OUTPUT_FULL_TEXT(ctx->buf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,8 +136,10 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
|
|||
{.name = "%ip", .value = addr_string}};
|
||||
|
||||
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
||||
buffer = format_placeholders(format_up, &placeholders[0], num);
|
||||
char *formatted = format_placeholders(ctx->format_up, &placeholders[0], num);
|
||||
OUTPUT_FORMATTED;
|
||||
free(formatted);
|
||||
|
||||
END_COLOR;
|
||||
OUTPUT_FULL_TEXT(buffer);
|
||||
free(buffer);
|
||||
OUTPUT_FULL_TEXT(ctx->buf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue