From: Baptiste Daroussin Date: Tue, 19 Mar 2013 18:08:35 +0000 (+0100) Subject: Support colored output for CPU temperature on FreeBSD X-Git-Tag: 2.8~24 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=13ebebeb7ae17398bafe2bc0b75149b607f4f800;p=i3%2Fi3status Support colored output for CPU temperature on FreeBSD --- diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 8778dad..aefbcfb 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -14,6 +14,7 @@ #include #define TZ_ZEROC 2732 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), abs(((x) - TZ_ZEROC) % 10) +#define TZ_AVG(x) ((x) - TZ_ZEROC) / 10 #endif #if defined(__OpenBSD__) @@ -80,7 +81,16 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) goto error; + if (TZ_AVG(sysctl_rslt) >= max_threshold) { + START_COLOR("color_bad"); + colorful_output = true; + } outwalk += sprintf(outwalk, "%d.%d", TZ_KELVTOC(sysctl_rslt)); + if (colorful_output) { + END_COLOR; + colorful_output = false; + } + #elif defined(__OpenBSD__) struct sensordev sensordev; struct sensor sensor;