mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
refactored internal state keeping
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintBattery(FFstate* state)
|
||||
void ffPrintBattery(FFinstance* instance)
|
||||
{
|
||||
int scanned;
|
||||
|
||||
FILE* fullFile = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
|
||||
if(fullFile == NULL)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_full\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_full\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
uint32_t full;
|
||||
scanned = fscanf(fullFile, "%u", &full);
|
||||
if(scanned != 1)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fscanf(fullFile, \"%u\", &full) != 1");
|
||||
ffPrintError(instance, "Battery", "fscanf(fullFile, \"%u\", &full) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(fullFile);
|
||||
@@ -22,14 +22,14 @@ void ffPrintBattery(FFstate* state)
|
||||
FILE* nowFile = fopen("/sys/class/power_supply/BAT0/charge_now", "r");
|
||||
if(nowFile == NULL)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_now\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Battery", "fopen(\"/sys/class/power_supply/BAT0/charge_now\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
uint32_t now;
|
||||
scanned = fscanf(nowFile, "%u", &now);
|
||||
if(scanned != 1)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fscanf(nowFile, \"%u\", &now) != 1");
|
||||
ffPrintError(instance, "Battery", "fscanf(nowFile, \"%u\", &now) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(nowFile);
|
||||
@@ -37,20 +37,20 @@ void ffPrintBattery(FFstate* state)
|
||||
FILE* statusFile = fopen("/sys/class/power_supply/BAT0/status", "r");
|
||||
if(statusFile == NULL)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fopen(\"/sys/class/power_supply/BAT0/status\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Battery", "fopen(\"/sys/class/power_supply/BAT0/status\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
char status[256];
|
||||
scanned = fscanf(statusFile, "%s", status);
|
||||
if(scanned != 1)
|
||||
{
|
||||
ffPrintError(state, "Battery", "fscanf(statusFile, \"%u\", &status) != 1");
|
||||
ffPrintError(instance, "Battery", "fscanf(statusFile, \"%u\", &status) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(statusFile);
|
||||
|
||||
uint32_t percentage = (now / (double) full) * 100;
|
||||
|
||||
ffPrintLogoAndKey(state, "Battery");
|
||||
ffPrintLogoAndKey(instance, "Battery");
|
||||
printf("%u%% [%s]\n", percentage, status);
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintBreak(FFstate* state)
|
||||
void ffPrintBreak(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintLogoLine(instance);
|
||||
putchar('\n');
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintColors(FFstate* state)
|
||||
void ffPrintColors(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
printf("\033[4%dm ", i);
|
||||
|
||||
puts("\033[0m");
|
||||
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
for(uint8_t i = 8; i < 16; i++)
|
||||
printf("\033[48;5;%dm ", i);
|
||||
|
||||
+6
-8
@@ -1,31 +1,29 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
void ffPrintCPU(FFstate* state)
|
||||
void ffPrintCPU(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "CPU"))
|
||||
if(ffPrintCachedValue(instance, "CPU"))
|
||||
return;
|
||||
|
||||
char name[256];
|
||||
ffParsePropFile("/proc/cpuinfo", "model name%*s %[^\n]", name);
|
||||
if(name[0] == '\0')
|
||||
{
|
||||
ffPrintError(state, "CPU", "\"model name%*s %[^\\n]\" not found in \"/proc/cpuinfo\"");
|
||||
ffPrintError(instance, "CPU", "\"model name%*s %[^\\n]\" not found in \"/proc/cpuinfo\"");
|
||||
return;
|
||||
}
|
||||
|
||||
FILE* frequencyFile = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
|
||||
if(frequencyFile == NULL)
|
||||
{
|
||||
ffPrintError(state, "CPU", "fopen(\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq\", \"r\") == NULL");
|
||||
ffPrintError(instance, "CPU", "fopen(\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
uint32_t frequency;
|
||||
int scanned = fscanf(frequencyFile, "%u", &frequency);
|
||||
if(scanned != 1)
|
||||
{
|
||||
ffPrintError(state, "CPU", "fscanf(frequencyFile, \"%s\", frequency) != 1");
|
||||
ffPrintError(instance, "CPU", "fscanf(frequencyFile, \"%s\", frequency) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(frequencyFile);
|
||||
@@ -36,5 +34,5 @@ void ffPrintCPU(FFstate* state)
|
||||
char value[1024];
|
||||
sprintf(value, "%s (%i) @ %.9gGHz", name, get_nprocs(), ghz);
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "CPU", value);
|
||||
ffPrintAndSaveCachedValue(instance, "CPU", value);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
static void printKDE()
|
||||
{
|
||||
@@ -16,16 +15,16 @@ static void printKDE()
|
||||
printf("KDE Plasma %s", version);
|
||||
}
|
||||
|
||||
void ffPrintDesktopEnvironment(FFstate* state)
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
const char* currentDesktop = getenv("XDG_CURRENT_DESKTOP");
|
||||
if(currentDesktop == NULL)
|
||||
{
|
||||
ffPrintError(state, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
|
||||
ffPrintError(instance, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(state, "DE");
|
||||
ffPrintLogoAndKey(instance, "DE");
|
||||
|
||||
if(strcmp(currentDesktop, "KDE") == 0)
|
||||
printKDE();
|
||||
|
||||
+3
-3
@@ -2,13 +2,13 @@
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
void ffPrintDisk(FFstate* state)
|
||||
void ffPrintDisk(FFinstance* instance)
|
||||
{
|
||||
struct statvfs fs;
|
||||
int ret = statvfs("/", &fs);
|
||||
if(ret != 0)
|
||||
{
|
||||
ffPrintError(state, "Disk (/)", "statvfs(\"/\", &fs) != 0");
|
||||
ffPrintError(instance, "Disk (/)", "statvfs(\"/\", &fs) != 0");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@ void ffPrintDisk(FFstate* state)
|
||||
const uint32_t percentage = (used / (double) total) * 100.0;
|
||||
|
||||
|
||||
ffPrintLogoAndKey(state, "Disk (/)");
|
||||
ffPrintLogoAndKey(instance, "Disk (/)");
|
||||
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
|
||||
}
|
||||
+6
-6
@@ -16,13 +16,13 @@ static void parseFont(char* font, char* buffer)
|
||||
sprintf(buffer, "%s (%spt)", name, size);
|
||||
}
|
||||
|
||||
void ffPrintFont(FFstate* state)
|
||||
void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(state, ".config/kdeglobals", "font=%[^\n]", plasma);
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "font=%[^\n]", plasma);
|
||||
|
||||
char gtk2[256];
|
||||
ffParsePropFileHome(state, ".gtkrc-2.0", "gtk-font-name=\"%[^\"]+", gtk2);
|
||||
ffParsePropFileHome(instance, ".gtkrc-2.0", "gtk-font-name=\"%[^\"]+", gtk2);
|
||||
|
||||
char gtk2Pretty[256];
|
||||
if(gtk2[0] == '\0')
|
||||
@@ -31,7 +31,7 @@ void ffPrintFont(FFstate* state)
|
||||
parseFont(gtk2, gtk2Pretty);
|
||||
|
||||
char gtk3[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-3.0/settings.ini", "gtk-font-name=%[^\n]", gtk3);
|
||||
ffParsePropFileHome(instance, ".config/gtk-3.0/settings.ini", "gtk-font-name=%[^\n]", gtk3);
|
||||
|
||||
char gtk3Pretty[256];
|
||||
if(gtk3[0] == '\0')
|
||||
@@ -40,7 +40,7 @@ void ffPrintFont(FFstate* state)
|
||||
parseFont(gtk3, gtk3Pretty);
|
||||
|
||||
char gtk4[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-4.0/settings.ini", "gtk-font-name=%[^\n]", gtk4);
|
||||
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-font-name=%[^\n]", gtk4);
|
||||
|
||||
char gtk4Pretty[256];
|
||||
if(gtk4Pretty[0] == '\0')
|
||||
@@ -48,7 +48,7 @@ void ffPrintFont(FFstate* state)
|
||||
else
|
||||
parseFont(gtk4, gtk4Pretty);
|
||||
|
||||
ffPrintLogoAndKey(state, "Font");
|
||||
ffPrintLogoAndKey(instance, "Font");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
{
|
||||
|
||||
+5
-5
@@ -3,12 +3,12 @@
|
||||
#include <string.h>
|
||||
#include <pci/pci.h>
|
||||
|
||||
static void handleGPU(FFstate* state, struct pci_access* pacc, struct pci_dev* dev, uint16_t counter)
|
||||
static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, uint16_t counter)
|
||||
{
|
||||
char key[8];
|
||||
sprintf(key, "GPU%hu", counter);
|
||||
|
||||
if(ffPrintCachedValue(state, key))
|
||||
if(ffPrintCachedValue(instance, key))
|
||||
return;
|
||||
|
||||
char gpu[1024];
|
||||
@@ -31,10 +31,10 @@ static void handleGPU(FFstate* state, struct pci_access* pacc, struct pci_dev* d
|
||||
|
||||
strcat(gpu, name);
|
||||
|
||||
ffPrintAndSaveCachedValue(state, key, gpu);
|
||||
ffPrintAndSaveCachedValue(instance, key, gpu);
|
||||
}
|
||||
|
||||
void ffPrintGPU(FFstate* state)
|
||||
void ffPrintGPU(FFinstance* instance)
|
||||
{
|
||||
uint16_t counter = 0;
|
||||
|
||||
@@ -54,7 +54,7 @@ void ffPrintGPU(FFstate* state)
|
||||
strcmp("3D controller", class) == 0 ||
|
||||
strcmp("Display controller", class) == 0 )
|
||||
{
|
||||
handleGPU(state, pacc, dev, counter++);
|
||||
handleGPU(instance, pacc, dev, counter++);
|
||||
}
|
||||
}
|
||||
pci_cleanup(pacc);
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ffPrintHost(FFstate* state)
|
||||
void ffPrintHost(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "Host"))
|
||||
if(ffPrintCachedValue(instance, "Host"))
|
||||
return;
|
||||
|
||||
char host[1024];
|
||||
@@ -12,12 +12,12 @@ void ffPrintHost(FFstate* state)
|
||||
FILE* nameFile = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
|
||||
if(nameFile == NULL)
|
||||
{
|
||||
ffPrintError(state, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
if(fscanf(nameFile, "%[^\n]", host) != 1)
|
||||
{
|
||||
ffPrintError(state, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
|
||||
ffPrintError(instance, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(nameFile);
|
||||
@@ -31,5 +31,5 @@ void ffPrintHost(FFstate* state)
|
||||
fclose(versionFile);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "Host", host);
|
||||
ffPrintAndSaveCachedValue(instance, "Host", host);
|
||||
}
|
||||
+6
-6
@@ -2,27 +2,27 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ffPrintIcons(FFstate* state)
|
||||
void ffPrintIcons(FFinstance* instance)
|
||||
{
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(state, ".config/kdeglobals", "Theme=%[^\n]", plasma);
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "Theme=%[^\n]", plasma);
|
||||
|
||||
char gtk2[256];
|
||||
ffParsePropFileHome(state, ".gtkrc-2.0", "gtk-icon-theme-name=\"%[^\"]+", gtk2);
|
||||
ffParsePropFileHome(instance, ".gtkrc-2.0", "gtk-icon-theme-name=\"%[^\"]+", gtk2);
|
||||
if(gtk2[0] == '\0')
|
||||
strcpy(gtk2, "Adwaita");
|
||||
|
||||
char gtk3[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-3.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk3);
|
||||
ffParsePropFileHome(instance, ".config/gtk-3.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk3);
|
||||
if(gtk3[0] == '\0')
|
||||
strcpy(gtk3, "Adwaita");
|
||||
|
||||
char gtk4[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-4.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk4);
|
||||
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk4);
|
||||
if(gtk4[0] == '\0')
|
||||
strcpy(gtk4, "Adwaita");
|
||||
|
||||
ffPrintLogoAndKey(state, "Icons");
|
||||
ffPrintLogoAndKey(instance, "Icons");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintKernel(FFstate* state)
|
||||
void ffPrintKernel(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(state, "Kernel");
|
||||
printf("%s\n", state->utsname.release);
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
printf("%s\n", instance->state.utsname.release);
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintLocale(FFstate* state)
|
||||
void ffPrintLocale(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "Locale"))
|
||||
if(ffPrintCachedValue(instance, "Locale"))
|
||||
return;
|
||||
|
||||
char locale[256];
|
||||
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", locale);
|
||||
if(locale[0] == '\0')
|
||||
{
|
||||
ffPrintError(state, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
|
||||
ffPrintError(instance, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "Locale", locale);
|
||||
ffPrintAndSaveCachedValue(instance, "Locale", locale);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
// Impl by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
|
||||
void ffPrintMemory(FFstate* state)
|
||||
void ffPrintMemory(FFinstance* instance)
|
||||
{
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL) {
|
||||
ffPrintError(state, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ void ffPrintMemory(FFstate* state)
|
||||
uint32_t total_mem = total / 1024;
|
||||
uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100);
|
||||
|
||||
ffPrintLogoAndKey(state, "Memory");
|
||||
ffPrintLogoAndKey(instance, "Memory");
|
||||
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
|
||||
}
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintOS(FFstate* state)
|
||||
void ffPrintOS(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "OS"))
|
||||
if(ffPrintCachedValue(instance, "OS"))
|
||||
return;
|
||||
|
||||
char name[256];
|
||||
ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name);
|
||||
if(name[0] == '\0')
|
||||
{
|
||||
ffPrintError(state, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
|
||||
ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
|
||||
return;
|
||||
}
|
||||
|
||||
char os[1024];
|
||||
sprintf(os, "%s %s", name, state->utsname.machine);
|
||||
sprintf(os, "%s %s", name, instance->state.utsname.machine);
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "OS", os);
|
||||
ffPrintAndSaveCachedValue(instance, "OS", os);
|
||||
}
|
||||
@@ -31,9 +31,9 @@ static void printPacmanPackages()
|
||||
printf("%i (pacman) ", nums);
|
||||
}
|
||||
|
||||
void ffPrintPackages(FFstate* state)
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(state, "Packages");
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
printPacmanPackages();
|
||||
putchar('\n');
|
||||
}
|
||||
@@ -34,29 +34,29 @@ short getCurrentRate(Display* display)
|
||||
return currentRate;
|
||||
}
|
||||
|
||||
void ffPrintResolution(FFstate* state)
|
||||
void ffPrintResolution(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "Resolution"))
|
||||
if(ffPrintCachedValue(instance, "Resolution"))
|
||||
return;
|
||||
|
||||
void* x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
if(x11 == NULL)
|
||||
{
|
||||
ffPrintError(state, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
ffPrintError(instance, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
Display*(*ffXOpenDisplay)(const char*) = dlsym(x11, "XOpenDisplay");
|
||||
if(ffXOpenDisplay == NULL)
|
||||
{
|
||||
ffPrintError(state, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
||||
ffPrintError(instance, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
Display* display = ffXOpenDisplay(NULL);
|
||||
if(display == NULL)
|
||||
{
|
||||
ffPrintError(state, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
||||
ffPrintError(instance, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,5 +73,5 @@ void ffPrintResolution(FFstate* state)
|
||||
else
|
||||
sprintf(resolution, "%ix%i @ %dHz", screen->width, screen->height, currentRate);
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "Resolution", resolution);
|
||||
ffPrintAndSaveCachedValue(instance, "Resolution", resolution);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintSeperator(FFstate* state)
|
||||
void ffPrintSeperator(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
for(uint8_t i = 0; i < state->titleLength; i++)
|
||||
for(uint8_t i = 0; i < instance->config.titleLength; i++)
|
||||
putchar('-');
|
||||
putchar('\n');
|
||||
}
|
||||
+4
-4
@@ -2,15 +2,15 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ffPrintShell(FFstate* state)
|
||||
void ffPrintShell(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(state, "Shell"))
|
||||
if(ffPrintCachedValue(instance, "Shell"))
|
||||
return;
|
||||
|
||||
char* shellPath = getenv("SHELL");
|
||||
if(shellPath == NULL)
|
||||
{
|
||||
ffPrintError(state, "Shell", "getenv(\"SHELL\") == NULL");
|
||||
ffPrintError(instance, "Shell", "getenv(\"SHELL\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ void ffPrintShell(FFstate* state)
|
||||
else if(shellName[0] == '/')
|
||||
++shellName;
|
||||
|
||||
ffPrintAndSaveCachedValue(state, "Shell", shellName);
|
||||
ffPrintAndSaveCachedValue(instance, "Shell", shellName);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void printTerminalName(FFstate* state, const char* pid)
|
||||
void printTerminalName(FFinstance* instance, const char* pid)
|
||||
{
|
||||
char file[256];
|
||||
sprintf(file, "/proc/%s/stat", pid);
|
||||
@@ -12,7 +12,7 @@ void printTerminalName(FFstate* state, const char* pid)
|
||||
{
|
||||
char error[300];
|
||||
sprintf(error, "fopen(\"%s\", \"r\") == NULL", file);
|
||||
ffPrintError(state, "Terminal", error);
|
||||
ffPrintError(instance, "Terminal", error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ void printTerminalName(FFstate* state, const char* pid)
|
||||
char ppid[256];
|
||||
if(fscanf(stat, "%*s (%[^)])%*s%s", name, ppid) != 2)
|
||||
{
|
||||
ffPrintError(state, "Terminal", "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
|
||||
ffPrintError(instance, "Terminal", "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,11 +37,11 @@ void printTerminalName(FFstate* state, const char* pid)
|
||||
strcmp(name, "doas") == 0 ||
|
||||
strcmp(name, "strace") == 0 )
|
||||
{
|
||||
printTerminalName(state, ppid);
|
||||
printTerminalName(instance, ppid);
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(state, "Terminal");
|
||||
ffPrintLogoAndKey(instance, "Terminal");
|
||||
|
||||
if(
|
||||
strcmp(name, "systemd") == 0 ||
|
||||
@@ -56,9 +56,9 @@ void printTerminalName(FFstate* state, const char* pid)
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintTerminal(FFstate* state)
|
||||
void ffPrintTerminal(FFinstance* instance)
|
||||
{
|
||||
char ppid[256];
|
||||
sprintf(ppid, "%i", getppid());
|
||||
printTerminalName(state, ppid);
|
||||
printTerminalName(instance, ppid);
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,27 +2,27 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ffPrintTheme(FFstate* state)
|
||||
void ffPrintTheme(FFinstance* instance)
|
||||
{
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(state, ".config/kdeglobals", "Name=%[^\n]", plasma);
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "Name=%[^\n]", plasma);
|
||||
|
||||
char gtk2[256];
|
||||
ffParsePropFileHome(state, ".gtkrc-2.0", "gtk-theme-name=\"%[^\"]+", gtk2);
|
||||
ffParsePropFileHome(instance, ".gtkrc-2.0", "gtk-theme-name=\"%[^\"]+", gtk2);
|
||||
if(gtk2[0] == '\0')
|
||||
strcpy(gtk2, "Raleigh");
|
||||
|
||||
char gtk3[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-3.0/settings.ini", "gtk-theme-name=%[^\n]", gtk3);
|
||||
ffParsePropFileHome(instance, ".config/gtk-3.0/settings.ini", "gtk-theme-name=%[^\n]", gtk3);
|
||||
if(gtk3[0] == '\0')
|
||||
strcpy(gtk3, "Adwaita");
|
||||
|
||||
char gtk4[256];
|
||||
ffParsePropFileHome(state, ".config/gtk-4.0/settings.ini", "gtk-theme-name=%[^\n]", gtk4);
|
||||
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-theme-name=%[^\n]", gtk4);
|
||||
if(gtk4[0] == '\0')
|
||||
strcpy(gtk4, "Adwaita");
|
||||
|
||||
ffPrintLogoAndKey(state, "Theme");
|
||||
ffPrintLogoAndKey(instance, "Theme");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
|
||||
+4
-4
@@ -2,16 +2,16 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void ffPrintTitle(FFstate* state)
|
||||
void ffPrintTitle(FFinstance* instance)
|
||||
{
|
||||
char hostname[256];
|
||||
gethostname(hostname, 256);
|
||||
|
||||
state->titleLength = strlen(state->passwd->pw_name) + 1 + strlen(hostname);
|
||||
instance->config.titleLength = strlen(instance->state.passwd->pw_name) + 1 + strlen(hostname);
|
||||
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"@"FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"\n",
|
||||
state->color, state->passwd->pw_name, state->color, hostname
|
||||
instance->config.color, instance->state.passwd->pw_name, instance->config.color, hostname
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
void ffPrintUptime(FFstate* state)
|
||||
void ffPrintUptime(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(state, "Uptime");
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
|
||||
if(state->sysinfo.uptime < 60)
|
||||
if(instance->state.sysinfo.uptime < 60)
|
||||
{
|
||||
printf("%ld seconds\n", state->sysinfo.uptime);
|
||||
printf("%ld seconds\n", instance->state.sysinfo.uptime);
|
||||
return;
|
||||
}
|
||||
|
||||
int days = state->sysinfo.uptime / 86400;
|
||||
int hours = (state->sysinfo.uptime - (days * 86400)) / 3600;
|
||||
int minutes = (state->sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
|
||||
int days = instance->state.sysinfo.uptime / 86400;
|
||||
int hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
|
||||
int minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
|
||||
|
||||
if(days > 0)
|
||||
printf("%d day%s, ", days, days <= 1 ? "" : "s");
|
||||
|
||||
Reference in New Issue
Block a user