i3 - improved tiling WM


Support colored output for CPU temperature on FreeBSD

Patch status: rejected

Patch by Baptiste Daroussin

To apply this patch, use:
curl http://cr.i3wm.org/patch/94/raw.patch | git am

b/src/print_cpu_temperature.c

13
@@ -14,6 +14,7 @@
14
 #include <sys/sysctl.h>
15
 #define TZ_ZEROC 2732
16
 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), abs(((x) - TZ_ZEROC) % 10)
17
+#define TZ_AVG(x) ((x) - TZ_ZEROC) / 10
18
 #endif
19
 
20
 #if defined(__OpenBSD__)
21
@@ -35,9 +36,9 @@ static char *thermal_zone;
22
  *
23
  */
24
 void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int max_threshold) {
25
-        char *outwalk = buffer;
26
 #ifdef THERMAL_ZONE
27
         const char *walk;
28
+        char *outwalk = buffer;
29
         bool colorful_output = false;
30
 
31
         if (path == NULL)
32
@@ -80,7 +81,16 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
33
                         if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0))
34
                                 goto error;
35
 
36
+                        if (TZ_AVG(sysctl_rslt) >= max_threshold) {
37
+                                START_COLOR("color_bad");
38
+                                colorful_output = true;
39
+                        }
40
                         outwalk += sprintf(outwalk, "%d.%d", TZ_KELVTOC(sysctl_rslt));
41
+                        if (colorful_output) {
42
+                                END_COLOR;
43
+                                colorful_output = false;
44
+                        }
45
+
46
 #elif defined(__OpenBSD__)
47
         struct sensordev sensordev;
48
         struct sensor sensor;