diff options
author | Simon Elsbrock <simon@iodev.org> | 2012-05-22 23:14:59 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-05-25 09:53:49 +0200 |
commit | 7c02c10b728a099a6d328df9cfd9a3f1c4b88702 (patch) | |
tree | f5203932e086b125987a8889c774bbd63854f012 /src/print_battery_info.c | |
parent | 7a77472a810b0a955f2755dd028216965b56be31 (diff) |
colorize battery output if remaining time below threshold
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r-- | src/print_battery_info.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 1c000e1..cc7c5fe 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -26,7 +26,7 @@ * worn off your battery is. * */ -void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, bool last_full_capacity) { +void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity) { time_t empty_time; struct tm *empty_tm; char buf[1024]; @@ -120,6 +120,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char minutes = seconds / 60; seconds -= (minutes * 60); + if (threshold > 0 && seconds_remaining < 60 * threshold) + START_COLOR("color_bad"); + (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", max(hours, 0), max(minutes, 0), max(seconds, 0)); @@ -129,6 +132,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d", max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0)); + + END_COLOR; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int state; |