2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintBattery(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2021-03-01 19:53:20 +01:00
|
|
|
char model[256];
|
|
|
|
|
ffGetFileContent("/sys/class/power_supply/BAT0/model_name", model, sizeof(model));
|
|
|
|
|
|
|
|
|
|
char technology[32];
|
|
|
|
|
ffGetFileContent("/sys/class/power_supply/BAT0/technology", technology, sizeof(technology));
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-03-01 19:53:20 +01:00
|
|
|
char capacity[32];
|
|
|
|
|
ffGetFileContent("/sys/class/power_supply/BAT0/capacity", capacity, sizeof(capacity));
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-03-01 19:53:20 +01:00
|
|
|
char status[32];
|
|
|
|
|
ffGetFileContent("/sys/class/power_supply/BAT0/status", status, sizeof(status));
|
|
|
|
|
|
|
|
|
|
if(model[0] == '\0' && capacity[0] == '\0' && status[0] == '\0')
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2021-03-01 19:53:20 +01:00
|
|
|
ffPrintError(instance, "Battery", "No file in /sys/class/power_supply/BAT0/ could be read");
|
2021-02-18 22:25:36 +01:00
|
|
|
return;
|
2021-02-19 16:23:41 +01:00
|
|
|
}
|
2021-03-01 19:53:20 +01:00
|
|
|
|
|
|
|
|
ffPrintLogoAndKey(instance, "Battery");
|
|
|
|
|
|
|
|
|
|
if(model[0] != '\0')
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2021-03-01 19:53:20 +01:00
|
|
|
printf("%s ", model);
|
|
|
|
|
|
|
|
|
|
if(technology[0] != '\0')
|
|
|
|
|
printf("(%s) ", technology);
|
2021-02-19 16:23:41 +01:00
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-03-01 19:53:20 +01:00
|
|
|
if(capacity[0] != '\0')
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2021-03-01 19:53:20 +01:00
|
|
|
printf("[%s%%", capacity);
|
|
|
|
|
|
|
|
|
|
if(status[0] == '\0')
|
|
|
|
|
puts("]");
|
|
|
|
|
else
|
|
|
|
|
printf("; %s]\n", status);
|
2021-02-19 16:23:41 +01:00
|
|
|
}
|
2021-03-01 19:53:20 +01:00
|
|
|
else
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2021-03-01 19:53:20 +01:00
|
|
|
if(status[0] != '\0')
|
|
|
|
|
printf("%s", status);
|
|
|
|
|
else
|
|
|
|
|
putchar('\n');
|
2021-02-19 16:23:41 +01:00
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
|
|
|
|
}
|