This commit is contained in:
Your Name 2023-11-26 13:28:41 +03:00
parent b88f882a17
commit 18697ea260
3 changed files with 24 additions and 32 deletions

View File

@ -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

View File

@ -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) {

View File

@ -5,27 +5,20 @@
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++)
printf("%s\n", fetch.logo[i]);