X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_load.c;h=5d97a2ca5a08c538a27705aba1718026c6a07689;hb=96923a5bc060c2195cdde25e77235410c69585e7;hp=7ba4ae1a9534428cf3181f592b776130fe0b788f;hpb=5cdbb3045b4524d12f310c4c040a09489fefb57b;p=i3%2Fi3status diff --git a/src/print_load.c b/src/print_load.c index 7ba4ae1..5d97a2c 100644 --- a/src/print_load.c +++ b/src/print_load.c @@ -1,4 +1,5 @@ // vim:ts=4:sw=4:expandtab +#include #include "i3status.h" #include #include @@ -6,46 +7,50 @@ #include #include -void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold) { +void print_load(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const float max_threshold) { char *outwalk = buffer; /* Get load */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__DragonFly__) double loadavg[3]; + const char *selected_format = format; const char *walk; bool colorful_output = false; if (getloadavg(loadavg, 3) == -1) goto error; - for (walk = format; *walk != '\0'; walk++) { + if (loadavg[0] >= max_threshold) { + START_COLOR("color_bad"); + colorful_output = true; + if (format_above_threshold != NULL) + selected_format = format_above_threshold; + } + + for (walk = selected_format; *walk != '\0'; walk++) { if (*walk != '%') { *(outwalk++) = *walk; - continue; - } - if (loadavg[0] >= max_threshold) { - START_COLOR("color_bad"); - colorful_output = true; - } - if (BEGINS_WITH(walk + 1, "1min")) { + } else if (BEGINS_WITH(walk + 1, "1min")) { outwalk += sprintf(outwalk, "%1.2f", loadavg[0]); walk += strlen("1min"); - } - if (BEGINS_WITH(walk + 1, "5min")) { + } else if (BEGINS_WITH(walk + 1, "5min")) { outwalk += sprintf(outwalk, "%1.2f", loadavg[1]); walk += strlen("5min"); - } - if (BEGINS_WITH(walk + 1, "15min")) { + } else if (BEGINS_WITH(walk + 1, "15min")) { outwalk += sprintf(outwalk, "%1.2f", loadavg[2]); walk += strlen("15min"); + + } else { + *(outwalk++) = '%'; } - if (colorful_output) - END_COLOR; } + if (colorful_output) + END_COLOR; + *outwalk = '\0'; OUTPUT_FULL_TEXT(buffer);