]> git.sur5r.net Git - i3/i3status/commitdiff
Support colored output for CPU temperature on FreeBSD
authorBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 19 Mar 2013 18:08:35 +0000 (19:08 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 20 Mar 2013 10:16:53 +0000 (11:16 +0100)
src/print_cpu_temperature.c

index 8778dad326a7c9d1a7c39ce1268463361b8d71af..aefbcfbeffc8cce409abe5be7a2890fe9e165b1b 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/sysctl.h>
 #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;