mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
refactored internal state keeping
This commit is contained in:
+21
-3
@@ -25,8 +25,7 @@ include_directories(
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/fastfetch.c
|
||||
set(SRCS
|
||||
src/util.c
|
||||
src/logo.c
|
||||
src/modules/break.c
|
||||
@@ -53,7 +52,26 @@ add_executable(${PROJECT_NAME}
|
||||
src/modules/colors.c
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
add_executable(fastfetch
|
||||
src/fastfetch.c
|
||||
${SRCS}
|
||||
)
|
||||
|
||||
target_link_libraries(fastfetch
|
||||
${CMAKE_DL_LIBS}
|
||||
pci
|
||||
)
|
||||
|
||||
add_executable(flashfetch
|
||||
src/flashfetch.c
|
||||
${SRCS}
|
||||
)
|
||||
|
||||
target_compile_definitions(flashfetch PUBLIC
|
||||
FASTFETCH_BUILD_FLASHFETCH
|
||||
)
|
||||
|
||||
target_link_libraries(flashfetch
|
||||
${CMAKE_DL_LIBS}
|
||||
pci
|
||||
)
|
||||
+50
-38
@@ -47,7 +47,7 @@ static void printCommandHelp(const char* command)
|
||||
printf("No specific help for command %s provided\n", command);
|
||||
}
|
||||
|
||||
static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
static void parseArguments(int argc, char** argv, FFconfig* config)
|
||||
{
|
||||
bool colorText = true;
|
||||
|
||||
@@ -74,12 +74,12 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
}
|
||||
else if(strcmp(argv[i], "--print-logos") == 0)
|
||||
{
|
||||
ffPrintLogos(state->colorLogo);
|
||||
ffPrintLogos(config->colorLogo);
|
||||
exit(0);
|
||||
}
|
||||
else if(strcmp(argv[i], "--show-errors") == 0)
|
||||
{
|
||||
state->showErrors = true;
|
||||
config->showErrors = true;
|
||||
}
|
||||
else if(strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--logo") == 0)
|
||||
{
|
||||
@@ -89,7 +89,7 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
exit(41);
|
||||
}
|
||||
|
||||
ffLoadLogoSet(state, argv[i + 1]);
|
||||
ffLoadLogoSet(config, argv[i + 1]);
|
||||
++i;
|
||||
}
|
||||
else if(strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--color") == 0)
|
||||
@@ -105,7 +105,7 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
printf("Error: max color string length is 28, %zu given\n", len);
|
||||
exit(43);
|
||||
}
|
||||
sprintf(state->color, "\033[%sm", argv[i + 1]);
|
||||
sprintf(config->color, "\033[%sm", argv[i + 1]);
|
||||
++i;
|
||||
}
|
||||
else if(strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--seperator") == 0)
|
||||
@@ -115,7 +115,7 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
printf("Error: usage: %s <width>\n", argv[i]);
|
||||
exit(44);
|
||||
}
|
||||
if(sscanf(argv[i + 1], "%hd", &state->logo_seperator) != 1)
|
||||
if(sscanf(argv[i + 1], "%hd", &config->logo_seperator) != 1)
|
||||
{
|
||||
printf("Error: couldn't parse %s to uint16_t\n", argv[i + 1]);
|
||||
exit(45);
|
||||
@@ -129,7 +129,7 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
printf("Error: usage: %s <offset>\n", argv[i]);
|
||||
exit(46);
|
||||
}
|
||||
if(sscanf(argv[i + 1], "%hi", &state->offsetx) != 1)
|
||||
if(sscanf(argv[i + 1], "%hi", &config->offsetx) != 1)
|
||||
{
|
||||
printf("Error: couldn't parse %s to int16_t\n", argv[i + 1]);
|
||||
exit(47);
|
||||
@@ -138,16 +138,16 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
}
|
||||
else if(strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--recache") == 0)
|
||||
{
|
||||
state->recache = true;
|
||||
config->recache = true;
|
||||
}
|
||||
else if(strcmp(argv[i], "--no-color") == 0)
|
||||
{
|
||||
colorText = false;
|
||||
state->colorLogo = false;
|
||||
config->colorLogo = false;
|
||||
}
|
||||
else if(strcmp(argv[i], "--no-color-logo") == 0)
|
||||
{
|
||||
state->colorLogo = false;
|
||||
config->colorLogo = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,42 +156,54 @@ static void parseArguments(int argc, char** argv, FFstate* state)
|
||||
}
|
||||
}
|
||||
|
||||
ffLoadLogo(state); //We need to do this here, because of --no-color
|
||||
ffLoadLogo(config); //We need to do this here, because of --no-color
|
||||
if(colorText)
|
||||
strcpy(state->color, state->logo.color);
|
||||
strcpy(config->color, config->logo.color);
|
||||
else
|
||||
state->color[0] = '\0';
|
||||
config->color[0] = '\0';
|
||||
}
|
||||
|
||||
static void defaultConfig(FFconfig* config)
|
||||
{
|
||||
config->logo_seperator = 4;
|
||||
config->offsetx = 0;
|
||||
config->titleLength = 20; // This is overwritten by ffPrintTitle
|
||||
config->colorLogo = true;
|
||||
config->showErrors = false;
|
||||
config->recache = false;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FFstate state;
|
||||
ffInitState(&state);
|
||||
parseArguments(argc, argv, &state);
|
||||
FFinstance instance;
|
||||
ffInitState(&instance.state);
|
||||
defaultConfig(&instance.config);
|
||||
|
||||
parseArguments(argc, argv, &instance.config);
|
||||
|
||||
//Start the printing
|
||||
ffPrintTitle(&state);
|
||||
ffPrintSeperator(&state);
|
||||
ffPrintOS(&state);
|
||||
ffPrintHost(&state);
|
||||
ffPrintKernel(&state);
|
||||
ffPrintUptime(&state);
|
||||
ffPrintPackages(&state);
|
||||
ffPrintShell(&state);
|
||||
ffPrintResolution(&state);
|
||||
ffPrintDesktopEnvironment(&state);
|
||||
ffPrintTheme(&state);
|
||||
ffPrintIcons(&state);
|
||||
ffPrintFont(&state);
|
||||
ffPrintTerminal(&state);
|
||||
ffPrintCPU(&state);
|
||||
ffPrintGPU(&state);
|
||||
ffPrintMemory(&state);
|
||||
ffPrintDisk(&state);
|
||||
ffPrintBattery(&state);
|
||||
ffPrintLocale(&state);
|
||||
ffPrintBreak(&state);
|
||||
ffPrintColors(&state);
|
||||
ffPrintTitle(&instance);
|
||||
ffPrintSeperator(&instance);
|
||||
ffPrintOS(&instance);
|
||||
ffPrintHost(&instance);
|
||||
ffPrintKernel(&instance);
|
||||
ffPrintUptime(&instance);
|
||||
ffPrintPackages(&instance);
|
||||
ffPrintShell(&instance);
|
||||
ffPrintResolution(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance);
|
||||
ffPrintTerminal(&instance);
|
||||
ffPrintCPU(&instance);
|
||||
ffPrintGPU(&instance);
|
||||
ffPrintMemory(&instance);
|
||||
ffPrintDisk(&instance);
|
||||
ffPrintBattery(&instance);
|
||||
ffPrintLocale(&instance);
|
||||
ffPrintBreak(&instance);
|
||||
ffPrintColors(&instance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+47
-37
@@ -28,12 +28,8 @@ typedef struct FFlogo
|
||||
char color[32];
|
||||
} FFlogo;
|
||||
|
||||
typedef struct FFstate
|
||||
typedef struct FFconfig
|
||||
{
|
||||
//Actual state stuff
|
||||
uint8_t current_row;
|
||||
|
||||
//Configuration stuff
|
||||
FFlogo logo;
|
||||
uint16_t logo_seperator;
|
||||
int16_t offsetx;
|
||||
@@ -42,51 +38,65 @@ typedef struct FFstate
|
||||
bool colorLogo;
|
||||
bool showErrors;
|
||||
bool recache;
|
||||
} FFconfig;
|
||||
|
||||
//Common stuff
|
||||
typedef struct FFstate
|
||||
{
|
||||
uint8_t current_row;
|
||||
struct passwd* passwd;
|
||||
struct utsname utsname;
|
||||
struct sysinfo sysinfo;
|
||||
} FFstate;
|
||||
|
||||
typedef struct FFinstance
|
||||
{
|
||||
FFconfig config;
|
||||
FFstate state;
|
||||
} FFinstance;
|
||||
|
||||
//Util functions
|
||||
void ffInitState(FFstate* state);
|
||||
void ffPrintLogoLine(FFstate* state);
|
||||
void ffPrintKey(FFstate* state, const char* key);
|
||||
void ffPrintLogoAndKey(FFstate* state, const char* key);
|
||||
void ffPrintKey(FFconfig* config, const char* key);
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* key);
|
||||
void ffParsePropFile(const char* file, const char* regex, char* buffer);
|
||||
void ffParsePropFileHome(FFstate* state, const char* relativeFile, const char* regex, char* buffer);
|
||||
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer);
|
||||
void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4);
|
||||
void ffPrintError(FFstate* state, const char* key, const char* message);
|
||||
bool ffPrintCachedValue(FFstate* state, const char* key);
|
||||
void ffPrintAndSaveCachedValue(FFstate* state, const char* key, const char* value);
|
||||
void ffPrintError(FFinstance* instance, const char* key, const char* message);
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key);
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char* value);
|
||||
|
||||
void ffLoadLogoSet(FFstate* state, const char* logo);
|
||||
void ffLoadLogo(FFstate* state);
|
||||
//Logo functions
|
||||
void ffLoadLogoSet(FFconfig* config, const char* logo);
|
||||
void ffLoadLogo(FFconfig* config);
|
||||
void ffPrintLogoLine(FFinstance* instance);
|
||||
|
||||
#ifndef FLASHFETCH_BUILD_FLASHFATCH
|
||||
void ffListLogos();
|
||||
void ffPrintLogos(bool color);
|
||||
#endif
|
||||
|
||||
void ffPrintBreak(FFstate* state);
|
||||
void ffPrintTitle(FFstate* state);
|
||||
void ffPrintSeperator(FFstate* state);
|
||||
void ffPrintOS(FFstate* state);
|
||||
void ffPrintHost(FFstate* state);
|
||||
void ffPrintKernel(FFstate* state);
|
||||
void ffPrintUptime(FFstate* state);
|
||||
void ffPrintPackages(FFstate* state);
|
||||
void ffPrintShell(FFstate* state);
|
||||
void ffPrintResolution(FFstate* state);
|
||||
void ffPrintDesktopEnvironment(FFstate* state);
|
||||
void ffPrintTheme(FFstate* state);
|
||||
void ffPrintIcons(FFstate* state);
|
||||
void ffPrintFont(FFstate* state);
|
||||
void ffPrintTerminal(FFstate* state);
|
||||
void ffPrintCPU(FFstate* state);
|
||||
void ffPrintGPU(FFstate* state);
|
||||
void ffPrintMemory(FFstate* state);
|
||||
void ffPrintDisk(FFstate* state);
|
||||
void ffPrintBattery(FFstate* state);
|
||||
void ffPrintLocale(FFstate* state);
|
||||
void ffPrintColors(FFstate* state);
|
||||
//Module functions
|
||||
void ffPrintBreak(FFinstance* state);
|
||||
void ffPrintTitle(FFinstance* state);
|
||||
void ffPrintSeperator(FFinstance* state);
|
||||
void ffPrintOS(FFinstance* state);
|
||||
void ffPrintHost(FFinstance* state);
|
||||
void ffPrintKernel(FFinstance* state);
|
||||
void ffPrintUptime(FFinstance* state);
|
||||
void ffPrintPackages(FFinstance* state);
|
||||
void ffPrintShell(FFinstance* state);
|
||||
void ffPrintResolution(FFinstance* state);
|
||||
void ffPrintDesktopEnvironment(FFinstance* state);
|
||||
void ffPrintTheme(FFinstance* state);
|
||||
void ffPrintIcons(FFinstance* state);
|
||||
void ffPrintFont(FFinstance* state);
|
||||
void ffPrintTerminal(FFinstance* state);
|
||||
void ffPrintCPU(FFinstance* state);
|
||||
void ffPrintGPU(FFinstance* state);
|
||||
void ffPrintMemory(FFinstance* state);
|
||||
void ffPrintDisk(FFinstance* state);
|
||||
void ffPrintBattery(FFinstance* state);
|
||||
void ffPrintLocale(FFinstance* state);
|
||||
void ffPrintColors(FFinstance* state);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FFinstance instance;
|
||||
ffInitState(&instance.state);
|
||||
|
||||
instance.config.logo_seperator = 4;
|
||||
instance.config.offsetx = 0;
|
||||
instance.config.titleLength = 20; // This is overwritten by ffPrintTitle
|
||||
instance.config.colorLogo = true;
|
||||
instance.config.showErrors = false;
|
||||
instance.config.recache = false;
|
||||
ffLoadLogoSet(&instance.config, "arch");
|
||||
|
||||
//Printing
|
||||
|
||||
ffPrintTitle(&instance);
|
||||
ffPrintSeperator(&instance);
|
||||
ffPrintOS(&instance);
|
||||
ffPrintHost(&instance);
|
||||
ffPrintKernel(&instance);
|
||||
ffPrintUptime(&instance);
|
||||
ffPrintPackages(&instance);
|
||||
ffPrintShell(&instance);
|
||||
ffPrintResolution(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance);
|
||||
ffPrintTerminal(&instance);
|
||||
ffPrintCPU(&instance);
|
||||
ffPrintGPU(&instance);
|
||||
ffPrintMemory(&instance);
|
||||
ffPrintDisk(&instance);
|
||||
ffPrintBattery(&instance);
|
||||
ffPrintLocale(&instance);
|
||||
ffPrintBreak(&instance);
|
||||
ffPrintColors(&instance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+24
-20
@@ -67,65 +67,67 @@ static void loadArchLogo(FFlogo* logo, bool doColor)
|
||||
sprintf(logo->chars[19], FASTFETCH_TEXT_MODIFIER_BOLT"%s.` `/"FASTFETCH_TEXT_MODIFIER_RESET, color);
|
||||
}
|
||||
|
||||
void ffLoadLogoSet(FFstate* state, const char* logo)
|
||||
void ffLoadLogoSet(FFconfig* config, const char* logo)
|
||||
{
|
||||
if(strcasecmp(logo, "none") == 0)
|
||||
{
|
||||
loadNoneLogo(&state->logo);
|
||||
state->logo_seperator = 0; //This is wanted in most cases, so just set it
|
||||
loadNoneLogo(&config->logo);
|
||||
config->logo_seperator = 0; //This is wanted in most cases, so just set it
|
||||
}
|
||||
else if(strcasecmp(logo, "arch") == 0)
|
||||
{
|
||||
loadArchLogo(&state->logo, state->colorLogo);
|
||||
loadArchLogo(&config->logo, config->colorLogo);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(state->showErrors)
|
||||
if(config->showErrors)
|
||||
printf(FASTFETCH_TEXT_MODIFIER_ERROR"Error: unknown logo: %s"FASTFETCH_TEXT_MODIFIER_RESET"\n", logo);
|
||||
loadUnknownLogo(&state->logo);
|
||||
loadUnknownLogo(&config->logo);
|
||||
}
|
||||
}
|
||||
|
||||
void ffLoadLogo(FFstate* state)
|
||||
void ffLoadLogo(FFconfig* config)
|
||||
{
|
||||
char id[256];
|
||||
ffParsePropFile("/etc/os-release", "ID=%[^\n]", id);
|
||||
if(id[0] == '\0')
|
||||
{
|
||||
if(state->showErrors)
|
||||
if(config->showErrors)
|
||||
puts(FASTFETCH_TEXT_MODIFIER_ERROR"Error: \"ID=%[^\\n]\" not found in \"/etc/os-release\""FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
loadUnknownLogo(&state->logo);
|
||||
loadUnknownLogo(&config->logo);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffLoadLogoSet(state, id);
|
||||
ffLoadLogoSet(config, id);
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintLogoLine(FFstate* state)
|
||||
void ffPrintLogoLine(FFinstance* instance)
|
||||
{
|
||||
for(int16_t i = 0; i < state->offsetx; i++)
|
||||
for(int16_t i = 0; i < instance->config.offsetx; i++)
|
||||
putchar(' ');
|
||||
|
||||
int16_t cut = state->offsetx >= 0 ? 0 :
|
||||
(state->logo.width > state->offsetx * -1 ? state->offsetx * -1 : state->logo.width);
|
||||
int16_t cut = instance->config.offsetx >= 0 ? 0 :
|
||||
(instance->config.logo.width > instance->config.offsetx * -1 ? instance->config.offsetx * -1 : instance->config.logo.width);
|
||||
|
||||
if(state->current_row < state->logo.height)
|
||||
if(instance->state.current_row < instance->config.logo.height)
|
||||
{
|
||||
printf(state->logo.chars[state->current_row] + cut);
|
||||
printf(instance->config.logo.chars[instance->state.current_row] + cut);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(uint8_t i = 0; i < state->logo.width - cut; i++)
|
||||
for(uint8_t i = 0; i < instance->config.logo.width - cut; i++)
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < state->logo_seperator; i++)
|
||||
for(uint16_t i = 0; i < instance->config.logo_seperator; i++)
|
||||
putchar(' ');
|
||||
|
||||
++state->current_row;
|
||||
++instance->state.current_row;
|
||||
}
|
||||
|
||||
#ifndef FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
static FFlogo* getLogos(uint8_t* size, bool color)
|
||||
{
|
||||
#define FASTFETCH_LOGO_AMOUNT 3
|
||||
@@ -163,4 +165,6 @@ void ffPrintLogos(bool doColor)
|
||||
puts(logos[i].chars[k]);
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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");
|
||||
|
||||
+19
-25
@@ -12,23 +12,17 @@ void ffInitState(FFstate* state)
|
||||
state->passwd = getpwuid(getuid());
|
||||
uname(&state->utsname);
|
||||
sysinfo(&state->sysinfo);
|
||||
state->logo_seperator = 4;
|
||||
state->offsetx = 0;
|
||||
state->titleLength = 20; // This is overwritten by ffPrintTitle
|
||||
state->colorLogo = true;
|
||||
state->showErrors = false;
|
||||
state->recache = false;
|
||||
}
|
||||
|
||||
void ffPrintKey(FFstate* state, const char* key)
|
||||
void ffPrintKey(FFconfig* config, const char* key)
|
||||
{
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET": ", state->color, key);
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET": ", config->color, key);
|
||||
}
|
||||
|
||||
void ffPrintLogoAndKey(FFstate* state, const char* key)
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* key)
|
||||
{
|
||||
ffPrintLogoLine(state);
|
||||
ffPrintKey(state, key);
|
||||
ffPrintLogoLine(instance);
|
||||
ffPrintKey(&instance->config, key);
|
||||
}
|
||||
|
||||
void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
|
||||
@@ -52,10 +46,10 @@ void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
|
||||
free(line);
|
||||
}
|
||||
|
||||
void ffParsePropFileHome(FFstate* state, const char* relativeFile, const char* regex, char* buffer)
|
||||
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer)
|
||||
{
|
||||
char absolutePath[512];
|
||||
strcpy(absolutePath, state->passwd->pw_dir);
|
||||
strcpy(absolutePath, instance->state.passwd->pw_dir);
|
||||
strcat(absolutePath, "/");
|
||||
strcat(absolutePath, relativeFile);
|
||||
|
||||
@@ -108,21 +102,21 @@ void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4)
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintError(FFstate* state, const char* key, const char* message)
|
||||
void ffPrintError(FFinstance* instance, const char* key, const char* message)
|
||||
{
|
||||
if(!state->showErrors)
|
||||
if(!instance->config.showErrors)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(state, key);
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
printf(FASTFETCH_TEXT_MODIFIER_ERROR"%s\n"FASTFETCH_TEXT_MODIFIER_RESET, message);
|
||||
}
|
||||
|
||||
static void getCacheFileName(FFstate* state, const char* key, char* buffer)
|
||||
static void getCacheFileName(FFinstance* instance, const char* key, char* buffer)
|
||||
{
|
||||
const char* xdgCache = getenv("XDG_CACHE_HOME");
|
||||
if(xdgCache == NULL)
|
||||
{
|
||||
strcpy(buffer, state->passwd->pw_dir);
|
||||
strcpy(buffer, instance->state.passwd->pw_dir);
|
||||
strcat(buffer, "/.cache");
|
||||
}
|
||||
else
|
||||
@@ -138,13 +132,13 @@ static void getCacheFileName(FFstate* state, const char* key, char* buffer)
|
||||
strcat(buffer, key);
|
||||
}
|
||||
|
||||
bool ffPrintCachedValue(FFstate* state, const char* key)
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key)
|
||||
{
|
||||
if(state->recache)
|
||||
if(instance->config.recache)
|
||||
return false;
|
||||
|
||||
char fileName[256];
|
||||
getCacheFileName(state, key, fileName);
|
||||
getCacheFileName(instance, key, fileName);
|
||||
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
if(fd == -1)
|
||||
@@ -160,19 +154,19 @@ bool ffPrintCachedValue(FFstate* state, const char* key)
|
||||
|
||||
value[readed] = '\0'; //Somehow read doesn't alway do this
|
||||
|
||||
ffPrintLogoAndKey(state, key);
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
puts(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffPrintAndSaveCachedValue(FFstate* state, const char* key, const char* value)
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char* value)
|
||||
{
|
||||
ffPrintLogoAndKey(state, key);
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
puts(value);
|
||||
|
||||
char fileName[256];
|
||||
getCacheFileName(state, key, fileName);
|
||||
getCacheFileName(instance, key, fileName);
|
||||
|
||||
int fd = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if(fd == -1)
|
||||
|
||||
Reference in New Issue
Block a user