diff --git a/README.md b/README.md index 5285edf..67a5d79 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -![kfetch](/img/kfetch.jpg) +![kfetch](/img/kfetch.jpg) +themes/ - contain various versions of config.h +exp: + cp themes/tree.h config.h diff --git a/build.sh b/build.sh index 2dd208f..3108dc0 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ CC=cc FLAGS="-Os -s" -$CC -Iinclude -I. src/main.c -c -o main.o -$CC -Iinclude -I. src/fetch.c -c -o fetch.o -$CC $FLAGS main.o fetch.o -o kfetch +$CC -Iinclude -I. src/main.c -c -o main.o && +$CC -Iinclude -I. src/fetch.c -c -o fetch.o && +$CC $FLAGS main.o fetch.o -o kfetch && rm main.o fetch.o diff --git a/config.h b/config.h index 4b62e0c..86cafb3 100644 --- a/config.h +++ b/config.h @@ -9,9 +9,14 @@ typedef struct { } PARAMETR; /* Config, EDIT THERE */ +#define COLORS "\033[31m<> \033[32m<> \033[33m<> \033[34m<> \033[35m<> \033[36m<>\033[0m" #define FONT_COLOR "\033[1;37m" #define PC_CHAR "<>" +/* #define PRINT_TOTAL_MEM */ +/* #define PRINT_USER_MEM */ +#define PRINT_USED_AND_TOTAL_MEM + #ifdef _MAIN_H PARAMETR CONFIG[] = { {" os ", PrintOs}, @@ -19,13 +24,14 @@ PARAMETR CONFIG[] = { {" usr ", GetUser}, {" upt ", GetUptime}, {" arch ", GetArch}, - {" shl ", GetShell}, - {" pkg ", GetPkg}, + {"shell ", GetShell}, + {" pkgs ", GetPkg}, {" mem ", GetMem}, - {" mod ", GetModel}, + {"model ", GetModel}, {" host ", GetHostname}, + {" lAVG ", GetAVG}, {" ", Blank}, - {" ", PrintColors} + {COLORS, Blank} }; #endif diff --git a/include/fetch.h b/include/fetch.h index a2c2951..6d9d6ad 100644 --- a/include/fetch.h +++ b/include/fetch.h @@ -1,5 +1,5 @@ -#ifndef _FUNCS_H -#define _FUNCS_H +#ifndef _FETCH_H +#define _FETCH_H #include #include @@ -36,7 +36,6 @@ int GetOs(char *os_name, size_t len); void GetArt(FETCH *fetch, int flag); int GetKernel(const char *title, const FETCH fetch); int PrintOs(const char *title, const FETCH fetch); -int PrintColors(const char *title, const FETCH fetch); int Blank(const char *title, const FETCH fetch); int GetUser(const char *title, const FETCH fetch); int GetUptime(const char *title, const FETCH fetch); @@ -46,5 +45,6 @@ int GetPkg(const char *title, const FETCH fetch); int GetMem(const char *title, const FETCH fetch); int GetModel(const char *title, const FETCH fetch); int GetHostname(const char *title, const FETCH fetch); +int GetAVG(const char *title, const FETCH fetch); #endif diff --git a/include/logo.h b/include/logo.h index 6407a8a..9b1469f 100644 --- a/include/logo.h +++ b/include/logo.h @@ -102,3 +102,4 @@ char *Unknow[] = { }; #endif + diff --git a/src/fetch.c b/src/fetch.c index e62fe83..4ec73e4 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -103,15 +103,6 @@ int PrintOs(const char *title, const FETCH fetch) { return 0; } -int PrintColors(const char *title, const FETCH fetch) { - printf("%s%s%s", fetch.color, title, fetch.font_color); - - for (int i = 1; i < 7; i++) - printf("\033[1;3%dm%s\033[0m ", i, PC_CHAR); - - return 0; -} - int Blank(const char *title, const FETCH fetch) { printf("%s%s%s", fetch.color, title, fetch.font_color); return 0; @@ -195,14 +186,22 @@ int GetMem(const char *title, const FETCH fetch) { if (fp == NULL) return 1; - off_t unused = 0, total = 0, available = 0; - if (fscanf(fp, "MemTotal: %lu kB\nMemFree: %lu kB\nMemAvailable: %lu kB", &total, &unused, &available) < 0) + off_t free = 0, total = 0; + if (fscanf(fp, "MemTotal: %lu kB\nMemFree: %lu kB", &total, &free) < 0) return 1; - UNUSED(unused); - printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - available) / 1024, (uintmax_t)total / 1024); - fclose(fp); +#ifdef PRINT_USED_AND_TOTAL_MEM + printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - free) / 1024, (uintmax_t)total / 1024); +#elif PRINT_TOTALMEM + printf("%s%s%s%lumb", fetch.color, title, fetch.font_color, (uintmax_t)total / 1024); + +#else + printf("%s%s%s%lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - free) / 1024); + +#endif + + fclose(fp); return 0; } @@ -241,3 +240,19 @@ int GetHostname(const char *title, const FETCH fetch) { printf("%s%s%s%s", fetch.color, title, fetch.font_color, hostname); return 0; } + +int GetAVG(const char *title, const FETCH fetch) { +#ifndef __ANDROID__ + double avg[3] = {0, 0, 0}; + + if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0) + return 1; + + printf("%s%s%s%.2f %.2f %.2f", fetch.color, title, fetch.font_color, avg[0], avg[1], avg[2]); + return 0; + +#else + return 1; + +#endif +} diff --git a/src/main.c b/src/main.c index b3e457d..2652bd2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ #define _MAIN_H #include #include -#include +#include #include "fetch.h" #include "config.h" diff --git a/themes/.gitignore b/themes/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/themes/default.h b/themes/default.h new file mode 100644 index 0000000..86cafb3 --- /dev/null +++ b/themes/default.h @@ -0,0 +1,39 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#include "fetch.h" + +typedef struct { + char *title; + int (*func)(const char *title, const FETCH fetch); +} PARAMETR; + +/* Config, EDIT THERE */ +#define COLORS "\033[31m<> \033[32m<> \033[33m<> \033[34m<> \033[35m<> \033[36m<>\033[0m" +#define FONT_COLOR "\033[1;37m" +#define PC_CHAR "<>" + +/* #define PRINT_TOTAL_MEM */ +/* #define PRINT_USER_MEM */ +#define PRINT_USED_AND_TOTAL_MEM + +#ifdef _MAIN_H +PARAMETR CONFIG[] = { + {" os ", PrintOs}, + {" kr ", GetKernel}, + {" usr ", GetUser}, + {" upt ", GetUptime}, + {" arch ", GetArch}, + {"shell ", GetShell}, + {" pkgs ", GetPkg}, + {" mem ", GetMem}, + {"model ", GetModel}, + {" host ", GetHostname}, + {" lAVG ", GetAVG}, + {" ", Blank}, + {COLORS, Blank} +}; + +#endif + +#endif diff --git a/themes/fira.h b/themes/fira.h new file mode 100644 index 0000000..1ebe6e6 --- /dev/null +++ b/themes/fira.h @@ -0,0 +1,32 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#include "fetch.h" + +typedef struct { + char *title; + int (*func)(const char *title, const FETCH fetch); +} PARAMETR; + +/* Config, EDIT THERE */ +#define COLORS " \033[31mx \033[32mx \033[33mx \033[34mx \033[35mx \033[0m" +#define FONT_COLOR "\033[1;37m" +#define PC_CHAR "<>" + +/* #define PRINT_TOTAL_MEM */ +/* #define PRINT_USER_MEM */ +#define PRINT_USED_AND_TOTAL_MEM + +#ifdef _MAIN_H +PARAMETR CONFIG[] = { + {"  ", PrintOs}, + {"  ", GetKernel}, + {"  ", GetUptime}, + {"  ", GetPkg}, + {" ", Blank}, + {COLORS, Blank} +}; + +#endif + +#endif diff --git a/themes/tree.h b/themes/tree.h new file mode 100644 index 0000000..aa210c6 --- /dev/null +++ b/themes/tree.h @@ -0,0 +1,41 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#include "fetch.h" + +typedef struct { + char *title; + int (*func)(const char *title, const FETCH fetch); +} PARAMETR; + +/* Config, EDIT THERE */ +#define COLORS " \033[41;31m++ \033[42;32m++ \033[43;33m++ \033[44;34m++ \033[45;35m++ \033[46;36m++\033[0m" +#define FONT_COLOR "\033[1;37m" +#define PC_CHAR "<>" + +/* #define PRINT_TOTAL_MEM */ +/* #define PRINT_USER_MEM */ +#define PRINT_USED_AND_TOTAL_MEM + +#ifdef _MAIN_H +PARAMETR CONFIG[] = { + {" pc: ", Blank}, + {" - mem ", GetMem}, + {" - kr ", GetKernel}, + {" - ar ", GetArch}, + {" - mod ", GetModel}, + {" - ht ", GetHostname}, + {" ", Blank}, + {" - other: ", Blank}, + {" - os ", PrintOs}, + {" - shl ", GetShell}, + {" - pkg ", GetPkg}, + {" - up ", GetUptime}, + {" - avg ", GetAVG}, + {" ", Blank}, + {COLORS, Blank} +}; + +#endif + +#endif