oohh
This commit is contained in:
parent
76e0dcb8ed
commit
4fdee929ee
39
config.h
39
config.h
@ -2,32 +2,31 @@
|
|||||||
#define _CONFIG_H
|
#define _CONFIG_H
|
||||||
|
|
||||||
#include "fetch.h"
|
#include "fetch.h"
|
||||||
|
#include "structs.h"
|
||||||
typedef struct {
|
|
||||||
char *title;
|
|
||||||
int (*func)(const char *title, const FETCH fetch);
|
|
||||||
} PARAMETR;
|
|
||||||
|
|
||||||
/* Config, EDIT THERE */
|
/* Config, EDIT THERE */
|
||||||
#define COLORS " \033[31m(>_<) \033[32m(OwO) \033[33m($w$) \033[34m(;~;)\033[0m"
|
#define COLORS " \033[31m<> \033[32m<> \033[33m<> \033[34m<> \033[35m<> \033[36m<>\033[0m"
|
||||||
#define FONT_COLOR "\033[0m"
|
#define FONT_COLOR "\033[1;37m"
|
||||||
|
|
||||||
#define BAR_WIDTH 1
|
#ifdef _MAIN_C
|
||||||
#define BATT_NAME NULL
|
#define ON_ERROR_STR "none"
|
||||||
|
|
||||||
#ifdef _MAIN_H
|
|
||||||
PARAMETR CONFIG[] = {
|
PARAMETR CONFIG[] = {
|
||||||
{" -> ", PrintOs},
|
{PrintOs, {.str0=" os ", .str1=NULL}},
|
||||||
{" ", Blank},
|
{GetKernel, {.str0=" kr ", .str1=NULL}},
|
||||||
{" <- ", GetUptime},
|
{GetUser, {.str0=" usr ", .str1=NULL}},
|
||||||
{" ", Blank},
|
{GetUptime, {.str0=" upt ", .str1=NULL}},
|
||||||
{" -> ", GetMem},
|
{GetArch, {.str0=" arch ", .str1=NULL}},
|
||||||
{" ", Blank},
|
{GetShell, {.str0="shell ", .str1=NULL}},
|
||||||
{" <- ", GetArch},
|
{GetPkg, {.str0=" pkgs ", .str1=NULL}},
|
||||||
{" ", Blank},
|
{GetMem, {.str0=" mem ", .str1=NULL}},
|
||||||
{COLORS, Blank}
|
{GetModel, {.str0="model ", .str1=NULL}},
|
||||||
|
{GetHostname, {.str0=" host ", .str1=NULL}},
|
||||||
|
{GetAVG, {.str0=" AVG ", .str1=NULL}},
|
||||||
|
{Blank, {.str0=" ", .str1=NULL}},
|
||||||
|
{Execute, {.str0=" Id's ", .str1=NULL, .str2="id -gn"}},
|
||||||
|
{Blank, {.str0=COLORS, .str1=NULL}}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,53 +1,47 @@
|
|||||||
#ifndef _FETCH_H
|
#ifndef _FETCH_H
|
||||||
#define _FETCH_H
|
#define _FETCH_H
|
||||||
|
|
||||||
#include <time.h>
|
#include "structs.h"
|
||||||
#include <sys/utsname.h>
|
#ifdef _FETCH_C
|
||||||
|
#include <time.h>
|
||||||
#if defined(CLOCK_BOOTTIME)
|
#if defined(CLOCK_BOOTTIME)
|
||||||
#define CLOCK CLOCK_BOOTTIME
|
#define CLOCK CLOCK_BOOTTIME
|
||||||
#elif defined(CLOCK_UPTIME)
|
#elif defined(CLOCK_UPTIME)
|
||||||
#define CLOCK CLOCK_UPTIME
|
#define CLOCK CLOCK_UPTIME
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#define CLOCK CLOCK_MONOTONIC
|
#define CLOCK CLOCK_MONOTONIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OS_SIZE 128
|
#define MODEL_BUFF_SIZE 512
|
||||||
#define MODEL_BUFF_SIZE 512
|
static const char *MODELS[] = {
|
||||||
static const char *MODELS[] = {
|
|
||||||
"/sys/devices/virtual/dmi/id/product_name",
|
"/sys/devices/virtual/dmi/id/product_name",
|
||||||
"/sys/devices/virtual/dmi/id/product_version",
|
"/sys/devices/virtual/dmi/id/product_version",
|
||||||
"/sys/firmware/devicetree/base/model"
|
"/sys/firmware/devicetree/base/model"
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char os_name[OS_SIZE + 1];
|
|
||||||
struct utsname uts;
|
|
||||||
|
|
||||||
char *pkg_cmd;
|
#if defined(_FETCH_C) || defined(_MAIN_C)
|
||||||
char *color;
|
|
||||||
char *font_color;
|
|
||||||
size_t logo_size;
|
|
||||||
char **logo;
|
|
||||||
} FETCH;
|
|
||||||
|
|
||||||
FETCH Init(void);
|
|
||||||
int GetOs(char *os_name, size_t len);
|
int GetOs(char *os_name, size_t len);
|
||||||
void GetArt(FETCH *fetch, int flag);
|
void GetArt(FETCH *fetch, int flag);
|
||||||
int GetKernel(const char *title, const FETCH fetch);
|
FETCH Init(void);
|
||||||
int PrintOs(const char *title, const FETCH fetch);
|
#endif
|
||||||
int Blank(const char *title, const FETCH fetch);
|
|
||||||
int GetUser(const char *title, const FETCH fetch);
|
#if defined(_CONFIG_C) || defined(_MAIN_C)
|
||||||
int GetUptime(const char *title, const FETCH fetch);
|
int GetKernel(const struct par par, const FETCH fetch);
|
||||||
int GetArch(const char *title, const FETCH fetch);
|
int PrintOs(const struct par par, const FETCH fetch);
|
||||||
int GetShell(const char *title, const FETCH fetch);
|
int Blank(const struct par par, const FETCH fetch);
|
||||||
int GetPkg(const char *title, const FETCH fetch);
|
int GetUser(const struct par par, const FETCH fetch);
|
||||||
int GetMem(const char *title, const FETCH fetch);
|
int GetUptime(const struct par par, const FETCH fetch);
|
||||||
int GetModel(const char *title, const FETCH fetch);
|
int GetArch(const struct par par, const FETCH fetch);
|
||||||
int GetHostname(const char *title, const FETCH fetch);
|
int GetShell(const struct par par, const FETCH fetch);
|
||||||
int GetAVG(const char *title, const FETCH fetch);
|
int GetPkg(const struct par par, const FETCH fetch);
|
||||||
int GetBattery(const char *title, const FETCH fetch);
|
int GetMem(const struct par par, const FETCH fetch);
|
||||||
int Execute(const char *title, const FETCH fetch);
|
int GetModel(const struct par par, const FETCH fetch);
|
||||||
int eBlank(const char *title, const FETCH fetch);
|
int GetHostname(const struct par par, const FETCH fetch);
|
||||||
|
int GetAVG(const struct par par, const FETCH fetch);
|
||||||
|
int Execute(const struct par par, const FETCH fetch);
|
||||||
|
int eBlank(const struct par par, const FETCH fetch);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,14 +69,23 @@ char *OpenBSD[] = {
|
|||||||
" "
|
" "
|
||||||
};
|
};
|
||||||
|
|
||||||
char *PlainOs[] = {
|
char *Manana[] = {
|
||||||
" ",
|
"\033[1;32m -: \033[0m",
|
||||||
" (\\(\\ ",
|
"\033[1;32m =* .*: \033[0m",
|
||||||
" j . .) ",
|
"\033[1;32m =*=. \033[1;31m:+* =\033[1;32m *** \033[0m",
|
||||||
" | ° ! ",
|
"\033[1;32m -*+.- \033[1;31m*****#\033[1;32m =*-*- \033[0m",
|
||||||
" ? ; ",
|
"\033[1;32m .**:.= \033[1;31m****-\033[1;32m .*:.** \033[0m",
|
||||||
" c?\".UJ ",
|
"\033[1;32m +** :* \033[1;31m==:\033[1;32m *+ .**: \033[0m",
|
||||||
" "
|
"\033[1;32m :**+ -* =*: :**= \033[0m",
|
||||||
|
"\033[1;32m +**: -*. .*+ .**= \033[0m",
|
||||||
|
"\033[1;32m .**+ -*- +*. .**= \033[0m",
|
||||||
|
"\033[1;32m -**: -*= =*- +*= \033[0m",
|
||||||
|
"\033[1;32m +*+ :*+ .*= =*- \033[0m",
|
||||||
|
"\033[1;32m .**. ** *= :*: \033[0m",
|
||||||
|
"\033[1;32m -*: :*. == *. \033[0m",
|
||||||
|
"\033[1;32m +- +- := +. \033[0m",
|
||||||
|
"\033[1;32m .- .= .- : \033[0m",
|
||||||
|
"\033[1;32m :.. \033[0m"
|
||||||
};
|
};
|
||||||
|
|
||||||
char *Ubuntu[] = {
|
char *Ubuntu[] = {
|
||||||
|
30
include/structs.h
Normal file
30
include/structs.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef _STRUCTS_H
|
||||||
|
#define _STRUCTS_H
|
||||||
|
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#define OS_SIZE 128
|
||||||
|
typedef struct {
|
||||||
|
char os_name[OS_SIZE + 1];
|
||||||
|
struct utsname uts;
|
||||||
|
|
||||||
|
char *pkg_cmd;
|
||||||
|
char *color;
|
||||||
|
|
||||||
|
size_t logo_size;
|
||||||
|
char **logo;
|
||||||
|
} FETCH;
|
||||||
|
|
||||||
|
struct par {
|
||||||
|
char *str0;
|
||||||
|
char *str1;
|
||||||
|
char *str2;
|
||||||
|
int error_flag;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int (*func)(const struct par par, const FETCH fetch);
|
||||||
|
struct par par;
|
||||||
|
} PARAMETR;
|
||||||
|
|
||||||
|
#endif
|
130
src/fetch.c
130
src/fetch.c
@ -1,3 +1,4 @@
|
|||||||
|
#define _FETCH_C
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -8,6 +9,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include "fetch.h"
|
#include "fetch.h"
|
||||||
|
#include "structs.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
|
|
||||||
@ -24,7 +26,6 @@ FETCH Init(void) {
|
|||||||
if (GetOs(fetch.os_name, 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);
|
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", fetch.uts.sysname);
|
||||||
|
|
||||||
fetch.font_color = FONT_COLOR;
|
|
||||||
GetArt(&fetch, 1);
|
GetArt(&fetch, 1);
|
||||||
return fetch;
|
return fetch;
|
||||||
}
|
}
|
||||||
@ -77,18 +78,15 @@ void GetArt(FETCH *fetch, int flag) {
|
|||||||
else if (strstr(fetch->os_name, "Arch") || strstr(fetch->os_name, "Artix"))
|
else if (strstr(fetch->os_name, "Arch") || strstr(fetch->os_name, "Artix"))
|
||||||
SetArt(fetch, sizeof(Arch), "pacman -Qq | wc -l", Arch, "\033[0;34m", flag);
|
SetArt(fetch, sizeof(Arch), "pacman -Qq | wc -l", Arch, "\033[0;34m", flag);
|
||||||
|
|
||||||
else if (strstr(fetch->os_name, "PlainOs"))
|
|
||||||
SetArt(fetch, sizeof(PlainOs), NULL, PlainOs, "\033[37m", flag);
|
|
||||||
|
|
||||||
else if (strstr(fetch->os_name, "OpenBSD"))
|
|
||||||
SetArt(fetch, sizeof(OpenBSD), "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '", OpenBSD, "\033[1;33m", flag);
|
|
||||||
|
|
||||||
else if (strstr(fetch->os_name, "Ubuntu"))
|
else if (strstr(fetch->os_name, "Ubuntu"))
|
||||||
SetArt(fetch, sizeof(Ubuntu), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Ubuntu, "\033[1;33m", flag);
|
SetArt(fetch, sizeof(Ubuntu), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Ubuntu, "\033[1;33m", flag);
|
||||||
|
|
||||||
else if (strstr(fetch->os_name, "Mint"))
|
else if (strstr(fetch->os_name, "Mint"))
|
||||||
SetArt(fetch, sizeof(Lmint), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Lmint, "\033[1;32m", flag);
|
SetArt(fetch, sizeof(Lmint), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Lmint, "\033[1;32m", flag);
|
||||||
|
|
||||||
|
else if (strstr(fetch->os_name, "Manana"))
|
||||||
|
SetArt(fetch, sizeof(Manana), "pacman -Qq | wc -l", Manana, "\033[1;32m", flag);
|
||||||
|
|
||||||
else if (!chdir("/system") && !strcmp(fetch->os_name, "Linux"))
|
else if (!chdir("/system") && !strcmp(fetch->os_name, "Linux"))
|
||||||
SetArt(fetch, sizeof(Android), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Android, "\033[32m", flag);
|
SetArt(fetch, sizeof(Android), "dpkg -l | tail -n+6 | wc -l | tr -d ' '", Android, "\033[32m", flag);
|
||||||
|
|
||||||
@ -96,33 +94,32 @@ void GetArt(FETCH *fetch, int flag) {
|
|||||||
SetArt(fetch, sizeof(Unknow), NULL, Unknow, "\033[1;36m", flag);
|
SetArt(fetch, sizeof(Unknow), NULL, Unknow, "\033[1;36m", flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetKernel(const char *title, const FETCH fetch) {
|
int GetKernel(struct par par, const FETCH fetch) {
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.uts.release);
|
printf("%s%s", FONT_COLOR, fetch.uts.release);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PrintOs(const char *title, const FETCH fetch) {
|
int PrintOs(struct par par, const FETCH fetch) {
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.os_name);
|
printf("%s%s", FONT_COLOR, fetch.os_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Blank(const char *title, const FETCH fetch) {
|
int Blank(struct par par, const FETCH fetch) {
|
||||||
printf("%s%s%s", fetch.color, title, fetch.font_color);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetUser(const char *title, const FETCH fetch) {
|
int GetUser(struct par par, const FETCH fetch) {
|
||||||
UNUSED(fetch);
|
UNUSED(fetch);
|
||||||
|
|
||||||
struct passwd *pw = getpwuid(geteuid());
|
struct passwd *pw = getpwuid(geteuid());
|
||||||
if (pw == 0)
|
if (pw == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, pw->pw_name);
|
printf("%s%s", FONT_COLOR, pw->pw_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetUptime(const char *title, const FETCH fetch) {
|
int GetUptime(struct par par, const FETCH fetch) {
|
||||||
#ifdef CLOCK
|
#ifdef CLOCK
|
||||||
struct timespec uptime;
|
struct timespec uptime;
|
||||||
if (clock_gettime(CLOCK, &uptime) == -1)
|
if (clock_gettime(CLOCK, &uptime) == -1)
|
||||||
@ -133,10 +130,10 @@ int GetUptime(const char *title, const FETCH fetch) {
|
|||||||
int mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
|
int mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
|
||||||
|
|
||||||
if (days > 0)
|
if (days > 0)
|
||||||
printf("%s%s%s%d days", fetch.color, title, fetch.font_color, days);
|
printf("%s%d days", FONT_COLOR, days);
|
||||||
|
|
||||||
else
|
else
|
||||||
printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins);
|
printf("%s%dh %dm", FONT_COLOR, hours, mins);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
@ -144,12 +141,12 @@ int GetUptime(const char *title, const FETCH fetch) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetArch(const char *title, const FETCH fetch) {
|
int GetArch(struct par par, const FETCH fetch) {
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, fetch.uts.machine);
|
printf("%s%s", FONT_COLOR, fetch.uts.machine);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetShell(const char *title, const FETCH fetch) {
|
int GetShell(struct par par, const FETCH fetch) {
|
||||||
char *shell = getenv("SHELL");
|
char *shell = getenv("SHELL");
|
||||||
if (shell == NULL)
|
if (shell == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
@ -158,11 +155,11 @@ int GetShell(const char *title, const FETCH fetch) {
|
|||||||
if (splt == NULL)
|
if (splt == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, splt + 1);
|
printf("%s%s", FONT_COLOR, splt + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetPkg(const char *title, const FETCH fetch) {
|
int GetPkg(struct par par, const FETCH fetch) {
|
||||||
if (fetch.pkg_cmd == NULL)
|
if (fetch.pkg_cmd == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -170,7 +167,7 @@ int GetPkg(const char *title, const FETCH fetch) {
|
|||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("%s%s%s", fetch.color, title, fetch.font_color);
|
printf("%s", FONT_COLOR);
|
||||||
|
|
||||||
int ch;
|
int ch;
|
||||||
while ((ch = getc(fp))) {
|
while ((ch = getc(fp))) {
|
||||||
@ -184,22 +181,22 @@ int GetPkg(const char *title, const FETCH fetch) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetMem(const char *title, const FETCH fetch) {
|
int GetMem(struct par par, const FETCH fetch) {
|
||||||
FILE *fp = fopen("/proc/meminfo", "r");
|
FILE *fp = fopen("/proc/meminfo", "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
off_t free = 0, total = 0, cached = 0, buffer = 0, unused = 0;
|
off_t free = 0, total = 0, cached = 0, buffer = 0, unused = 0;
|
||||||
if (fscanf(fp, "MemTotal: %ju kB\nMemFree: %ju kB\nMemAvailable: %ju kB\nBuffers: %ju kB\nCached: %ju kB", &total, &free, &unused, &buffer, &cached) < 0)
|
if (fscanf(fp, "MemTotal: %jd kB\nMemFree: %jd kB\nMemAvailable: %jd kB\nBuffers: %jd kB\nCached: %jd kB", &total, &free, &unused, &buffer, &cached) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - (cached + free + buffer)) / 1024, (uintmax_t)total / 1024);
|
printf("%s%lumb / %lumb", FONT_COLOR, (uintmax_t)(total - (cached + free + buffer)) / 1024, (uintmax_t)total / 1024);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetModel(const char *title, const FETCH fetch) {
|
int GetModel(struct par par, const FETCH fetch) {
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
for (size_t i = 0; i < sizeof(MODELS) / sizeof(char *); i++) {
|
for (size_t i = 0; i < sizeof(MODELS) / sizeof(char *); i++) {
|
||||||
fp = fopen(MODELS[i], "r");
|
fp = fopen(MODELS[i], "r");
|
||||||
@ -219,30 +216,31 @@ int GetModel(const char *title, const FETCH fetch) {
|
|||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
|
||||||
printf("%s%s%s%.25s", fetch.color, title, fetch.font_color, model_buffer);
|
printf("%s%.25s", FONT_COLOR, model_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetHostname(const char *title, const FETCH fetch) {
|
int GetHostname(struct par par, const FETCH fetch) {
|
||||||
char hostname[HOST_NAME_MAX + 1];
|
char hostname[HOST_NAME_MAX + 1];
|
||||||
if (gethostname(hostname, sizeof(hostname)) < 0)
|
if (gethostname(hostname, sizeof(hostname)) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("%s%s%s%s", fetch.color, title, fetch.font_color, hostname);
|
printf("%s%s", FONT_COLOR, hostname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetAVG(const char *title, const FETCH fetch) {
|
int GetAVG(struct par par, const FETCH fetch) {
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
double avg[3] = {0, 0, 0};
|
double avg[3] = {0, 0, 0};
|
||||||
|
|
||||||
if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0)
|
if (getloadavg(avg, sizeof(avg) / sizeof(avg[0])) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
printf("%s%s%s%.2f %.2f %.2f", fetch.color, title, fetch.font_color, avg[0], avg[1], avg[2]);
|
printf("%s%.2f %.2f %.2f", FONT_COLOR, avg[0], avg[1], avg[2]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -251,67 +249,15 @@ int GetAVG(const char *title, const FETCH fetch) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBar(int cur, int max) {
|
int Execute(struct par par, const FETCH fetch) {
|
||||||
int bar = max / BAR_WIDTH;
|
if (par.str2 == NULL)
|
||||||
|
|
||||||
#ifdef FIRA_CODE
|
|
||||||
char *start = "";
|
|
||||||
if (cur * bar > 0)
|
|
||||||
start = "";
|
|
||||||
|
|
||||||
char *end = "";
|
|
||||||
if (cur < max)
|
|
||||||
end = "";
|
|
||||||
|
|
||||||
char *bar_filled = "";
|
|
||||||
char *bar_void = "";
|
|
||||||
|
|
||||||
#else
|
|
||||||
char *start = "[";
|
|
||||||
char *end = "]";
|
|
||||||
char *bar_filled = "#";
|
|
||||||
char *bar_void = ".";
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("%s", start);
|
|
||||||
|
|
||||||
for (int i = 0; i < BAR_WIDTH; i++) {
|
|
||||||
if (i * bar < cur)
|
|
||||||
printf("%s", bar_filled);
|
|
||||||
|
|
||||||
else
|
|
||||||
printf("%s", bar_void);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s", end);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetBattery(const char *title, const FETCH fetch) {
|
|
||||||
if (BATT_NAME == NULL)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
FILE *fp = fopen(BATT_NAME, "r");
|
FILE *fp = popen(par.str2, "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int capacity = 0;
|
printf("%s", FONT_COLOR);
|
||||||
if (fscanf(fp, "%d", &capacity) < 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
printf("%s%s%s", fetch.color, title, fetch.font_color);
|
|
||||||
DrawBar(capacity, 100);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Execute(const char *title, const FETCH fetch) {
|
|
||||||
FILE *fp = popen(title, "r");
|
|
||||||
if (fp == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
printf("%s", fetch.font_color);
|
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getc(fp))) {
|
while ((c = getc(fp))) {
|
||||||
@ -324,9 +270,3 @@ int Execute(const char *title, const FETCH fetch) {
|
|||||||
pclose(fp);
|
pclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int eBlank(const char *title, const FETCH fetch) {
|
|
||||||
printf("%s%s%s", fetch.color, title, fetch.font_color);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
18
src/main.c
18
src/main.c
@ -1,8 +1,8 @@
|
|||||||
#define _MAIN_H
|
#define _MAIN_C
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "fetch.h"
|
#include "structs.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@ -37,24 +37,28 @@ int main(int argc, char **argv) {
|
|||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (size_t i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) {
|
for (size_t i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) {
|
||||||
/* Print ascii logo */
|
/* Print ascii logo */
|
||||||
if (j < fetch.logo_size && !flag && !l_flag)
|
if (j < fetch.logo_size && !l_flag)
|
||||||
printf("%s", fetch.logo[j]);
|
printf("%s", fetch.logo[j]);
|
||||||
|
|
||||||
else if (j >= fetch.logo_size && !flag && !l_flag)
|
else if (j >= fetch.logo_size && !l_flag)
|
||||||
printf("%s", fetch.logo[fetch.logo_size - 1]);
|
printf("%s", fetch.logo[fetch.logo_size - 1]);
|
||||||
|
|
||||||
/* Function exec */
|
/* Function exec */
|
||||||
if (CONFIG[i].func(CONFIG[i].title, fetch)) {
|
printf("%s%s", fetch.color, CONFIG[i].par.str0);
|
||||||
|
if (CONFIG[i].func(CONFIG[i].par, fetch)) {
|
||||||
flag = 1;
|
flag = 1;
|
||||||
printf("\033[0m");
|
printf("%s%s", FONT_COLOR, ON_ERROR_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
flag = 0;
|
flag = 0;
|
||||||
|
if (CONFIG[i].par.str1 != NULL)
|
||||||
|
printf(CONFIG[i].par.str1, fetch.color);
|
||||||
|
}
|
||||||
|
|
||||||
j++;
|
j++;
|
||||||
printf("\033[0m\n");
|
printf("\033[0m\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (; j < fetch.logo_size; j++)
|
for (; j < fetch.logo_size; j++)
|
||||||
if (!l_flag)
|
if (!l_flag)
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
#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 BAR_WIDTH 10
|
|
||||||
/* Uncomment if you use firacode font */
|
|
||||||
/* #define FIRA_CODE */
|
|
||||||
|
|
||||||
/* Full path to capacity file */
|
|
||||||
/* Example: /sys/class/power_supply/battery/capacity */
|
|
||||||
#define BATT_NAME NULL
|
|
||||||
|
|
||||||
#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},
|
|
||||||
{" batt ", GetBattery},
|
|
||||||
{" ", Blank},
|
|
||||||
{COLORS, Blank}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||||||
#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 BAR_WIDTH 10
|
|
||||||
/* Uncomment if you use firacode font */
|
|
||||||
/* #define FIRA_CODE */
|
|
||||||
|
|
||||||
/* Full path to capacity file */
|
|
||||||
/* Example: /sys/class/power_supply/battery/capacity */
|
|
||||||
#define BATT_NAME NULL
|
|
||||||
|
|
||||||
#ifdef _MAIN_H
|
|
||||||
PARAMETR CONFIG[] = {
|
|
||||||
{" ", Blank},
|
|
||||||
{"\033[1;31m ", PrintOs},
|
|
||||||
{" ", GetKernel},
|
|
||||||
{" ", GetUptime},
|
|
||||||
{" ", GetPkg},
|
|
||||||
{" ", Blank},
|
|
||||||
{COLORS, Blank}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||||||
#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 BAR_WIDTH 10
|
|
||||||
/* Uncomment if you use firacode font */
|
|
||||||
/* #define FIRA_CODE */
|
|
||||||
|
|
||||||
/* Full path to capacity file */
|
|
||||||
/* Example: /sys/class/power_supply/battery/capacity */
|
|
||||||
#define BATT_NAME NULL
|
|
||||||
|
|
||||||
#ifdef _MAIN_H
|
|
||||||
PARAMETR CONFIG[] = {
|
|
||||||
{" ", Blank},
|
|
||||||
{" arch ", GetArch},
|
|
||||||
{" upt ", GetUptime},
|
|
||||||
{" pkgs ", GetPkg},
|
|
||||||
{" os ", PrintOs},
|
|
||||||
{" ", Blank},
|
|
||||||
{COLORS, Blank}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||||||
#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 BAR_WIDTH 10
|
|
||||||
/* Uncomment if you use firacode font */
|
|
||||||
/* #define FIRA_CODE */
|
|
||||||
|
|
||||||
/* Full path to capacity file */
|
|
||||||
/* Example: /sys/class/power_supply/battery/capacity */
|
|
||||||
#define BATT_NAME NULL
|
|
||||||
|
|
||||||
#ifdef _MAIN_H
|
|
||||||
PARAMETR CONFIG[] = {
|
|
||||||
{" pc: ", Blank},
|
|
||||||
{" - mem ", GetMem},
|
|
||||||
{" - kr ", GetKernel},
|
|
||||||
{" - ar ", GetArch},
|
|
||||||
{" - mod ", GetModel},
|
|
||||||
{" - ht ", GetHostname},
|
|
||||||
{" ", Blank},
|
|
||||||
{" - info: ", Blank},
|
|
||||||
{" - os ", PrintOs},
|
|
||||||
{" - shl ", GetShell},
|
|
||||||
{" - pkg ", GetPkg},
|
|
||||||
{" - up ", GetUptime},
|
|
||||||
{" - avg ", GetAVG},
|
|
||||||
{" - bat ", GetBattery},
|
|
||||||
{" ", Blank},
|
|
||||||
{COLORS, Blank}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user