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

This commit is contained in:
8nlight 2023-10-18 23:55:28 +03:00
parent c40de0102a
commit d9bce24e52
5 changed files with 45 additions and 27 deletions

View File

@ -1,3 +1,4 @@
CFLAGS?= -s -flto -Os -pedantic
CC?=cc
all:
cc fetch.c $(CFLAGS) -o kfetch
$(CC) fetch.c $(CFLAGS) -o kfetch

View File

@ -3,7 +3,7 @@
int main(void) {
Init();
void (*FUNCS[])(void) = {PrintOs, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, GetArch, Blank, PrintColors};
void (*FUNCS[])(void) = {PrintOs, GetAvg, GetKernel, GetShell, GetUptime, GetUser, GetPkgs, GetArch, Blank, PrintColors};
size_t i;
for (i = 0; i < sizeof(FUNCS) / sizeof(void *); i++) {
@ -12,8 +12,7 @@ int main(void) {
//If art is less than buffer size
else if (i >= Logo.size)
for (size_t j = 0; j < strlen(Logo.art[Logo.size - 1]); j++)
printf(" ");
printf("%s", Logo.art[Logo.size - 1]);
FUNCS[i]();

34
funcs.h
View File

@ -1,8 +1,12 @@
//Base funcs
#ifndef FUNCS_H
#define FUNCS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pwd.h>
#include <time.h>
#include <sys/utsname.h>
@ -47,7 +51,7 @@ void Init(void) {
Logo = GetArt();
if (uname(&Uts) < 0) {
fprintf(stderr, "WTF, uname dont work\n");
fprintf(stderr, "kfetch: uaname() failed: %s\n", strerror(errno));
exit(1);
}
}
@ -79,19 +83,20 @@ void PrintOs(void) {
}
void GetUptime(void) {
int UptimeH = 0;
int UptimeM = 0;
#ifdef CLOCK
struct timespec uptime;
clock_gettime(CLOCK, &uptime);
int UptimeH = uptime.tv_sec / 3600;
int UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
UptimeH = uptime.tv_sec / 3600;
UptimeM = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
#endif
printf("%sUPTIME \033[0;37m%dh %dm\033[0m", Logo.color, UptimeH, UptimeM);
#else
printf("%s UPTIME \033[0;37m0h 0m\033[0m", Logo.color);
#endif
}
void GetUser(void) {
@ -142,7 +147,6 @@ char *GetOs(void) {
}
void PrintColors(void) {
printf(" ");
for (int i = 0; i < 7; i++)
printf("\033[1;3%dm● \033[0;3%dm● \033[0m", i, i);
}
@ -151,6 +155,19 @@ void GetArch(void) {
printf("%sARCH \033[0;37m%s", Logo.color, Uts.machine);
}
void GetAvg(void) {
double avg[3] = {0, 0, 0};
#ifndef __ANDROID__
if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0) {
fprintf(stderr, "kfetch: getloadavg() failed\n");
return;
}
#endif
printf("%sLoadAvg \033[0;37m%.2f %.2f %.2f", Logo.color, avg[0], avg[1], avg[2]);
}
void Blank(void) {
return;
}
@ -198,3 +215,4 @@ LOGO GetArt(void) {
return art;
}
#endif

View File

@ -1,6 +1,7 @@
Edit FUNCS in fetch.c
GetShell
GetAvg
GetKernel
PrintOs
GetUptime

View File

@ -19,7 +19,7 @@ char *Void[] = {
};
char *Alpine[] = {
" /\\ /\\ ",
"\033[34m /\\ /\\ ",
"\033[34m / \\ \\ ",
"\033[34m / \\ \\ ",
"\033[34m / \\ \\ ",
@ -40,7 +40,6 @@ char *Arch[] = {
};
char *Unknow[] = {
" ",
"\033[1;36m ___ ",
"\033[1;36m (\033[0m..\033[1;36m | ",
"\033[1;36m (\033[33m<> \033[1;36m| ",