+ if (BEGINS_WITH(walk + 1, "status")) {
+ const char *statusstr;
+ switch (batt_info.status) {
+ case CS_CHARGING:
+ statusstr = status_chr;
+ break;
+ case CS_DISCHARGING:
+ statusstr = status_bat;
+ break;
+ case CS_FULL:
+ statusstr = status_full;
+ break;
+ default:
+ statusstr = status_unk;
+ }
+
+ outwalk += sprintf(outwalk, "%s", statusstr);
+ walk += strlen("status");
+ } else if (BEGINS_WITH(walk + 1, "percentage")) {
+ if (integer_battery_capacity) {
+ outwalk += sprintf(outwalk, "%.00f%s", batt_info.percentage_remaining, pct_mark);
+ } else {
+ outwalk += sprintf(outwalk, "%.02f%s", batt_info.percentage_remaining, pct_mark);
+ }
+ walk += strlen("percentage");
+ } else if (BEGINS_WITH(walk + 1, "remaining")) {
+ if (batt_info.seconds_remaining >= 0) {
+ int seconds, hours, minutes;
+
+ hours = batt_info.seconds_remaining / 3600;
+ seconds = batt_info.seconds_remaining - (hours * 3600);
+ minutes = seconds / 60;
+ seconds -= (minutes * 60);
+
+ if (hide_seconds)
+ outwalk += sprintf(outwalk, "%02d:%02d",
+ max(hours, 0), max(minutes, 0));
+ else
+ outwalk += sprintf(outwalk, "%02d:%02d:%02d",
+ max(hours, 0), max(minutes, 0), max(seconds, 0));
+ }
+ walk += strlen("remaining");
+ EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+ } else if (BEGINS_WITH(walk + 1, "emptytime")) {
+ if (batt_info.seconds_remaining >= 0) {
+ time_t empty_time = time(NULL) + batt_info.seconds_remaining;
+ set_timezone(NULL); /* Use local time. */
+ struct tm *empty_tm = localtime(&empty_time);
+
+ if (hide_seconds)
+ outwalk += sprintf(outwalk, "%02d:%02d",
+ max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0));
+ else
+ outwalk += sprintf(outwalk, "%02d:%02d:%02d",
+ max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
+ }
+ walk += strlen("emptytime");
+ EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+ } else if (BEGINS_WITH(walk + 1, "consumption")) {
+ if (batt_info.present_rate >= 0)
+ outwalk += sprintf(outwalk, "%1.2fW", batt_info.present_rate / 1e6);
+
+ walk += strlen("consumption");
+ EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+ }
+ }
+
+ if (colorful_output)
+ END_COLOR;
+
+ OUTPUT_FULL_TEXT(buffer);