From 18697ea260440b21c25244fc668af3ac81c38b47 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 26 Nov 2023 13:28:41 +0300 Subject: [PATCH] fix --- config.h | 18 +++++++++--------- src/fetch.c | 23 +++++++++++------------ src/main.c | 15 ++++----------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/config.h b/config.h index 2d57acf..1a999dd 100644 --- a/config.h +++ b/config.h @@ -13,15 +13,15 @@ typedef struct { #define PC_CHAR "%" static PARAMETR CONFIG[] = { - {"Os ", PrintOs}, - {"Krnl ", GetKernel}, - {"User ", GetUser}, - {"Uptm ", GetUptime}, - {"Arch ", GetArch}, - {"Shll ", GetShell}, - {"Pkgs ", GetPkg}, - {" ", Blank}, - {" ", PrintColors} + {" OS ", PrintOs}, + {" KERNEL ", GetKernel}, + {" USER ", GetUser}, + {" UPTIME ", GetUptime}, + {" ARCH ", GetArch}, + {" SHELL ", GetShell}, + {" PKGS ", GetPkg}, + {"", Blank}, + {"", PrintColors} }; #endif diff --git a/src/fetch.c b/src/fetch.c index 7890d79..a284ac2 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -47,7 +47,7 @@ int GetOs(char *os_name, size_t len) { } void SetArt(FETCH *fetch, size_t size, char *pkg_cmd, char **logo, char *color) { - fetch->logo_size = size; + fetch->logo_size = size / sizeof(char *); fetch->logo = logo; fetch->pkg_cmd = pkg_cmd; fetch->color = color; @@ -55,28 +55,28 @@ void SetArt(FETCH *fetch, size_t size, char *pkg_cmd, char **logo, char *color) void GetArt(FETCH *fetch) { if (strstr(fetch->os_name, "Debian")) - SetArt(fetch, sizeof(Debian) / sizeof(char *), "dpkg -l | tail -n+6 | wc -l", Debian, "\033[0;31m"); + SetArt(fetch, sizeof(Debian), "dpkg -l | tail -n+6 | wc -l", Debian, "\033[0;31m"); else if (strstr(fetch->os_name, "Void")) - SetArt(fetch, sizeof(Void) / sizeof(char *), "xbps-query -l | wc -l", Void, "\033[0;32m"); + SetArt(fetch, sizeof(Void), "xbps-query -l | wc -l", Void, "\033[0;32m"); else if (strstr(fetch->os_name, "Alpine")) - SetArt(fetch, sizeof(Alpine) / sizeof(char *), "grep 'P:' /lib/apk/db/installed | wc -l", Alpine, "\033[1;34m"); + SetArt(fetch, sizeof(Alpine), "grep 'P:' /lib/apk/db/installed | wc -l", Alpine, "\033[1;34m"); else if (strstr(fetch->os_name, "Arch") || strstr(fetch->os_name, "Artix")) - SetArt(fetch, sizeof(Arch) / sizeof(char *), "pacman -Qq | wc -l", Arch, "\033[0;34m"); + SetArt(fetch, sizeof(Arch), "pacman -Qq | wc -l", Arch, "\033[0;34m"); else if (strstr(fetch->os_name, "PlainOs")) - SetArt(fetch, sizeof(PlainOs) / sizeof(char *), NULL, PlainOs, "\033[37m"); + SetArt(fetch, sizeof(PlainOs), NULL, PlainOs, "\033[37m"); else if (strstr(fetch->os_name, "OpenBSD")) - SetArt(fetch, sizeof(OpenBSD) / sizeof(char *), "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '", OpenBSD, "\033[1;33m"); + SetArt(fetch, sizeof(OpenBSD), "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '", OpenBSD, "\033[1;33m"); else if (!chdir("/system")) - SetArt(fetch, sizeof(Android) / sizeof(char *), "dpkg -l | tail -n+6 | wc -l", Android, "\033[32m"); + SetArt(fetch, sizeof(Android), "dpkg -l | tail -n+6 | wc -l", Android, "\033[32m"); else - SetArt(fetch, sizeof(Unknow) / sizeof(char *), NULL, Unknow, "\033[1;36m"); + SetArt(fetch, sizeof(Unknow), NULL, Unknow, "\033[1;36m"); } int GetKernel(const char *title, const FETCH fetch) { @@ -90,8 +90,7 @@ int PrintOs(const char *title, const FETCH fetch) { } int PrintColors(const char *title, const FETCH fetch) { - UNUSED(title); - UNUSED(fetch); + printf("%s%s%s", fetch.color, title, fetch.font_color); for (int i = 1; i < 7; i++) printf("\033[1;3%dm%s\033[0m \033[0;3%dm%s\033[0m ", i, PC_CHAR, i, PC_CHAR); @@ -102,7 +101,7 @@ int PrintColors(const char *title, const FETCH fetch) { int Blank(const char *title, const FETCH fetch) { UNUSED(title); UNUSED(fetch); - return 1; + return 0; } int GetUser(const char *title, const FETCH fetch) { diff --git a/src/main.c b/src/main.c index 3b373e4..af920c8 100644 --- a/src/main.c +++ b/src/main.c @@ -5,26 +5,19 @@ int main(void) { FETCH fetch = Init(); - /* Function failed */ - int flag = 0; - size_t i; for (i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) { - if (i < fetch.logo_size && !flag) + if (i < fetch.logo_size) printf("%s", fetch.logo[i]); - if (i >= fetch.logo_size && !flag) + if (i >= fetch.logo_size) printf("%s", fetch.logo[fetch.logo_size - 1]); - if (!CONFIG[i].func(CONFIG[i].title, fetch)) { - flag = 0; + if (!CONFIG[i].func(CONFIG[i].title, fetch)) printf("\033[0m\n"); - } - else { - flag = 1; + else printf("\033[0m"); - } } for (; i < fetch.logo_size; i++)