add GetBattery

This commit is contained in:
Your Name 2024-01-03 17:46:33 +03:00
parent d28f74ea00
commit 6d15bf5b9e
5 changed files with 66 additions and 7 deletions

View file

@ -256,3 +256,37 @@ int GetAVG(const char *title, const FETCH fetch) {
#endif
}
void DrawBar(char *color, int cur, int max) {
printf("[");
int bar = max / BAR_WIDTH;
for (int i = 0; i < BAR_WIDTH; i++) {
if (i * bar < cur)
printf("%s-\033[0m", color);
else
printf("\033[1;30m-\033[0m");
}
printf("]");
}
int GetBattery(const char *title, const FETCH fetch) {
if (BATT_NAME == NULL)
return 1;
FILE *fp = fopen(BATT_NAME, "r");
if (fp == NULL)
return 1;
int capacity = 0;
if (fscanf(fp, "%d", &capacity) < 0)
return 1;
printf("%s%s%s", fetch.color, title, fetch.font_color);
DrawBar(fetch.color, capacity, 100);
return 0;
}