add GetBattery
This commit is contained in:
parent
d28f74ea00
commit
6d15bf5b9e
24
config.h
24
config.h
@ -9,8 +9,13 @@ typedef struct {
|
||||
} PARAMETR;
|
||||
|
||||
/* Config, EDIT THERE */
|
||||
#define COLORS " \033[31mx \033[32mx \033[33mx \033[34mx \033[35mx \033[0m"
|
||||
#define COLORS "\033[31m<> \033[32m<> \033[33m<> \033[34m<> \033[35m<> \033[36m<>\033[0m"
|
||||
#define FONT_COLOR "\033[1;37m"
|
||||
#define BAR_WIDTH 10
|
||||
|
||||
/* Full path to capacity file */
|
||||
/* Example: /sys/class/power_supply/battery/capacity */
|
||||
#define BATT_NAME NULL
|
||||
|
||||
/* #define PRINT_TOTAL_MEM */
|
||||
/* #define PRINT_USER_MEM */
|
||||
@ -18,11 +23,18 @@ typedef struct {
|
||||
|
||||
#ifdef _MAIN_H
|
||||
PARAMETR CONFIG[] = {
|
||||
{" ", Blank},
|
||||
{"\033[1;31m ", PrintOs},
|
||||
{" ", GetKernel},
|
||||
{" ", GetUptime},
|
||||
{" ", GetPkg},
|
||||
{" os ", PrintOs},
|
||||
{" kr ", GetKernel},
|
||||
{" usr ", GetUser},
|
||||
{" upt ", GetUptime},
|
||||
{" arch ", GetArch},
|
||||
{"shell ", GetShell},
|
||||
{" pkgs ", GetPkg},
|
||||
{" mem ", GetMem},
|
||||
{"model ", GetModel},
|
||||
{" host ", GetHostname},
|
||||
{" lAVG ", GetAVG},
|
||||
{" batt ", GetBattery},
|
||||
{" ", Blank},
|
||||
{COLORS, Blank}
|
||||
};
|
||||
|
@ -46,5 +46,6 @@ int GetMem(const char *title, const FETCH fetch);
|
||||
int GetModel(const char *title, const FETCH fetch);
|
||||
int GetHostname(const char *title, const FETCH fetch);
|
||||
int GetAVG(const char *title, const FETCH fetch);
|
||||
int GetBattery(const char *title, const FETCH fetch);
|
||||
|
||||
#endif
|
||||
|
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;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,11 @@ typedef struct {
|
||||
/* Config, EDIT THERE */
|
||||
#define COLORS "\033[31m<> \033[32m<> \033[33m<> \033[34m<> \033[35m<> \033[36m<>\033[0m"
|
||||
#define FONT_COLOR "\033[1;37m"
|
||||
#define BAR_WIDTH 10
|
||||
|
||||
/* Full path to capacity file */
|
||||
/* Example: /sys/class/power_supply/battery/capacity */
|
||||
#define BATT_NAME NULL
|
||||
|
||||
/* #define PRINT_TOTAL_MEM */
|
||||
/* #define PRINT_USER_MEM */
|
||||
@ -29,6 +34,7 @@ PARAMETR CONFIG[] = {
|
||||
{"model ", GetModel},
|
||||
{" host ", GetHostname},
|
||||
{" lAVG ", GetAVG},
|
||||
{" batt ", GetBattery},
|
||||
{" ", Blank},
|
||||
{COLORS, Blank}
|
||||
};
|
||||
|
@ -11,6 +11,11 @@ typedef struct {
|
||||
/* Config, EDIT THERE */
|
||||
#define COLORS " \033[41;31m++ \033[42;32m++ \033[43;33m++ \033[44;34m++ \033[45;35m++ \033[46;36m++\033[0m"
|
||||
#define FONT_COLOR "\033[1;37m"
|
||||
#define BAR_WIDTH 10
|
||||
|
||||
/* Full path to capacity file */
|
||||
/* Example: /sys/class/power_supply/battery/capacity */
|
||||
#define BATT_NAME NULL
|
||||
|
||||
/* #define PRINT_TOTAL_MEM */
|
||||
/* #define PRINT_USER_MEM */
|
||||
@ -25,12 +30,13 @@ PARAMETR CONFIG[] = {
|
||||
{" - mod ", GetModel},
|
||||
{" - ht ", GetHostname},
|
||||
{" ", Blank},
|
||||
{" - other: ", Blank},
|
||||
{" - info: ", Blank},
|
||||
{" - os ", PrintOs},
|
||||
{" - shl ", GetShell},
|
||||
{" - pkg ", GetPkg},
|
||||
{" - up ", GetUptime},
|
||||
{" - avg ", GetAVG},
|
||||
{" - bat ", GetBattery},
|
||||
{" ", Blank},
|
||||
{COLORS, Blank}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user