This commit is contained in:
Your Name 2024-10-20 09:03:05 +00:00
parent ce965804d3
commit 2d8ac6280f
9 changed files with 116 additions and 51 deletions

View File

@ -9,8 +9,6 @@
#define FONT_COLOR "\033[1;37m"
#ifdef _MAIN_C
#define ON_ERROR_STR "none"
PARAMETR CONFIG[] = {
{PrintOs, {.str0=" os ", .str1=NULL}},
{GetKernel, {.str0=" kr ", .str1=NULL}},

View File

@ -9,7 +9,8 @@ typedef struct {
struct utsname uts;
char *pkg_cmd;
char *color;
char *logo_color;
char *font_color;
size_t logo_size;
char **logo;

BIN
kfetch

Binary file not shown.

View File

@ -27,6 +27,18 @@ FETCH Init(void) {
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
GetArt(&fetch, 1);
#ifdef LOGO_COLOR
fetch.logo_color = LOGO_COLOR;
#endif
#ifdef FONT_COLOR
fetch.font_color = FONT_COLOR;
#else
fetch.font_color = "\033[37m";
#endif
return fetch;
}
@ -62,7 +74,7 @@ void SetArt(FETCH *fetch, size_t size, char *pkg_cmd, char **logo, char *color,
if (flag)
fetch->pkg_cmd = pkg_cmd;
fetch->color = color;
fetch->logo_color = color;
}
void GetArt(FETCH *fetch, int flag) {
@ -98,12 +110,12 @@ void GetArt(FETCH *fetch, int flag) {
}
int GetKernel(struct par par, const FETCH fetch) {
printf("%s%s", FONT_COLOR, fetch.uts.release);
printf("%s%s", fetch.font_color, fetch.uts.release);
return 0;
}
int PrintOs(struct par par, const FETCH fetch) {
printf("%s%s", FONT_COLOR, fetch.os_name);
printf("%s%s", fetch.font_color, fetch.os_name);
return 0;
}
@ -118,7 +130,7 @@ int GetUser(struct par par, const FETCH fetch) {
if (pw == 0)
return 1;
printf("%s%s", FONT_COLOR, pw->pw_name);
printf("%s%s", fetch.font_color, pw->pw_name);
return 0;
}
@ -133,10 +145,10 @@ int GetUptime(struct par par, const FETCH fetch) {
int mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
if (days > 0)
printf("%s%d days", FONT_COLOR, days);
printf("%s%d days", fetch.font_color, days);
else
printf("%s%dh %dm", FONT_COLOR, hours, mins);
printf("%s%dh %dm", fetch.font_color, hours, mins);
return 0;
#endif
@ -145,7 +157,7 @@ int GetUptime(struct par par, const FETCH fetch) {
}
int GetArch(struct par par, const FETCH fetch) {
printf("%s%s", FONT_COLOR, fetch.uts.machine);
printf("%s%s", fetch.font_color, fetch.uts.machine);
return 0;
}
@ -158,7 +170,7 @@ int GetShell(struct par par, const FETCH fetch) {
if (splt == NULL)
return 1;
printf("%s%s", FONT_COLOR, splt + 1);
printf("%s%s", fetch.font_color, splt + 1);
return 0;
}
@ -170,7 +182,7 @@ int GetPkg(struct par par, const FETCH fetch) {
if (fp == NULL)
return 1;
printf("%s", FONT_COLOR);
printf("%s", fetch.font_color);
int ch;
while ((ch = getc(fp))) {
@ -195,7 +207,7 @@ int GetMem(struct par par, const FETCH fetch) {
fclose(fp);
printf("%s%lumb / %lumb", FONT_COLOR, (uintmax_t)(total - (cached + free + buffer)) / 1024, (uintmax_t)total / 1024);
printf("%s%lumb / %lumb", fetch.font_color, (uintmax_t)(total - (cached + free + buffer)) / 1024, (uintmax_t)total / 1024);
return 0;
}
@ -219,7 +231,7 @@ int GetModel(struct par par, const FETCH fetch) {
if (ptr != NULL)
*ptr = '\0';
printf("%s%s", FONT_COLOR, model_buffer);
printf("%s%s", fetch.font_color, model_buffer);
}
fclose(fp);
@ -231,7 +243,7 @@ int GetHostname(struct par par, const FETCH fetch) {
if (gethostname(hostname, sizeof(hostname)) < 0)
return 1;
printf("%s%s", FONT_COLOR, hostname);
printf("%s%s", fetch.font_color, hostname);
return 0;
}
@ -242,7 +254,7 @@ int GetAVG(struct par par, const FETCH fetch) {
if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0)
return 1;
printf("%s%.2f %.2f %.2f", FONT_COLOR, avg[0], avg[1], avg[2]);
printf("%s%.2f %.2f %.2f", fetch.font_color, avg[0], avg[1], avg[2]);
return 0;
@ -260,7 +272,7 @@ int Execute(struct par par, const FETCH fetch) {
if (fp == NULL)
return 1;
printf("%s", FONT_COLOR);
printf("%s", fetch.font_color);
int c;
while ((c = getc(fp))) {

View File

@ -2,36 +2,71 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "structs.h"
#include "config.h"
int main(int argc, char **argv) {
#ifdef ERROR_STR
char *error_str = ERROR_STR;
#else
char *error_str = "none";
#endif
#ifdef STRIP_RESET_ESCAPE
char *reset = "";
#else
char *reset = "\033[0m";
#endif
#ifdef DONT_PRINT_LOGO
char l_flag = 1;
#else
char l_flag = 0;
char *d_flag = NULL;
#endif
int opt;
while ((opt = getopt(argc, argv, "hld:")) != -1) {
switch (opt) {
case 'l':
l_flag = 1;
break;
void print_unescape(char newline, char *str) {
#ifdef STRIP_LOGO_ESCAPES
size_t len = strlen(str);
case 'd':
d_flag = optarg;
break;
char *str2 = malloc(len);
if (str2 == NULL) {
fprintf(stderr, "kfetch: malloc: %s\n", strerror(errno));
exit(1);
}
case 'h':
default:
printf("kfetch [-hld]\n\t-h Help\n\t-l Dont print logo\n\t-d STR Set STR as distro name\n");
return 0;
size_t j = 0;
for (size_t i = 0; i < len; i++) {
if (str[i] == '\033') {
while (str[i] != 'm') {
if (i > len) {
fputs("kfetch: wrong logo string\n", stderr);
exit(1);
}
i++;
}
continue;
}
str2[j] = str[i];
j++;
}
str2[j] = '\0';
printf("%s%c", str2, newline);
free(str2);
#else
printf("%s%c", str, newline);
#endif
}
int main(int argc, char **argv) {
FETCH fetch = Init();
if (d_flag != NULL) {
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", d_flag);
GetArt(&fetch, 0);
}
size_t j = 0;
for (size_t i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) {
@ -40,29 +75,29 @@ int main(int argc, char **argv) {
/* Print ascii logo */
if (j < fetch.logo_size && !l_flag)
printf("%s", fetch.logo[j]);
print_unescape('\0', fetch.logo[j]);
else if (j >= fetch.logo_size && !l_flag)
printf("%s", fetch.logo[fetch.logo_size - 1]);
print_unescape('\0', fetch.logo[fetch.logo_size - 1]);
/* Function exec */
printf("%s%s", fetch.color, CONFIG[i].par.str0);
printf("%s%s", fetch.logo_color, CONFIG[i].par.str0);
if (CONFIG[i].func(CONFIG[i].par, fetch))
printf("%s%s", FONT_COLOR, ON_ERROR_STR);
printf("%s%s", fetch.font_color, error_str);
else {
if (CONFIG[i].par.str1 != NULL)
printf(CONFIG[i].par.str1, fetch.color);
printf(CONFIG[i].par.str1, fetch.font_color);
}
j++;
printf("\033[0m\n");
printf("%s\n", reset);
}
for (; j < fetch.logo_size - 1; j++)
if (!l_flag)
printf("%s\n", fetch.logo[j]);
print_unescape('\n', fetch.logo[j]);
printf("\033[0m");
printf("%s", reset);
return 0;
}

26
themes/8nl.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef _CONFIG_H
#define _CONFIG_H
#include "fetch.h"
#include "structs.h"
#define STRIP_RESET_ESCAPE
#define STRIP_LOGO_ESCAPES
#define FONT_COLOR ""
#define LOGO_COLOR ""
#ifdef _MAIN_C
PARAMETR CONFIG[] = {
{PrintOs, {.str0=" Os : ", .str1=NULL}},
{GetMem, {.str0=" Mem : ", .str1=NULL}},
{GetModel, {.str0=" Host : ", .str1=NULL}},
{GetUptime, {.str0=" Uptime : ", .str1=NULL}},
{Blank, {.str0=" ", .str1=NULL}},
{GetUser, {.str0=" ", .str1=",%s Hi!"}},
{Execute, {.str0=" Outside: ", .str2="wget https://wttr.in/?format=\"%t+%C\" -qO-"}},
{Execute, {.str0=" Playing: ", .str2="basename \"$(mocp -Q \"%file\")\""}}
};
#endif
#endif

View File

@ -9,8 +9,6 @@
#define FONT_COLOR "\033[1;37m"
#ifdef _MAIN_C
#define ON_ERROR_STR "none"
PARAMETR CONFIG[] = {
{PrintOs, {.str0=" os ", .str1=NULL}},
{GetKernel, {.str0=" kr ", .str1=NULL}},

View File

@ -8,8 +8,6 @@
#define FONT_COLOR "\033[1;37m"
#ifdef _MAIN_C
#define ON_ERROR_STR "none"
PARAMETR CONFIG[] = {
{PrintOs, {.str0=" Os : ", .str1=NULL}},
{GetMem, {.str0=" Mem : ", .str1=NULL}},

View File

@ -11,9 +11,6 @@
#define BORDER "-------------------"
#define STR1 "\033[1;37m Somechars"
#define STR2 "\033[1;37m Somechars x2"
#define ON_ERROR_STR "none"
PARAMETR CONFIG[] = {
{Blank, {.str0=STR1, .str1=NULL}},
{Blank, {.str0=BORDER, .str1=NULL}},