fix
This commit is contained in:
parent
b14ca9e430
commit
c65640c4f6
12 changed files with 241 additions and 296 deletions
76
src/fetch.c
Normal file
76
src/fetch.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "fetch.h"
|
||||
#include "config.h"
|
||||
#include "logo.h"
|
||||
|
||||
#define UNUSED(x) ((void)x)
|
||||
|
||||
FETCH Init(void) {
|
||||
FETCH fetch;
|
||||
if (uname(&fetch.uts) < 0) {
|
||||
fprintf(stderr, "kfetch: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(fetch.os_name, '\0', sizeof(fetch.os_name));
|
||||
if (GetOs(fetch.os_name, sizeof(fetch.os_name)))
|
||||
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
|
||||
|
||||
else
|
||||
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.os_name + strlen("NAME=\""));
|
||||
|
||||
fetch.font_color = FONT_COLOR;
|
||||
GetArt(&fetch);
|
||||
return fetch;
|
||||
}
|
||||
|
||||
int GetOs(char *os_name, size_t len) {
|
||||
FILE *fp = fopen("/etc/os-release", "r");
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
|
||||
while (fgets(os_name, len, fp)) {
|
||||
if (!strncmp(os_name, "NAME=", 5)) {
|
||||
os_name[strlen(os_name) - 2] = '\0';
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void GetArt(FETCH *fetch) {
|
||||
fetch->color = "\033[36m";
|
||||
fetch->logo = Unknow;
|
||||
fetch->logo_size = sizeof(Unknow) / sizeof(char *);
|
||||
}
|
||||
|
||||
void GetKernel(const char *title, const FETCH fetch) {
|
||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.uts.release);
|
||||
}
|
||||
|
||||
void PrintOs(const char *title, const FETCH fetch) {
|
||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.os_name);
|
||||
}
|
||||
|
||||
void PrintColors(const char *title, const FETCH fetch) {
|
||||
UNUSED(title);
|
||||
UNUSED(fetch);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Blank(const char *title, const FETCH fetch) {
|
||||
UNUSED(title);
|
||||
UNUSED(fetch);
|
||||
|
||||
printf("");
|
||||
}
|
24
src/main.c
Normal file
24
src/main.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include "fetch.h"
|
||||
#include "config.h"
|
||||
|
||||
int main(void) {
|
||||
FETCH fetch = Init();
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) {
|
||||
if (i < fetch.logo_size)
|
||||
printf("%s", fetch.logo[i]);
|
||||
|
||||
if (i >= fetch.logo_size)
|
||||
printf("%s", fetch.logo[fetch.logo_size - 1]);
|
||||
|
||||
CONFIG[i].func(CONFIG[i].title, fetch);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
for (; i < fetch.logo_size; i++)
|
||||
printf("%s\n", fetch.logo[i]);
|
||||
|
||||
printf("\n\033[0m");
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue