diff options
author | Simon Elsbrock <simon@iodev.org> | 2012-09-05 18:39:48 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-09-05 23:28:31 +0200 |
commit | 59d52ad78759ef7b194f9ca50f9d03d721d14398 (patch) | |
tree | 19e1b013164b6e8ca4116863562bedc94b5c6a49 /src/print_battery_info.c | |
parent | 1c4677a644dfc504d64a58f1b6bb81302eabac9b (diff) |
print_battery.c: do END_COLOR only if START_COLOR was used
Diffstat (limited to 'src/print_battery_info.c')
-rw-r--r-- | src/print_battery_info.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 4fbf411..e439bc6 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -42,6 +42,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char const char *walk, *last; char *outwalk = buffer; bool watt_as_unit; + bool colorful_output; int full_design = -1, remaining = -1, present_rate = -1, @@ -151,9 +152,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0 && percentage_remaining < low_threshold) { START_COLOR("color_bad"); + colorful_output = true; } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0 && seconds_remaining < 60 * low_threshold) { START_COLOR("color_bad"); + colorful_output = true; } } @@ -170,7 +173,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW", ((float)present_rate / 1000.0 / 1000.0)); - END_COLOR; + if (colorful_output) + END_COLOR; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int state; |