mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 00:03:58 +01:00
all keys can now be set!
This commit is contained in:
+219
-217
@@ -28,65 +28,60 @@ void ffDefaultConfig(FFconfig* config)
|
||||
config->cacheSave = true;
|
||||
config->printRemainingLogo = true;
|
||||
|
||||
ffStrbufInit(&config->osFormat);
|
||||
ffStrbufInit(&config->hostFormat);
|
||||
ffStrbufInit(&config->kernelFormat);
|
||||
ffStrbufInit(&config->uptimeFormat);
|
||||
ffStrbufInit(&config->packagesFormat);
|
||||
ffStrbufInit(&config->shellFormat);
|
||||
ffStrbufInit(&config->resolutionFormat);
|
||||
ffStrbufInit(&config->deFormat);
|
||||
ffStrbufInit(&config->wmFormat);
|
||||
ffStrbufInit(&config->themeFormat);
|
||||
ffStrbufInit(&config->iconsFormat);
|
||||
ffStrbufInit(&config->fontFormat);
|
||||
ffStrbufInit(&config->terminalFormat);
|
||||
ffStrbufInit(&config->termFontFormat);
|
||||
ffStrbufInit(&config->cpuFormat);
|
||||
ffStrbufInit(&config->gpuFormat);
|
||||
ffStrbufInit(&config->memoryFormat);
|
||||
ffStrbufInit(&config->diskFormat);
|
||||
ffStrbufInit(&config->batteryFormat);
|
||||
ffStrbufInit(&config->localeFormat);
|
||||
//Since most of these properties are unlikely to be used at once, give them minimal heap space (the \0 character)
|
||||
ffStrbufInitA(&config->osFormat, 1);
|
||||
ffStrbufInitA(&config->osKey, 1);
|
||||
ffStrbufInitA(&config->hostFormat, 1);
|
||||
ffStrbufInitA(&config->hostKey, 1);
|
||||
ffStrbufInitA(&config->kernelFormat, 1);
|
||||
ffStrbufInitA(&config->kernelKey, 1);
|
||||
ffStrbufInitA(&config->uptimeFormat, 1);
|
||||
ffStrbufInitA(&config->uptimeKey, 1);
|
||||
ffStrbufInitA(&config->packagesFormat, 1);
|
||||
ffStrbufInitA(&config->packagesKey, 1);
|
||||
ffStrbufInitA(&config->shellFormat, 1);
|
||||
ffStrbufInitA(&config->shellKey, 1);
|
||||
ffStrbufInitA(&config->resolutionFormat, 1);
|
||||
ffStrbufInitA(&config->resolutionKey, 1);
|
||||
ffStrbufInitA(&config->deFormat, 1);
|
||||
ffStrbufInitA(&config->deKey, 1);
|
||||
ffStrbufInitA(&config->wmFormat, 1);
|
||||
ffStrbufInitA(&config->wmKey, 1);
|
||||
ffStrbufInitA(&config->themeFormat, 1);
|
||||
ffStrbufInitA(&config->themeKey, 1);
|
||||
ffStrbufInitA(&config->iconsFormat, 1);
|
||||
ffStrbufInitA(&config->iconsKey, 1);
|
||||
ffStrbufInitA(&config->fontFormat, 1);
|
||||
ffStrbufInitA(&config->fontKey, 1);
|
||||
ffStrbufInitA(&config->terminalFormat, 1);
|
||||
ffStrbufInitA(&config->terminalKey, 1);
|
||||
ffStrbufInitA(&config->termFontFormat, 1);
|
||||
ffStrbufInitA(&config->termFontKey, 1);
|
||||
ffStrbufInitA(&config->cpuFormat, 1);
|
||||
ffStrbufInitA(&config->cpuKey, 1);
|
||||
ffStrbufInitA(&config->gpuFormat, 1);
|
||||
ffStrbufInitA(&config->gpuKey, 1);
|
||||
ffStrbufInitA(&config->memoryFormat, 1);
|
||||
ffStrbufInitA(&config->memoryKey, 1);
|
||||
ffStrbufInitA(&config->diskFormat, 1);
|
||||
ffStrbufInitA(&config->diskKey, 1);
|
||||
ffStrbufInitA(&config->batteryFormat, 1);
|
||||
ffStrbufInitA(&config->batteryKey, 1);
|
||||
ffStrbufInitA(&config->localeFormat, 1);
|
||||
ffStrbufInitA(&config->localeKey, 1);
|
||||
|
||||
ffStrbufInitA(&config->libPCI, 256);
|
||||
ffStrbufInitA(&config->libX11, 256);
|
||||
ffStrbufInitA(&config->libXrandr, 256);
|
||||
ffStrbufInitA(&config->libPCI, 1);
|
||||
ffStrbufInitA(&config->libX11, 1);
|
||||
ffStrbufInitA(&config->libXrandr, 1);
|
||||
|
||||
ffStrbufInitA(&config->diskFolders, 128);
|
||||
ffStrbufInitA(&config->diskFolders, 1);
|
||||
}
|
||||
|
||||
static void ffCleanup(FFinstance* instance)
|
||||
{
|
||||
ffStrbufDestroy(&instance->config.color);
|
||||
ffStrbufDestroy(&instance->config.seperator);
|
||||
|
||||
ffStrbufDestroy(&instance->config.osFormat);
|
||||
ffStrbufDestroy(&instance->config.hostFormat);
|
||||
ffStrbufDestroy(&instance->config.kernelFormat);
|
||||
ffStrbufDestroy(&instance->config.uptimeFormat);
|
||||
ffStrbufDestroy(&instance->config.packagesFormat);
|
||||
ffStrbufDestroy(&instance->config.shellFormat);
|
||||
ffStrbufDestroy(&instance->config.resolutionFormat);
|
||||
ffStrbufDestroy(&instance->config.deFormat);
|
||||
ffStrbufDestroy(&instance->config.wmFormat);
|
||||
ffStrbufDestroy(&instance->config.themeFormat);
|
||||
ffStrbufDestroy(&instance->config.iconsFormat);
|
||||
ffStrbufDestroy(&instance->config.fontFormat);
|
||||
ffStrbufDestroy(&instance->config.terminalFormat);
|
||||
ffStrbufDestroy(&instance->config.termFontFormat);
|
||||
ffStrbufDestroy(&instance->config.cpuFormat);
|
||||
ffStrbufDestroy(&instance->config.gpuFormat);
|
||||
ffStrbufDestroy(&instance->config.memoryFormat);
|
||||
ffStrbufDestroy(&instance->config.diskFormat);
|
||||
ffStrbufDestroy(&instance->config.batteryFormat);
|
||||
ffStrbufDestroy(&instance->config.localeFormat);
|
||||
|
||||
ffStrbufDestroy(&instance->config.libPCI);
|
||||
ffStrbufDestroy(&instance->config.libX11);
|
||||
ffStrbufDestroy(&instance->config.libXrandr);
|
||||
|
||||
ffStrbufDestroy(&instance->config.diskFolders);
|
||||
// Place for cleaning up
|
||||
// I dont destroy the global strbufs, because the OS is typically faster doing it after the program terminates
|
||||
// This eliminates one function call per strbuf + setting things like length to 0
|
||||
}
|
||||
|
||||
void ffFinish(FFinstance* instance)
|
||||
@@ -97,15 +92,120 @@ void ffFinish(FFinstance* instance)
|
||||
ffCleanup(instance);
|
||||
}
|
||||
|
||||
void ffPrintKey(FFconfig* config, const char* key)
|
||||
void ffPrintKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
|
||||
{
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"%s", config->color.chars, key, config->seperator.chars);
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT);
|
||||
ffStrbufWriteTo(&instance->config.color, stdout);
|
||||
if(customKey == NULL || customKey->length == 0)
|
||||
printf(defKey);
|
||||
else
|
||||
ffStrbufWriteTo(customKey, stdout);
|
||||
printf(FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
ffStrbufWriteTo(&instance->config.seperator, stdout);
|
||||
}
|
||||
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* key)
|
||||
void ffPrintLogoAndKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
|
||||
{
|
||||
ffPrintLogoLine(instance);
|
||||
ffPrintKey(&instance->config, key);
|
||||
ffPrintKey(instance, customKey, defKey);
|
||||
}
|
||||
|
||||
void ffPrintError(FFinstance* instance, FFstrbuf* customKey, const char* defKey, const char* message, ...)
|
||||
{
|
||||
if(!instance->config.showErrors)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(instance, customKey, defKey);
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, message);
|
||||
|
||||
printf(FASTFETCH_TEXT_MODIFIER_ERROR);
|
||||
vprintf(message, arguments);
|
||||
puts(FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
static const FFstrbuf* getCacheDir(FFinstance* instance)
|
||||
{
|
||||
static FFstrbuf cacheDir;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
return &cacheDir;
|
||||
|
||||
ffStrbufInitS(&cacheDir, getenv("XDG_CACHE_HOME"));
|
||||
|
||||
if(cacheDir.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&cacheDir, "/.cache/");
|
||||
}
|
||||
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
|
||||
ffStrbufAppendS(&cacheDir, "fastfetch/");
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
|
||||
init = true;
|
||||
return &cacheDir;
|
||||
}
|
||||
|
||||
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey)
|
||||
{
|
||||
if(instance->config.recache)
|
||||
return false;
|
||||
|
||||
FFstrbuf cacheFile;
|
||||
ffStrbufInitA(&cacheFile, 128);
|
||||
ffStrbufAppend(&cacheFile, getCacheDir(instance));
|
||||
ffStrbufAppendS(&cacheFile, defKey);
|
||||
|
||||
FF_STRBUF_CREATE(value);
|
||||
ffGetFileContent(cacheFile.chars, &value);
|
||||
|
||||
ffStrbufDestroy(&cacheFile);
|
||||
|
||||
if(value.length == 0)
|
||||
{
|
||||
ffStrbufDestroy(&value);
|
||||
return false;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, customKey, defKey);
|
||||
ffStrbufPutTo(&value, stdout);
|
||||
ffStrbufDestroy(&value);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value)
|
||||
{
|
||||
if(value->length == 0)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(instance, customKey, defKey);
|
||||
ffStrbufPutTo(value, stdout);
|
||||
|
||||
if(!instance->config.cacheSave)
|
||||
return;
|
||||
|
||||
FFstrbuf cacheFile;
|
||||
ffStrbufInit(&cacheFile);
|
||||
ffStrbufAppend(&cacheFile, getCacheDir(instance));
|
||||
ffStrbufAppendS(&cacheFile, defKey);
|
||||
|
||||
int fd = open(cacheFile.chars, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if(fd == -1)
|
||||
return;
|
||||
|
||||
bool failed = write(fd, value->chars, value->length) != value->length;
|
||||
|
||||
close(fd);
|
||||
|
||||
if(failed)
|
||||
unlink(cacheFile.chars);
|
||||
|
||||
ffStrbufDestroy(&cacheFile);
|
||||
}
|
||||
|
||||
void ffParsePropFile(const char* fileName, const char* regex, char* buffer)
|
||||
@@ -142,83 +242,6 @@ void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const c
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
}
|
||||
|
||||
static inline bool strSet(const char* str)
|
||||
{
|
||||
return str != NULL && str[0] != '\0';
|
||||
}
|
||||
|
||||
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4)
|
||||
{
|
||||
if(strSet(gtk2) && strSet(gtk3) && strSet(gtk4))
|
||||
{
|
||||
if((strcmp(gtk2, gtk3) == 0) && (strcmp(gtk2, gtk4) == 0))
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3/4]", gtk2);
|
||||
else if(strcmp(gtk2, gtk3) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3], %s [GTK4]", gtk2, gtk4);
|
||||
else if(strcmp(gtk3, gtk4) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3/4]", gtk2, gtk3);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3], %s [GTK4]", gtk2, gtk3, gtk4);
|
||||
}
|
||||
else if(strSet(gtk2) && strSet(gtk3))
|
||||
{
|
||||
if(strcmp(gtk2, gtk3) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3]", gtk2);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3]", gtk2, gtk3);
|
||||
}
|
||||
else if(strSet(gtk3) && strSet(gtk4))
|
||||
{
|
||||
if(strcmp(gtk3, gtk4) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK3/4]", gtk3);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK3], %s [GTK4]", gtk3, gtk4);
|
||||
}
|
||||
else if(strSet(gtk2))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK2]", gtk2);
|
||||
}
|
||||
else if(strSet(gtk3))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK3]", gtk3);
|
||||
}
|
||||
else if(strSet(gtk4))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK4]", gtk4);
|
||||
}
|
||||
}
|
||||
|
||||
void ffParseFont(char* font, char* buffer)
|
||||
{
|
||||
char name[64];
|
||||
char size[32];
|
||||
int scanned = sscanf(font, "%[^,], %[^,]", name, size);
|
||||
|
||||
if(scanned == 0)
|
||||
strcpy(buffer, font);
|
||||
else if(scanned == 1)
|
||||
strcpy(buffer, name);
|
||||
else
|
||||
sprintf(buffer, "%s (%spt)", name, size);
|
||||
}
|
||||
|
||||
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...)
|
||||
{
|
||||
if(!instance->config.showErrors)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, message);
|
||||
|
||||
printf(FASTFETCH_TEXT_MODIFIER_ERROR);
|
||||
vprintf(message, arguments);
|
||||
puts(FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
void ffAppendFileContent(const char* fileName, FFstrbuf* buffer)
|
||||
{
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
@@ -247,87 +270,6 @@ void ffGetFileContent(const char* fileName, FFstrbuf* buffer)
|
||||
ffAppendFileContent(fileName, buffer);
|
||||
}
|
||||
|
||||
static const FFstrbuf* getCacheDir(FFinstance* instance)
|
||||
{
|
||||
static FFstrbuf cacheDir;
|
||||
static bool init = false;
|
||||
if(init)
|
||||
return &cacheDir;
|
||||
|
||||
ffStrbufInitS(&cacheDir, getenv("XDG_CACHE_HOME"));
|
||||
|
||||
if(cacheDir.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&cacheDir, "/.cache/");
|
||||
}
|
||||
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder but whow knews
|
||||
|
||||
ffStrbufAppendS(&cacheDir, "fastfetch/");
|
||||
mkdir(cacheDir.chars, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
|
||||
init = true;
|
||||
return &cacheDir;
|
||||
}
|
||||
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key)
|
||||
{
|
||||
if(instance->config.recache)
|
||||
return false;
|
||||
|
||||
FFstrbuf cacheFile;
|
||||
ffStrbufInitA(&cacheFile, 128);
|
||||
ffStrbufAppend(&cacheFile, getCacheDir(instance));
|
||||
ffStrbufAppendS(&cacheFile, key);
|
||||
|
||||
FF_STRBUF_CREATE(value);
|
||||
ffGetFileContent(cacheFile.chars, &value);
|
||||
|
||||
ffStrbufDestroy(&cacheFile);
|
||||
|
||||
if(value.length == 0)
|
||||
{
|
||||
ffStrbufDestroy(&value);
|
||||
return false;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffStrbufPutTo(&value, stdout);
|
||||
ffStrbufDestroy(&value);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, FFstrbuf* value)
|
||||
{
|
||||
if(value->length == 0)
|
||||
return;
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffStrbufPutTo(value, stdout);
|
||||
|
||||
if(!instance->config.cacheSave)
|
||||
return;
|
||||
|
||||
FFstrbuf cacheFile;
|
||||
ffStrbufInit(&cacheFile);
|
||||
ffStrbufAppend(&cacheFile, getCacheDir(instance));
|
||||
ffStrbufAppendS(&cacheFile, key);
|
||||
|
||||
int fd = open(cacheFile.chars, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if(fd == -1)
|
||||
return;
|
||||
|
||||
bool failed = write(fd, value->chars, value->length) != value->length;
|
||||
|
||||
close(fd);
|
||||
|
||||
if(failed)
|
||||
unlink(cacheFile.chars);
|
||||
|
||||
ffStrbufDestroy(&cacheFile);
|
||||
}
|
||||
|
||||
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp)
|
||||
{
|
||||
FFformatarg arguments[numArgs];
|
||||
@@ -431,7 +373,7 @@ void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
void ffPrintFormatString(FFinstance* instance, const char* key, FFstrbuf* formatstr, uint32_t numArgs, ...)
|
||||
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...)
|
||||
{
|
||||
FFstrbuf buffer;
|
||||
ffStrbufInitA(&buffer, 256);
|
||||
@@ -445,9 +387,69 @@ void ffPrintFormatString(FFinstance* instance, const char* key, FFstrbuf* format
|
||||
|
||||
if(buffer.length > 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffPrintLogoAndKey(instance, customKey, defKey);
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&buffer);
|
||||
}
|
||||
|
||||
static inline bool strSet(const char* str)
|
||||
{
|
||||
return str != NULL && str[0] != '\0';
|
||||
}
|
||||
|
||||
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4)
|
||||
{
|
||||
if(strSet(gtk2) && strSet(gtk3) && strSet(gtk4))
|
||||
{
|
||||
if((strcmp(gtk2, gtk3) == 0) && (strcmp(gtk2, gtk4) == 0))
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3/4]", gtk2);
|
||||
else if(strcmp(gtk2, gtk3) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3], %s [GTK4]", gtk2, gtk4);
|
||||
else if(strcmp(gtk3, gtk4) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3/4]", gtk2, gtk3);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3], %s [GTK4]", gtk2, gtk3, gtk4);
|
||||
}
|
||||
else if(strSet(gtk2) && strSet(gtk3))
|
||||
{
|
||||
if(strcmp(gtk2, gtk3) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK2/3]", gtk2);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3]", gtk2, gtk3);
|
||||
}
|
||||
else if(strSet(gtk3) && strSet(gtk4))
|
||||
{
|
||||
if(strcmp(gtk3, gtk4) == 0)
|
||||
ffStrbufSetF(buffer, "%s [GTK3/4]", gtk3);
|
||||
else
|
||||
ffStrbufSetF(buffer, "%s [GTK3], %s [GTK4]", gtk3, gtk4);
|
||||
}
|
||||
else if(strSet(gtk2))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK2]", gtk2);
|
||||
}
|
||||
else if(strSet(gtk3))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK3]", gtk3);
|
||||
}
|
||||
else if(strSet(gtk4))
|
||||
{
|
||||
ffStrbufSetF(buffer, "%s [GTK4]", gtk4);
|
||||
}
|
||||
}
|
||||
|
||||
void ffParseFont(char* font, char* buffer)
|
||||
{
|
||||
char name[64];
|
||||
char size[32];
|
||||
int scanned = sscanf(font, "%[^,], %[^,]", name, size);
|
||||
|
||||
if(scanned == 0)
|
||||
strcpy(buffer, font);
|
||||
else if(scanned == 1)
|
||||
strcpy(buffer, name);
|
||||
else
|
||||
sprintf(buffer, "%s (%spt)", name, size);
|
||||
}
|
||||
|
||||
+218
-29
@@ -80,10 +80,33 @@ static inline void printHelp()
|
||||
" --battery-format <format>\n"
|
||||
" --locale-format <format>\n"
|
||||
"\n"
|
||||
"Key options: Provide a custom key for an output\n"
|
||||
" --os-key <key>\n"
|
||||
" --host-key <key>\n"
|
||||
" --kernel-key <key>\n"
|
||||
" --uptime-format <key>\n"
|
||||
" --packages-format <key>\n"
|
||||
" --shell-format <key>\n"
|
||||
" --resolution-format <key>\n"
|
||||
" --de-format <key>\n"
|
||||
" --wm-format <key>\n"
|
||||
" --theme-format <key>\n"
|
||||
" --icons-format <key>\n"
|
||||
" --font-format <key>\n"
|
||||
" --terminal-format <key>\n"
|
||||
" --terminal-font-format <key>\n"
|
||||
" --cpu-format <key>\n"
|
||||
" --gpu-format <key>: takes the gpu index as format argument\n"
|
||||
" --memory-format <key>\n"
|
||||
" --disk-format <key>: takes the mount path as format argument\n"
|
||||
" --battery-format <key>: takes the battery index as format argument\n"
|
||||
" --locale-format <key>\n"
|
||||
"\n"
|
||||
"Library optins: Set the path of a library to load\n"
|
||||
" --lib-PCI <path>\n"
|
||||
" --lib-X11 <path>\n"
|
||||
" --lib-Xrandr <path>\n"
|
||||
"\n"
|
||||
"Module specific options:\n"
|
||||
" --disk-folders <folders>: A colon seperated list of folder paths for the disk output. Default is \"/:/home\"\n"
|
||||
"\n"
|
||||
@@ -208,45 +231,170 @@ static inline void printCommandHelp(const char* command)
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "host-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("host", "{} {} {}", 3, "Host family", "Host name", "Host version");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("host", "{} {} {}", 3,
|
||||
"Host family",
|
||||
"Host name",
|
||||
"Host version"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "kernel-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("kernel", "{2}", 3, "Kernel sysname", "Kernel release", "Kernel version");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("kernel", "{2}", 3,
|
||||
"Kernel sysname",
|
||||
"Kernel release",
|
||||
"Kernel version"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "uptime-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("uptime", "{} days {} hours {} mins", 4, "Days", "Hours", "Minutes", "Seconds");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("uptime", "{} days {} hours {} mins", 4,
|
||||
"Days",
|
||||
"Hours",
|
||||
"Minutes",
|
||||
"Seconds"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "packages-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman), {3} (flatpak)", 3, "Number of all packages", "Number of pacman packages", "Number of flatpak packages");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman), {3} (flatpak)", 3,
|
||||
"Number of all packages",
|
||||
"Number of pacman packages",
|
||||
"Number of flatpak packages"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "shell-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("shell", "{2}", 2, "Shell path (without name)", "Shell name");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("shell", "{2}", 2,
|
||||
"Shell path (without name)",
|
||||
"Shell name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "resolution-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("resolution", "{}x{} @ {}Hz", 3, "Screen width", "Screen height", "Screen refresh rate");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("resolution", "{}x{} @ {}Hz", 3,
|
||||
"Screen width",
|
||||
"Screen height",
|
||||
"Screen refresh rate"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "de-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("de", "{} {} ({})", 3, "DE name", "DE version", "Name of display server");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("de", "{} {} ({})", 3,
|
||||
"DE name",
|
||||
"DE version",
|
||||
"Name of display server"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "wm-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("wm", "{2}", 2, "WM process name", "WM pretty name");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("wm", "{2}", 2,
|
||||
"WM process name",
|
||||
"WM pretty name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "theme-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("theme", "{} [Plasma], {5}", 5, "Plasma theme", "GTK2 theme", "GTK3 theme", "GTK4 theme", "Combined GTK themes");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("theme", "{} [Plasma], {5}", 5,
|
||||
"Plasma theme",
|
||||
"GTK2 theme",
|
||||
"GTK3 theme",
|
||||
"GTK4 theme",
|
||||
"Combined GTK themes"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "icons-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("icons", "{} [Plasma], {5}", 5, "Plasma icons", "GTK2 icons", "GTK3 icons", "GTK4 icons", "Combined GTK icons");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("icons", "{} [Plasma], {5}", 5,
|
||||
"Plasma icons",
|
||||
"GTK2 icons",
|
||||
"GTK3 icons",
|
||||
"GTK4 icons",
|
||||
"Combined GTK icons"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "font-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("font", "{} [Plasma], {5}", 5, "Plasma font", "GTK2 font", "GTK3 font", "GTK4 font", "Combined GTK fonts");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("font", "{} [Plasma], {5}", 5,
|
||||
"Plasma font",
|
||||
"GTK2 font",
|
||||
"GTK3 font",
|
||||
"GTK4 font",
|
||||
"Combined GTK fonts"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "terminal-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("terminal", "{3}", 3, "Terminal executable name", "Terminal process name", "Terminal name");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("terminal", "{3}", 3,
|
||||
"Terminal executable name",
|
||||
"Terminal process name",
|
||||
"Terminal name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "terminal-font-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("terminal-font", "{}", 1, "Terminal font name");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("terminal-font", "{}", 1,
|
||||
"Terminal font name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "cpu-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("cpu", "{2} ({4}) @ {7}GHz", 11, "CPU name", "Prettified CPU name", "CPU Vendor name (Vendor ID)", "CPU logical core count online", "CPU logical core count configured", "CPU physical core count", "frequency bios limit", "frequency scaling max", "frequency scaling min", "frequency info max", "frequency info min");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("cpu", "{2} ({4}) @ {7}GHz", 11,
|
||||
"CPU name",
|
||||
"Prettified CPU name",
|
||||
"CPU Vendor name (Vendor ID)",
|
||||
"CPU logical core count online",
|
||||
"CPU logical core count configured",
|
||||
"CPU physical core count",
|
||||
"frequency bios limit",
|
||||
"frequency scaling max",
|
||||
"frequency scaling min",
|
||||
"frequency info max",
|
||||
"frequency info min"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "gpu-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("gpu", "{} {}", 2, "GPU vendor", "GPU name");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("gpu", "{} {}", 2,
|
||||
"GPU vendor",
|
||||
"GPU name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "memory-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("memory", "{}MiB / {}MiB ({}%)", 3, "Used memory", "Total memory", "Used memory percentage");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("memory", "{}MiB / {}MiB ({}%)", 3,
|
||||
"Used memory",
|
||||
"Total memory",
|
||||
"Used memory percentage"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "disk-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("disk", "{}GB / {}GB ({4}%)", 4, "Used disk space", "Total disk space", "Number of files", "Used disk space percentage");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("disk", "{}GB / {}GB ({4}%)", 4,
|
||||
"Used disk space",
|
||||
"Total disk space",
|
||||
"Number of files",
|
||||
"Used disk space percentage"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "battery-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("battery", "{} {} ({}) [{}%; {}]", 5, "Battery manufactor", "Battery model", "Battery technology", "Battery capacity", "Battery status");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("battery", "{} {} ({}) [{}%; {}]", 5,
|
||||
"Battery manufactor",
|
||||
"Battery model",
|
||||
"Battery technology",
|
||||
"Battery capacity",
|
||||
"Battery status"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "locale-format") == 0)
|
||||
constructAndPrintCommandHelpFormat("locale", "{}", 1, "Locale code");
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("locale", "{}", 1,
|
||||
"Locale code"
|
||||
);
|
||||
}
|
||||
else
|
||||
printf("No specific help for command %s provided\n", command);
|
||||
fprintf(stderr, "No specific help for command %s provided\n", command);
|
||||
}
|
||||
|
||||
static inline bool optionParseBoolean(const char* str)
|
||||
@@ -265,9 +413,10 @@ static inline void optionParseString(const char* key, const char* value, FFstrbu
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <str>\n", key);
|
||||
fprintf(stderr, "Error: usage: %s <str>\n", key);
|
||||
exit(477);
|
||||
}
|
||||
ffStrbufEnsureCapacity(buffer, 64); //This is not needed as ffStrbufSetS will resize capacity if needed, but giving an higher start should improve performance
|
||||
ffStrbufSetS(buffer, value);
|
||||
}
|
||||
|
||||
@@ -316,12 +465,12 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <width>\n", key);
|
||||
fprintf(stderr, "Error: usage: %s <width>\n", key);
|
||||
exit(404);
|
||||
}
|
||||
if(sscanf(value, "%hd", &instance->config.logo_spacing) != 1)
|
||||
{
|
||||
printf("Error: couldn't parse %s to uint16_t\n", value);
|
||||
fprintf(stderr, "Error: couldn't parse %s to uint16_t\n", value);
|
||||
exit(405);
|
||||
}
|
||||
}
|
||||
@@ -329,12 +478,12 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <offset>\n", key);
|
||||
fprintf(stderr, "Error: usage: %s <offset>\n", key);
|
||||
exit(408);
|
||||
}
|
||||
if(sscanf(value, "%hi", &instance->config.offsetx) != 1)
|
||||
{
|
||||
printf("Error: couldn't parse %s to int16_t\n", value);
|
||||
fprintf(stderr, "Error: couldn't parse %s to int16_t\n", value);
|
||||
exit(409);
|
||||
}
|
||||
}
|
||||
@@ -342,7 +491,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <key=value>\n", key);
|
||||
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
|
||||
exit(411);
|
||||
}
|
||||
|
||||
@@ -350,7 +499,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
|
||||
if(seperator == NULL)
|
||||
{
|
||||
printf("Error: usage: %s <key=value>, '=' missing\n", key);
|
||||
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
|
||||
exit(412);
|
||||
}
|
||||
|
||||
@@ -380,44 +529,84 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.color);
|
||||
else if(strcasecmp(key, "--os-format") == 0)
|
||||
optionParseString(key, value, &instance->config.osFormat);
|
||||
else if(strcasecmp(key, "--os-key") == 0)
|
||||
optionParseString(key, value, &instance->config.osKey);
|
||||
else if(strcasecmp(key, "--host-format") == 0)
|
||||
optionParseString(key, value, &instance->config.hostFormat);
|
||||
else if(strcasecmp(key, "--host-key") == 0)
|
||||
optionParseString(key, value, &instance->config.hostKey);
|
||||
else if(strcasecmp(key, "--kernel-format") == 0)
|
||||
optionParseString(key, value, &instance->config.kernelFormat);
|
||||
else if(strcasecmp(key, "--kernel-key") == 0)
|
||||
optionParseString(key, value, &instance->config.kernelKey);
|
||||
else if(strcasecmp(key, "--uptime-format") == 0)
|
||||
optionParseString(key, value, &instance->config.uptimeFormat);
|
||||
else if(strcasecmp(key, "--uptime-key") == 0)
|
||||
optionParseString(key, value, &instance->config.uptimeKey);
|
||||
else if(strcasecmp(key, "--packages-format") == 0)
|
||||
optionParseString(key, value, &instance->config.packagesFormat);
|
||||
else if(strcasecmp(key, "--packages-key") == 0)
|
||||
optionParseString(key, value, &instance->config.packagesKey);
|
||||
else if(strcasecmp(key, "--shell-format") == 0)
|
||||
optionParseString(key, value, &instance->config.shellFormat);
|
||||
else if(strcasecmp(key, "--shell-key") == 0)
|
||||
optionParseString(key, value, &instance->config.shellKey);
|
||||
else if(strcasecmp(key, "--resolution-format") == 0)
|
||||
optionParseString(key, value, &instance->config.resolutionFormat);
|
||||
else if(strcasecmp(key, "--resolution-key") == 0)
|
||||
optionParseString(key, value, &instance->config.resolutionKey);
|
||||
else if(strcasecmp(key, "--de-format") == 0)
|
||||
optionParseString(key, value, &instance->config.deFormat);
|
||||
else if(strcasecmp(key, "--de-key") == 0)
|
||||
optionParseString(key, value, &instance->config.deKey);
|
||||
else if(strcasecmp(key, "--wm-format") == 0)
|
||||
optionParseString(key, value, &instance->config.wmFormat);
|
||||
else if(strcasecmp(key, "--wm-key") == 0)
|
||||
optionParseString(key, value, &instance->config.wmKey);
|
||||
else if(strcasecmp(key, "--theme-format") == 0)
|
||||
optionParseString(key, value, &instance->config.themeFormat);
|
||||
else if(strcasecmp(key, "--theme-key") == 0)
|
||||
optionParseString(key, value, &instance->config.themeKey);
|
||||
else if(strcasecmp(key, "--icons-format") == 0)
|
||||
optionParseString(key, value, &instance->config.iconsFormat);
|
||||
else if(strcasecmp(key, "--icons-key") == 0)
|
||||
optionParseString(key, value, &instance->config.iconsKey);
|
||||
else if(strcasecmp(key, "--font-format") == 0)
|
||||
optionParseString(key, value, &instance->config.fontFormat);
|
||||
else if(strcasecmp(key, "--font-key") == 0)
|
||||
optionParseString(key, value, &instance->config.fontKey);
|
||||
else if(strcasecmp(key, "--terminal-format") == 0)
|
||||
optionParseString(key, value, &instance->config.terminalFormat);
|
||||
else if(strcasecmp(key, "--terminal-key") == 0)
|
||||
optionParseString(key, value, &instance->config.terminalKey);
|
||||
else if(strcasecmp(key, "--terminal-font-format") == 0)
|
||||
optionParseString(key, value, &instance->config.termFontFormat);
|
||||
else if(strcasecmp(key, "--terminal-font-key") == 0)
|
||||
optionParseString(key, value, &instance->config.termFontKey);
|
||||
else if(strcasecmp(key, "--cpu-format") == 0)
|
||||
optionParseString(key, value, &instance->config.cpuFormat);
|
||||
else if(strcasecmp(key, "--cpu-key") == 0)
|
||||
optionParseString(key, value, &instance->config.cpuKey);
|
||||
else if(strcasecmp(key, "--gpu-format") == 0)
|
||||
optionParseString(key, value, &instance->config.gpuFormat);
|
||||
else if(strcasecmp(key, "--gpu-key") == 0)
|
||||
optionParseString(key, value, &instance->config.gpuKey);
|
||||
else if(strcasecmp(key, "--memory-format") == 0)
|
||||
optionParseString(key, value, &instance->config.memoryFormat);
|
||||
else if(strcasecmp(key, "--memory-key") == 0)
|
||||
optionParseString(key, value, &instance->config.memoryKey);
|
||||
else if(strcasecmp(key, "--disk-format") == 0)
|
||||
optionParseString(key, value, &instance->config.diskFormat);
|
||||
else if(strcasecmp(key, "--disk-key") == 0)
|
||||
optionParseString(key, value, &instance->config.diskKey);
|
||||
else if(strcasecmp(key, "--battery-format") == 0)
|
||||
optionParseString(key, value, &instance->config.batteryFormat);
|
||||
else if(strcasecmp(key, "--battery-key") == 0)
|
||||
optionParseString(key, value, &instance->config.batteryKey);
|
||||
else if(strcasecmp(key, "--locale-format") == 0)
|
||||
optionParseString(key, value, &instance->config.localeFormat);
|
||||
else if(strcasecmp(key, "--locale-key") == 0)
|
||||
optionParseString(key, value, &instance->config.localeKey);
|
||||
else if(strcasecmp(key, "--lib-PCI") == 0)
|
||||
optionParseString(key, value, &instance->config.libPCI);
|
||||
else if(strcasecmp(key, "--lib-X11") == 0)
|
||||
@@ -428,7 +617,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.diskFolders);
|
||||
else
|
||||
{
|
||||
printf("Error: unknown option: %s\n", key);
|
||||
fprintf(stderr, "Error: unknown option: %s\n", key);
|
||||
exit(400);
|
||||
}
|
||||
}
|
||||
@@ -616,7 +805,7 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
else if(strcasecmp(line, "colors") == 0)
|
||||
ffPrintColors(instance);
|
||||
else
|
||||
ffPrintError(instance, line, "<no implementaion provided>");
|
||||
ffPrintError(instance, NULL, line, "<no implementaion provided>");
|
||||
}
|
||||
|
||||
static void run(FFinstance* instance, FFdata* data)
|
||||
|
||||
+30
-10
@@ -47,25 +47,45 @@ typedef struct FFconfig
|
||||
bool printRemainingLogo;
|
||||
|
||||
FFstrbuf osFormat;
|
||||
FFstrbuf osKey;
|
||||
FFstrbuf hostFormat;
|
||||
FFstrbuf hostKey;
|
||||
FFstrbuf kernelFormat;
|
||||
FFstrbuf kernelKey;
|
||||
FFstrbuf uptimeFormat;
|
||||
FFstrbuf uptimeKey;
|
||||
FFstrbuf packagesFormat;
|
||||
FFstrbuf packagesKey;
|
||||
FFstrbuf shellFormat;
|
||||
FFstrbuf shellKey;
|
||||
FFstrbuf resolutionFormat;
|
||||
FFstrbuf resolutionKey;
|
||||
FFstrbuf deFormat;
|
||||
FFstrbuf deKey;
|
||||
FFstrbuf wmFormat;
|
||||
FFstrbuf wmKey;
|
||||
FFstrbuf themeFormat;
|
||||
FFstrbuf themeKey;
|
||||
FFstrbuf iconsFormat;
|
||||
FFstrbuf iconsKey;
|
||||
FFstrbuf fontFormat;
|
||||
FFstrbuf fontKey;
|
||||
FFstrbuf terminalFormat;
|
||||
FFstrbuf terminalKey;
|
||||
FFstrbuf termFontFormat;
|
||||
FFstrbuf termFontKey;
|
||||
FFstrbuf cpuFormat;
|
||||
FFstrbuf cpuKey;
|
||||
FFstrbuf gpuFormat;
|
||||
FFstrbuf gpuKey;
|
||||
FFstrbuf memoryFormat;
|
||||
FFstrbuf memoryKey;
|
||||
FFstrbuf diskFormat;
|
||||
FFstrbuf diskKey;
|
||||
FFstrbuf batteryFormat;
|
||||
FFstrbuf batteryKey;
|
||||
FFstrbuf localeFormat;
|
||||
FFstrbuf localeKey;
|
||||
|
||||
FFstrbuf libPCI;
|
||||
FFstrbuf libX11;
|
||||
@@ -102,26 +122,26 @@ typedef enum FFformatargtype
|
||||
typedef struct FFformatarg
|
||||
{
|
||||
FFformatargtype type;
|
||||
void* value;
|
||||
const void* value;
|
||||
} FFformatarg;
|
||||
|
||||
//Util functions
|
||||
//Common functions
|
||||
void ffInitState(FFstate* state);
|
||||
void ffDefaultConfig(FFconfig* config);
|
||||
void ffPrintKey(FFconfig* config, const char* key);
|
||||
void ffPrintLogoAndKey(FFinstance* instance, const char* key);
|
||||
void ffPrintKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
|
||||
void ffPrintLogoAndKey(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
|
||||
void ffPrintError(FFinstance* instance, FFstrbuf* customKey, const char* defKey, const char* message, ...);
|
||||
bool ffPrintCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey);
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* value);
|
||||
void ffAppendFileContent(const char* fileName, FFstrbuf* buffer);
|
||||
void ffGetFileContent(const char* fileName, FFstrbuf* buffer);
|
||||
void ffParsePropFile(const char* file, const char* regex, char* buffer);
|
||||
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer);
|
||||
void ffParseFont(char* font, char* buffer);
|
||||
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4);
|
||||
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...);
|
||||
bool ffPrintCachedValue(FFinstance* instance, const char* key);
|
||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, FFstrbuf* value);
|
||||
void ffParseFormatStringV(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, va_list argp);
|
||||
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
|
||||
void ffPrintFormatString(FFinstance* instance, const char* key, FFstrbuf* formatstr, uint32_t numArgs, ...);
|
||||
void ffPrintFormatString(FFinstance* instance, FFstrbuf* customKey, const char* defKey, FFstrbuf* formatstr, uint32_t numArgs, ...);
|
||||
void ffParseFont(char* font, char* buffer);
|
||||
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4);
|
||||
void ffFinish(FFinstance* instance);
|
||||
|
||||
//Logo functions
|
||||
|
||||
+45
-11
@@ -6,31 +6,42 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
{
|
||||
FF_STRBUF_CREATE(manufactor);
|
||||
char manufactorPath[42];
|
||||
sprintf(manufactorPath, "/sys/class/power_supply/BAT%i/manufacturer", index);
|
||||
sprintf(manufactorPath, "/sys/class/power_supply/BAT%hhu/manufacturer", index);
|
||||
ffGetFileContent(manufactorPath, &manufactor);
|
||||
|
||||
FF_STRBUF_CREATE(model);
|
||||
char modelPath[40];
|
||||
sprintf(modelPath, "/sys/class/power_supply/BAT%i/model_name", index);
|
||||
sprintf(modelPath, "/sys/class/power_supply/BAT%hhu/model_name", index);
|
||||
ffGetFileContent(modelPath, &model);
|
||||
|
||||
FF_STRBUF_CREATE(technology);
|
||||
char technologyPath[40];
|
||||
sprintf(technologyPath, "/sys/class/power_supply/BAT%i/technology", index);
|
||||
sprintf(technologyPath, "/sys/class/power_supply/BAT%hhu/technology", index);
|
||||
ffGetFileContent(technologyPath, &technology);
|
||||
|
||||
FF_STRBUF_CREATE(capacity);
|
||||
char capacityPath[38];
|
||||
sprintf(capacityPath, "/sys/class/power_supply/BAT%i/capacity", index);
|
||||
sprintf(capacityPath, "/sys/class/power_supply/BAT%hhu/capacity", index);
|
||||
ffGetFileContent(capacityPath, &capacity);
|
||||
|
||||
FF_STRBUF_CREATE(status);
|
||||
char statusPath[36];
|
||||
sprintf(statusPath, "/sys/class/power_supply/BAT%i/status", index);
|
||||
sprintf(statusPath, "/sys/class/power_supply/BAT%hhu/status", index);
|
||||
ffGetFileContent(statusPath, &status);
|
||||
|
||||
char key[10];
|
||||
sprintf(key, "Battery %i", index);
|
||||
uint8_t indexPlusOne = index + 1;
|
||||
|
||||
FF_STRBUF_CREATE(key);
|
||||
if(instance->config.batteryKey.length == 0)
|
||||
{
|
||||
ffStrbufAppendF(&key, "Battery %hhu", indexPlusOne);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&key, &instance->config.batteryKey, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &indexPlusOne}
|
||||
);
|
||||
}
|
||||
|
||||
if(instance->config.batteryFormat.length == 0)
|
||||
{
|
||||
@@ -41,11 +52,11 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
capacity.length == 0 &&
|
||||
status.length == 0
|
||||
) {
|
||||
ffPrintError(instance, key, "No file in /sys/class/power_supply/BAT0/ could be read or all battery options are disabled");
|
||||
ffPrintError(instance, &key, NULL, "No file in /sys/class/power_supply/BAT%hhu/ could be read or all battery options are disabled", index);
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffPrintLogoAndKey(instance, &key, NULL);
|
||||
|
||||
if(manufactor.length > 0)
|
||||
printf("%s ", manufactor.chars);
|
||||
@@ -75,7 +86,7 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, key, &instance->config.batteryFormat, 5,
|
||||
ffPrintFormatString(instance, &key, NULL, &instance->config.batteryFormat, 5,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &manufactor},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &model},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &technology},
|
||||
@@ -89,10 +100,12 @@ static void printBattery(FFinstance* instance, uint8_t index)
|
||||
ffStrbufDestroy(&technology);
|
||||
ffStrbufDestroy(&capacity);
|
||||
ffStrbufDestroy(&status);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
|
||||
void ffPrintBattery(FFinstance* instance)
|
||||
{
|
||||
uint8_t batteryCounter = 0;
|
||||
for(uint8_t i = 0; i < 5; i++)
|
||||
{
|
||||
char path[30];
|
||||
@@ -101,8 +114,29 @@ void ffPrintBattery(FFinstance* instance)
|
||||
DIR* dir = opendir(path);
|
||||
if(dir != NULL)
|
||||
{
|
||||
printBattery(instance, i);
|
||||
printBattery(instance, batteryCounter++);
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
if(batteryCounter == 0)
|
||||
{
|
||||
if(!instance->config.showErrors)
|
||||
return;
|
||||
|
||||
FF_STRBUF_CREATE(key);
|
||||
if(instance->config.batteryKey.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&key, "Battery");
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&key, &instance->config.batteryKey, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &batteryCounter}
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintError(instance, &key, NULL, "No battery found in /sys/class/power_supply/");
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ static double getGhz(const char* file)
|
||||
|
||||
void ffPrintCPU(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "CPU"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.cpuKey, "CPU"))
|
||||
return;
|
||||
|
||||
char name[256]; name[0] = '\0';
|
||||
@@ -100,7 +100,7 @@ void ffPrintCPU(FFinstance* instance)
|
||||
ffStrbufAppendS(&cpu, " unknwon processor");
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, "CPU", "No CPU info found in /proc/cpuinfo");
|
||||
ffPrintError(instance, &instance->config.cpuKey, "CPU", "No CPU info found in /proc/cpuinfo");
|
||||
ffStrbufDestroy(&cpu);
|
||||
ffStrbufDestroy(&namePretty);
|
||||
return;
|
||||
@@ -129,7 +129,7 @@ void ffPrintCPU(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "CPU", &cpu);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.cpuKey, "CPU", &cpu);
|
||||
ffStrbufDestroy(&cpu);
|
||||
|
||||
ffStrbufDestroy(&namePretty);
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
void ffPrintCustom(FFinstance* instance, const char* key, const char* value)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffPrintLogoAndKey(instance, NULL, key);
|
||||
puts(value);
|
||||
}
|
||||
|
||||
+3
-3
@@ -42,11 +42,11 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
{
|
||||
if(sessionDesktop.length == 0 && sessionType.length == 0)
|
||||
{
|
||||
ffPrintError(instance, "DE", "Neither DE nor Display Server could be determined");
|
||||
ffPrintError(instance, &instance->config.deKey, "DE", "Neither DE nor Display Server could be determined");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "DE");
|
||||
ffPrintLogoAndKey(instance, &instance->config.deKey, "DE");
|
||||
|
||||
if(sessionDesktop.length > 0)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "DE", &instance->config.deFormat, 3,
|
||||
ffPrintFormatString(instance, &instance->config.deFormat, "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}
|
||||
|
||||
+31
-12
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
static void printStatvfs(FFinstance* instance, const char* key, struct statvfs* fs)
|
||||
static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs)
|
||||
{
|
||||
const uint32_t GB = 1024 * 1024 * 1024;
|
||||
|
||||
@@ -15,12 +15,12 @@ static void printStatvfs(FFinstance* instance, const char* key, struct statvfs*
|
||||
|
||||
if(instance->config.diskFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key);
|
||||
ffPrintLogoAndKey(instance, key, NULL);
|
||||
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, key, &instance->config.diskFormat, 4,
|
||||
ffPrintFormatString(instance, key, NULL, &instance->config.diskFormat, 4,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &files},
|
||||
@@ -29,24 +29,43 @@ static void printStatvfs(FFinstance* instance, const char* key, struct statvfs*
|
||||
}
|
||||
}
|
||||
|
||||
static void createKey(FFinstance* instance, FFstrbuf* key, const char* folderPath)
|
||||
{
|
||||
if(instance->config.diskKey.length == 0)
|
||||
{
|
||||
ffStrbufAppendF(key, "Disk (%s)", folderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(key, &instance->config.diskKey, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, folderPath}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static void printStatvfsCreateKey(FFinstance* instance, const char* folderPath, struct statvfs* fs)
|
||||
{
|
||||
FF_STRBUF_CREATE(key);
|
||||
createKey(instance, &key, folderPath);
|
||||
printStatvfs(instance, &key, fs);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
|
||||
static void printFolder(FFinstance* instance, const char* folderPath)
|
||||
{
|
||||
FF_STRBUF_CREATE(key);
|
||||
ffStrbufAppendS(&key, "Disk (");
|
||||
ffStrbufAppendS(&key, folderPath);
|
||||
ffStrbufAppendC(&key, ')');
|
||||
createKey(instance, &key, folderPath);
|
||||
|
||||
struct statvfs fs;
|
||||
int ret = statvfs(folderPath, &fs);
|
||||
if(ret != 0 && instance->config.diskFormat.length == 0)
|
||||
{
|
||||
ffPrintError(instance, key.chars, "statvfs(\"%s\", &fs) != 0", folderPath);
|
||||
ffPrintError(instance, &key, NULL, "statvfs(\"%s\", &fs) != 0", folderPath);
|
||||
ffStrbufDestroy(&key);
|
||||
return;
|
||||
}
|
||||
|
||||
printStatvfs(instance, key.chars, &fs);
|
||||
|
||||
printStatvfs(instance, &key, &fs);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
|
||||
@@ -62,15 +81,15 @@ void ffPrintDisk(FFinstance* instance)
|
||||
|
||||
if(rootRet != 0 && homeRet != 0)
|
||||
{
|
||||
ffPrintError(instance, "Disk", "statvfs failed for both / and /home");
|
||||
ffPrintError(instance, NULL, "Disk", "statvfs failed for both / and /home");
|
||||
return;
|
||||
}
|
||||
|
||||
if(rootRet == 0)
|
||||
printStatvfs(instance, "Disk (/)", &fsRoot);
|
||||
printStatvfsCreateKey(instance, "/", &fsRoot);
|
||||
|
||||
if(homeRet == 0 && (rootRet != 0 || fsRoot.f_fsid != fsHome.f_fsid))
|
||||
printStatvfs(instance, "Disk (/home)", &fsHome);
|
||||
printStatvfsCreateKey(instance, "/home", &fsHome);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+2
-2
@@ -43,13 +43,13 @@ void ffPrintFont(FFinstance* instance)
|
||||
|
||||
if(instance->config.fontFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Font");
|
||||
ffPrintLogoAndKey(instance, &instance->config.fontKey, "Font");
|
||||
printf("%s [Plasma], ", plasmaPretty);
|
||||
ffStrbufPutTo(>kPretty, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Font", &instance->config.fontFormat, 5,
|
||||
ffPrintFormatString(instance, &instance->config.fontKey, "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},
|
||||
|
||||
+26
-13
@@ -3,12 +3,24 @@
|
||||
#include <pci/pci.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, uint16_t counter, char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...))
|
||||
static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, uint32_t counter, char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...))
|
||||
{
|
||||
char key[8];
|
||||
sprintf(key, "GPU%hu", counter);
|
||||
char cacheKey[8];
|
||||
sprintf(cacheKey, "GPU%u", counter);
|
||||
|
||||
if(ffPrintCachedValue(instance, key))
|
||||
FF_STRBUF_CREATE(key);
|
||||
if(instance->config.gpuKey.length == 0)
|
||||
{
|
||||
ffStrbufAppendF(&key, "GPU %u", counter);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&key, &instance->config.gpuKey, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &counter}
|
||||
);
|
||||
}
|
||||
|
||||
if(ffPrintCachedValue(instance, &key, cacheKey))
|
||||
return;
|
||||
|
||||
char vendor[512];
|
||||
@@ -37,8 +49,9 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, key, &gpu);
|
||||
ffPrintAndSaveCachedValue(instance, &key, cacheKey, &gpu);
|
||||
ffStrbufDestroy(&gpu);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
|
||||
void ffPrintGPU(FFinstance* instance)
|
||||
@@ -50,53 +63,53 @@ void ffPrintGPU(FFinstance* instance)
|
||||
pci = dlopen(instance->config.libPCI.chars, RTLD_LAZY);
|
||||
if(pci == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
struct pci_access*(*ffpci_alloc)() = dlsym(pci, "pci_alloc");
|
||||
if(ffpci_alloc == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_alloc\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_alloc\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
void(*ffpci_init)(struct pci_access*) = dlsym(pci, "pci_init");
|
||||
if(ffpci_init == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_init\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_init\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
void(*ffpci_scan_bus)(struct pci_access*) = dlsym(pci, "pci_scan_bus");
|
||||
if(ffpci_scan_bus == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_init\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_init\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
int(*ffpci_fill_info)(struct pci_dev*, int) = dlsym(pci, "pci_fill_info");
|
||||
if(ffpci_fill_info == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_fill_info\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_fill_info\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...) = dlsym(pci, "pci_lookup_name");
|
||||
if(ffpci_lookup_name == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_lookup_name\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_lookup_name\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
void(*ffpci_cleanup)(struct pci_access*) = dlsym(pci, "pci_cleanup");
|
||||
if(ffpci_cleanup == NULL)
|
||||
{
|
||||
ffPrintError(instance, "GPU", "dlsym(pci, \"pci_cleanup\") == NULL");
|
||||
ffPrintError(instance, NULL, "GPU", "dlsym(pci, \"pci_cleanup\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t counter = 0;
|
||||
uint32_t counter = 0;
|
||||
|
||||
struct pci_access *pacc;
|
||||
struct pci_dev *dev;
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
void ffPrintHost(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "Host"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.hostKey, "Host"))
|
||||
return;
|
||||
|
||||
FF_STRBUF_CREATE(family);
|
||||
@@ -20,7 +20,7 @@ void ffPrintHost(FFinstance* instance)
|
||||
{
|
||||
if(family.length == 0 && name.length == 0)
|
||||
{
|
||||
ffPrintError(instance, "Host", "neither family nor name could be determined");
|
||||
ffPrintError(instance, &instance->config.hostKey, "Host", "neither family nor name could be determined");
|
||||
return;
|
||||
}
|
||||
else if(name.length == 0)
|
||||
@@ -56,7 +56,7 @@ void ffPrintHost(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Host", &host);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.hostKey, "Host", &host);
|
||||
ffStrbufDestroy(&host);
|
||||
|
||||
ffStrbufDestroy(&family);
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ void ffPrintIcons(FFinstance* instance)
|
||||
|
||||
if(instance->config.iconsFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Icons");
|
||||
ffPrintLogoAndKey(instance, &instance->config.iconsKey, "Icons");
|
||||
|
||||
if(plasma[0] == '\0')
|
||||
printf("Breeze [Plasma], ");
|
||||
@@ -36,7 +36,7 @@ void ffPrintIcons(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Icons", &instance->config.iconsFormat, 5,
|
||||
ffPrintFormatString(instance, &instance->config.iconsKey, "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},
|
||||
|
||||
@@ -4,12 +4,12 @@ void ffPrintKernel(FFinstance* instance)
|
||||
{
|
||||
if(instance->config.kernelFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Kernel");
|
||||
ffPrintLogoAndKey(instance, &instance->config.kernelKey, "Kernel");
|
||||
puts(instance->state.utsname.release);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Kernel", &instance->config.kernelFormat, 3,
|
||||
ffPrintFormatString(instance, &instance->config.kernelKey, "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}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
void ffPrintLocale(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "Locale"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.localeKey, "Locale"))
|
||||
return;
|
||||
|
||||
char localeCode[256];
|
||||
@@ -30,7 +30,7 @@ void ffPrintLocale(FFinstance* instance)
|
||||
strcpy(localeCode, getenv("LC_MESSAGES"));
|
||||
/* User has broken system */
|
||||
else
|
||||
ffPrintError(instance, "Locale", "Locale not found!");
|
||||
ffPrintError(instance, &instance->config.localeKey, "Locale", "Locale not found!");
|
||||
/* /etc/locale.conf exists */
|
||||
} else {
|
||||
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode);
|
||||
@@ -52,6 +52,6 @@ void ffPrintLocale(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Locale", &locale);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.localeKey, "Locale", &locale);
|
||||
ffStrbufDestroy(&locale);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ void ffPrintMemory(FFinstance* instance)
|
||||
{
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL) {
|
||||
ffPrintError(instance, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
|
||||
ffPrintError(instance, &instance->config.memoryKey, "Memory", "fopen(\"/proc/meminfo\", \"r\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ void ffPrintMemory(FFinstance* instance)
|
||||
|
||||
if(instance->config.memoryFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Memory");
|
||||
ffPrintLogoAndKey(instance, &instance->config.memoryKey, "Memory");
|
||||
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Memory", &instance->config.memoryFormat, 3,
|
||||
ffPrintFormatString(instance, &instance->config.memoryKey, "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}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
void ffPrintOS(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "OS"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.osKey, "OS"))
|
||||
return;
|
||||
|
||||
// Documentation of the fields:
|
||||
@@ -124,6 +124,6 @@ void ffPrintOS(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "OS", &os);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.osKey, "OS", &os);
|
||||
ffStrbufDestroy(&os);
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
if(all == 0)
|
||||
{
|
||||
ffPrintError(instance, "Packages", "No packages from known package managers found");
|
||||
ffPrintError(instance, &instance->config.packagesKey, "Packages", "No packages from known package managers found");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "Packages");
|
||||
ffPrintLogoAndKey(instance, &instance->config.packagesKey, "Packages");
|
||||
|
||||
#define FF_PRINT_PACKAGE(name) \
|
||||
if(name > 0) \
|
||||
@@ -57,7 +57,7 @@ void ffPrintPackages(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Packages", &instance->config.packagesFormat, 3,
|
||||
ffPrintFormatString(instance, &instance->config.packagesKey, "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}
|
||||
|
||||
@@ -40,7 +40,7 @@ static int getCurrentRate(FFinstance* instance, Display* display)
|
||||
|
||||
void ffPrintResolution(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "Resolution"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.resolutionFormat, "Resolution"))
|
||||
return;
|
||||
|
||||
void* x11;
|
||||
@@ -50,21 +50,21 @@ void ffPrintResolution(FFinstance* instance)
|
||||
x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY);
|
||||
if(x11 == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
Display*(*ffXOpenDisplay)(const char*) = dlsym(x11, "XOpenDisplay");
|
||||
if(ffXOpenDisplay == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
Display* display = ffXOpenDisplay(NULL);
|
||||
if(display == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,6 @@ void ffPrintResolution(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Resolution", &resolution);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.resolutionKey, "Resolution", &resolution);
|
||||
ffStrbufDestroy(&resolution);
|
||||
}
|
||||
|
||||
+3
-3
@@ -2,13 +2,13 @@
|
||||
|
||||
void ffPrintShell(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintCachedValue(instance, "Shell"))
|
||||
if(ffPrintCachedValue(instance, &instance->config.shellKey, "Shell"))
|
||||
return;
|
||||
|
||||
char* shellPath = getenv("SHELL");
|
||||
if(shellPath == NULL)
|
||||
{
|
||||
ffPrintError(instance, "Shell", "getenv(\"SHELL\") == NULL");
|
||||
ffPrintError(instance, &instance->config.shellKey, "Shell", "getenv(\"SHELL\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ void ffPrintShell(FFinstance* instance)
|
||||
);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Shell", &shell);
|
||||
ffPrintAndSaveCachedValue(instance, &instance->config.shellKey, "Shell", &shell);
|
||||
ffStrbufDestroy(&shell);
|
||||
}
|
||||
|
||||
@@ -96,16 +96,16 @@ void ffPrintTerminal(FFinstance* instance)
|
||||
{
|
||||
if(error->length > 0)
|
||||
{
|
||||
ffPrintError(instance, "Terminal", error->chars);
|
||||
ffPrintError(instance, &instance->config.terminalKey, "Terminal", error->chars);
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "Terminal");
|
||||
ffPrintLogoAndKey(instance, &instance->config.terminalKey, "Terminal");
|
||||
ffStrbufPutTo(name, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Terminal", &instance->config.terminalFormat, 3,
|
||||
ffPrintFormatString(instance, &instance->config.terminalKey, "Terminal", &instance->config.terminalFormat, 3,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, exeName},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, processName},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, name}
|
||||
|
||||
@@ -4,12 +4,12 @@ static void printTerminalFont(FFinstance* instance, char* font)
|
||||
{
|
||||
if(instance->config.termFontFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Terminal font");
|
||||
ffPrintLogoAndKey(instance, &instance->config.termFontKey, "Terminal font");
|
||||
puts(font);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Terminal font", &instance->config.termFontFormat, 1,
|
||||
ffPrintFormatString(instance, &instance->config.termFontKey, "Terminal font", &instance->config.termFontFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, font}
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ static void printKonsole(FFinstance* instance)
|
||||
ffParsePropFileHome(instance, ".config/konsolerc", "DefaultProfile=%[^\n]", profile);
|
||||
if(profile[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "Terminal Font", "Couldn't find \"DefaultProfile=%[^\n]\" in \".config/konsolerc\"");
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Couldn't find \"DefaultProfile=%[^\n]\" in \".config/konsolerc\"");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ static void printKonsole(FFinstance* instance)
|
||||
ffParsePropFileHome(instance, profilePath, "Font=%[^\n]", font);
|
||||
if(font[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void ffPrintTerminalFont(FFinstance* instance)
|
||||
if(error->length > 0)
|
||||
{
|
||||
if(instance->config.termFontFormat.length == 0)
|
||||
ffPrintError(instance, "Terminal Font", "Terminal Font needs successfull terminal detection");
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Terminal Font needs successfull terminal detection");
|
||||
else
|
||||
printTerminalFont(instance, "");
|
||||
|
||||
@@ -77,6 +77,6 @@ void ffPrintTerminalFont(FFinstance* instance)
|
||||
if(instance->config.termFontFormat.length > 0)
|
||||
printTerminalFont(instance, "");
|
||||
else
|
||||
ffPrintError(instance, "Terminal Font", "Unknown terminal: %s", error->chars);
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Unknown terminal: %s", error->chars);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ void ffPrintTheme(FFinstance* instance)
|
||||
|
||||
if(instance->config.themeFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Theme");
|
||||
ffPrintLogoAndKey(instance, &instance->config.themeKey, "Theme");
|
||||
|
||||
if(plasma[0] != '\0')
|
||||
printf("%s [Plasma], ", plasma);
|
||||
@@ -34,7 +34,7 @@ void ffPrintTheme(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Theme", &instance->config.themeFormat, 5,
|
||||
ffPrintFormatString(instance, &instance->config.themeKey, "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},
|
||||
|
||||
@@ -9,7 +9,7 @@ void ffPrintUptime(FFinstance* instance)
|
||||
|
||||
if(instance->config.uptimeFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "Uptime");
|
||||
ffPrintLogoAndKey(instance, &instance->config.uptimeKey, "Uptime");
|
||||
|
||||
if(days == 0 && hours == 0 && minutes == 0)
|
||||
{
|
||||
@@ -28,7 +28,7 @@ void ffPrintUptime(FFinstance* instance)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "Uptime", &instance->config.uptimeFormat, 4,
|
||||
ffPrintFormatString(instance, &instance->config.uptimeKey, "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},
|
||||
|
||||
+4
-4
@@ -7,7 +7,7 @@ void ffPrintWM(FFinstance* instance)
|
||||
DIR* proc = opendir("/proc/");
|
||||
if(proc == NULL)
|
||||
{
|
||||
ffPrintError(instance, "WM", "opendir(\"/proc/\") == NULL");
|
||||
ffPrintError(instance, &instance->config.wmKey, "WM", "opendir(\"/proc/\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,16 +39,16 @@ void ffPrintWM(FFinstance* instance)
|
||||
{
|
||||
if(prettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, "WM", "No process name matches the name of known display managers");
|
||||
ffPrintError(instance, &instance->config.wmKey, "WM", "No process name matches the name of known display managers");
|
||||
return;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, "WM");
|
||||
ffPrintLogoAndKey(instance, &instance->config.wmKey, "WM");
|
||||
ffStrbufPutTo(&prettyName, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, "WM", &instance->config.wmFormat, 2,
|
||||
ffPrintFormatString(instance, &instance->config.wmKey, "WM", &instance->config.wmFormat, 2,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &processName},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &prettyName}
|
||||
);
|
||||
|
||||
@@ -88,6 +88,8 @@ void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t allocate)
|
||||
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
|
||||
{
|
||||
uint32_t allocate = strbuf->allocated;
|
||||
if(allocate < 2)
|
||||
allocate = 2;
|
||||
while((strbuf->length + free) > allocate)
|
||||
allocate *= 2;
|
||||
ffStrbufEnsureCapacity(strbuf, allocate);
|
||||
|
||||
Reference in New Issue
Block a user