add GetBattery
This commit is contained in:
parent
d28f74ea00
commit
6d15bf5b9e
5 changed files with 66 additions and 7 deletions
34
src/fetch.c
34
src/fetch.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue