mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
format options for every output!
This commit is contained in:
+52
-64
@@ -5,59 +5,34 @@
|
||||
static void printBattery(FFinstance* instance, uint8_t index)
|
||||
{
|
||||
char manufactor[128];
|
||||
if(instance->config.batteryShowManufacturer)
|
||||
{
|
||||
char manufactorPath[42];
|
||||
sprintf(manufactorPath, "/sys/class/power_supply/BAT%i/manufacturer", index);
|
||||
ffGetFileContent(manufactorPath, manufactor, sizeof(manufactor));
|
||||
}
|
||||
else
|
||||
manufactor[0] = '\0';
|
||||
char manufactorPath[42];
|
||||
sprintf(manufactorPath, "/sys/class/power_supply/BAT%i/manufacturer", index);
|
||||
ffGetFileContent(manufactorPath, manufactor, sizeof(manufactor));
|
||||
|
||||
char model[128];
|
||||
if(instance->config.batteryShowModel)
|
||||
{
|
||||
char modelPath[40];
|
||||
sprintf(modelPath, "/sys/class/power_supply/BAT%i/model_name", index);
|
||||
ffGetFileContent(modelPath, model, sizeof(model));
|
||||
}
|
||||
else
|
||||
model[0] = '\0';
|
||||
char modelPath[40];
|
||||
sprintf(modelPath, "/sys/class/power_supply/BAT%i/model_name", index);
|
||||
ffGetFileContent(modelPath, model, sizeof(model));
|
||||
|
||||
char technology[32];
|
||||
if(instance->config.batteryShowTechnology)
|
||||
{
|
||||
char technologyPath[40];
|
||||
sprintf(technologyPath, "/sys/class/power_supply/BAT%i/technology", index);
|
||||
ffGetFileContent(technologyPath, technology, sizeof(technology));
|
||||
}
|
||||
else
|
||||
technology[0] = '\0';
|
||||
char technologyPath[40];
|
||||
sprintf(technologyPath, "/sys/class/power_supply/BAT%i/technology", index);
|
||||
ffGetFileContent(technologyPath, technology, sizeof(technology));
|
||||
|
||||
char capacity[32];
|
||||
if(instance->config.batteryShowCapacity)
|
||||
{
|
||||
char capacityPath[38];
|
||||
sprintf(capacityPath, "/sys/class/power_supply/BAT%i/capacity", index);
|
||||
ffGetFileContent(capacityPath, capacity, sizeof(capacity));
|
||||
}
|
||||
else
|
||||
capacity[0] = '\0';
|
||||
char capacityPath[38];
|
||||
sprintf(capacityPath, "/sys/class/power_supply/BAT%i/capacity", index);
|
||||
ffGetFileContent(capacityPath, capacity, sizeof(capacity));
|
||||
|
||||
char status[32];
|
||||
if(instance->config.batteryShowStatus)
|
||||
{
|
||||
char statusPath[36];
|
||||
sprintf(statusPath, "/sys/class/power_supply/BAT%i/status", index);
|
||||
ffGetFileContent(statusPath, status, sizeof(status));
|
||||
}
|
||||
else
|
||||
status[0] = '\0';
|
||||
char statusPath[36];
|
||||
sprintf(statusPath, "/sys/class/power_supply/BAT%i/status", index);
|
||||
ffGetFileContent(statusPath, status, sizeof(status));
|
||||
|
||||
char key[10];
|
||||
sprintf(key, "Battery %i", index);
|
||||
|
||||
if(manufactor[0] == '\0' && model[0] == '\0' && technology[0] == '\0' && capacity[0] == '\0' && status[0] == '\0')
|
||||
if(manufactor[0] == '\0' && model[0] == '\0' && technology[0] == '\0' && capacity[0] == '\0' && status[0] == '\0' && ffStrbufIsEmpty(&instance->config.batteryFormat))
|
||||
{
|
||||
ffPrintError(instance, key, "No file in /sys/class/power_supply/BAT0/ could be read or all battery options are disabled");
|
||||
return;
|
||||
@@ -65,37 +40,50 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
|
||||
if(instance->config.batteryFormat[0] != '\0')
|
||||
if(ffStrbufIsEmpty(&instance->config.batteryFormat))
|
||||
{
|
||||
printf(instance->config.batteryFormat, manufactor, model, technology, capacity, status);
|
||||
putchar('\n');
|
||||
return;
|
||||
}
|
||||
if(manufactor[0] != '\0')
|
||||
printf("%s ", manufactor);
|
||||
|
||||
if(manufactor[0] != '\0')
|
||||
printf("%s ", manufactor);
|
||||
if(model[0] != '\0')
|
||||
printf("%s ", model);
|
||||
|
||||
if(model[0] != '\0')
|
||||
printf("%s ", model);
|
||||
if(technology[0] != '\0')
|
||||
printf("(%s) ", technology);
|
||||
|
||||
if(technology[0] != '\0')
|
||||
printf("(%s) ", technology);
|
||||
|
||||
if(capacity[0] != '\0')
|
||||
{
|
||||
printf("[%s%%", capacity);
|
||||
|
||||
if(status[0] == '\0')
|
||||
puts("]");
|
||||
if(capacity[0] != '\0')
|
||||
{
|
||||
printf("[%s%%", capacity);
|
||||
|
||||
if(status[0] == '\0')
|
||||
puts("]");
|
||||
else
|
||||
printf("; %s]\n", status);
|
||||
}
|
||||
else
|
||||
printf("; %s]\n", status);
|
||||
{
|
||||
if(status[0] != '\0')
|
||||
printf("%s", status);
|
||||
else
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(status[0] != '\0')
|
||||
printf("%s", status);
|
||||
else
|
||||
putchar('\n');
|
||||
FFstrbuf battery;
|
||||
ffStrbufInit(&battery);
|
||||
|
||||
ffParseFormatString(&battery, &instance->config.batteryFormat, 5,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, manufactor},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, model},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, technology},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, capacity},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, status}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&battery, stdout);
|
||||
putchar('\n');
|
||||
ffStrbufDestroy(&battery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-3
@@ -31,8 +31,26 @@ void ffPrintCPU(FFinstance* instance)
|
||||
frequency /= 1000; //to MHz
|
||||
double ghz = (double) frequency / 1000.0; //to GHz
|
||||
|
||||
char value[1024];
|
||||
sprintf(value, "%s (%i) @ %.9gGHz", name, get_nprocs(), ghz);
|
||||
int numProcs = get_nprocs();
|
||||
|
||||
ffPrintLogoAndKey(instance, "CPU");
|
||||
|
||||
FFstrbuf cpu;
|
||||
ffStrbufInit(&cpu);
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.cpuFormat))
|
||||
{
|
||||
ffStrbufSetF(&cpu, "%s (%i) @ %.9gGHz", name, numProcs, ghz);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&cpu, &instance->config.cpuFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &numProcs},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &ghz}
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "CPU", value);
|
||||
ffPrintAndSaveCachedValue(instance, "CPU", cpu.chars);
|
||||
ffStrbufDestroy(&cpu);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
static void getKDE(FFstrbuf* name, FFstrbuf* version, FFstrbuf* type)
|
||||
{
|
||||
ffStrbufSetS(name, "KDE Plasma");
|
||||
|
||||
char versionBuf[256];
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=%[^\n]", versionBuf);
|
||||
|
||||
ffStrbufSetS(version, versionBuf);
|
||||
}
|
||||
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf sessionDesktop;
|
||||
ffStrbufInitS(&sessionDesktop, getenv("XDG_CURRENT_DESKTOP"));
|
||||
if(ffStrbufIsEmpty(&sessionDesktop))
|
||||
ffStrbufSetS(&sessionDesktop, getenv("XDG_SESSION_DESKTOP"));
|
||||
|
||||
FFstrbuf sessionVersion;
|
||||
ffStrbufInit(&sessionVersion);
|
||||
|
||||
FFstrbuf sessionType;
|
||||
ffStrbufInit(&sessionType);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&sessionDesktop, "KDE") == 0)
|
||||
getKDE(&sessionDesktop, &sessionVersion, &sessionType);
|
||||
|
||||
if(ffStrbufIsEmpty(&sessionType))
|
||||
{
|
||||
const char* xdgSessionType = getenv("XDG_SESSION_TYPE");
|
||||
if(strcasecmp(xdgSessionType, "wayland") == 0)
|
||||
ffStrbufSetS(&sessionType, "Wayland");
|
||||
else if(strcasecmp(xdgSessionType, "x11") == 0)
|
||||
ffStrbufSetS(&sessionType, "X11");
|
||||
else if(strcasecmp(xdgSessionType, "tty") == 0)
|
||||
ffStrbufSetS(&sessionType, "TTY");
|
||||
else if(strcasecmp(xdgSessionType, "mir") == 0)
|
||||
ffStrbufSetS(&sessionType, "Mir");
|
||||
else if(xdgSessionType != NULL)
|
||||
ffStrbufSetS(&sessionType, xdgSessionType);
|
||||
}
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.deFormat))
|
||||
{
|
||||
if(ffStrbufIsEmpty(&sessionDesktop) && ffStrbufIsEmpty(&sessionType))
|
||||
{
|
||||
ffPrintError(instance, "DE", "Neither DE nor Display Server could be determined");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "DE");
|
||||
|
||||
if(!ffStrbufIsEmpty(&sessionDesktop))
|
||||
{
|
||||
ffStrbufWriteTo(&sessionDesktop, stdout);
|
||||
|
||||
if(!ffStrbufIsEmpty(&sessionVersion))
|
||||
{
|
||||
putchar(' ');
|
||||
ffStrbufWriteTo(&sessionVersion, stdout);
|
||||
}
|
||||
|
||||
if(!ffStrbufIsEmpty(&sessionType))
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
if(!ffStrbufIsEmpty(&sessionType))
|
||||
printf("(%s)", sessionType.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "DE");
|
||||
|
||||
FFstrbuf de;
|
||||
ffStrbufInit(&de);
|
||||
|
||||
ffParseFormatString(&de, &instance->config.deFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionDesktop},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionVersion},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionType}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&de, stdout);
|
||||
ffStrbufDestroy(&de);
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
ffStrbufDestroy(&sessionType);
|
||||
ffStrbufDestroy(&sessionVersion);
|
||||
ffStrbufDestroy(&sessionDesktop);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
static void printKDE()
|
||||
{
|
||||
char version[256];
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=%[^\n]", version);
|
||||
if(version[0] == '\0')
|
||||
{
|
||||
printf("KDE Plasma ");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("KDE Plasma %s", version);
|
||||
}
|
||||
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
const char* currentDesktop = getenv("XDG_CURRENT_DESKTOP");
|
||||
if(currentDesktop == NULL)
|
||||
{
|
||||
ffPrintError(instance, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "DE");
|
||||
|
||||
if(strcasecmp(currentDesktop, "KDE") == 0)
|
||||
printKDE();
|
||||
else
|
||||
printf("%s", currentDesktop);
|
||||
|
||||
const char* sessionType = getenv("XDG_SESSION_TYPE");
|
||||
if(sessionType == NULL)
|
||||
putchar('\n');
|
||||
else if(strcasecmp(sessionType, "wayland") == 0)
|
||||
puts(" (Wayland)");
|
||||
else if(strcasecmp(sessionType, "x11") == 0)
|
||||
puts(" (X11)");
|
||||
else if(strcasecmp(sessionType, "tty") == 0)
|
||||
puts(" TTY");
|
||||
else if(strcasecmp(sessionType, "mir") == 0)
|
||||
puts(" (Mir)");
|
||||
else
|
||||
printf(" (%s)\n", sessionType);
|
||||
}
|
||||
+25
-7
@@ -12,14 +12,32 @@ void ffPrintDisk(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t GB = (1024 * 1024) * 1024;
|
||||
uint32_t GB = (1024 * 1024) * 1024;
|
||||
|
||||
const uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
|
||||
const uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
|
||||
const uint32_t used = total - available;
|
||||
const uint32_t percentage = (used / (double) total) * 100.0;
|
||||
uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
|
||||
uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
|
||||
uint32_t used = total - available;
|
||||
uint8_t percentage = (used / (double) total) * 100.0;
|
||||
|
||||
|
||||
ffPrintLogoAndKey(instance, "Disk (/)");
|
||||
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.diskFormat))
|
||||
{
|
||||
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf disk;
|
||||
ffStrbufInit(&disk);
|
||||
|
||||
ffParseFormatString(&disk, &instance->config.diskFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &percentage}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&disk, stdout);
|
||||
putchar('\n');
|
||||
ffStrbufDestroy(&disk);
|
||||
}
|
||||
}
|
||||
+27
-6
@@ -4,6 +4,12 @@ void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "font=%[^\n]", plasma);
|
||||
|
||||
char plasmaPretty[256];
|
||||
if(plasma[0] == '\0')
|
||||
strcpy(plasmaPretty, "Noto Sans (10pt)");
|
||||
else
|
||||
ffParseFont(plasma, plasmaPretty);
|
||||
|
||||
char gtk2[256];
|
||||
ffParsePropFileHome(instance, ".gtkrc-2.0", "gtk-font-name=\"%[^\"]+", gtk2);
|
||||
@@ -32,19 +38,34 @@ void ffPrintFont(FFinstance* instance)
|
||||
else
|
||||
ffParseFont(gtk4, gtk4Pretty);
|
||||
|
||||
FFstrbuf gtkPretty;
|
||||
ffStrbufInit(>kPretty);
|
||||
ffFormatGtkPretty(>kPretty, gtk2Pretty, gtk3Pretty, gtk4Pretty);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Font");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
if(ffStrbufIsEmpty(&instance->config.fontFormat))
|
||||
{
|
||||
printf("Noto Sans (10pt) [Plasma], ");
|
||||
printf("%s [Plasma], ", plasmaPretty);
|
||||
ffStrbufWriteTo(>kPretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
char plasmaPretty[256];
|
||||
ffParseFont(plasma, plasmaPretty);
|
||||
printf("%s [Plasma], ", plasmaPretty);
|
||||
FFstrbuf font;
|
||||
ffStrbufInit(&font);
|
||||
|
||||
ffParseFormatString(&font, &instance->config.fontFormat, 5,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasmaPretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2Pretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3Pretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4Pretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, >kPretty}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&font, stdout);
|
||||
ffStrbufDestroy(&font);
|
||||
}
|
||||
|
||||
ffPrintGtkPretty(gtk2Pretty, gtk3Pretty, gtk4Pretty);
|
||||
putchar('\n');
|
||||
ffStrbufDestroy(>kPretty);
|
||||
}
|
||||
+23
-9
@@ -11,32 +11,46 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_
|
||||
if(ffPrintCachedValue(instance, key))
|
||||
return;
|
||||
|
||||
char gpu[1024];
|
||||
FFstrbuf gpu;
|
||||
ffStrbufInit(&gpu);
|
||||
|
||||
char vendor[512];
|
||||
ffpci_lookup_name(pacc, vendor, sizeof(vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
|
||||
|
||||
char vendorPretty[512];
|
||||
if(strcasecmp(vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0)
|
||||
strcpy(vendorPretty, "AMD ATI");
|
||||
else
|
||||
strcpy(vendorPretty, vendor);
|
||||
|
||||
char name[512];
|
||||
ffpci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
|
||||
|
||||
if(strcasecmp(vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0)
|
||||
ffPrintLogoAndKey(instance, "GPU");
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.gpuFormat))
|
||||
{
|
||||
strcpy(gpu, "AMD ATI ");
|
||||
ffStrbufSetF(&gpu, "%s %s", vendorPretty, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(gpu, vendor);
|
||||
strcat(gpu, " ");
|
||||
ffParseFormatString(&gpu, &instance->config.gpuFormat, 2,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, vendorPretty},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name}
|
||||
);
|
||||
}
|
||||
|
||||
strcat(gpu, name);
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, key, gpu);
|
||||
ffPrintAndSaveCachedValue(instance, key, gpu.chars);
|
||||
ffStrbufDestroy(&gpu);
|
||||
}
|
||||
|
||||
void ffPrintGPU(FFinstance* instance)
|
||||
{
|
||||
void* pci = dlopen("libpci.so", RTLD_LAZY);
|
||||
void* pci;
|
||||
if(ffStrbufIsEmpty(&instance->config.libPCI))
|
||||
pci = dlopen("libpci.so", RTLD_LAZY);
|
||||
else
|
||||
pci = dlopen(instance->config.libPCI.chars, RTLD_LAZY);
|
||||
if(pci == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
|
||||
|
||||
+23
-16
@@ -12,33 +12,40 @@ void ffPrintHost(FFinstance* instance)
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", name, sizeof(name));
|
||||
|
||||
char version[256];
|
||||
if(instance->config.hostShowVersion || instance->config.hostFormat[0] != '\0')
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
|
||||
else
|
||||
version[0] = '\0';
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
|
||||
|
||||
char host[1024];
|
||||
|
||||
if(instance->config.hostFormat[0] != '\0')
|
||||
{
|
||||
snprintf(host, sizeof(host), instance->config.hostFormat, family, name, version);
|
||||
}
|
||||
else if(family[0] == '\0' && name[0] == '\0')
|
||||
if(family[0] == '\0' && name[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "Host", "neither family nor name could be determined");
|
||||
return;
|
||||
}else if(family[0] != '\0' && name[0] != '\0')
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "Host");
|
||||
|
||||
FFstrbuf host;
|
||||
ffStrbufInit(&host);
|
||||
|
||||
if(!ffStrbufIsEmpty(&instance->config.hostFormat))
|
||||
{
|
||||
snprintf(host, sizeof(host), "%s %s %s", family, name, instance->config.hostShowVersion ? version : "");
|
||||
ffParseFormatString(&host, &instance->config.hostFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, family},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, version}
|
||||
);
|
||||
}
|
||||
else if(family[0] != '\0' && name[0] != '\0')
|
||||
{
|
||||
ffStrbufSetF(&host, "%s %s %s", family, name, version);
|
||||
}
|
||||
else if(family[0] != '\0')
|
||||
{
|
||||
snprintf(host, sizeof(host), "%s %s", family, instance->config.hostShowVersion ? version : "");
|
||||
ffStrbufSetF(&host, "%s %s", family, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(host, sizeof(host), "%s %s", name, instance->config.hostShowVersion ? version : "");
|
||||
ffStrbufSetF(&host, "%s %s", name, version);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Host", host);
|
||||
ffPrintAndSaveCachedValue(instance, "Host", host.chars);
|
||||
ffStrbufDestroy(&host);
|
||||
}
|
||||
+32
-6
@@ -19,14 +19,40 @@ void ffPrintIcons(FFinstance* instance)
|
||||
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk4);
|
||||
if(gtk4[0] == '\0')
|
||||
strcpy(gtk4, "Adwaita");
|
||||
|
||||
|
||||
FFstrbuf gtkPretty;
|
||||
ffStrbufInit(>kPretty);
|
||||
ffFormatGtkPretty(>kPretty, gtk2, gtk3, gtk4);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Icons");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
else
|
||||
printf("%s [Plasma], ", plasma);
|
||||
if(ffStrbufIsEmpty(&instance->config.iconsFormat))
|
||||
{
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
else
|
||||
printf("%s [Plasma], ", plasma);
|
||||
|
||||
ffStrbufWriteTo(>kPretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf icons;
|
||||
ffStrbufInit(&icons);
|
||||
|
||||
ffParseFormatString(&icons, &instance->config.iconsFormat, 5,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasma},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, >kPretty}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&icons, stdout);
|
||||
ffStrbufDestroy(&icons);
|
||||
}
|
||||
|
||||
ffPrintGtkPretty(gtk2, gtk3, gtk4);
|
||||
putchar('\n');
|
||||
|
||||
ffStrbufDestroy(>kPretty);
|
||||
}
|
||||
+18
-9
@@ -2,14 +2,23 @@
|
||||
|
||||
void ffPrintKernel(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
|
||||
if(instance->config.kernelShowRelease && instance->config.kernelShowVersion)
|
||||
printf("%s %s\n", instance->state.utsname.release, instance->state.utsname.version);
|
||||
else if(instance->config.kernelShowRelease)
|
||||
if(ffStrbufIsEmpty(&instance->config.kernelFormat))
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
puts(instance->state.utsname.release);
|
||||
else if(instance->config.kernelShowVersion)
|
||||
puts(instance->state.utsname.version);
|
||||
else
|
||||
puts(instance->state.utsname.sysname);
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf kernel;
|
||||
ffStrbufInit(&kernel);
|
||||
|
||||
ffParseFormatString(&kernel, &instance->config.kernelFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version}
|
||||
);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
ffStrbufWriteTo(&kernel, stdout);
|
||||
ffStrbufDestroy(&kernel);
|
||||
}
|
||||
+22
-4
@@ -5,13 +5,31 @@ void ffPrintLocale(FFinstance* instance)
|
||||
if(ffPrintCachedValue(instance, "Locale"))
|
||||
return;
|
||||
|
||||
char locale[256];
|
||||
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", locale);
|
||||
if(locale[0] == '\0')
|
||||
char localeCode[256];
|
||||
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode);
|
||||
if(localeCode[0] == '\0' && ffStrbufIsEmpty(&instance->config.localeFormat))
|
||||
{
|
||||
ffPrintError(instance, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Locale", locale);
|
||||
ffPrintLogoAndKey(instance, "Locale");
|
||||
|
||||
FFstrbuf locale;
|
||||
ffStrbufInit(&locale);
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.localeFormat))
|
||||
{
|
||||
ffStrbufSetS(&locale, localeCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&locale, &instance->config.localeFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, localeCode}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Locale", locale.chars);
|
||||
ffStrbufDestroy(&locale);
|
||||
}
|
||||
+20
-1
@@ -31,5 +31,24 @@ void ffPrintMemory(FFinstance* instance)
|
||||
uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Memory");
|
||||
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.memoryFormat))
|
||||
{
|
||||
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf memory;
|
||||
ffStrbufInit(&memory);
|
||||
|
||||
ffParseFormatString(&memory, &instance->config.memoryFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used_mem},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total_mem},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &percentage}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&memory, stdout);
|
||||
putchar('\n');
|
||||
ffStrbufDestroy(&memory);
|
||||
}
|
||||
}
|
||||
+17
-8
@@ -7,20 +7,29 @@ void ffPrintOS(FFinstance* instance)
|
||||
|
||||
char name[256];
|
||||
ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name);
|
||||
if(name[0] == '\0' && instance->config.osFormat[0] == '\0') //With custom format string we pass an empty string as name
|
||||
if(name[0] == '\0' && ffStrbufIsEmpty(&instance->config.osFormat)) //With custom format string we pass an empty string as name
|
||||
{
|
||||
ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
|
||||
return;
|
||||
}
|
||||
|
||||
char os[1024];
|
||||
ffPrintLogoAndKey(instance, "OS");
|
||||
|
||||
if(instance->config.osFormat[0] != '\0')
|
||||
sprintf(os, instance->config.osFormat, name, instance->state.utsname.machine);
|
||||
else if(instance->config.osShowArchitecture)
|
||||
sprintf(os, "%s %s", name, instance->state.utsname.machine);
|
||||
FFstrbuf os;
|
||||
ffStrbufInit(&os);
|
||||
|
||||
if(!ffStrbufIsEmpty(&instance->config.osFormat))
|
||||
{
|
||||
ffParseFormatString(&os, &instance->config.osFormat, 2,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.machine}
|
||||
);
|
||||
}
|
||||
else
|
||||
strcpy(os, name);
|
||||
{
|
||||
ffStrbufSetF(&os, "%s %s", name, instance->state.utsname.machine);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "OS", os);
|
||||
ffPrintAndSaveCachedValue(instance, "OS", os.chars);
|
||||
ffStrbufDestroy(&os);
|
||||
}
|
||||
+24
-43
@@ -25,8 +25,8 @@ static uint32_t get_num_dirs(const char* dirname) {
|
||||
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
uint32_t pacman = instance->config.packagesShowPacman ? get_num_dirs("/var/lib/pacman/local") : 0;
|
||||
uint32_t flatpak = instance->config.packagesShowFlatpak ? get_num_dirs("/var/lib/flatpak/app") : 0;
|
||||
uint32_t pacman = get_num_dirs("/var/lib/pacman/local");
|
||||
uint32_t flatpak = get_num_dirs("/var/lib/flatpak/app");
|
||||
|
||||
uint32_t all = pacman + flatpak;
|
||||
|
||||
@@ -36,50 +36,17 @@ void ffPrintPackages(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
|
||||
if(instance->config.packagesFormat[0] != '\0')
|
||||
if(ffStrbufIsEmpty(&instance->config.packagesFormat))
|
||||
{
|
||||
printf(instance->config.packagesFormat, all, pacman, flatpak, all);
|
||||
putchar('\n');
|
||||
return;
|
||||
}
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
|
||||
if(instance->config.packagesCombined)
|
||||
{
|
||||
printf("%u", all);
|
||||
|
||||
if(instance->config.packagesCombinedNames)
|
||||
{
|
||||
printf(" (");
|
||||
|
||||
#define FF_PRINT_PACKAGE(name) \
|
||||
if(name > 0) \
|
||||
{ \
|
||||
printf(#name); \
|
||||
if((all = all - name) > 0) \
|
||||
printf(", "); \
|
||||
} \
|
||||
|
||||
FF_PRINT_PACKAGE(pacman)
|
||||
FF_PRINT_PACKAGE(flatpak)
|
||||
|
||||
#undef FF_PRINT_PACKAGE
|
||||
|
||||
printf(")");
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
#define FF_PRINT_PACKAGE(name) \
|
||||
if(name > 0) \
|
||||
{ \
|
||||
printf("%u ("#name")", name); \
|
||||
if((all = all - name) > 0) \
|
||||
printf(", "); \
|
||||
};
|
||||
if(name > 0) \
|
||||
{ \
|
||||
printf("%u ("#name")", name); \
|
||||
if((all = all - name) > 0) \
|
||||
printf(", "); \
|
||||
};
|
||||
|
||||
FF_PRINT_PACKAGE(pacman)
|
||||
FF_PRINT_PACKAGE(flatpak)
|
||||
@@ -87,5 +54,19 @@ void ffPrintPackages(FFinstance* instance)
|
||||
#undef FF_PRINT_PACKAGE
|
||||
|
||||
putchar('\n');
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf packages;
|
||||
ffStrbufInit(&packages);
|
||||
|
||||
ffParseFormatString(&packages, &instance->config.packagesFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &all},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &pacman},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &flatpak}
|
||||
);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
ffStrbufWriteTo(&packages, stdout);
|
||||
ffStrbufDestroy(&packages);
|
||||
}
|
||||
+28
-14
@@ -3,11 +3,11 @@
|
||||
#include "X11/extensions/Xrandr.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
static short getCurrentRate(FFinstance* instance, Display* display)
|
||||
static int getCurrentRate(FFinstance* instance, Display* display)
|
||||
{
|
||||
void* xrandr;
|
||||
if(instance->config.resolutionLibXrandr[0] != '\0')
|
||||
xrandr = dlopen(instance->config.resolutionLibXrandr, RTLD_LAZY);
|
||||
if(!ffStrbufIsEmpty(&instance->config.libXrandr))
|
||||
xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY);
|
||||
else
|
||||
xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
if(xrandr == NULL)
|
||||
@@ -35,7 +35,7 @@ static short getCurrentRate(FFinstance* instance, Display* display)
|
||||
|
||||
dlclose(xrandr);
|
||||
|
||||
return currentRate;
|
||||
return (int) currentRate;
|
||||
}
|
||||
|
||||
void ffPrintResolution(FFinstance* instance)
|
||||
@@ -44,8 +44,8 @@ void ffPrintResolution(FFinstance* instance)
|
||||
return;
|
||||
|
||||
void* x11;
|
||||
if(instance->config.resolutionLibX11[0] != '\0')
|
||||
x11 = dlopen(instance->config.resolutionLibX11, RTLD_LAZY);
|
||||
if(!ffStrbufIsEmpty(&instance->config.libX11))
|
||||
x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY);
|
||||
else
|
||||
x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
if(x11 == NULL)
|
||||
@@ -70,18 +70,32 @@ void ffPrintResolution(FFinstance* instance)
|
||||
|
||||
Screen* screen = DefaultScreenOfDisplay(display);
|
||||
|
||||
short currentRate = instance->config.resolutionShowRefreshRate ? getCurrentRate(instance, display) : 0;
|
||||
int currentRate = getCurrentRate(instance, display);
|
||||
|
||||
dlclose(x11);
|
||||
|
||||
char resolution[1024];
|
||||
ffPrintLogoAndKey(instance, "Resolution");
|
||||
|
||||
if(instance->config.resolutionFormat[0] != '\0')
|
||||
sprintf(resolution, instance->config.resolutionFormat, screen->width, screen->height, currentRate);
|
||||
else if(currentRate == 0)
|
||||
sprintf(resolution, "%ix%i", screen->width, screen->height);
|
||||
FFstrbuf resolution;
|
||||
ffStrbufInit(&resolution);
|
||||
|
||||
if(!ffStrbufIsEmpty(&instance->config.resolutionFormat))
|
||||
{
|
||||
|
||||
ffParseFormatString(&resolution, &instance->config.resolutionFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->width},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->height},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, ¤tRate}
|
||||
);
|
||||
}
|
||||
else
|
||||
sprintf(resolution, "%ix%i @ %dHz", screen->width, screen->height, currentRate);
|
||||
{
|
||||
ffStrbufAppendF(&resolution, "%ix%i", screen->width, screen->height);
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Resolution", resolution);
|
||||
if(currentRate > 0)
|
||||
ffStrbufAppendF(&resolution, " @ %iHz", currentRate);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Resolution", resolution.chars);
|
||||
ffStrbufDestroy(&resolution);
|
||||
}
|
||||
+27
-9
@@ -12,20 +12,38 @@ void ffPrintShell(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
char* value;
|
||||
char empty[1];
|
||||
empty[0] = '\0';
|
||||
|
||||
if(!instance->config.shellShowPath)
|
||||
char* shellName = strrchr(shellPath, '/');
|
||||
if(shellName == NULL)
|
||||
{
|
||||
char* shellName = strrchr(shellPath, '/');
|
||||
if(shellName != NULL)
|
||||
value = ++shellName;
|
||||
else
|
||||
value = shellPath;
|
||||
shellName = shellPath;
|
||||
shellPath = empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = shellPath;
|
||||
*shellName = '\0';
|
||||
++shellName;
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Shell", value);
|
||||
ffPrintLogoAndKey(instance, "Shell");
|
||||
|
||||
FFstrbuf shell;
|
||||
ffStrbufInit(&shell);
|
||||
|
||||
if(!ffStrbufIsEmpty(&instance->config.shellFormat))
|
||||
{
|
||||
ffParseFormatString(&shell, &instance->config.shellFormat, 2,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellPath},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellName}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufSetS(&shell, shellName);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Shell", shell.chars);
|
||||
ffStrbufDestroy(&shell);
|
||||
}
|
||||
+24
-10
@@ -54,7 +54,7 @@ static void getTerminalName(FFinstance* instance, const char* pid, char* termina
|
||||
|
||||
void ffPopulateTerminal(FFinstance* instance)
|
||||
{
|
||||
if(instance->state.terminal.value != NULL || instance->state.terminal.error != NULL)
|
||||
if(instance->state.terminal.calculated)
|
||||
return;
|
||||
|
||||
static char terminal[256];
|
||||
@@ -68,27 +68,41 @@ void ffPopulateTerminal(FFinstance* instance)
|
||||
getTerminalName(instance, ppid, terminal, error);
|
||||
|
||||
if(terminal[0] != '\0')
|
||||
instance->state.terminal.value = terminal;
|
||||
ffStrbufSetS(&instance->state.terminal.value, terminal);
|
||||
|
||||
if(error[0] != '\0')
|
||||
instance->state.terminal.error = error;
|
||||
|
||||
instance->state.terminal.calculated = true;
|
||||
}
|
||||
|
||||
void ffPrintTerminal(FFinstance* instance)
|
||||
{
|
||||
ffPopulateTerminal(instance);
|
||||
|
||||
if(instance->state.terminal.value != NULL)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Terminal");
|
||||
puts(instance->state.terminal.value);
|
||||
}
|
||||
else if(instance->state.terminal.error != NULL)
|
||||
|
||||
if(instance->state.terminal.error != NULL)
|
||||
{
|
||||
ffPrintError(instance, "Terminal", instance->state.terminal.error);
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "Terminal");
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.terminalFormat))
|
||||
{
|
||||
ffStrbufWriteTo(&instance->state.terminal.value, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, "Terminal", "ffPopulateTerminal failed");
|
||||
FFstrbuf terminal;
|
||||
ffStrbufInit(&terminal);
|
||||
|
||||
ffParseFormatString(&terminal, &instance->config.terminalFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.terminal.value}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&terminal, stdout);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
+31
-19
@@ -1,5 +1,28 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
static void printTerminalFont(FFinstance* instance, char* font)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Terminal font");
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.termFontFormat))
|
||||
{
|
||||
puts(font);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf termfont;
|
||||
ffStrbufInit(&termfont);
|
||||
|
||||
ffParseFormatString(&termfont, &instance->config.termFontFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, font}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&termfont, stdout);
|
||||
putchar('\n');
|
||||
ffStrbufDestroy(&termfont);
|
||||
}
|
||||
}
|
||||
|
||||
static void printKonsole(FFinstance* instance)
|
||||
{
|
||||
char profile[128];
|
||||
@@ -17,16 +40,14 @@ static void printKonsole(FFinstance* instance)
|
||||
ffParsePropFileHome(instance, profilePath, "Font=%[^\n]", font);
|
||||
if(font[0] == '\0')
|
||||
{
|
||||
char error[289];
|
||||
sprintf(error, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
|
||||
ffPrintError(instance, "Terminal Font", error);
|
||||
ffPrintError(instance, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
|
||||
return;
|
||||
}
|
||||
|
||||
char fontPretty[128];
|
||||
ffParseFont(font, fontPretty);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Terminal Font");
|
||||
puts(fontPretty);
|
||||
printTerminalFont(instance, fontPretty);
|
||||
}
|
||||
|
||||
static void printTTY(FFinstance* instance)
|
||||
@@ -36,8 +57,7 @@ static void printTTY(FFinstance* instance)
|
||||
if(font[0] == '\0')
|
||||
strcpy(font, "hardware-supplied VGA font");
|
||||
|
||||
ffPrintLogoAndKey(instance, "Terminal Font");
|
||||
puts(font);
|
||||
printTerminalFont(instance, font);
|
||||
}
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance)
|
||||
@@ -47,21 +67,13 @@ void ffPrintTerminalFont(FFinstance* instance)
|
||||
if(instance->state.terminal.error != NULL)
|
||||
{
|
||||
ffPrintError(instance, "Terminal Font", "Terminal Font needs successfull terminal detection");
|
||||
}
|
||||
else if(instance->state.terminal.value == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Terminal Font", "ffPopulateTerminal failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcasecmp(instance->state.terminal.value, "konsole") == 0)
|
||||
if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "konsole") == 0)
|
||||
printKonsole(instance);
|
||||
else if(strcasecmp(instance->state.terminal.value, "TTY") == 0)
|
||||
else if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "TTY") == 0)
|
||||
printTTY(instance);
|
||||
else
|
||||
{
|
||||
char error[256];
|
||||
sprintf(error, "Unknown terminal: %s", instance->state.terminal.value);
|
||||
ffPrintError(instance, "Terminal Font", error);
|
||||
}
|
||||
|
||||
ffPrintError(instance, "Terminal Font", "Unknown terminal: %s", instance->state.terminal.value);
|
||||
}
|
||||
+28
-6
@@ -19,14 +19,36 @@ void ffPrintTheme(FFinstance* instance)
|
||||
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-theme-name=%[^\n]", gtk4);
|
||||
if(gtk4[0] == '\0')
|
||||
strcpy(gtk4, "Adwaita");
|
||||
|
||||
|
||||
FFstrbuf gtkPretty;
|
||||
ffStrbufInit(>kPretty);
|
||||
|
||||
ffFormatGtkPretty(>kPretty, gtk2, gtk3, gtk4);
|
||||
|
||||
ffPrintLogoAndKey(instance, "Theme");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
else
|
||||
printf("%s [Plasma], ", plasma);
|
||||
if(ffStrbufIsEmpty(&instance->config.themeFormat))
|
||||
{
|
||||
if(plasma[0] != '\0')
|
||||
printf("%s [Plasma], ", plasma);
|
||||
|
||||
ffPrintGtkPretty(gtk2, gtk3, gtk4);
|
||||
ffStrbufWriteTo(>kPretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf theme;
|
||||
ffStrbufInit(&theme);
|
||||
|
||||
ffParseFormatString(&theme, &instance->config.themeFormat, 5,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasma},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, >kPretty}
|
||||
);
|
||||
|
||||
ffStrbufWriteTo(&theme, stdout);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
+1
-1
@@ -10,6 +10,6 @@ void ffPrintTitle(FFinstance* instance)
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"@"FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"\n",
|
||||
instance->config.color, instance->state.passwd->pw_name, instance->config.color, hostname
|
||||
instance->config.color.chars, instance->state.passwd->pw_name, instance->config.color.chars, hostname
|
||||
);
|
||||
}
|
||||
+36
-16
@@ -2,26 +2,46 @@
|
||||
|
||||
void ffPrintUptime(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
|
||||
if(instance->state.sysinfo.uptime < 60)
|
||||
uint32_t days = instance->state.sysinfo.uptime / 86400;
|
||||
uint32_t hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
|
||||
uint32_t minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
|
||||
uint32_t seconds = instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60);
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.uptimeFormat))
|
||||
{
|
||||
printf("%ld seconds\n", instance->state.sysinfo.uptime);
|
||||
return;
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
|
||||
if(days == 0 && hours == 0 && minutes == 0)
|
||||
{
|
||||
printf("%u seconds\n", seconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(days > 0)
|
||||
printf("%u day%s, ", days, days <= 1 ? "" : "s");
|
||||
if(hours > 0)
|
||||
printf("%u hour%s, ", hours, hours <= 1 ? "" : "s");
|
||||
if(minutes > 0)
|
||||
printf("%u min%s", minutes, minutes <= 1 ? "" : "s");
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf uptime;
|
||||
ffStrbufInit(&uptime);
|
||||
|
||||
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");
|
||||
|
||||
if(hours > 0)
|
||||
printf("%d hour%s, ", hours, hours <= 1 ? "" : "s");
|
||||
ffParseFormatString(&uptime, &instance->config.uptimeFormat, 4,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &days},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &hours},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &minutes},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &seconds}
|
||||
);
|
||||
|
||||
if(minutes > 0)
|
||||
printf("%d min%s", minutes, minutes <= 1 ? "" : "s");
|
||||
|
||||
putchar('\n');
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
ffStrbufWriteTo(&uptime, stdout);
|
||||
ffStrbufDestroy(&uptime);
|
||||
}
|
||||
}
|
||||
+33
-14
@@ -2,12 +2,14 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
static void parseProcessName(const char* name, char* buffer)
|
||||
static bool parseProcessName(FFstrbuf* name)
|
||||
{
|
||||
if(strcasecmp(name, "kwin_wayland") == 0)
|
||||
strcpy(buffer, "KWin (Wayland)");
|
||||
else if(strcasecmp(name, "kwin_x11") == 0)
|
||||
strcpy(buffer, "KWin (X11)");
|
||||
if(ffStrbufIgnCaseCompS(name, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(name, "kwin_x11") == 0)
|
||||
ffStrbufSetS(name, "KWin");
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffPrintWM(FFinstance* instance)
|
||||
@@ -21,8 +23,10 @@ void ffPrintWM(FFinstance* instance)
|
||||
|
||||
struct dirent* dirent;
|
||||
|
||||
char name[32];
|
||||
name[0] = '\0';
|
||||
FFstrbuf name;
|
||||
ffStrbufInit(&name);
|
||||
|
||||
bool found = false;
|
||||
|
||||
while((dirent = readdir(proc)) != NULL)
|
||||
{
|
||||
@@ -35,24 +39,39 @@ void ffPrintWM(FFinstance* instance)
|
||||
char comm[17]; //MAX_COMM_LENGTH is 17 + null terminator
|
||||
ffGetFileContent(path, comm, sizeof(comm));
|
||||
|
||||
if(comm[0] == '\0')
|
||||
continue;
|
||||
ffStrbufSetS(&name, comm);
|
||||
|
||||
parseProcessName(comm, name);
|
||||
|
||||
if(name[0] != '\0')
|
||||
if((found = parseProcessName(&name)))
|
||||
break;
|
||||
}
|
||||
|
||||
closedir(proc);
|
||||
|
||||
if(name[0] == '\0')
|
||||
if(!found)
|
||||
{
|
||||
ffPrintError(instance, "WM", "No process name matches the name of known display managers");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ffStrbufIsEmpty(&instance->config.wmFormat))
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "WM");
|
||||
ffStrbufWriteTo(&name, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf wm;
|
||||
ffStrbufInit(&wm);
|
||||
|
||||
ffParseFormatString(&wm, &instance->config.wmFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name}
|
||||
);
|
||||
|
||||
ffPrintLogoAndKey(instance, "WM");
|
||||
puts(name);
|
||||
ffStrbufWriteTo(&wm, stdout);
|
||||
|
||||
ffStrbufDestroy(&wm);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
Reference in New Issue
Block a user