mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
flashfetch loads default values too now
This commit is contained in:
+2
-47
@@ -184,20 +184,6 @@ static void defaultConfig(FFconfig* config)
|
||||
config->recache = false;
|
||||
}
|
||||
|
||||
static void trimTrailingWhitespaces(char* buffer)
|
||||
{
|
||||
uint32_t end = 0;
|
||||
|
||||
for(uint32_t i = 0; buffer[i] != '\0'; i++)
|
||||
{
|
||||
if(buffer[i] != ' ')
|
||||
end = i;
|
||||
}
|
||||
|
||||
if(buffer[end + 1] == ' ')
|
||||
buffer[end + 1] = '\0';
|
||||
}
|
||||
|
||||
static FILE* createStructureFile(const char* filename)
|
||||
{
|
||||
FILE* f = fopen(filename, "wr");
|
||||
@@ -232,37 +218,6 @@ static FILE* createStructureFile(const char* filename)
|
||||
return f;
|
||||
}
|
||||
|
||||
static bool customValue(FFinstance* instance, const char* key, const char* valueDir)
|
||||
{
|
||||
char fileName[256];
|
||||
strcpy(fileName, valueDir);
|
||||
strcat(fileName, key);
|
||||
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
if(fd == 0) //The file doesn't exist
|
||||
return false;
|
||||
|
||||
char value[1024];
|
||||
|
||||
ssize_t readed = read(fd, value, sizeof(value) - 1);
|
||||
if(readed < 1)
|
||||
return false;
|
||||
|
||||
close(fd);
|
||||
|
||||
if(value[readed - 1] == '\n')
|
||||
value[readed - 1] = '\0';
|
||||
else
|
||||
value[readed] = '\0';
|
||||
|
||||
trimTrailingWhitespaces(value);
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
puts(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void parseLine(FFinstance* instance, const char* line)
|
||||
{
|
||||
if(strcasecmp(line, "break") == 0)
|
||||
@@ -348,9 +303,9 @@ static void parseStructureFile(FFinstance* instance)
|
||||
if(line[read - 1] == '\n')
|
||||
line[read - 1] = '\0';
|
||||
|
||||
trimTrailingWhitespaces(line);
|
||||
ffTrimTrailingWhitespace(line);
|
||||
|
||||
if(!customValue(instance, line, valueDir))
|
||||
if(!ffPrintCustomValue(instance, line))
|
||||
parseLine(instance, line);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,10 @@ void ffParsePropFile(const char* file, 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(FFinstance* instance, const char* key, const char* message);
|
||||
void ffTrimTrailingWhitespace(char* buffer);
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key);
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char* value);
|
||||
bool ffPrintCustomValue(FFinstance* instance, const char* key);
|
||||
|
||||
//Logo functions
|
||||
void ffLoadLogoSet(FFconfig* config, const char* logo);
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
void ffPrintBattery(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Battery"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
int scanned;
|
||||
|
||||
FILE* fullFile = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
|
||||
|
||||
static void printKDE()
|
||||
{
|
||||
char version[256];
|
||||
@@ -17,6 +15,11 @@ static void printKDE()
|
||||
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "DE"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
const char* currentDesktop = getenv("XDG_CURRENT_DESKTOP");
|
||||
if(currentDesktop == NULL)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
|
||||
void ffPrintDisk(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Disk (/)"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
struct statvfs fs;
|
||||
int ret = statvfs("/", &fs);
|
||||
if(ret != 0)
|
||||
|
||||
+5
-2
@@ -1,7 +1,5 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
|
||||
|
||||
static void parseFont(char* font, char* buffer)
|
||||
{
|
||||
char name[64];
|
||||
@@ -18,6 +16,11 @@ static void parseFont(char* font, char* buffer)
|
||||
|
||||
void ffPrintFont(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Font"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "font=%[^\n]", plasma);
|
||||
|
||||
|
||||
+5
-2
@@ -1,9 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
|
||||
|
||||
void ffPrintIcons(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Icons"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "Theme=%[^\n]", plasma);
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
void ffPrintKernel(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Kernel"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
printf("%s\n", instance->state.utsname.release);
|
||||
puts(instance->state.utsname.release);
|
||||
}
|
||||
@@ -3,6 +3,11 @@
|
||||
// Impl by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
|
||||
void ffPrintMemory(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Memory"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL) {
|
||||
ffPrintError(instance, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
|
||||
|
||||
@@ -33,6 +33,11 @@ static void printPacmanPackages()
|
||||
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Packages"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
printPacmanPackages();
|
||||
putchar('\n');
|
||||
|
||||
@@ -58,6 +58,11 @@ void printTerminalName(FFinstance* instance, const char* pid)
|
||||
|
||||
void ffPrintTerminal(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Terminal"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
char ppid[256];
|
||||
sprintf(ppid, "%i", getppid());
|
||||
printTerminalName(instance, ppid);
|
||||
|
||||
+5
-2
@@ -1,9 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
|
||||
|
||||
void ffPrintTheme(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Theme"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
char plasma[256];
|
||||
ffParsePropFileHome(instance, ".config/kdeglobals", "Name=%[^\n]", plasma);
|
||||
|
||||
|
||||
+5
-2
@@ -1,9 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
|
||||
|
||||
void ffPrintTitle(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Title"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
char hostname[256];
|
||||
gethostname(hostname, 256);
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
void ffPrintUptime(FFinstance* instance)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, "Uptime"))
|
||||
return;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
|
||||
if(instance->state.sysinfo.uptime < 60)
|
||||
|
||||
+106
-20
@@ -111,49 +111,134 @@ void ffPrintError(FFinstance* instance, const char* key, const char* message)
|
||||
printf(FASTFETCH_TEXT_MODIFIER_ERROR"%s"FASTFETCH_TEXT_MODIFIER_RESET"\n", message);
|
||||
}
|
||||
|
||||
static void getCacheFileName(FFinstance* instance, const char* key, char* buffer)
|
||||
void ffTrimTrailingWhitespace(char* buffer)
|
||||
{
|
||||
uint32_t end = 0;
|
||||
|
||||
for(uint32_t i = 0; buffer[i] != '\0'; i++)
|
||||
{
|
||||
if(buffer[i] != ' ')
|
||||
end = i;
|
||||
}
|
||||
|
||||
if(buffer[end + 1] == ' ')
|
||||
buffer[end + 1] = '\0';
|
||||
}
|
||||
|
||||
static void getFileContent(const char* fileName, char* buffer, uint32_t bufferSize)
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
if(fd == -1)
|
||||
return;
|
||||
|
||||
ssize_t readed = read(fd, buffer, bufferSize - 1);
|
||||
if(readed < 1)
|
||||
return;
|
||||
|
||||
close(fd);
|
||||
|
||||
if(buffer[readed - 1] == '\n')
|
||||
buffer[readed - 1] = '\0';
|
||||
else
|
||||
buffer[readed] = '\0';
|
||||
|
||||
ffTrimTrailingWhitespace(buffer);
|
||||
}
|
||||
|
||||
static const char* getCacheDir(FFinstance* instance)
|
||||
{
|
||||
static char cache[256];
|
||||
static bool init = false;
|
||||
if(init)
|
||||
return cache;
|
||||
|
||||
const char* xdgCache = getenv("XDG_CACHE_HOME");
|
||||
if(xdgCache == NULL)
|
||||
{
|
||||
strcpy(buffer, instance->state.passwd->pw_dir);
|
||||
strcat(buffer, "/.cache");
|
||||
strcpy(cache, instance->state.passwd->pw_dir);
|
||||
strcat(cache, "/.cache");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(buffer, xdgCache);
|
||||
strcpy(cache, xdgCache);
|
||||
}
|
||||
|
||||
mkdir(buffer, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
mkdir(cache, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
|
||||
strcat(buffer, "/fastfetch/");
|
||||
mkdir(buffer, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
strcat(cache, "/fastfetch/");
|
||||
mkdir(cache, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
|
||||
init = true;
|
||||
return cache;
|
||||
}
|
||||
|
||||
static const char* getConfigDir(FFinstance* instance)
|
||||
{
|
||||
static char config[256];
|
||||
static bool init = false;
|
||||
if(init)
|
||||
return config;
|
||||
|
||||
const char* xdgConfig = getenv("XDG_CONFIG_HOME");
|
||||
if(xdgConfig == NULL)
|
||||
{
|
||||
strcpy(config, instance->state.passwd->pw_dir);
|
||||
strcat(config, "/.config");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(config, xdgConfig);
|
||||
}
|
||||
|
||||
mkdir(config, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a config folder but whow knews
|
||||
|
||||
strcat(buffer, key);
|
||||
strcat(config, "/fastfetch/");
|
||||
mkdir(config, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
|
||||
init = true;
|
||||
return config;
|
||||
}
|
||||
|
||||
bool ffPrintCustomValue(FFinstance* instance, const char* key)
|
||||
{
|
||||
char fileName[256];
|
||||
strcpy(fileName, getConfigDir(instance));
|
||||
strcat(fileName, key);
|
||||
|
||||
char value[1024];
|
||||
getFileContent(fileName, value, sizeof(value));
|
||||
|
||||
if(value[0] == '\0')
|
||||
return false;
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
puts(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key)
|
||||
{
|
||||
#ifdef FASTFETCH_BUILD_FLASHFETCH
|
||||
if(ffPrintCustomValue(instance, key))
|
||||
return true;
|
||||
#endif // FASTFETCH_BUILD_FLASHFETCH
|
||||
|
||||
if(instance->config.recache)
|
||||
return false;
|
||||
|
||||
char fileName[256];
|
||||
getCacheFileName(instance, key, fileName);
|
||||
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
if(fd == -1)
|
||||
return false;
|
||||
strcpy(fileName, getCacheDir(instance));
|
||||
strcat(fileName, key);
|
||||
|
||||
char value[1024];
|
||||
getFileContent(fileName, value, sizeof(value));
|
||||
|
||||
ssize_t readed = read(fd, value, sizeof(value) - 1);
|
||||
if(readed < 1)
|
||||
if(value[0] == '\0')
|
||||
return false;
|
||||
|
||||
close(fd);
|
||||
|
||||
value[readed] = '\0'; //Somehow read doesn't alway do this
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
puts(value);
|
||||
|
||||
@@ -166,7 +251,8 @@ void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char
|
||||
puts(value);
|
||||
|
||||
char fileName[256];
|
||||
getCacheFileName(instance, key, fileName);
|
||||
strcpy(fileName, getCacheDir(instance));
|
||||
strcat(fileName, key);
|
||||
|
||||
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