Загрузить файлы в «»

This commit is contained in:
8nlight 2023-08-20 09:54:50 +03:00
parent 5c50c6cbd2
commit 69af8be271
4 changed files with 61 additions and 40 deletions

View File

@ -3,7 +3,7 @@
int main(void) {
Init();
void (*FUNCS[])(void) = {PrintOs, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, Blank, PrintColors};
void (*FUNCS[])(void) = {PrintOs, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, GetArch, Blank, PrintColors};
size_t i;
for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) {
@ -17,7 +17,7 @@ int main(void) {
FUNCS[i]();
printf("\n");
printf("\033[0m\n");
}

35
funcs.h
View File

@ -38,6 +38,7 @@ void GetUser(void);
void GetPkgs(void);
char *GetOs(void);
void PrintColors(void);
void GetArch(void);
void Blank(void);
LOGO GetArt(void);
@ -56,28 +57,28 @@ void Init(void) {
void GetShell(void) {
char *shell = getenv("SHELL");
if (shell == NULL) {
printf("%s SHELL \033[37mNothing\033[0m", Logo.color);
printf("%s SHELL \033[0;37mNothing\033[0m", Logo.color);
return;
}
char *splt = strrchr(shell, '/');
if (splt != NULL)
printf("%s SHELL \033[37m%s\033[0m", Logo.color, splt + 1);
printf("%s SHELL \033[0;37m%s\033[0m", Logo.color, splt + 1);
}
void GetKernel(void) {
printf("%s KERNEL \033[37m%s\033[0m", Logo.color, Uts.release);
printf("%s KERNEL \033[0;37m%s\033[0m", Logo.color, Uts.release);
}
void PrintOs(void) {
if (Os == NULL) {
printf("%s OS \033[37mUnknow\033[0m", Logo.color);
printf("%s OS \033[0;37m%s\033[0m", Logo.color, Uts.sysname);
return;
}
printf("%s OS \033[37m%s\033[0m", Logo.color, Os + strlen("PRETTY_NAME= "));
printf("%s OS \033[0;37m%s\033[0m", Logo.color, Os + strlen("PRETTY_NAME= "));
}
@ -89,10 +90,10 @@ void GetUptime(void) {
int UptimeH = uptime.tv_sec / 3600;
int UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
printf("%s UPTIME \033[37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
printf("%s UPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
#else
printf("%s UPTIME \033[37m0h 0m\033[0m", Logo.color);
printf("%s UPTIME \033[0;37m0h 0m\033[0m", Logo.color);
#endif
}
@ -100,18 +101,18 @@ void GetUptime(void) {
void GetUser(void) {
struct passwd *pw = getpwuid(geteuid());
printf("%s USER \033[37m%s\033[0m", Logo.color, pw->pw_name);
printf("%s USER \033[0;37m%s\033[0m", Logo.color, pw->pw_name);
}
void GetPkgs(void) {
if (Logo.pkg_cmd == NULL) {
printf("%s PKGS \033[37m0", Logo.color);
printf("%s PKGS \033[0;37m0", Logo.color);
return;
}
FILE *fp = popen(Logo.pkg_cmd, "r");
printf("%s PKGS \033[37m", Logo.color);
printf("%s PKGS \033[0;37m", Logo.color);
char ch;
while ((ch = fgetc(fp)) != '\n')
@ -133,8 +134,9 @@ char *GetOs(void) {
while (getline(&line, &len, fp) != EOF) {
if (strstr(line, "PRETTY_NAME=") != NULL) {
line[strlen(line) - 2] = '\0';
fclose(fp);
//Need free (in main())
return line;
}
}
@ -147,13 +149,20 @@ char *GetOs(void) {
void PrintColors(void) {
printf(" ");
for (int i = 0; i < 7; i++)
printf("\033[1;3%dm$ \033[0m", i);
printf("\033[1;3%dm\033[0;3%dm● \033[0m", i, i);
}
void GetArch(void) {
printf("%s ARCH \033[0;37m%s", Logo.color, Uts.machine);
}
void Blank(void) {
return;
}
LOGO GetArt(void) {
LOGO art;
@ -161,7 +170,7 @@ LOGO GetArt(void) {
art.size = sizeof(Unknow) / sizeof(char *);
art.pkg_cmd = NULL;
art.art = Unknow;
art.color = "\033[0;35m";
art.color = "\033[1;35m";
if (Os == NULL)
return art;

11
funcs.list Normal file
View File

@ -0,0 +1,11 @@
Edit FUNCS in fetch.c
GetShell
GetKernel
PrintOs
GetUptime
GetUser
GetPkgs
PrintColors
GetArch
Blank

View File

@ -23,7 +23,7 @@ char *Alpine[] = {
"\033[34m / \\ \\ ",
"\033[34m / \\ \\ ",
"\033[34m / \\ \\ ",
"\033[34m/ \\ \\",
"\033[34m/ \\ \\ ",
"\033[34m \\ ",
" "
};
@ -35,6 +35,7 @@ char *Unknow[] = {
"\033[35m / \033[0m__\033[35m \\ ",
"\033[35m ( \033[0m/ \\\033[35m /| ",
"\033[33m_\033[35m/ \033[0m\\__/\033[35m/_) ",
"\033[33m\\/\033[35m-____\033[33m\\/ ",
"\033[35m\\/\033[35m-____\033[33m\\/ ",
" "
};