Support colored output for CPU temperature on FreeBSD
Patch status: merged
Patch by Baptiste Daroussin
To apply this patch, use:
curl http://cr.i3wm.org/patch/96/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 |
@@ -80,7 +81,16 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const |
| 22 |
if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) |
| 23 |
goto error; |
| 24 |
|
| 25 |
+ if (TZ_AVG(sysctl_rslt) >= max_threshold) {
|
| 26 |
+ START_COLOR("color_bad");
|
| 27 |
+ colorful_output = true; |
| 28 |
+ } |
| 29 |
outwalk += sprintf(outwalk, "%d.%d", TZ_KELVTOC(sysctl_rslt)); |
| 30 |
+ if (colorful_output) {
|
| 31 |
+ END_COLOR; |
| 32 |
+ colorful_output = false; |
| 33 |
+ } |
| 34 |
+ |
| 35 |
#elif defined(__OpenBSD__) |
| 36 |
struct sensordev sensordev; |
| 37 |
struct sensor sensor; |