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

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) { int main(void) {
Init(); 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; size_t i;
for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) { for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) {
@ -17,7 +17,7 @@ int main(void) {
FUNCS[i](); FUNCS[i]();
printf("\n"); printf("\033[0m\n");
} }

35
funcs.h
View File

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

@ -35,6 +35,7 @@ char *Unknow[] = {
"\033[35m / \033[0m__\033[35m \\ ", "\033[35m / \033[0m__\033[35m \\ ",
"\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[0m\\__/\033[35m/_) ",
"\033[33m\\/\033[35m-____\033[33m\\/ ", "\033[35m\\/\033[35m-____\033[33m\\/ ",
" " " "
}; };