diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2013-03-19 19:08:35 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-20 11:16:53 +0100 |
commit | 13ebebeb7ae17398bafe2bc0b75149b607f4f800 (patch) | |
tree | 204ebf84ba5aec0627a9f4c74217fa6d2e2f0f05 | |
parent | 1ec54a297179318237f6b7498d3fa69f0dd4a225 (diff) |
Support colored output for CPU temperature on FreeBSD
-rw-r--r-- | src/print_cpu_temperature.c | 10 |
1 files changed, 10 insertions, 0 deletions
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 <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; |