This commit is contained in:
Your Name 2024-01-03 18:27:09 +03:00
parent 2fac712297
commit f9ccaaa80b
6 changed files with 38 additions and 8 deletions

View File

@ -12,6 +12,8 @@ typedef struct {
#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
/* Uncomment if you use firacode font */
/* #define FIRA_CODE */
/* Full path to capacity file */
/* Example: /sys/class/power_supply/battery/capacity */

View File

@ -257,19 +257,40 @@ int GetAVG(const char *title, const FETCH fetch) {
#endif
}
void DrawBar(char *color, int cur, int max) {
printf("[");
void DrawBar(int cur, int max) {
int bar = max / BAR_WIDTH;
#ifdef FIRA_CODE
char *start = "";
if (cur * bar > 0)
start = "";
char *end = "";
if (cur < max)
end = "";
char *bar_filled = "";
char *bar_void = "";
#else
char *start = "[";
char *end = "]";
char *bar_filled = "#";
char *bar_void = ".";
#endif
printf("%s", start);
for (int i = 0; i < BAR_WIDTH; i++) {
if (i * bar < cur)
printf("%s-\033[0m", color);
printf("%s", bar_filled);
else
printf("\033[1;30m-\033[0m");
printf("%s", bar_void);
}
printf("]");
printf("%s", end);
}
int GetBattery(const char *title, const FETCH fetch) {
@ -285,8 +306,7 @@ int GetBattery(const char *title, const FETCH fetch) {
return 1;
printf("%s%s%s", fetch.color, title, fetch.font_color);
DrawBar(fetch.color, capacity, 100);
DrawBar(capacity, 100);
return 0;
}

View File

@ -12,6 +12,8 @@ typedef struct {
#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
/* Uncomment if you use firacode font */
/* #define FIRA_CODE */
/* Full path to capacity file */
/* Example: /sys/class/power_supply/battery/capacity */

View File

@ -12,6 +12,8 @@ typedef struct {
#define COLORS " \033[31mx \033[32mx \033[33mx \033[34mx \033[35mx \033[0m"
#define FONT_COLOR "\033[1;37m"
#define BAR_WIDTH 10
/* Uncomment if you use firacode font */
/* #define FIRA_CODE */
/* Full path to capacity file */
/* Example: /sys/class/power_supply/battery/capacity */

View File

@ -12,6 +12,8 @@ typedef struct {
#define COLORS " \033[31mx \033[32mx \033[33mx \033[34mx \033[35mx \033[0m"
#define FONT_COLOR "\033[1;37m"
#define BAR_WIDTH 10
/* Uncomment if you use firacode font */
/* #define FIRA_CODE */
/* Full path to capacity file */
/* Example: /sys/class/power_supply/battery/capacity */

View File

@ -12,6 +12,8 @@ typedef struct {
#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
/* Uncomment if you use firacode font */
/* #define FIRA_CODE */
/* Full path to capacity file */
/* Example: /sys/class/power_supply/battery/capacity */