From 7c02c10b728a099a6d328df9cfd9a3f1c4b88702 Mon Sep 17 00:00:00 2001 From: Simon Elsbrock Date: Tue, 22 May 2012 23:14:59 +0200 Subject: colorize battery output if remaining time below threshold --- src/print_battery_info.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3