]> git.sur5r.net Git - i3/i3status/blob - src/print_battery_info.c
Merge pull request #201 from jasperla/openbsd_bat_info
[i3/i3status] / src / print_battery_info.c
1 // vim:ts=4:sw=4:expandtab
2 #include <ctype.h>
3 #include <time.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <yajl/yajl_gen.h>
8 #include <yajl/yajl_version.h>
9
10 #include "i3status.h"
11
12 #if defined(LINUX)
13 #include <errno.h>
14 #include <glob.h>
15 #include <sys/types.h>
16 #endif
17
18 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
19 #include <sys/types.h>
20 #include <sys/sysctl.h>
21 #include <dev/acpica/acpiio.h>
22 #endif
23
24 #if defined(__OpenBSD__)
25 #include <sys/types.h>
26 #include <sys/ioctl.h>
27 #include <sys/fcntl.h>
28 #include <machine/apmvar.h>
29 #endif
30
31 #if defined(__NetBSD__)
32 #include <fcntl.h>
33 #include <prop/proplib.h>
34 #include <sys/envsys.h>
35 #endif
36
37 typedef enum {
38     CS_UNKNOWN,
39     CS_DISCHARGING,
40     CS_CHARGING,
41     CS_FULL,
42 } charging_status_t;
43
44 /* A description of the state of one or more batteries. */
45 struct battery_info {
46     /* measured properties */
47     int full_design;  /* in uAh */
48     int full_last;    /* in uAh */
49     int remaining;    /* in uAh */
50     int present_rate; /* in uA, always non-negative */
51
52     /* derived properties */
53     int seconds_remaining;
54     float percentage_remaining;
55     charging_status_t status;
56 };
57
58 #if defined(LINUX) || defined(__NetBSD__)
59 /*
60  * Add batt_info data to acc.
61  */
62 static void add_battery_info(struct battery_info *acc, const struct battery_info *batt_info) {
63     if (acc->remaining < 0) {
64         /* initialize accumulator so we can add to it */
65         acc->full_design = 0;
66         acc->full_last = 0;
67         acc->remaining = 0;
68         acc->present_rate = 0;
69     }
70
71     acc->full_design += batt_info->full_design;
72     acc->full_last += batt_info->full_last;
73     acc->remaining += batt_info->remaining;
74
75     /* make present_rate negative for discharging and positive for charging */
76     int present_rate = (acc->status == CS_DISCHARGING ? -1 : 1) * acc->present_rate;
77     present_rate += (batt_info->status == CS_DISCHARGING ? -1 : 1) * batt_info->present_rate;
78
79     /* merge status */
80     switch (acc->status) {
81         case CS_UNKNOWN:
82             acc->status = batt_info->status;
83             break;
84
85         case CS_DISCHARGING:
86             if (present_rate > 0)
87                 acc->status = CS_CHARGING;
88             /* else if batt_info is DISCHARGING: no conflict
89              * else if batt_info is CHARGING: present_rate should indicate that
90              * else if batt_info is FULL: but something else is discharging */
91             break;
92
93         case CS_CHARGING:
94             if (present_rate < 0)
95                 acc->status = CS_DISCHARGING;
96             /* else if batt_info is DISCHARGING: present_rate should indicate that
97              * else if batt_info is CHARGING: no conflict
98              * else if batt_info is FULL: but something else is charging */
99             break;
100
101         case CS_FULL:
102             if (batt_info->status != CS_UNKNOWN)
103                 acc->status = batt_info->status;
104             /* else: retain FULL, since it is more specific than UNKNOWN */
105             break;
106     }
107
108     acc->present_rate = abs(present_rate);
109 }
110 #endif
111
112 static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen, char *buffer, int number, const char *path, const char *format_down) {
113     char *outwalk = buffer;
114
115 #if defined(LINUX)
116     char buf[1024];
117     const char *walk, *last;
118     bool watt_as_unit = false;
119     int voltage = -1;
120     char batpath[512];
121     sprintf(batpath, path, number);
122     INSTANCE(batpath);
123
124     if (!slurp(batpath, buf, sizeof(buf))) {
125         OUTPUT_FULL_TEXT(format_down);
126         return false;
127     }
128
129     for (walk = buf, last = buf; (walk - buf) < 1024; walk++) {
130         if (*walk == '\n') {
131             last = walk + 1;
132             continue;
133         }
134
135         if (*walk != '=')
136             continue;
137
138         if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW=")) {
139             watt_as_unit = true;
140             batt_info->remaining = atoi(walk + 1);
141         } else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW=")) {
142             watt_as_unit = false;
143             batt_info->remaining = atoi(walk + 1);
144         } else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW="))
145             batt_info->present_rate = abs(atoi(walk + 1));
146         else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW="))
147             voltage = abs(atoi(walk + 1));
148         /* on some systems POWER_SUPPLY_POWER_NOW does not exist, but actually
149          * it is the same as POWER_SUPPLY_CURRENT_NOW but with μWh as
150          * unit instead of μAh. We will calculate it as we need it
151          * later. */
152         else if (BEGINS_WITH(last, "POWER_SUPPLY_POWER_NOW="))
153             batt_info->present_rate = abs(atoi(walk + 1));
154         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Charging"))
155             batt_info->status = CS_CHARGING;
156         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Full"))
157             batt_info->status = CS_FULL;
158         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Discharging"))
159             batt_info->status = CS_DISCHARGING;
160         else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS="))
161             batt_info->status = CS_UNKNOWN;
162         else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN=") ||
163                  BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN="))
164             batt_info->full_design = atoi(walk + 1);
165         else if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL=") ||
166                  BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL="))
167             batt_info->full_last = atoi(walk + 1);
168     }
169
170     /* the difference between POWER_SUPPLY_ENERGY_NOW and
171      * POWER_SUPPLY_CHARGE_NOW is the unit of measurement. The energy is
172      * given in mWh, the charge in mAh. So calculate every value given in
173      * ampere to watt */
174     if (!watt_as_unit && voltage != -1) {
175         batt_info->present_rate = (((float)voltage / 1000.0) * ((float)batt_info->present_rate / 1000.0));
176         batt_info->remaining = (((float)voltage / 1000.0) * ((float)batt_info->remaining / 1000.0));
177         batt_info->full_design = (((float)voltage / 1000.0) * ((float)batt_info->full_design / 1000.0));
178         batt_info->full_last = (((float)voltage / 1000.0) * ((float)batt_info->full_last / 1000.0));
179     }
180 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
181     int state;
182     int sysctl_rslt;
183     size_t sysctl_size = sizeof(sysctl_rslt);
184
185     if (sysctlbyname(BATT_LIFE, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
186         OUTPUT_FULL_TEXT(format_down);
187         return false;
188     }
189
190     batt_info->percentage_remaining = sysctl_rslt;
191     if (sysctlbyname(BATT_TIME, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
192         OUTPUT_FULL_TEXT(format_down);
193         return false;
194     }
195
196     batt_info->seconds_remaining = sysctl_rslt * 60;
197     if (sysctlbyname(BATT_STATE, &sysctl_rslt, &sysctl_size, NULL, 0) != 0) {
198         OUTPUT_FULL_TEXT(format_down);
199         return false;
200     }
201
202     state = sysctl_rslt;
203     if (state == 0 && batt_info->percentage_remaining == 100)
204         batt_info->status = CS_FULL;
205     else if ((state & ACPI_BATT_STAT_CHARGING) && batt_info->percentage_remaining < 100)
206         batt_info->status = CS_CHARGING;
207     else
208         batt_info->status = CS_DISCHARGING;
209 #elif defined(__OpenBSD__)
210     /*
211          * We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and
212          * the generic interface on macppc/sparc64/zaurus, instead of using sysctl(3) and
213          * probing acpi(4) devices.
214          */
215     struct apm_power_info apm_info;
216     int apm_fd;
217
218     apm_fd = open("/dev/apm", O_RDONLY);
219     if (apm_fd < 0) {
220         OUTPUT_FULL_TEXT("can't open /dev/apm");
221         return false;
222     }
223     if (ioctl(apm_fd, APM_IOC_GETPOWER, &apm_info) < 0)
224         OUTPUT_FULL_TEXT("can't read power info");
225
226     close(apm_fd);
227
228     /* Don't bother to go further if there's no battery present. */
229     if ((apm_info.battery_state == APM_BATTERY_ABSENT) ||
230         (apm_info.battery_state == APM_BATT_UNKNOWN)) {
231         OUTPUT_FULL_TEXT(format_down);
232         return false;
233     }
234
235     switch (apm_info.ac_state) {
236         case APM_AC_OFF:
237             batt_info->status = CS_DISCHARGING;
238             break;
239         case APM_AC_ON:
240             batt_info->status = CS_CHARGING;
241             break;
242         default:
243             /* If we don't know what's going on, just assume we're discharging. */
244             batt_info->status = CS_DISCHARGING;
245             break;
246     }
247
248     batt_info->percentage_remaining = apm_info.battery_life;
249
250     /* Can't give a meaningful value for remaining minutes if we're charging. */
251     if (batt_info->status != CS_CHARGING) {
252         batt_info->seconds_remaining = apm_info.minutes_left * 60;
253     }
254 #elif defined(__NetBSD__)
255     /*
256      * Using envsys(4) via sysmon(4).
257      */
258     int fd, rval;
259     bool is_found = false;
260     char sensor_desc[16];
261
262     prop_dictionary_t dict;
263     prop_array_t array;
264     prop_object_iterator_t iter;
265     prop_object_iterator_t iter2;
266     prop_object_t obj, obj2, obj3, obj4, obj5;
267
268     if (number >= 0)
269         (void)snprintf(sensor_desc, sizeof(sensor_desc), "acpibat%d", number);
270
271     fd = open("/dev/sysmon", O_RDONLY);
272     if (fd < 0) {
273         OUTPUT_FULL_TEXT("can't open /dev/sysmon");
274         return false;
275     }
276
277     rval = prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict);
278     if (rval == -1) {
279         close(fd);
280         return false;
281     }
282
283     if (prop_dictionary_count(dict) == 0) {
284         prop_object_release(dict);
285         close(fd);
286         return false;
287     }
288
289     iter = prop_dictionary_iterator(dict);
290     if (iter == NULL) {
291         prop_object_release(dict);
292         close(fd);
293     }
294
295     /* iterate over the dictionary returned by the kernel */
296     while ((obj = prop_object_iterator_next(iter)) != NULL) {
297         /* skip this dict if it's not what we're looking for */
298         if (number < 0) {
299             /* we want all batteries */
300             if (!BEGINS_WITH(prop_dictionary_keysym_cstring_nocopy(obj),
301                              "acpibat"))
302                 continue;
303         } else {
304             /* we want a specific battery */
305             if (strcmp(sensor_desc,
306                        prop_dictionary_keysym_cstring_nocopy(obj)) != 0)
307                 continue;
308         }
309
310         is_found = true;
311
312         array = prop_dictionary_get_keysym(dict, obj);
313         if (prop_object_type(array) != PROP_TYPE_ARRAY) {
314             prop_object_iterator_release(iter);
315             prop_object_release(dict);
316             close(fd);
317             return false;
318         }
319
320         iter2 = prop_array_iterator(array);
321         if (!iter2) {
322             prop_object_iterator_release(iter);
323             prop_object_release(dict);
324             close(fd);
325             return false;
326         }
327
328         struct battery_info batt_buf = {
329             .full_design = 0,
330             .full_last = 0,
331             .remaining = 0,
332             .present_rate = 0,
333             .status = CS_UNKNOWN,
334         };
335         int voltage = -1;
336         bool watt_as_unit = false;
337
338         /* iterate over array of dicts specific to target battery */
339         while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
340             obj3 = prop_dictionary_get(obj2, "description");
341
342             if (obj3 == NULL)
343                 continue;
344
345             if (strcmp("charging", prop_string_cstring_nocopy(obj3)) == 0) {
346                 obj3 = prop_dictionary_get(obj2, "cur-value");
347
348                 if (prop_number_integer_value(obj3))
349                     batt_buf.status = CS_CHARGING;
350                 else
351                     batt_buf.status = CS_DISCHARGING;
352             } else if (strcmp("charge", prop_string_cstring_nocopy(obj3)) == 0) {
353                 obj3 = prop_dictionary_get(obj2, "cur-value");
354                 obj4 = prop_dictionary_get(obj2, "max-value");
355                 obj5 = prop_dictionary_get(obj2, "type");
356
357                 batt_buf.remaining = prop_number_integer_value(obj3);
358                 batt_buf.full_design = prop_number_integer_value(obj4);
359
360                 if (strcmp("Ampere hour", prop_string_cstring_nocopy(obj5)) == 0)
361                     watt_as_unit = false;
362                 else
363                     watt_as_unit = true;
364             } else if (strcmp("discharge rate", prop_string_cstring_nocopy(obj3)) == 0) {
365                 obj3 = prop_dictionary_get(obj2, "cur-value");
366                 batt_buf.present_rate = prop_number_integer_value(obj3);
367             } else if (strcmp("charge rate", prop_string_cstring_nocopy(obj3)) == 0) {
368                 obj3 = prop_dictionary_get(obj2, "cur-value");
369                 batt_info->present_rate = prop_number_integer_value(obj3);
370             } else if (strcmp("last full cap", prop_string_cstring_nocopy(obj3)) == 0) {
371                 obj3 = prop_dictionary_get(obj2, "cur-value");
372                 batt_buf.full_last = prop_number_integer_value(obj3);
373             } else if (strcmp("voltage", prop_string_cstring_nocopy(obj3)) == 0) {
374                 obj3 = prop_dictionary_get(obj2, "cur-value");
375                 voltage = prop_number_integer_value(obj3);
376             }
377         }
378         prop_object_iterator_release(iter2);
379
380         if (!watt_as_unit && voltage != -1) {
381             batt_buf.present_rate = (((float)voltage / 1000.0) * ((float)batt_buf.present_rate / 1000.0));
382             batt_buf.remaining = (((float)voltage / 1000.0) * ((float)batt_buf.remaining / 1000.0));
383             batt_buf.full_design = (((float)voltage / 1000.0) * ((float)batt_buf.full_design / 1000.0));
384             batt_buf.full_last = (((float)voltage / 1000.0) * ((float)batt_buf.full_last / 1000.0));
385         }
386
387         if (batt_buf.remaining == batt_buf.full_design)
388             batt_buf.status = CS_FULL;
389
390         add_battery_info(batt_info, &batt_buf);
391     }
392
393     prop_object_iterator_release(iter);
394     prop_object_release(dict);
395     close(fd);
396
397     if (!is_found) {
398         OUTPUT_FULL_TEXT(format_down);
399         return false;
400     }
401
402     batt_info->present_rate = abs(batt_info->present_rate);
403 #endif
404
405     return true;
406 }
407
408 /*
409  * Populate batt_info with aggregate information about all batteries.
410  * Returns false on error, and an error message will have been written.
411  */
412 static bool slurp_all_batteries(struct battery_info *batt_info, yajl_gen json_gen, char *buffer, const char *path, const char *format_down) {
413 #if defined(LINUX)
414     char *outwalk = buffer;
415     bool is_found = false;
416
417     char *placeholder;
418     char *globpath = sstrdup(path);
419     if ((placeholder = strstr(path, "%d")) != NULL) {
420         char *globplaceholder = globpath + (placeholder - path);
421         *globplaceholder = '*';
422         strcpy(globplaceholder + 1, placeholder + 2);
423     }
424
425     if (!strcmp(globpath, path)) {
426         OUTPUT_FULL_TEXT("no '%d' in battery path");
427         return false;
428     }
429
430     glob_t globbuf;
431     if (glob(globpath, 0, NULL, &globbuf) == 0) {
432         for (size_t i = 0; i < globbuf.gl_pathc; i++) {
433             /* Probe to see if there is such a battery. */
434             struct battery_info batt_buf = {
435                 .full_design = 0,
436                 .full_last = 0,
437                 .remaining = 0,
438                 .present_rate = 0,
439                 .status = CS_UNKNOWN,
440             };
441             if (!slurp_battery_info(&batt_buf, json_gen, buffer, i, globbuf.gl_pathv[i], format_down))
442                 return false;
443
444             is_found = true;
445             add_battery_info(batt_info, &batt_buf);
446         }
447     }
448     globfree(&globbuf);
449     free(globpath);
450
451     if (!is_found) {
452         OUTPUT_FULL_TEXT(format_down);
453         return false;
454     }
455
456     batt_info->present_rate = abs(batt_info->present_rate);
457 #else
458     /* FreeBSD and OpenBSD only report aggregates. NetBSD always
459      * iterates through all batteries, so it's more efficient to
460      * aggregate in slurp_battery_info. */
461     return slurp_battery_info(batt_info, json_gen, buffer, -1, path, format_down);
462 #endif
463
464     return true;
465 }
466
467 void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_unk, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) {
468     const char *walk;
469     char *outwalk = buffer;
470     struct battery_info batt_info = {
471         .full_design = -1,
472         .full_last = -1,
473         .remaining = -1,
474         .present_rate = -1,
475         .seconds_remaining = -1,
476         .percentage_remaining = -1,
477         .status = CS_UNKNOWN,
478     };
479     bool colorful_output = false;
480
481 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)
482     /* These OSes report battery stats in whole percent. */
483     integer_battery_capacity = true;
484 #endif
485 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__OpenBSD__)
486     /* These OSes report battery time in minutes. */
487     hide_seconds = true;
488 #endif
489
490     if (number < 0) {
491         if (!slurp_all_batteries(&batt_info, json_gen, buffer, path, format_down))
492             return;
493     } else {
494         if (!slurp_battery_info(&batt_info, json_gen, buffer, number, path, format_down))
495             return;
496     }
497
498     int full = (last_full_capacity ? batt_info.full_last : batt_info.full_design);
499     if (full < 0 && batt_info.percentage_remaining < 0) {
500         /* We have no physical measurements and no estimates. Nothing
501          * much we can report, then. */
502         OUTPUT_FULL_TEXT(format_down);
503         return;
504     }
505
506     if (batt_info.percentage_remaining < 0) {
507         batt_info.percentage_remaining = (((float)batt_info.remaining / (float)full) * 100);
508         /* Some batteries report POWER_SUPPLY_CHARGE_NOW=<full_design> when fully
509          * charged, even though that’s plainly wrong. For people who chose to see
510          * the percentage calculated based on the last full capacity, we clamp the
511          * value to 100%, as that makes more sense.
512          * See http://bugs.debian.org/785398 */
513         if (last_full_capacity && batt_info.percentage_remaining > 100) {
514             batt_info.percentage_remaining = 100;
515         }
516     }
517
518     if (batt_info.seconds_remaining < 0 && batt_info.present_rate > 0 && batt_info.status != CS_FULL) {
519         if (batt_info.status == CS_CHARGING)
520             batt_info.seconds_remaining = 3600.0 * (full - batt_info.remaining) / batt_info.present_rate;
521         else if (batt_info.status == CS_DISCHARGING)
522             batt_info.seconds_remaining = 3600.0 * batt_info.remaining / batt_info.present_rate;
523         else
524             batt_info.seconds_remaining = 0;
525     }
526
527     if (batt_info.status == CS_DISCHARGING && low_threshold > 0) {
528         if (batt_info.percentage_remaining >= 0 && strcasecmp(threshold_type, "percentage") == 0 && batt_info.percentage_remaining < low_threshold) {
529             START_COLOR("color_bad");
530             colorful_output = true;
531         } else if (batt_info.seconds_remaining >= 0 && strcasecmp(threshold_type, "time") == 0 && batt_info.seconds_remaining < 60 * low_threshold) {
532             START_COLOR("color_bad");
533             colorful_output = true;
534         }
535     }
536
537 #define EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT()                   \
538     do {                                                       \
539         if (outwalk == prevoutwalk) {                          \
540             if (outwalk > buffer && isspace((int)outwalk[-1])) \
541                 outwalk--;                                     \
542             else if (isspace((int)*(walk + 1)))                \
543                 walk++;                                        \
544         }                                                      \
545     } while (0)
546
547     for (walk = format; *walk != '\0'; walk++) {
548         char *prevoutwalk = outwalk;
549
550         if (*walk != '%') {
551             *(outwalk++) = *walk;
552             continue;
553         }
554
555         if (BEGINS_WITH(walk + 1, "status")) {
556             const char *statusstr;
557             switch (batt_info.status) {
558                 case CS_CHARGING:
559                     statusstr = status_chr;
560                     break;
561                 case CS_DISCHARGING:
562                     statusstr = status_bat;
563                     break;
564                 case CS_FULL:
565                     statusstr = status_full;
566                     break;
567                 default:
568                     statusstr = status_unk;
569             }
570
571             outwalk += sprintf(outwalk, "%s", statusstr);
572             walk += strlen("status");
573         } else if (BEGINS_WITH(walk + 1, "percentage")) {
574             if (integer_battery_capacity) {
575                 outwalk += sprintf(outwalk, "%.00f%s", batt_info.percentage_remaining, pct_mark);
576             } else {
577                 outwalk += sprintf(outwalk, "%.02f%s", batt_info.percentage_remaining, pct_mark);
578             }
579             walk += strlen("percentage");
580         } else if (BEGINS_WITH(walk + 1, "remaining")) {
581             if (batt_info.seconds_remaining >= 0) {
582                 int seconds, hours, minutes;
583
584                 hours = batt_info.seconds_remaining / 3600;
585                 seconds = batt_info.seconds_remaining - (hours * 3600);
586                 minutes = seconds / 60;
587                 seconds -= (minutes * 60);
588
589                 if (hide_seconds)
590                     outwalk += sprintf(outwalk, "%02d:%02d",
591                                        max(hours, 0), max(minutes, 0));
592                 else
593                     outwalk += sprintf(outwalk, "%02d:%02d:%02d",
594                                        max(hours, 0), max(minutes, 0), max(seconds, 0));
595             }
596             walk += strlen("remaining");
597             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
598         } else if (BEGINS_WITH(walk + 1, "emptytime")) {
599             if (batt_info.seconds_remaining >= 0) {
600                 time_t empty_time = time(NULL) + batt_info.seconds_remaining;
601                 struct tm *empty_tm = localtime(&empty_time);
602
603                 if (hide_seconds)
604                     outwalk += sprintf(outwalk, "%02d:%02d",
605                                        max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0));
606                 else
607                     outwalk += sprintf(outwalk, "%02d:%02d:%02d",
608                                        max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
609             }
610             walk += strlen("emptytime");
611             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
612         } else if (BEGINS_WITH(walk + 1, "consumption")) {
613             if (batt_info.present_rate >= 0)
614                 outwalk += sprintf(outwalk, "%1.2fW", batt_info.present_rate / 1e6);
615
616             walk += strlen("consumption");
617             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
618         }
619     }
620
621     if (colorful_output)
622         END_COLOR;
623
624     OUTPUT_FULL_TEXT(buffer);
625 }