wireless: fix colors (+param struct)
This commit is contained in:
parent
9d9a6e8072
commit
4722198875
14
i3status.c
14
i3status.c
@ -693,7 +693,19 @@ int main(int argc, char *argv[]) {
|
|||||||
interface = first_eth_interface(NET_TYPE_WIRELESS);
|
interface = first_eth_interface(NET_TYPE_WIRELESS);
|
||||||
if (interface == NULL)
|
if (interface == NULL)
|
||||||
interface = title;
|
interface = title;
|
||||||
print_wireless_info(json_gen, buffer, interface, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"), cfg_getstr(sec, "format_bitrate"), cfg_getstr(sec, "format_noise"), cfg_getstr(sec, "format_quality"), cfg_getstr(sec, "format_signal"));
|
wireless_info_ctx_t ctx = {
|
||||||
|
.json_gen = json_gen,
|
||||||
|
.buf = buffer,
|
||||||
|
.buflen = sizeof(buffer),
|
||||||
|
.interface = interface,
|
||||||
|
.format_up = cfg_getstr(sec, "format_up"),
|
||||||
|
.format_down = cfg_getstr(sec, "format_down"),
|
||||||
|
.format_bitrate = cfg_getstr(sec, "format_bitrate"),
|
||||||
|
.format_noise = cfg_getstr(sec, "format_noise"),
|
||||||
|
.format_quality = cfg_getstr(sec, "format_quality"),
|
||||||
|
.format_signal = cfg_getstr(sec, "format_signal"),
|
||||||
|
};
|
||||||
|
print_wireless_info(&ctx);
|
||||||
SEC_CLOSE_MAP;
|
SEC_CLOSE_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,9 +61,7 @@ void print_file_contents(file_contents_ctx_t *ctx) {
|
|||||||
|
|
||||||
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
||||||
char *formatted = format_placeholders(walk, &placeholders[0], num);
|
char *formatted = format_placeholders(walk, &placeholders[0], num);
|
||||||
|
|
||||||
OUTPUT_FORMATTED;
|
OUTPUT_FORMATTED;
|
||||||
|
|
||||||
free(formatted);
|
free(formatted);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
@ -498,15 +498,16 @@ error1:
|
|||||||
* | 127.0.0.1 | no IP | IPv4 | ok |
|
* | 127.0.0.1 | no IP | IPv4 | ok |
|
||||||
* | 127.0.0.1 | ::1/128 | IPv4 | ok |
|
* | 127.0.0.1 | ::1/128 | IPv4 | ok |
|
||||||
*/
|
*/
|
||||||
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down, const char *format_bitrate, const char *format_noise, const char *format_quality, const char *format_signal) {
|
void print_wireless_info(wireless_info_ctx_t *ctx) {
|
||||||
const char *walk;
|
const char *walk;
|
||||||
char *outwalk = buffer;
|
char *outwalk = ctx->buf;
|
||||||
wireless_info_t info;
|
wireless_info_t info;
|
||||||
|
#define json_gen ctx->json_gen
|
||||||
|
|
||||||
INSTANCE(interface);
|
INSTANCE(ctx->interface);
|
||||||
|
|
||||||
char *ipv4_address = sstrdup(get_ip_addr(interface, AF_INET));
|
char *ipv4_address = sstrdup(get_ip_addr(ctx->interface, AF_INET));
|
||||||
char *ipv6_address = sstrdup(get_ip_addr(interface, AF_INET6));
|
char *ipv6_address = sstrdup(get_ip_addr(ctx->interface, AF_INET6));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removing '%' and following characters from IPv6 since the interface identifier is redundant,
|
* Removing '%' and following characters from IPv6 since the interface identifier is redundant,
|
||||||
@ -523,12 +524,12 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
if (ipv4_address == NULL) {
|
if (ipv4_address == NULL) {
|
||||||
if (ipv6_address == NULL) {
|
if (ipv6_address == NULL) {
|
||||||
START_COLOR("color_bad");
|
START_COLOR("color_bad");
|
||||||
outwalk += sprintf(outwalk, "%s", format_down);
|
outwalk += sprintf(outwalk, "%s", ctx->format_down);
|
||||||
|
|
||||||
END_COLOR;
|
END_COLOR;
|
||||||
free(ipv4_address);
|
free(ipv4_address);
|
||||||
free(ipv6_address);
|
free(ipv6_address);
|
||||||
OUTPUT_FULL_TEXT(buffer);
|
OUTPUT_FULL_TEXT(ctx->buf);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
prefer_ipv4 = false;
|
prefer_ipv4 = false;
|
||||||
@ -538,11 +539,11 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *ip_address = (prefer_ipv4) ? ipv4_address : ipv6_address;
|
const char *ip_address = (prefer_ipv4) ? ipv4_address : ipv6_address;
|
||||||
if (!get_wireless_info(interface, &info)) {
|
if (!get_wireless_info(ctx->interface, &info)) {
|
||||||
walk = format_down;
|
walk = ctx->format_down;
|
||||||
START_COLOR("color_bad");
|
START_COLOR("color_bad");
|
||||||
} else {
|
} else {
|
||||||
walk = format_up;
|
walk = ctx->format_up;
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY)
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY)
|
||||||
START_COLOR((info.quality < info.quality_average ? "color_degraded" : "color_good"));
|
START_COLOR((info.quality < info.quality_average ? "color_degraded" : "color_good"));
|
||||||
else {
|
else {
|
||||||
@ -564,7 +565,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
|
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
|
||||||
if (info.quality_max)
|
if (info.quality_max)
|
||||||
snprintf(string_quality, STRING_SIZE, format_quality, PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
|
snprintf(string_quality, STRING_SIZE, ctx->format_quality, PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
|
||||||
else
|
else
|
||||||
snprintf(string_quality, STRING_SIZE, "%d", info.quality);
|
snprintf(string_quality, STRING_SIZE, "%d", info.quality);
|
||||||
} else {
|
} else {
|
||||||
@ -573,7 +574,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
|
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
|
||||||
if (info.signal_level_max)
|
if (info.signal_level_max)
|
||||||
snprintf(string_signal, STRING_SIZE, format_signal, PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
|
snprintf(string_signal, STRING_SIZE, ctx->format_signal, PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
|
||||||
else
|
else
|
||||||
snprintf(string_signal, STRING_SIZE, "%d dBm", info.signal_level);
|
snprintf(string_signal, STRING_SIZE, "%d dBm", info.signal_level);
|
||||||
} else {
|
} else {
|
||||||
@ -582,7 +583,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
|
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
|
||||||
if (info.noise_level_max)
|
if (info.noise_level_max)
|
||||||
snprintf(string_noise, STRING_SIZE, format_noise, PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
|
snprintf(string_noise, STRING_SIZE, ctx->format_noise, PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
|
||||||
else
|
else
|
||||||
snprintf(string_noise, STRING_SIZE, "%d dBm", info.noise_level);
|
snprintf(string_noise, STRING_SIZE, "%d dBm", info.noise_level);
|
||||||
} else {
|
} else {
|
||||||
@ -605,7 +606,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
snprintf(string_ip, STRING_SIZE, "%s", ip_address);
|
snprintf(string_ip, STRING_SIZE, "%s", ip_address);
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
print_bitrate(string_bitrate, sizeof(string_bitrate), info.bitrate, format_bitrate);
|
print_bitrate(string_bitrate, sizeof(string_bitrate), info.bitrate, ctx->format_bitrate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
placeholder_t placeholders[] = {
|
placeholder_t placeholders[] = {
|
||||||
@ -618,11 +619,12 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
{.name = "%bitrate", .value = string_bitrate}};
|
{.name = "%bitrate", .value = string_bitrate}};
|
||||||
|
|
||||||
const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
|
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;
|
||||||
|
free(formatted);
|
||||||
|
|
||||||
END_COLOR;
|
END_COLOR;
|
||||||
free(ipv4_address);
|
free(ipv4_address);
|
||||||
free(ipv6_address);
|
free(ipv6_address);
|
||||||
OUTPUT_FULL_TEXT(buffer);
|
OUTPUT_FULL_TEXT(ctx->buf);
|
||||||
free(buffer);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user