GetMem fix

This commit is contained in:
Your Name 2023-12-15 18:02:11 +03:00
parent 14fce9786e
commit 8a789784cc
3 changed files with 28 additions and 30 deletions

View File

@ -13,16 +13,16 @@ typedef struct {
#define PC_CHAR "%"
static PARAMETR CONFIG[] = {
{" OS ", PrintOs},
{" KERNEL ", GetKernel},
{" USER ", GetUser},
{" UPTIME ", GetUptime},
{" ARCH ", GetArch},
{" SHELL ", GetShell},
{" PKGS ", GetPkg},
{" RAM ", GetMem},
{" ", Blank},
{" COLORS ", PrintColors}
{" OS ", PrintOs},
{" KERNEL ", GetKernel},
{" USER ", GetUser},
{" UPTIME ", GetUptime},
{" ARCH ", GetArch},
{" SHELL ", GetShell},
{" PKGS ", GetPkg},
{" RAM ", GetMem},
{" ", Blank},
{" COLORS ", PrintColors}
};
#endif

View File

@ -5,11 +5,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#if defined(__LINUX__) || defined(__ANDROID__)
#include <sys/sysinfo.h>
#endif
#include "fetch.h"
#include "config.h"
#include "logo.h"
@ -124,17 +119,20 @@ int GetUser(const char *title, const FETCH fetch) {
}
int GetUptime(const char *title, const FETCH fetch) {
int hours = 0;
int mins = 0;
#ifdef CLOCK
struct timespec uptime;
clock_gettime(CLOCK, &uptime);
hours = uptime.tv_sec / 3600;
mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
int days = uptime.tv_sec / 86400;
int hours = uptime.tv_sec / 3600;
int mins = (uptime.tv_sec / 60) - (uptime.tv_sec / 3600 * 60);
if (days > 0)
printf("%s%s%s%dd %dh %dm", fetch.color, title, fetch.font_color, days, hours, mins);
else
printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins);
printf("%s%s%s%dh %dm", fetch.color, title, fetch.font_color, hours, mins);
return 0;
#endif
@ -182,17 +180,17 @@ int GetPkg(const char *title, const FETCH fetch) {
}
int GetMem(const char *title, const FETCH fetch) {
#if defined(__LINUX__) || defined(__ANDROID__)
struct sysinfo sinfo;
if (sysinfo(&sinfo) < 0)
unsigned int free = 0, cache = 0, total = 0, unused;
UNUSED(unused);
FILE *fp = fopen("/proc/meminfo", "r");
if (fp == NULL)
return 1;
printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, sinfo.freeram / 1048576, sinfo.totalram / 1048576);
fscanf(fp, "MemTotal: %u kB\nMemFree: %u kB\nMemAvailable: %u kB\nBuffers: %u kB\nCached: %u kB", &total, &free, &unused, &unused, &cache);
#else
printf("%s%s%s0mb / 0mb", fetch.color, title, fetch.font_color);
#endif
printf("%s%s%s%umb / %umb", fetch.color, title, fetch.font_color, (free + cache) / 1024, total / 1024);
fclose(fp);
return 0;
}

View File

@ -23,6 +23,6 @@ int main(void) {
for (; i < fetch.logo_size; i++)
printf("%s\n", fetch.logo[i]);
printf("\033[0m\n");
printf("\033[0m");
return 0;
}