From f9ccaaa80bf998372332bdc31cd72db54a09664b Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 3 Jan 2024 18:27:09 +0300 Subject: [PATCH] fixed --- config.h | 2 ++ src/fetch.c | 36 ++++++++++++++++++++++++++++-------- themes/default.h | 2 ++ themes/fira.h | 2 ++ themes/mini.h | 2 ++ themes/tree.h | 2 ++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/config.h b/config.h index 96c980f..c679da2 100644 --- a/config.h +++ b/config.h @@ -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 */ diff --git a/src/fetch.c b/src/fetch.c index c1cbc06..07b95b5 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -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; } diff --git a/themes/default.h b/themes/default.h index 96c980f..c679da2 100644 --- a/themes/default.h +++ b/themes/default.h @@ -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 */ diff --git a/themes/fira.h b/themes/fira.h index 98976eb..f01bc53 100644 --- a/themes/fira.h +++ b/themes/fira.h @@ -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 */ diff --git a/themes/mini.h b/themes/mini.h index b718714..a6afe5a 100644 --- a/themes/mini.h +++ b/themes/mini.h @@ -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 */ diff --git a/themes/tree.h b/themes/tree.h index 391d6b9..8d85c73 100644 --- a/themes/tree.h +++ b/themes/tree.h @@ -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 */