Merge branch 'LinusDierheimer:master' into master

This commit is contained in:
xzvf
2022-07-04 20:10:01 +02:00
committed by GitHub
80 changed files with 1115 additions and 939 deletions
+3
View File
@@ -25,6 +25,9 @@ Output of `fastfetch --load-config devinfo`:
```
Output of `fastfetch --load-config devinfo-verbose`:
<!--
Note that this output will contain you public IP. If it is not relevant for the issue, feel free to remove it before uploading.
-->
```
//paste here
```
+1 -8
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs
project(fastfetch
VERSION 1.5.3
VERSION 1.5.6
LANGUAGES C
)
@@ -477,13 +477,6 @@ target_link_libraries(flashfetch
###################
if (BUILD_TESTS)
add_executable(fastfetch-test-performance
tests/performance.c
)
target_link_libraries(fastfetch-test-performance
PRIVATE libfastfetch
)
add_executable(fastfetch-test-strbuf
tests/strbuf.c
)
-2
View File
@@ -12,8 +12,6 @@ Here i just add things that are easy to forget.
- `libffprint`: contains the printing functions, logos, format etc
- `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time
- [ ] Better OS output for all possible combinations of /etc/os-release variables.
- [ ] Expose temperatures to CPU format string
- [ ] Expose temperatures to GPU format string
- [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0}
- [ ] Make LocalIP module more configurable
- [ ] Automatic migrate old config files to newer versions
+1 -1
View File
@@ -50,7 +50,7 @@ Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resoluti
##### Logos
```
Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Kubuntu, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Ubuntu, Void, Zorin
Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Kubuntu, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Ubuntu, Void, Zorin
```
* Most of the logos have a small variant. Access it by appending _small to the logo name.
* Some logos have an old variant. Access it by appending _old to the logo name.
+35
View File
@@ -225,6 +225,41 @@ __fastfetch_completion()
"--opengl-format"
"--opencl-key"
"--opencl-format"
"--os-error"
"--host-error"
"--kernel-error"
"--uptime-error"
"--processes-error"
"--packages-error"
"--shell-error"
"--resolution-error"
"--de-error"
"--wm-error"
"--wm-theme-error"
"--theme-error"
"--icons-error"
"--font-error"
"--cursor-error"
"--terminal-error"
"--terminal-font-error"
"--cpu-error"
"--cpu-usage-error"
"--gpu-error"
"--memory-error"
"--disk-error"
"--battery-error"
"--locale-error"
"--disk-error"
"--local-ip-error"
"--public-ip-error"
"--player-error"
"--song-error"
"--datetime-error"
"--date-error"
"--time-error"
"--vulkan-error"
"--opengl-error"
"--opencl-error"
)
local FF_OPTIONS_PATH=(
+2 -2
View File
@@ -17,9 +17,9 @@
--cursor-format "Theme: {}; Size: {}"
--terminal-format "Process: {}; Path: {}; Exe: {}"
--terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}"
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
--cpu-usage-format "Percentage: {}"
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}"
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}; Temperature: {}"
--memory-format "Used: {}; Total: {}; Percentage: {}"
--disk-format "Used: {}; Total: {}; Files: {}; Percentage: {}"
--battery-format "Manufactor: {}; Model: {}; Technology: {}; Capacaty: {}; Status: {}"
+43 -17
View File
@@ -1,9 +1,13 @@
#include "fastfetch.h"
#include <stdlib.h>
#define FF_CACHE_VALUE_EXTENSION "ffcv"
#define FF_CACHE_SPLIT_EXTENSION "ffcs"
static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer)
#define FF_CACHE_EXTENSION_DATA "ffcd"
static void getCacheFilePath(const FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer)
{
ffStrbufAppend(buffer, &instance->state.cacheDir);
ffStrbufAppendS(buffer, moduleName);
@@ -20,7 +24,7 @@ static void readCacheFile(FFinstance* instance, const char* moduleName, const ch
FFstrbuf path;
ffStrbufInitA(&path, 64);
getCacheFilePath(instance, moduleName, extension, &path);
ffAppendFileContent(path.chars, buffer);
ffAppendFileBuffer(path.chars, buffer);
ffStrbufDestroy(&path);
}
@@ -29,7 +33,7 @@ static void writeCacheFile(FFinstance* instance, const char* moduleName, const c
FFstrbuf path;
ffStrbufInitA(&path, 64);
getCacheFilePath(instance, moduleName, extension, &path);
ffWriteFileContent(path.chars, content);
ffWriteFileBuffer(path.chars, content);
ffStrbufDestroy(&path);
}
@@ -77,7 +81,7 @@ void ffCacheClose(FFcache* cache)
fclose(cache->split);
}
static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat)
static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs)
{
FFstrbuf content;
ffStrbufInitA(&content, 512);
@@ -95,7 +99,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const
{
uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0');
uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter;
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key);
puts(content.chars + startIndex);
startIndex = nullByteIndex + 1;
++moduleCounter;
@@ -106,7 +110,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const
return moduleCounter > 1;
}
static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs)
static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs)
{
FFstrbuf content;
ffStrbufInitA(&content, 512);
@@ -134,7 +138,7 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
if(argumentCounter == numArgs)
{
uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter;
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments);
ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments);
++moduleCounter;
argumentCounter = 0;
}
@@ -148,27 +152,27 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
return moduleCounter > 1;
}
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs)
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs)
{
if(instance->config.recache)
return false;
if(formatString == NULL || formatString->length == 0)
return printCachedValue(instance, moduleName, customKeyFormat);
if(moduleArgs->outputFormat.length == 0)
return printCachedValue(instance, moduleName, moduleArgs);
else
return printCachedFormat(instance, moduleName, customKeyFormat, formatString, numArgs);
return printCachedFormat(instance, moduleName, moduleArgs, numArgs);
}
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments)
{
if(formatString == NULL || formatString->length == 0)
if(moduleArgs->outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key);
ffStrbufPutTo(value, stdout);
}
else
{
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments);
ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments);
}
if(cache->value != NULL)
@@ -191,10 +195,32 @@ void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8
}
}
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments)
{
FFcache cache;
ffCacheOpenWrite(instance, moduleName, &cache);
ffPrintAndAppendToCache(instance, moduleName, 0, customKeyFormat, &cache, value, formatString, numArgs, arguments);
ffPrintAndAppendToCache(instance, moduleName, 0, moduleArgs, &cache, value, numArgs, arguments);
ffCacheClose(&cache);
}
void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data)
{
FFstrbuf path;
ffStrbufInitA(&path, 128);
getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path);
ffWriteFileData(path.chars, dataSize, data);
ffStrbufDestroy(&path);
}
bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data)
{
if(instance->config.recache)
return false;
FFstrbuf path;
ffStrbufInitA(&path, 128);
getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path);
ssize_t result = ffReadFileData(path.chars, dataSize, data);
ffStrbufDestroy(&path);
return result > 0 && (size_t) result == dataSize;
}
+2 -33
View File
@@ -32,15 +32,6 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg)
}
}
static inline bool placeholderValueIsForError(const FFstrbuf* placeholderValue)
{
return
ffStrbufIgnCaseCompS(placeholderValue, "e") == 0 ||
ffStrbufIgnCaseCompS(placeholderValue, "error") == 0 ||
ffStrbufIgnCaseCompS(placeholderValue, "0") == 0
;
}
static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue)
{
uint32_t result = UINT32_MAX;
@@ -72,6 +63,7 @@ static inline bool formatArgSet(const FFformatarg* arg)
{
return arg->value != NULL && (
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value == *(double*)arg->value) || //NaN
(arg->type == FF_FORMAT_ARG_TYPE_INT && *(int*)arg->value > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_STRING && *(const char*)arg->value != '\0') ||
@@ -81,7 +73,7 @@ static inline bool formatArgSet(const FFformatarg* arg)
);
}
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments)
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments)
{
uint32_t argCounter = 0;
@@ -128,13 +120,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
while(i < formatstr->length && formatstr->chars[i] != '}')
ffStrbufAppendC(&placeholderValue, formatstr->chars[i++]);
// test for error, if so print it
if(placeholderValueIsForError(&placeholderValue)) {
ffStrbufAppend(buffer, error);
ffStrbufDestroy(&placeholderValue);
continue;
}
// test if for stop, if so break the loop
if(placeholderValue.length == 1 && placeholderValue.chars[0] == '-')
{
@@ -186,14 +171,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
{
ffStrbufSubstrAfter(&placeholderValue, 0);
// continue if an error is set
if(placeholderValueIsForError(&placeholderValue) && error != NULL && error->length > 0)
{
++numOpenIfs;
ffStrbufDestroy(&placeholderValue);
continue;
}
uint32_t index = getArgumentIndex(&placeholderValue);
// testing for an invalid index
@@ -223,14 +200,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
{
ffStrbufSubstrAfter(&placeholderValue, 0);
//continue if an error os not set
if(placeholderValueIsForError(&placeholderValue) && (error == NULL || error->length == 0))
{
++numOpenNotIfs;
ffStrbufDestroy(&placeholderValue);
continue;
}
uint32_t index = getArgumentIndex(&placeholderValue);
// testing for an invalid index
+54 -79
View File
@@ -1,5 +1,6 @@
#include "fastfetch.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <signal.h>
@@ -19,13 +20,9 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInitA(buffer, 64);
ffStrbufAppendS(buffer, xdgConfigHome);
ffStrbufTrimRight(buffer, '/');
ffStrbufEnsureEndsWithC(buffer, '/');
}
FFstrbuf xdgConfigDirs;
ffStrbufInitA(&xdgConfigDirs, 64);
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
#define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \
if(ffListFirstIndexComp(&state->configDirs, element, strbufEqualsAdapter) < state->configDirs.length - 1) \
--state->configDirs.length;
@@ -33,14 +30,19 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* userConfigHome = ffListAdd(&state->configDirs);
ffStrbufInitA(userConfigHome, 64);
ffStrbufAppendS(userConfigHome, state->passwd->pw_dir);
ffStrbufAppendS(userConfigHome, "/.config");
ffStrbufAppendS(userConfigHome, "/.config/");
FF_ENSURE_ONLY_ONCE_IN_LIST(userConfigHome)
FFstrbuf* userHome = ffListAdd(&state->configDirs);
ffStrbufInitA(userHome, 64);
ffStrbufAppendS(userHome, state->passwd->pw_dir);
ffStrbufEnsureEndsWithC(userHome, '/');
FF_ENSURE_ONLY_ONCE_IN_LIST(userHome)
FFstrbuf xdgConfigDirs;
ffStrbufInitA(&xdgConfigDirs, 64);
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
uint32_t startIndex = 0;
while (startIndex < xdgConfigDirs.length)
{
@@ -50,7 +52,7 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInitA(buffer, 64);
ffStrbufAppendS(buffer, xdgConfigDirs.chars + startIndex);
ffStrbufTrimRight(buffer, '/');
ffStrbufEnsureEndsWithC(buffer, '/');
FF_ENSURE_ONLY_ONCE_IN_LIST(buffer);
startIndex = colonIndex + 1;
@@ -58,12 +60,12 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* systemConfigHome = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfigHome, 64);
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg");
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg/");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigHome)
FFstrbuf* systemConfig = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfig, 64);
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc");
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc/");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfig)
#undef FF_ENSURE_ONLY_ONCE_IN_LIST
@@ -80,8 +82,8 @@ static void initCacheDir(FFstate* state)
ffStrbufAppendS(&state->cacheDir, state->passwd->pw_dir);
ffStrbufAppendS(&state->cacheDir, "/.cache/");
}
else if(!ffStrbufEndsWithC(&state->cacheDir, '/'))
ffStrbufAppendC(&state->cacheDir, '/');
else
ffStrbufEnsureEndsWithC(&state->cacheDir, '/');
mkdir(state->cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder, but who knows
@@ -102,6 +104,13 @@ static void initState(FFstate* state)
initCacheDir(state);
}
static void initModuleArg(FFModuleArgs* args)
{
ffStrbufInitA(&args->key, 0);
ffStrbufInitA(&args->outputFormat, 0);
ffStrbufInitA(&args->errorFormat, 0);
}
static void defaultConfig(FFinstance* instance)
{
ffStrbufInit(&instance->config.logoSource);
@@ -128,74 +137,40 @@ static void defaultConfig(FFinstance* instance)
instance->config.glType = FF_GL_TYPE_AUTO;
instance->config.pipe = false;
ffStrbufInitA(&instance->config.osFormat, 0);
ffStrbufInitA(&instance->config.osKey, 0);
ffStrbufInitA(&instance->config.hostFormat, 0);
ffStrbufInitA(&instance->config.hostKey, 0);
ffStrbufInitA(&instance->config.kernelFormat, 0);
ffStrbufInitA(&instance->config.kernelKey, 0);
ffStrbufInitA(&instance->config.uptimeFormat, 0);
ffStrbufInitA(&instance->config.uptimeKey, 0);
ffStrbufInitA(&instance->config.processesFormat, 0);
ffStrbufInitA(&instance->config.processesKey, 0);
ffStrbufInitA(&instance->config.packagesFormat, 0);
ffStrbufInitA(&instance->config.packagesKey, 0);
ffStrbufInitA(&instance->config.shellFormat, 0);
ffStrbufInitA(&instance->config.shellKey, 0);
ffStrbufInitA(&instance->config.resolutionFormat, 0);
ffStrbufInitA(&instance->config.resolutionKey, 0);
ffStrbufInitA(&instance->config.deFormat, 0);
ffStrbufInitA(&instance->config.deKey, 0);
ffStrbufInitA(&instance->config.wmFormat, 0);
ffStrbufInitA(&instance->config.wmKey, 0);
ffStrbufInitA(&instance->config.wmThemeFormat, 0);
ffStrbufInitA(&instance->config.wmThemeKey, 0);
ffStrbufInitA(&instance->config.themeFormat, 0);
ffStrbufInitA(&instance->config.themeKey, 0);
ffStrbufInitA(&instance->config.iconsFormat, 0);
ffStrbufInitA(&instance->config.iconsKey, 0);
ffStrbufInitA(&instance->config.fontFormat, 0);
ffStrbufInitA(&instance->config.fontKey, 0);
ffStrbufInitA(&instance->config.cursorKey, 0);
ffStrbufInitA(&instance->config.cursorFormat, 0);
ffStrbufInitA(&instance->config.terminalFormat, 0);
ffStrbufInitA(&instance->config.terminalKey, 0);
ffStrbufInitA(&instance->config.termFontFormat, 0);
ffStrbufInitA(&instance->config.termFontKey, 0);
ffStrbufInitA(&instance->config.cpuFormat, 0);
ffStrbufInitA(&instance->config.cpuKey, 0);
ffStrbufInitA(&instance->config.cpuUsageFormat, 0);
ffStrbufInitA(&instance->config.cpuUsageKey, 0);
ffStrbufInitA(&instance->config.gpuFormat, 0);
ffStrbufInitA(&instance->config.gpuKey, 0);
ffStrbufInitA(&instance->config.memoryFormat, 0);
ffStrbufInitA(&instance->config.memoryKey, 0);
ffStrbufInitA(&instance->config.diskFormat, 0);
ffStrbufInitA(&instance->config.diskKey, 0);
ffStrbufInitA(&instance->config.batteryFormat, 0);
ffStrbufInitA(&instance->config.batteryKey, 0);
ffStrbufInitA(&instance->config.localeFormat, 0);
ffStrbufInitA(&instance->config.localeKey, 0);
ffStrbufInitA(&instance->config.localIpKey, 0);
ffStrbufInitA(&instance->config.localIpFormat, 0);
ffStrbufInitA(&instance->config.publicIpKey, 0);
ffStrbufInitA(&instance->config.publicIpFormat, 0);
ffStrbufInitA(&instance->config.playerKey, 0);
ffStrbufInitA(&instance->config.playerFormat, 0);
ffStrbufInitA(&instance->config.songKey, 0);
ffStrbufInitA(&instance->config.songFormat, 0);
ffStrbufInitA(&instance->config.dateTimeKey, 0);
ffStrbufInitA(&instance->config.dateTimeFormat, 0);
ffStrbufInitA(&instance->config.dateKey, 0);
ffStrbufInitA(&instance->config.dateFormat, 0);
ffStrbufInitA(&instance->config.timeKey, 0);
ffStrbufInitA(&instance->config.timeFormat, 0);
ffStrbufInitA(&instance->config.vulkanKey, 0);
ffStrbufInitA(&instance->config.vulkanFormat, 0);
ffStrbufInitA(&instance->config.openGLKey, 0);
ffStrbufInitA(&instance->config.openGLFormat, 0);
ffStrbufInitA(&instance->config.openCLKey, 0);
ffStrbufInitA(&instance->config.openCLFormat, 0);
initModuleArg(&instance->config.os);
initModuleArg(&instance->config.host);
initModuleArg(&instance->config.kernel);
initModuleArg(&instance->config.uptime);
initModuleArg(&instance->config.processes);
initModuleArg(&instance->config.packages);
initModuleArg(&instance->config.shell);
initModuleArg(&instance->config.resolution);
initModuleArg(&instance->config.de);
initModuleArg(&instance->config.wm);
initModuleArg(&instance->config.wmTheme);
initModuleArg(&instance->config.theme);
initModuleArg(&instance->config.icons);
initModuleArg(&instance->config.font);
initModuleArg(&instance->config.cursor);
initModuleArg(&instance->config.terminal);
initModuleArg(&instance->config.terminalFont);
initModuleArg(&instance->config.cpu);
initModuleArg(&instance->config.cpuUsage);
initModuleArg(&instance->config.gpu);
initModuleArg(&instance->config.memory);
initModuleArg(&instance->config.disk);
initModuleArg(&instance->config.battery);
initModuleArg(&instance->config.locale);
initModuleArg(&instance->config.localIP);
initModuleArg(&instance->config.publicIP);
initModuleArg(&instance->config.player);
initModuleArg(&instance->config.song);
initModuleArg(&instance->config.dateTime);
initModuleArg(&instance->config.date);
initModuleArg(&instance->config.time);
initModuleArg(&instance->config.vulkan);
initModuleArg(&instance->config.openGL);
initModuleArg(&instance->config.openCL);
ffStrbufInitA(&instance->config.libPCI, 0);
ffStrbufInitA(&instance->config.libVulkan, 0);
+36 -15
View File
@@ -1,17 +1,11 @@
#include "fastfetch.h"
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <termios.h>
#include <poll.h>
bool ffWriteFDContent(int fd, const FFstrbuf* content)
{
return write(fd, content->chars, content->length) != -1;
}
static void createSubfolders(const char* fileName)
{
FFstrbuf path;
@@ -28,7 +22,13 @@ static void createSubfolders(const char* fileName)
ffStrbufDestroy(&path);
}
bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
bool ffWriteFDBuffer(int fd, const FFstrbuf* content)
{
return write(fd, content->chars, content->length) != -1;
}
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
{
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC;
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@@ -42,14 +42,19 @@ bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
return false;
}
bool ret = ffWriteFDContent(fd, content);
bool ret = write(fd, data, dataSize) != -1;
close(fd);
return ret;
}
void ffAppendFDContent(int fd, FFstrbuf* buffer)
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer)
{
return ffWriteFileData(fileName, buffer->length, buffer->chars);
}
bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)
{
ssize_t readed = 0;
@@ -73,24 +78,40 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer)
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
return readed >= 0;
}
bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer)
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return -1;
ssize_t readed = read(fd, data, dataSize);
close(fd);
return readed;
}
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return false;
ffAppendFDContent(fd, buffer);
bool ret = ffAppendFDBuffer(fd, buffer);
close(fd);
return true;
return ret;
}
bool ffGetFileContent(const char* fileName, FFstrbuf* buffer)
bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
{
ffStrbufClear(buffer);
return ffAppendFileContent(fileName, buffer);
return ffAppendFileBuffer(fileName, buffer);
}
// Not thread safe!
+1
View File
@@ -1,6 +1,7 @@
#include "fastfetch.h"
#include <stdarg.h>
#include <dlfcn.h>
static void* libraryLoad(const char* path, int maxVersion)
{
-1
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
+57 -35
View File
@@ -10,6 +10,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
ffPrintColor(&instance->config.mainColor);
}
//NULL check is required for modules with custom keys, e.g. disk with the folder path
if(customKeyFormat == NULL || customKeyFormat->length == 0)
{
fputs(moduleName, stdout);
@@ -21,7 +22,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
{
FFstrbuf key;
ffStrbufInit(&key);
ffParseFormatString(&key, customKeyFormat, NULL, 1, (FFformatarg[]){
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffStrbufWriteTo(&key, stdout);
@@ -37,44 +38,12 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
}
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...)
{
if(!instance->config.showErrors)
return;
va_list arguments;
va_start(arguments, message);
if(formatString == NULL || formatString->length == 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
vprintf(message, arguments);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
else
{
FF_STRBUF_CREATE(error);
ffStrbufAppendVF(&error, message, arguments);
// calloc sets all to 0 and FF_FORMAT_ARG_TYPE_NULL also has value 0 so we don't need to explictly set it
FFformatarg* nullArgs = calloc(numFormatArgs, sizeof(FFformatarg));
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, &error, numFormatArgs, nullArgs);
free(nullArgs);
ffStrbufDestroy(&error);
}
va_end(arguments);
}
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
{
FFstrbuf buffer;
ffStrbufInitA(&buffer, 256);
ffParseFormatString(&buffer, formatString, error, numArgs, arguments);
ffParseFormatString(&buffer, format, numArgs, arguments);
if(buffer.length > 0)
{
@@ -85,6 +54,59 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
ffStrbufDestroy(&buffer);
}
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments)
{
ffPrintFormatString(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->outputFormat, numArgs, arguments);
}
static void printError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, va_list arguments)
{
bool hasCustomErrorFormat = customErrorFormat != NULL && customErrorFormat->length > 0;
if(!hasCustomErrorFormat && !instance->config.showErrors)
return;
if(hasCustomErrorFormat)
{
FFstrbuf error;
ffStrbufInit(&error);
ffStrbufAppendVF(&error, message, arguments);
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, 1, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &error}
});
ffStrbufDestroy(&error);
}
else
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
if(!instance->config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
vprintf(message, arguments);
if(!instance->config.pipe)
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
}
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...)
{
va_list arguments;
va_start(arguments, message);
printError(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, message, arguments);
va_end(arguments);
}
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...)
{
va_list arguments;
va_start(arguments, message);
printError(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->errorFormat, message, arguments);
va_end(arguments);
}
void ffPrintColor(const FFstrbuf* colorValue)
{
//If the color is not set, this would reset in \033[m, which resets everything.
+2 -2
View File
@@ -1,6 +1,6 @@
#include "fastfetch.h"
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
@@ -29,6 +29,6 @@ void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
//Parent
close(pipes[1]);
waitpid(childPid, NULL, 0);
ffAppendFDContent(pipes[0], buffer);
ffAppendFDBuffer(pipes[0], buffer);
close(pipes[0]);
}
+11 -10
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <stdlib.h>
static bool parsePropLinePointer(const char** line, const char* start, FFstrbuf* buffer)
{
if(**line == '\0')
@@ -174,21 +176,18 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ
{
bool foundAFile = false;
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
uint32_t baseDirLength = baseDir->length;
//We need to copy the config dir each time, because it used by multiple threads, so we can't directly write to it.
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
ffStrbufAppendS(&baseDir, relativeFile);
if(*relativeFile != '/')
ffStrbufAppendC(baseDir, '/');
ffStrbufAppendS(baseDir, relativeFile);
if(ffParsePropFileValues(baseDir->chars, numQueries, queries))
if(ffParsePropFileValues(baseDir.chars, numQueries, queries))
foundAFile = true;
ffStrbufSubstrBefore(baseDir, baseDirLength);
bool allSet = true;
for(uint32_t k = 0; k < numQueries; k++)
{
@@ -203,6 +202,8 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ
break;
}
ffStrbufDestroy(&baseDir);
return foundAFile;
}
+5
View File
@@ -2,6 +2,7 @@
#include <pthread.h>
#include <string.h>
#include <dlfcn.h>
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
static dataObject data; \
@@ -270,6 +271,7 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
#ifdef FF_HAVE_SQLITE3
#include <sqlite3.h>
#include <sys/stat.h>
typedef struct SQLiteData
{
@@ -299,6 +301,9 @@ static const SQLiteData* getSQLiteData(const FFinstance* instance)
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query)
{
if(!ffFileExists(dbPath, S_IFREG))
return 0;
const SQLiteData* data = getSQLiteData(instance);
if(data == NULL)
return 0;
+38
View File
@@ -237,6 +237,44 @@
#--opengl-format
#--opencl-format
# Error options:
# Sets the format string to use if an error occured
# For information on format strings, see "fastfetch --help format".
# Each of them take the error as first and only argument.
# If one of them is set, the module will appear, even if --show-errors is not given.
#--os-error
#--host-error
#--kernel-error
#--uptime-error
#--processes-error
#--packages-error
#--shell-error
#--resolution-error
#--de-error
#--wm-error
#--wm-theme-error
#--theme-error
#--icons-error
#--font-error
#--cursor-error
#--terminal-error
#--terminal-font-error
#--cpu-error
#--cpu-usage-error
#--gpu-error
#--memory-error
#--disk-error
#--battery-error
#--locale-error
#--local-ip-error
#--public-ip-error
#--player-error
#--song-error
#--datetime-error
#--vulkan-error
#--opengl-error
#--opencl-error
# Library options:
# Sets an user specific path to a library to load.
# Must be a valid path to a library.
+10 -70
View File
@@ -46,77 +46,17 @@ Display options:
--disable-linewrap <?value>: weather to disable linewrap during the run
--hide-cursor <?value>: weather to hide the cursor during the run
Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help.
--os-format <format>
--host-format <format>
--kernel-format <format>
--uptime-format <format>
--processes-format <format>
--packages-format <format>
--shell-format <format>
--resolution-format <format>
--de-format <format>
--wm-format <format>
--wm-theme-format <format>
--theme-format <format>
--icons-format <format>
--font-format <format>
--cursor-format <format>
--terminal-format <format>
--terminal-font-format <format>
--cpu-format <format>
--cpu-usage-format <format>
--gpu-format <format>
--memory-format <format>
--disk-format <format>
--battery-format <format>
--locale-format <format>
--local-ip-format <format>
--public-ip-format <format>
--player-format <format>
--song-format <format>
--datetime-format <format>
--time-format <format>
--date-format <format>
--vulkan-format <format>
--opengl-format <format>
--opencl-format <format>
General module options:
--<module>-format <format>: Sets the format string to use for each specific module.
To see how a format string works, use fastfetch --help format.
To see help about a specific format string, use fastfetch --help <module>-format.
Key options: Provide a custom key for an output
--os-key <key>
--host-key <key>
--kernel-key <key>
--uptime-key <key>
--processes-key <key>
--packages-key <key>
--shell-key <key>
--resolution-key <key>: takes the resolution index as argument
--de-key <key>
--wm-key <key>
--wm-theme-key <key>
--theme-key <key>
--icons-key <key>
--font-key <key>
--cursor-key <key>
--terminal-key <key>
--terminal-font-key <key>
--cpu-key <key>
--cpu-usage-key <key>
--gpu-key <key>: takes the gpu index as format argument
--memory-key <key>
--disk-key <key>: takes the mount path as format argument
--battery-key <key>: takes the battery index as format argument
--locale-key <key>
--local-ip-key <key>: takes the name of this network interface as format argument
--public-ip-key <key>
--player-key <key>
--song-key <key>
--datetime-key <key>
--time-key <key>
--date-key <key>
--vulkan-key <key>
--opengl-key <key>
--opencl-key <key>
--<module>-key <key>: Sets the key to use for each specific module.
For modules which print multiple lines, the string is parsed as a format string with the index as first character.
--<module>-error <format>: Sets the error format string to use for each specific module.
The error is given as the first and only argument.
Setting this for a module will cause it to appear, even if --show-errors is not given.
Library options: Set the path of a library to load
--lib-PCI <path>
-6
View File
@@ -19,24 +19,18 @@ If a "{?}" is found without an opener, it is printed as is.
To only print something if a variable is not set, do the same as with if, just replace every '?' with a '!'.
For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}"
There is a special variable set if an error occured during detection. You can access it with "{e}", "{error}" o
You can use ifs and not ifs with it like with an index. For example use "{?e}some text{?}", to print a text if an
To stop formatting at any point in the format string, use "{-}".
For example to print an error instead of the normal output if it occured, prefix the format string with "{?e}{e}{-
To print something with color, start a placeholder with a '#' and then the linux terminal color encoding.
"\\033[" at the start, and an 'm' at the end is automatically added, so don't do that.
A "{#}" is equivalent to a "{#0}" and resets everything to normal.
For example to print something pink and underline, use "{#4;35}...{#}".
If not in a format string, fastfetch wraps errors with "{#1;31}error{#}", so you might want to do that to if you
Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Sele
Which escape codes are supported and how they look is defined by your terminal.
If a format string evaluates to an empty value, the whole line in the output will be discarded.
You can therefore use --host-format " " to disable host output.
Note that --host-format "" would evaluate as not set, and therefore use the built-in host format
This can be used to print nothing if an error occured: prefix the format string with "{?e}{-}{?}...".
Format string is also the way to go to set a fixed value - just use one without placeholders.
For example when running in headless mode, you could use "--resolution-format "Preferred".
-1
View File
@@ -1,7 +1,6 @@
#include "fastfetch.h"
#include <time.h>
#include <pthread.h>
const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance)
@@ -1,4 +1,5 @@
#include "displayServer.h"
#include <pthread.h>
#include <dirent.h>
+81 -66
View File
@@ -1,50 +1,53 @@
#define _GNU_SOURCE //required for struct ucred
#include "displayServer.h"
#include <stdlib.h>
#include <string.h>
#ifdef FF_HAVE_WAYLAND
#include <wayland-client.h>
#include <pthread.h>
#include <dlfcn.h>
#include <wayland-client.h>
#include <sys/socket.h>
typedef struct WaylandData
{
const FFinstance* instance;
FFlist* results;
FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned)
FF_LIBRARY_SYMBOL(wl_proxy_add_listener)
FF_LIBRARY_SYMBOL(wl_proxy_destroy)
const struct wl_interface* ffwl_output_interface;
struct wl_output_listener output_listener;
} WaylandData;
static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){
FF_UNUSED(data, wl_registry, name);
static void waylandDetectWM(int fd, FFDisplayServerResult* result)
{
struct ucred ucred;
socklen_t len = sizeof(struct ucred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
return;
FFstrbuf procPath;
ffStrbufInit(&procPath);
ffStrbufAppendF(&procPath, "/proc/%d/cmdline", ucred.pid); //We check the cmdline for the process name, because it is not trimmed.
ffReadFileBuffer(procPath.chars, &result->wmProcessName);
ffStrbufSubstrBeforeFirstC(&result->wmProcessName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&result->wmProcessName, '/'); //Trim the path
ffStrbufDestroy(&procPath);
}
static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform)
static void stubListener(void* data, ...)
{
FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform);
}
static void waylandOutputDoneListener(void* data, struct wl_output* wl_output)
{
FF_UNUSED(data, wl_output);
}
static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor)
{
FF_UNUSED(data, wl_output, factor);
(void) data;
}
static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate)
{
if(!(flags & WL_OUTPUT_MODE_CURRENT))
return;
WaylandData* wldata = (WaylandData*) data;
WaylandData* wldata = data;
wldata->ffwl_proxy_destroy((struct wl_proxy*) output);
if(width <= 0 || height <= 0)
if(!(flags & WL_OUTPUT_MODE_CURRENT) || width <= 0 || height <= 0)
return;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -61,71 +64,84 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint
static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
{
if(strcmp(interface, "wl_output") == 0)
{
WaylandData* wldata = (WaylandData*) data;
WaylandData* wldata = data;
struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
if(strcmp(interface, wldata->ffwl_output_interface->name) == 0)
{
struct wl_proxy* output = wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy*) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
if(output == NULL)
return;
wldata->ffwl_proxy_add_listener((struct wl_proxy*) output, (void(**)(void)) &wldata->output_listener, data);
//Needs to be static, because the scope of the function will already be lost when calling the listener
static struct wl_output_listener outputListener = {
.mode = waylandOutputModeListener,
.geometry = (void*) stubListener,
//https://lists.freedesktop.org/archives/wayland-devel/2013-July/010278.html
#if WAYLAND_VERSION_MINOR >= 2
.done = (void*) stubListener,
.scale = (void*) stubListener,
#endif
//https://lists.freedesktop.org/archives/wayland-devel/2021-December/042064.html
#if WAYLAND_VERSION_MINOR >= 20
.name = (void*) stubListener,
.description = (void*) stubListener,
#endif
};
wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data);
}
}
void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result)
bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
{
if(getenv("XDG_RUNTIME_DIR") == NULL)
return;
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, false, "libwayland-client.so", 1)
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", 1)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_get_fd, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface, false)
WaylandData data;
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned, false)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy, false)
struct wl_display* display = ffwl_display_connect(NULL);
if(display == NULL)
{
dlclose(wayland);
return;
return false;
}
struct wl_registry* registry = (struct wl_registry*) ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL);
waylandDetectWM(ffwl_display_get_fd(display), result);
struct wl_proxy* registry = ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL);
if(registry == NULL)
{
ffwl_display_disconnect(display);
dlclose(wayland);
return;
return false;
}
data.instance = instance;
data.results = &result->resolutions;
struct wl_registry_listener regestry_listener;
regestry_listener.global = waylandGlobalAddListener;
regestry_listener.global_remove = waylandGlobalRemoveListener;
struct wl_registry_listener registry_listener = {
.global = waylandGlobalAddListener,
.global_remove = (void*) stubListener
};
data.output_listener.geometry = waylandOutputGeometryListener;
data.output_listener.mode = waylandOutputModeListener;
data.output_listener.done = waylandOutputDoneListener;
data.output_listener.scale = waylandOutputScaleListener;
data.ffwl_proxy_add_listener((struct wl_proxy*) registry, (void(**)(void)) &regestry_listener, &data);
data.ffwl_proxy_add_listener(registry, (void(**)(void)) &registry_listener, &data);
ffwl_display_dispatch(display);
ffwl_display_roundtrip(display);
data.ffwl_proxy_destroy((struct wl_proxy*) registry);
data.ffwl_proxy_destroy(registry);
ffwl_display_disconnect(display);
dlclose(wayland);
@@ -133,20 +149,21 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul
//So we can set set the session type to wayland.
//This is used as an indicator that we are running wayland by the x11 backends.
ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND);
return true;
}
#else
#endif
void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_UNUSED(instance);
//We try to detect wayland already here, so the x11 methods only to resolution detection.
//Wayland requires this to be set
if(getenv("XDG_RUNTIME_DIR") == NULL)
return;
#ifdef FF_HAVE_WAYLAND
if(detectWayland(instance, result))
return;
#endif
const char* xdgSessionType = getenv("XDG_SESSION_TYPE");
//If XDG_SESSION_TYPE is set, and doesn't contain "wayland", we are probably not running in a wayland session.
@@ -158,9 +175,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul
if(xdgSessionType == NULL && getenv("WAYLAND_DISPLAY") == NULL && getenv("WAYLAND_SOCKET") == NULL)
return;
//We are probably running a wayland compositor at this point, but fastfetch was compiled without the required library.
//Set the protocol name and use DRM for resolution detection.
//We are probably running a wayland compositor at this point,
//but fastfetch was compiled without the required library, or loading the library failed.
ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND);
}
#endif
+28 -11
View File
@@ -1,8 +1,11 @@
#include "displayServer.h"
#include <dirent.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
static const char* parseEnv()
{
@@ -40,6 +43,11 @@ static const char* parseEnv()
if(getenv("TDE_FULL_SESSION") != NULL)
return "Trinity";
if(
getenv("WAYLAND_DISPLAY") != NULL &&
ffFileExists("/mnt/wslg/", S_IFDIR)
) return "WSLg";
return NULL;
}
@@ -48,8 +56,21 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce
if(!ffStrSet(processName))
return;
if(strcasecmp(processName, "kwin_wayland") == 0 || strcasecmp(processName, "kwin_x11") == 0 || strcasecmp(processName, "kwin") == 0)
ffStrbufSetS(&result->wmPrettyName, "KWin");
if(
strcasecmp(processName, "kwin_wayland") == 0 ||
strcasecmp(processName, "kwin_wayland_wrapper") == 0 ||
strcasecmp(processName, "kwin_x11") == 0 ||
strcasecmp(processName, "kwin_x11_wrapper") == 0 ||
strcasecmp(processName, "kwin") == 0
) ffStrbufSetS(&result->wmPrettyName, "KWin");
else if(
strcasecmp(processName, "gnome-session-binary") == 0 ||
strcasecmp(processName, "Mutter") == 0
) ffStrbufSetS(&result->wmPrettyName, "Mutter");
else if(
strcasecmp(processName, "cinnamon-session") == 0 ||
strcasecmp(processName, "Muffin") == 0
) ffStrbufSetS(&result->wmPrettyName, "Muffin");
else if(strcasecmp(processName, "sway") == 0)
ffStrbufSetS(&result->wmPrettyName, "Sway");
else if(strcasecmp(processName, "weston") == 0)
@@ -64,10 +85,6 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce
ffStrbufSetS(&result->wmPrettyName, "Marco");
else if(strcasecmp(processName, "xmonad") == 0)
ffStrbufSetS(&result->wmPrettyName, "XMonad");
else if(strcasecmp(processName, "gnome-session-binary") == 0 || strcasecmp(processName, "Mutter") == 0)
ffStrbufSetS(&result->wmPrettyName, "Mutter");
else if(strcasecmp(processName, "cinnamon-session") == 0 || strcasecmp(processName, "Muffin") == 0)
ffStrbufSetS(&result->wmPrettyName, "Muffin");
else if( // WMs where the pretty name matches the process name
strcasecmp(processName, "dwm") == 0 ||
strcasecmp(processName, "bspwm") == 0 ||
@@ -329,7 +346,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
//Don't check for processes not owend by the current user.
ffStrbufAppendS(&procPath, "/loginuid");
ffGetFileContent(procPath.chars, &loginuid);
ffReadFileBuffer(procPath.chars, &loginuid);
if(ffStrbufComp(&userID, &loginuid) != 0)
{
ffStrbufSubstrBefore(&procPath, procPathLength);
@@ -340,7 +357,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
//We check the cmdline for the process name, because it is not trimmed.
ffStrbufAppendS(&procPath, "/cmdline");
ffGetFileContent(procPath.chars, &processName);
ffReadFileBuffer(procPath.chars, &processName);
ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&processName, '/');
@@ -371,7 +388,7 @@ void ffdsDetectWMDE(const FFinstance* instance, FFDisplayServerResult* result)
getWMProtocolNameFromEnv(result);
//We don't want to detect anything in TTY
//This can't happen if a X11 connection succeeded, so we don't need to clear wmProcessName
//This can't happen if a connection succeeded, so we don't need to clear wmProcessName
if(ffStrbufIgnCaseCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_TTY) == 0)
return;
+4 -2
View File
@@ -1,8 +1,10 @@
#include "displayServer.h"
#ifdef FF_HAVE_XCB
#include <xcb/xcb.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <xcb/xcb.h>
typedef struct XcbPropertyData
{
@@ -60,7 +62,7 @@ static void* xcbGetProperty(XcbPropertyData* data, xcb_connection_t* connection,
static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connection, xcb_window_t rootWindow, FFDisplayServerResult* result)
{
if(result->wmProcessName.length > 0)
if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0)
return;
xcb_window_t* wmWindow = (xcb_window_t*) xcbGetProperty(data, connection, rootWindow, "_NET_SUPPORTING_WM_CHECK");
+2 -1
View File
@@ -1,6 +1,7 @@
#include "displayServer.h"
#ifdef FF_HAVE_X11
#include <dlfcn.h>
#include <X11/Xlib.h>
typedef struct X11PropertyData
@@ -34,7 +35,7 @@ static unsigned char* x11GetProperty(X11PropertyData* data, Display* display, Wi
static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDisplayServerResult* result)
{
if(result->wmProcessName.length > 0)
if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0)
return;
Window* wmWindow = (Window*) x11GetProperty(data, display, DefaultRootWindow(display), "_NET_SUPPORTING_WM_CHECK");
+13 -14
View File
@@ -103,7 +103,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
uint32_t configDirLength = configDir->length;
// <configdir>/gtk-<version>.0/settings.ini
ffStrbufAppendS(configDir, "/gtk-");
ffStrbufAppendS(configDir, "gtk-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0/settings.ini");
detectGTKFromConfigFile(configDir->chars, result);
@@ -112,7 +112,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/gtk-<version>.0/gtkrc
ffStrbufAppendS(configDir, "/gtk-");
ffStrbufAppendS(configDir, "gtk-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0/gtkrc");
detectGTKFromConfigFile(configDir->chars, result);
@@ -121,7 +121,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/gtkrc-<version>.0
ffStrbufAppendS(configDir, "/gtkrc-");
ffStrbufAppendS(configDir, "gtkrc-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0");
detectGTKFromConfigFile(configDir->chars, result);
@@ -130,7 +130,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/.gtkrc-<version>.0
ffStrbufAppendS(configDir, "/.gtkrc-");
ffStrbufAppendS(configDir, ".gtkrc-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0");
detectGTKFromConfigFile(configDir->chars, result);
@@ -140,22 +140,21 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* result)
{
//We need to do this because we use multiple threads on configDirs
FFstrbuf baseDirCopy;
ffStrbufInitA(&baseDirCopy, 64);
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
ffStrbufSet(&baseDirCopy, baseDir);
detectGTKFromConfigDir(&baseDirCopy, version, result);
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
detectGTKFromConfigDir(&baseDir, version, result);
if(allPropertiesSet(result))
{
ffStrbufDestroy(&baseDirCopy);
return;
}
break;
}
ffStrbufDestroy(&baseDirCopy);
ffStrbufDestroy(&baseDir);
if(allPropertiesSet(result))
return;
//Mate, Cinnamon and Gnome use dconf to save theme config
//On other DEs, this will do nothing
+1
View File
@@ -7,6 +7,7 @@
#define FF_DBUS_TIMEOUT_MILLISECONDS 35
#ifdef FF_HAVE_DBUS
#include <dlfcn.h>
#include <dbus/dbus.h>
#define FF_DBUS_ITER_CONTINUE(iterator) \
+1
View File
@@ -1,6 +1,7 @@
#include "fastfetch.h"
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#if !defined(__ANDROID__)
+9 -10
View File
@@ -1,5 +1,6 @@
#include "fastfetch.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
@@ -11,9 +12,9 @@ typedef enum PlasmaCategory
PLASMA_CATEGORY_OTHER
} PlasmaCategory;
static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* result)
static bool detectFromConfigFile(const char* filename, FFPlasmaResult* result)
{
FILE* kdeglobals = fopen(filename->chars, "r");
FILE* kdeglobals = fopen(filename, "r");
if(kdeglobals == NULL)
return false;
@@ -95,17 +96,15 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance)
bool foundAFile = false;
//We need to do this because we use multiple threads on configDirs
FFstrbuf baseDirCopy;
ffStrbufInitA(&baseDirCopy, 64);
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
ffStrbufAppendS(&baseDir, "kdeglobals");
ffStrbufSet(&baseDirCopy, baseDir);
ffStrbufAppendS(&baseDirCopy, "/kdeglobals");
if(detectFromConfigFile(&baseDirCopy, &result))
if(detectFromConfigFile(baseDir.chars, &result))
foundAFile = true;
if(
@@ -116,7 +115,7 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance)
) break;
}
ffStrbufDestroy(&baseDirCopy);
ffStrbufDestroy(&baseDir);
if(!foundAFile)
{
+23 -13
View File
@@ -1,8 +1,8 @@
#include "fastfetch.h"
#include <string.h>
#include <pthread.h>
#include <dirent.h>
#include <string.h>
static bool isTempFile(const char* name)
{
@@ -20,30 +20,42 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
return false;
uint32_t dirLength = dir->length;
value->value = 0.0 / 0.0; //use NaN as error value
FFstrbuf valueString;
ffStrbufInit(&valueString);
struct dirent* dirent;
while((dirent = readdir(dirp)) != NULL)
{
if(isTempFile(dirent->d_name))
{
ffStrbufAppendS(dir, dirent->d_name);
ffGetFileContent(dir->chars, &value->value);
ffStrbufSubstrBefore(dir, dirLength);
break;
}
if(!isTempFile(dirent->d_name))
continue;
ffStrbufAppendS(dir, dirent->d_name);
ffReadFileBuffer(dir->chars, &valueString);
ffStrbufSubstrBefore(dir, dirLength);
//ffStrbufToDouble() returns NaN if the string couldn't be parsed
value->value = ffStrbufToDouble(&valueString);
if(value->value != value->value)
continue;
value->value /= 1000.0; //millidegrees to degrees
break;
}
closedir(dirp);
ffStrbufDestroy(&valueString);
if(value->value.length == 0)
if(value->value != value->value)
return false;
ffStrbufAppendS(dir, "name");
ffGetFileContent(dir->chars, &value->name);
ffReadFileBuffer(dir->chars, &value->name);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufAppendS(dir, "device/class");
ffGetFileContent(dir->chars, &value->deviceClass);
ffReadFileBuffer(dir->chars, &value->deviceClass);
ffStrbufSubstrBefore(dir, dirLength);
return value->name.length > 0 || value->deviceClass.length > 0;
@@ -92,12 +104,10 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance)
FFTempValue* temp = ffListAdd(&result.values);
ffStrbufInit(&temp->name);
ffStrbufInit(&temp->deviceClass);
ffStrbufInit(&temp->value);
if(!parseHwmonDir(&baseDir, temp))
{
ffStrbufDestroy(&temp->name);
ffStrbufDestroy(&temp->deviceClass);
ffStrbufDestroy(&temp->value);
--result.values.length;
}
+13 -3
View File
@@ -2,6 +2,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
@@ -20,7 +21,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb
ffStrbufAppendS(&cmdlineFilePath, pid);
ffStrbufAppendS(&cmdlineFilePath, "/cmdline");
ffGetFileContent(cmdlineFilePath.chars, exe);
ffReadFileBuffer(cmdlineFilePath.chars, exe);
ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments
ffStrbufTrimLeft(exe, '-'); //Happens in TTY
@@ -119,8 +120,17 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
term = getenv("SSH_TTY");
//Windows Terminal
if(!ffStrSet(term) && getenv("WT_SESSION") != NULL)
term = "Windows Terminal";
if(!ffStrSet(term) && (
getenv("WT_SESSION") != NULL ||
getenv("WT_PROFILE_ID") != NULL
)) term = "Windows Terminal";
//Termux
if(!ffStrSet(term) && (
getenv("TERMUX_VERSION") != NULL ||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL ||
getenv("TMUX_TMPDIR") != NULL
)) term = "Termux";
//Normal Terminal
if(!ffStrSet(term))
+3
View File
@@ -3,6 +3,8 @@
#include <pthread.h>
#ifdef FF_HAVE_VULKAN
#include <stdlib.h>
#include <dlfcn.h>
#include <vulkan/vulkan.h>
static inline void applyVulkanVersion(uint32_t vulkanVersion, FFVersion* ffVersion)
@@ -174,6 +176,7 @@ static void detectVulkan(const FFinstance* instance, FFVulkanResult* result)
ffStrbufInit(&gpu->vendor);
ffStrbufInit(&gpu->name);
ffStrbufInit(&gpu->driver);
gpu->temperature = 0.0 / 0.0; //NaN, no way to detect temperature using vulkan
ffStrbufAppendS(&gpu->name, physicalDeviceProperties.properties.deviceName);
}
+169 -101
View File
@@ -1,11 +1,9 @@
#include "fastfetch.h"
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
// Things only needed by fastfetch
typedef struct FFdata
@@ -236,7 +234,7 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "cpu-format") == 0)
{
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {14}GHz", 14,
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz", 15,
"CPU name",
"Prettified CPU name",
"CPU Vendor name (Vendor ID)",
@@ -244,6 +242,7 @@ static inline void printCommandHelp(const char* command)
"CPU logical core count configured",
"CPU physical core count",
"Always set core count",
"CPU package temperature",
"frequency bios limit",
"frequency scaling max",
"frequency scaling min",
@@ -261,12 +260,13 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "gpu-format") == 0)
{
constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 5,
constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 6,
"GPU vendor",
"GPU vendor pretty",
"GPU name",
"GPU name pretty",
"GPU driver"
"GPU driver",
"GPU temperature"
);
}
else if(strcasecmp(command, "memory-format") == 0)
@@ -888,146 +888,214 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
ffValuestoreSet(&data->valuestore, value, separator + 1);
}
////////////////////////
//Format + Key options//
////////////////////////
////////////////////////////////
//Format + Key + Error options//
////////////////////////////////
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);
optionParseString(key, value, &instance->config.os.key);
else if(strcasecmp(key, "--os-format") == 0)
optionParseString(key, value, &instance->config.os.outputFormat);
else if(strcasecmp(key, "--os-error") == 0)
optionParseString(key, value, &instance->config.os.errorFormat);
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);
optionParseString(key, value, &instance->config.host.key);
else if(strcasecmp(key, "--host-format") == 0)
optionParseString(key, value, &instance->config.host.outputFormat);
else if(strcasecmp(key, "--host-error") == 0)
optionParseString(key, value, &instance->config.host.errorFormat);
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);
optionParseString(key, value, &instance->config.kernel.key);
else if(strcasecmp(key, "--kernel-format") == 0)
optionParseString(key, value, &instance->config.kernel.outputFormat);
else if(strcasecmp(key, "--kernel-error") == 0)
optionParseString(key, value, &instance->config.kernel.errorFormat);
else if(strcasecmp(key, "--uptime-key") == 0)
optionParseString(key, value, &instance->config.uptimeKey);
else if(strcasecmp(key, "--processes-format") == 0)
optionParseString(key, value, &instance->config.processesFormat);
optionParseString(key, value, &instance->config.uptime.key);
else if(strcasecmp(key, "--uptime-format") == 0)
optionParseString(key, value, &instance->config.uptime.outputFormat);
else if(strcasecmp(key, "--uptime-error") == 0)
optionParseString(key, value, &instance->config.uptime.errorFormat);
else if(strcasecmp(key, "--processes-key") == 0)
optionParseString(key, value, &instance->config.processesKey);
else if(strcasecmp(key, "--packages-format") == 0)
optionParseString(key, value, &instance->config.packagesFormat);
optionParseString(key, value, &instance->config.processes.key);
else if(strcasecmp(key, "--processes-format") == 0)
optionParseString(key, value, &instance->config.processes.outputFormat);
else if(strcasecmp(key, "--processes-error") == 0)
optionParseString(key, value, &instance->config.processes.errorFormat);
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);
optionParseString(key, value, &instance->config.packages.key);
else if(strcasecmp(key, "--packages-format") == 0)
optionParseString(key, value, &instance->config.packages.outputFormat);
else if(strcasecmp(key, "--packages-error") == 0)
optionParseString(key, value, &instance->config.packages.errorFormat);
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);
optionParseString(key, value, &instance->config.shell.key);
else if(strcasecmp(key, "--shell-format") == 0)
optionParseString(key, value, &instance->config.shell.outputFormat);
else if(strcasecmp(key, "--shell-error") == 0)
optionParseString(key, value, &instance->config.shell.errorFormat);
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);
optionParseString(key, value, &instance->config.resolution.key);
else if(strcasecmp(key, "--resolution-format") == 0)
optionParseString(key, value, &instance->config.resolution.outputFormat);
else if(strcasecmp(key, "--resolution-error") == 0)
optionParseString(key, value, &instance->config.resolution.errorFormat);
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);
optionParseString(key, value, &instance->config.de.key);
else if(strcasecmp(key, "--de-format") == 0)
optionParseString(key, value, &instance->config.de.outputFormat);
else if(strcasecmp(key, "--de-error") == 0)
optionParseString(key, value, &instance->config.de.errorFormat);
else if(strcasecmp(key, "--wm-key") == 0)
optionParseString(key, value, &instance->config.wmKey);
else if(strcasecmp(key, "--wm-theme-format") == 0)
optionParseString(key, value, &instance->config.wmThemeFormat);
optionParseString(key, value, &instance->config.wm.key);
else if(strcasecmp(key, "--wm-format") == 0)
optionParseString(key, value, &instance->config.wm.outputFormat);
else if(strcasecmp(key, "--wm-error") == 0)
optionParseString(key, value, &instance->config.wm.errorFormat);
else if(strcasecmp(key, "--wm-theme-key") == 0)
optionParseString(key, value, &instance->config.wmThemeKey);
else if(strcasecmp(key, "--theme-format") == 0)
optionParseString(key, value, &instance->config.themeFormat);
optionParseString(key, value, &instance->config.wmTheme.key);
else if(strcasecmp(key, "--wm-theme-format") == 0)
optionParseString(key, value, &instance->config.wmTheme.outputFormat);
else if(strcasecmp(key, "--wm-theme-error") == 0)
optionParseString(key, value, &instance->config.wmTheme.errorFormat);
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);
optionParseString(key, value, &instance->config.theme.key);
else if(strcasecmp(key, "--theme-format") == 0)
optionParseString(key, value, &instance->config.theme.outputFormat);
else if(strcasecmp(key, "--theme-error") == 0)
optionParseString(key, value, &instance->config.theme.errorFormat);
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);
optionParseString(key, value, &instance->config.icons.key);
else if(strcasecmp(key, "--icons-format") == 0)
optionParseString(key, value, &instance->config.icons.outputFormat);
else if(strcasecmp(key, "--icons-error") == 0)
optionParseString(key, value, &instance->config.icons.errorFormat);
else if(strcasecmp(key, "--font-key") == 0)
optionParseString(key, value, &instance->config.fontKey);
optionParseString(key, value, &instance->config.font.key);
else if(strcasecmp(key, "--font-format") == 0)
optionParseString(key, value, &instance->config.font.outputFormat);
else if(strcasecmp(key, "--font-error") == 0)
optionParseString(key, value, &instance->config.font.errorFormat);
else if(strcasecmp(key, "--cursor-key") == 0)
optionParseString(key, value, &instance->config.cursorKey);
optionParseString(key, value, &instance->config.cursor.key);
else if(strcasecmp(key, "--cursor-format") == 0)
optionParseString(key, value, &instance->config.cursorFormat);
else if(strcasecmp(key, "--terminal-format") == 0)
optionParseString(key, value, &instance->config.terminalFormat);
optionParseString(key, value, &instance->config.cursor.outputFormat);
else if(strcasecmp(key, "--cursor-error") == 0)
optionParseString(key, value, &instance->config.cursor.errorFormat);
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);
optionParseString(key, value, &instance->config.terminal.key);
else if(strcasecmp(key, "--terminal-format") == 0)
optionParseString(key, value, &instance->config.terminal.outputFormat);
else if(strcasecmp(key, "--terminal-error") == 0)
optionParseString(key, value, &instance->config.terminal.errorFormat);
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-usage-format") == 0)
optionParseString(key, value, &instance->config.cpuUsageFormat);
optionParseString(key, value, &instance->config.terminalFont.key);
else if(strcasecmp(key, "--terminal-font-format") == 0)
optionParseString(key, value, &instance->config.terminalFont.outputFormat);
else if(strcasecmp(key, "--terminal-font-error") == 0)
optionParseString(key, value, &instance->config.terminalFont.errorFormat);
else if(strcasecmp(key, "--cpu-key") == 0)
optionParseString(key, value, &instance->config.cpuKey);
optionParseString(key, value, &instance->config.cpu.key);
else if(strcasecmp(key, "--cpu-format") == 0)
optionParseString(key, value, &instance->config.cpu.outputFormat);
else if(strcasecmp(key, "--cpu-error") == 0)
optionParseString(key, value, &instance->config.cpu.errorFormat);
else if(strcasecmp(key, "--cpu-usage-key") == 0)
optionParseString(key, value, &instance->config.cpuUsageKey);
else if(strcasecmp(key, "--gpu-format") == 0)
optionParseString(key, value, &instance->config.gpuFormat);
optionParseString(key, value, &instance->config.cpuUsage.key);
else if(strcasecmp(key, "--cpu-usage-format") == 0)
optionParseString(key, value, &instance->config.cpuUsage.outputFormat);
else if(strcasecmp(key, "--cpu-usage-error") == 0)
optionParseString(key, value, &instance->config.cpuUsage.errorFormat);
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);
optionParseString(key, value, &instance->config.gpu.key);
else if(strcasecmp(key, "--gpu-format") == 0)
optionParseString(key, value, &instance->config.gpu.outputFormat);
else if(strcasecmp(key, "--gpu-error") == 0)
optionParseString(key, value, &instance->config.gpu.errorFormat);
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);
optionParseString(key, value, &instance->config.memory.key);
else if(strcasecmp(key, "--memory-format") == 0)
optionParseString(key, value, &instance->config.memory.outputFormat);
else if(strcasecmp(key, "--memory-error") == 0)
optionParseString(key, value, &instance->config.memory.errorFormat);
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);
optionParseString(key, value, &instance->config.disk.key);
else if(strcasecmp(key, "--disk-format") == 0)
optionParseString(key, value, &instance->config.disk.outputFormat);
else if(strcasecmp(key, "--disk-error") == 0)
optionParseString(key, value, &instance->config.disk.errorFormat);
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);
optionParseString(key, value, &instance->config.battery.key);
else if(strcasecmp(key, "--battery-format") == 0)
optionParseString(key, value, &instance->config.battery.outputFormat);
else if(strcasecmp(key, "--battery-error") == 0)
optionParseString(key, value, &instance->config.battery.errorFormat);
else if(strcasecmp(key, "--locale-key") == 0)
optionParseString(key, value, &instance->config.localeKey);
optionParseString(key, value, &instance->config.locale.key);
else if(strcasecmp(key, "--locale-format") == 0)
optionParseString(key, value, &instance->config.locale.outputFormat);
else if(strcasecmp(key, "--locale-error") == 0)
optionParseString(key, value, &instance->config.locale.errorFormat);
else if(strcasecmp(key, "--local-ip-key") == 0)
optionParseString(key, value, &instance->config.localIpKey);
optionParseString(key, value, &instance->config.localIP.key);
else if(strcasecmp(key, "--local-ip-format") == 0)
optionParseString(key, value, &instance->config.localIpFormat);
optionParseString(key, value, &instance->config.localIP.outputFormat);
else if(strcasecmp(key, "--local-ip-error") == 0)
optionParseString(key, value, &instance->config.localIP.errorFormat);
else if(strcasecmp(key, "--public-ip-key") == 0)
optionParseString(key, value, &instance->config.publicIpKey);
optionParseString(key, value, &instance->config.publicIP.key);
else if(strcasecmp(key, "--public-ip-format") == 0)
optionParseString(key, value, &instance->config.publicIpFormat);
optionParseString(key, value, &instance->config.publicIP.outputFormat);
else if(strcasecmp(key, "--public-ip-error") == 0)
optionParseString(key, value, &instance->config.publicIP.errorFormat);
else if(strcasecmp(key, "--player-key") == 0)
optionParseString(key, value, &instance->config.playerKey);
optionParseString(key, value, &instance->config.player.key);
else if(strcasecmp(key, "--player-format") == 0)
optionParseString(key, value, &instance->config.playerFormat);
optionParseString(key, value, &instance->config.player.outputFormat);
else if(strcasecmp(key, "--player-error") == 0)
optionParseString(key, value, &instance->config.player.errorFormat);
else if(strcasecmp(key, "--song-key") == 0)
optionParseString(key, value, &instance->config.songKey);
optionParseString(key, value, &instance->config.song.key);
else if(strcasecmp(key, "--song-format") == 0)
optionParseString(key, value, &instance->config.songFormat);
optionParseString(key, value, &instance->config.song.outputFormat);
else if(strcasecmp(key, "--song-error") == 0)
optionParseString(key, value, &instance->config.song.errorFormat);
else if(strcasecmp(key, "--datetime-key") == 0)
optionParseString(key, value, &instance->config.dateTimeKey);
optionParseString(key, value, &instance->config.dateTime.key);
else if(strcasecmp(key, "--datetime-format") == 0)
optionParseString(key, value, &instance->config.dateTimeFormat);
optionParseString(key, value, &instance->config.dateTime.outputFormat);
else if(strcasecmp(key, "--datetime-error") == 0)
optionParseString(key, value, &instance->config.dateTime.errorFormat);
else if(strcasecmp(key, "--date-key") == 0)
optionParseString(key, value, &instance->config.dateKey);
optionParseString(key, value, &instance->config.date.key);
else if(strcasecmp(key, "--date-format") == 0)
optionParseString(key, value, &instance->config.dateFormat);
optionParseString(key, value, &instance->config.date.outputFormat);
else if(strcasecmp(key, "--date-error") == 0)
optionParseString(key, value, &instance->config.date.errorFormat);
else if(strcasecmp(key, "--time-key") == 0)
optionParseString(key, value, &instance->config.timeKey);
optionParseString(key, value, &instance->config.time.key);
else if(strcasecmp(key, "--time-format") == 0)
optionParseString(key, value, &instance->config.timeFormat);
optionParseString(key, value, &instance->config.time.outputFormat);
else if(strcasecmp(key, "--time-error") == 0)
optionParseString(key, value, &instance->config.time.errorFormat);
else if(strcasecmp(key, "--vulkan-key") == 0)
optionParseString(key, value, &instance->config.vulkanKey);
optionParseString(key, value, &instance->config.vulkan.key);
else if(strcasecmp(key, "--vulkan-format") == 0)
optionParseString(key, value, &instance->config.vulkanFormat);
optionParseString(key, value, &instance->config.vulkan.outputFormat);
else if(strcasecmp(key, "--vulkan-error") == 0)
optionParseString(key, value, &instance->config.vulkan.errorFormat);
else if(strcasecmp(key, "--opengl-key") == 0)
optionParseString(key, value, &instance->config.openGLKey);
optionParseString(key, value, &instance->config.openGL.key);
else if(strcasecmp(key, "--opengl-format") == 0)
optionParseString(key, value, &instance->config.openGLFormat);
optionParseString(key, value, &instance->config.openGL.outputFormat);
else if(strcasecmp(key, "--opengl-error") == 0)
optionParseString(key, value, &instance->config.openGL.errorFormat);
else if(strcasecmp(key, "--opencl-key") == 0)
optionParseString(key, value, &instance->config.openCLKey);
optionParseString(key, value, &instance->config.openCL.key);
else if(strcasecmp(key, "--opencl-format") == 0)
optionParseString(key, value, &instance->config.openCLFormat);
optionParseString(key, value, &instance->config.openCL.outputFormat);
else if(strcasecmp(key, "--opencl-error") == 0)
optionParseString(key, value, &instance->config.openCL.errorFormat);
///////////////////
//Library options//
+66 -89
View File
@@ -3,20 +3,15 @@
#ifndef FASTFETCH_INCLUDED
#define FASTFETCH_INCLUDED
#include <stddef.h>
#include "fastfetch_config.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include "fastfetch_config.h"
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
@@ -50,6 +45,13 @@ typedef enum FFGLType
FF_GL_TYPE_OSMESA
} FFGLType;
typedef struct FFModuleArgs
{
FFstrbuf key;
FFstrbuf outputFormat;
FFstrbuf errorFormat;
} FFModuleArgs;
typedef struct FFconfig
{
FFstrbuf logoSource;
@@ -74,74 +76,40 @@ typedef struct FFconfig
FFGLType glType;
bool pipe; //disables logo and all escape sequences
FFstrbuf osFormat;
FFstrbuf osKey;
FFstrbuf hostFormat;
FFstrbuf hostKey;
FFstrbuf kernelFormat;
FFstrbuf kernelKey;
FFstrbuf uptimeFormat;
FFstrbuf uptimeKey;
FFstrbuf processesFormat;
FFstrbuf processesKey;
FFstrbuf packagesFormat;
FFstrbuf packagesKey;
FFstrbuf shellFormat;
FFstrbuf shellKey;
FFstrbuf resolutionFormat;
FFstrbuf resolutionKey;
FFstrbuf deFormat;
FFstrbuf deKey;
FFstrbuf wmFormat;
FFstrbuf wmKey;
FFstrbuf wmThemeFormat;
FFstrbuf wmThemeKey;
FFstrbuf themeFormat;
FFstrbuf themeKey;
FFstrbuf iconsFormat;
FFstrbuf iconsKey;
FFstrbuf fontFormat;
FFstrbuf fontKey;
FFstrbuf cursorFormat;
FFstrbuf cursorKey;
FFstrbuf terminalFormat;
FFstrbuf terminalKey;
FFstrbuf termFontFormat;
FFstrbuf termFontKey;
FFstrbuf cpuFormat;
FFstrbuf cpuKey;
FFstrbuf cpuUsageFormat;
FFstrbuf cpuUsageKey;
FFstrbuf gpuFormat;
FFstrbuf gpuKey;
FFstrbuf memoryFormat;
FFstrbuf memoryKey;
FFstrbuf diskFormat;
FFstrbuf diskKey;
FFstrbuf batteryFormat;
FFstrbuf batteryKey;
FFstrbuf localeFormat;
FFstrbuf localeKey;
FFstrbuf localIpKey;
FFstrbuf localIpFormat;
FFstrbuf publicIpKey;
FFstrbuf publicIpFormat;
FFstrbuf playerKey;
FFstrbuf playerFormat;
FFstrbuf songKey;
FFstrbuf songFormat;
FFstrbuf dateTimeKey;
FFstrbuf dateTimeFormat;
FFstrbuf dateKey;
FFstrbuf dateFormat;
FFstrbuf timeKey;
FFstrbuf timeFormat;
FFstrbuf vulkanKey;
FFstrbuf vulkanFormat;
FFstrbuf openGLKey;
FFstrbuf openGLFormat;
FFstrbuf openCLKey;
FFstrbuf openCLFormat;
FFModuleArgs os;
FFModuleArgs host;
FFModuleArgs kernel;
FFModuleArgs uptime;
FFModuleArgs processes;
FFModuleArgs packages;
FFModuleArgs shell;
FFModuleArgs resolution;
FFModuleArgs de;
FFModuleArgs wm;
FFModuleArgs wmTheme;
FFModuleArgs theme;
FFModuleArgs icons;
FFModuleArgs font;
FFModuleArgs cursor;
FFModuleArgs terminal;
FFModuleArgs terminalFont;
FFModuleArgs cpu;
FFModuleArgs cpuUsage;
FFModuleArgs gpu;
FFModuleArgs memory;
FFModuleArgs disk;
FFModuleArgs battery;
FFModuleArgs locale;
FFModuleArgs localIP;
FFModuleArgs publicIP;
FFModuleArgs player;
FFModuleArgs song;
FFModuleArgs dateTime;
FFModuleArgs date;
FFModuleArgs time;
FFModuleArgs vulkan;
FFModuleArgs openGL;
FFModuleArgs openCL;
FFstrbuf libPCI;
FFstrbuf libVulkan;
@@ -269,6 +237,7 @@ typedef struct FFGPUResult
FFstrbuf vendor;
FFstrbuf name;
FFstrbuf driver;
double temperature;
} FFGPUResult;
typedef struct FFVulkanResult
@@ -300,8 +269,8 @@ typedef struct FFDisplayServerResult
typedef struct FFTempValue
{
FFstrbuf name;
FFstrbuf value;
FFstrbuf deviceClass;
double value;
} FFTempValue;
typedef struct FFTempsResult
@@ -444,11 +413,14 @@ void ffListFeatures();
void ffStartDetectionThreads(FFinstance* instance);
//common/io.c
void ffAppendFDContent(int fd, FFstrbuf* buffer);
bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between <file not found> and <empty file>
bool ffGetFileContent(const char* fileName, FFstrbuf* buffer);
bool ffWriteFDContent(int fd, const FFstrbuf* content);
bool ffWriteFileContent(const char* fileName, const FFstrbuf* buffer);
bool ffWriteFDBuffer(int fd, const FFstrbuf* content);
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer);
bool ffAppendFDBuffer(int fd, FFstrbuf* buffer);
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data);
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer);
bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer);
bool ffFileExists(const char* fileName, mode_t mode);
void ffSuppressIO(bool suppress); // Not thread safe!
@@ -457,8 +429,10 @@ void ffGetTerminalResponse(const char* request, const char* format, ...);
//common/printing.c
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat);
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...);
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...);
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times);
@@ -468,9 +442,12 @@ void ffCacheValidate(FFinstance* instance);
void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache);
void ffCacheClose(FFcache* cache);
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs);
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments);
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs);
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments);
void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data);
bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data);
//common/properties.c
bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer);
@@ -490,7 +467,7 @@ void ffFontDestroy(FFfont* font);
//common/format.c
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
//common/parsing.c
bool ffStrSet(const char* str);
@@ -573,7 +550,7 @@ const FFVulkanResult* ffDetectVulkan(const FFinstance* instance);
//Common
const FFTitleResult* ffDetectTitle(FFinstance* instance);
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format);
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs);
//Printing
+63 -11
View File
@@ -43,6 +43,56 @@ static const FFlogo* getLogoNone()
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlpine()
{
FF_LOGO_INIT
FF_LOGO_NAMES("alpine", "alpinelinux", "alpine-linux")
FF_LOGO_LINES(
" .hddddddddddddddddddddddh.\n"
" :dddddddddddddddddddddddddd:\n"
" /dddddddddddddddddddddddddddd/\n"
" +dddddddddddddddddddddddddddddd+\n"
" `sdddddddddddddddddddddddddddddddds`\n"
" `ydddddddddddd++hdddddddddddddddddddy`\n"
".hddddddddddd+` `+ddddh:-sdddddddddddh. \n"
"hdddddddddd+` `+y: .sddddddddddh\n"
"ddddddddh+` `//` `.` -sddddddddd\n"
"ddddddh+` `/hddh/` `:s- -sddddddd\n"
"ddddh+` `/+/dddddh/` `+s- -sddddd\n"
"ddd+` `/o` :dddddddh/` `oy- .yddd\n"
"hdddyo+ohddyosdddddddddho+oydddy++ohdddh\n"
".hddddddddddddddddddddddddddddddddddddh.\n"
" `yddddddddddddddddddddddddddddddddddy`\n"
" `sdddddddddddddddddddddddddddddddds`\n"
" +dddddddddddddddddddddddddddddd+\n"
" /dddddddddddddddddddddddddddd/\n"
" :dddddddddddddddddddddddddd:\n"
" .hddddddddddddddddddddddh.";
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlpineSmall()
{
FF_LOGO_INIT
FF_LOGO_NAMES("alpine_small", "alpine-linux-small")
FF_LOGO_LINES(
" /\\ /\\\n"
" // \\ \\\n"
" // \\ \\\n"
"/// \\ \\\n"
"// \\ \\\n"
" \\"
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAndroid()
{
FF_LOGO_INIT
@@ -155,18 +205,18 @@ static const FFlogo* getLogoArtix()
" 'oookkxxoo'\n"
" 'oiioxkkxxoo'\n"
" ':;:iiiioxxxoo'\n"
" `'.;::ioxxoo''\n"
" `'.;::ioxxoo'\n"
" '-. `':;jiooo'\n"
" 'oooio-.. `'i:io'\n"
" 'ooooxxxxoio:,. `'-;'\n"
" 'ooooxxxxxkkxoooIi:-. `'\n"
" 'ooooxxxxxkkkkxoiiiiiji'\n"
" 'ooooxxxxxkxxoiiii:'` .i'\n"
" 'ooooxxxxxoi:::'` .;ioxo'\n"
" 'ooooxooi::'` .:iiixkxxo'\n"
" 'ooooi:'` `'';ioxxo'\n"
"'i:'` '':io'\n"
"'` `'";
" 'oooio-.. `'i:io'\n"
" 'ooooxxxxoio:,. `'-;'\n"
" 'ooooxxxxxkkxoooIi:-. `'\n"
" 'ooooxxxxxkkkkxoiiiiiji'\n"
" 'ooooxxxxxkxxoiiii:'` .i'\n"
" 'ooooxxxxxoi:::'` .;ioxo'\n"
" 'ooooxooi::'` .:iiixkxxo'\n"
" 'ooooi:'` `'';ioxxo'\n"
" 'i:'` '':io'\n"
"'` `'";
)
FF_LOGO_COLORS(
"36" //cyan
@@ -1434,6 +1484,8 @@ GetLogoMethod* ffLogoBuiltinGetAll()
static GetLogoMethod logoMethods[] = {
ffLogoBuiltinGetUnknown,
getLogoNone,
getLogoAlpine,
getLogoAlpineSmall,
getLogoAndroid,
getLogoAndroidSmall,
getLogoArch,
+2
View File
@@ -1,6 +1,8 @@
#ifdef FF_HAVE_IMAGEMAGICK6
#include "image.h"
#include <dlfcn.h>
#include <magick/MagickCore.h>
static FF_LIBRARY_SYMBOL(ResizeImage);
+2
View File
@@ -1,6 +1,8 @@
#ifdef FF_HAVE_IMAGEMAGICK7
#include "image.h"
#include <dlfcn.h>
#include <MagickCore/MagickCore.h>
static FF_LIBRARY_SYMBOL(ResizeImage);
+6 -5
View File
@@ -17,6 +17,8 @@
#include <sys/ioctl.h>
#ifdef FF_HAVE_ZLIB
#include <stdlib.h>
#include <dlfcn.h>
#include <zlib.h>
static bool compressBlob(const FFinstance* instance, void** blob, size_t* length)
@@ -92,7 +94,7 @@ static void writeCacheStrbuf(FFLogoRequestData* requestData, const FFstrbuf* val
{
uint32_t cacheDirLength = requestData->cacheDir.length;
ffStrbufAppendS(&requestData->cacheDir, cacheFileName);
ffWriteFileContent(requestData->cacheDir.chars, value);
ffWriteFileBuffer(requestData->cacheDir.chars, value);
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
}
@@ -125,7 +127,7 @@ static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestDat
//Write result to stdout
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
fflush(stdout);
ffWriteFDContent(STDOUT_FILENO, result);
ffWriteFDBuffer(STDOUT_FILENO, result);
//Go to upper left corner
fputs("\033[9999999D", stdout);
@@ -373,7 +375,7 @@ static void readCachedStrbuf(FFLogoRequestData* requestData, FFstrbuf* result, c
{
uint32_t cacheDirLength = requestData->cacheDir.length;
ffStrbufAppendS(&requestData->cacheDir, cacheFileName);
ffAppendFileContent(requestData->cacheDir.chars, result);
ffAppendFileBuffer(requestData->cacheDir.chars, result);
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
}
@@ -533,8 +535,7 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
return false;
}
ffStrbufRecalculateLength(&requestData.cacheDir);
if(!ffStrbufEndsWithC(&requestData.cacheDir, '/'))
ffStrbufAppendC(&requestData.cacheDir, '/');
ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/');
ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelWidth);
ffStrbufAppendC(&requestData.cacheDir, '*');
+1 -1
View File
@@ -249,7 +249,7 @@ static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement)
FFstrbuf content;
ffStrbufInitA(&content, 2047);
if(!ffAppendFileContent(instance->config.logoSource.chars, &content))
if(!ffAppendFileBuffer(instance->config.logoSource.chars, &content))
{
ffStrbufDestroy(&content);
return false;
+13 -15
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include <unistd.h>
#include <dirent.h>
#define FF_BATTERY_MODULE_NAME "Battery"
@@ -24,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
@@ -35,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
@@ -50,7 +49,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//capacity must exist and be not empty
ffStrbufInit(&result->capacity);
ffStrbufAppendS(dir, "/capacity");
ffGetFileContent(dir->chars, &result->capacity);
ffReadFileBuffer(dir->chars, &result->capacity);
ffStrbufSubstrBefore(dir, dirLength);
if(result->capacity.length == 0)
@@ -64,30 +63,30 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
ffGetFileContent(dir->chars, &result->manufacturer);
ffReadFileBuffer(dir->chars, &result->manufacturer);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
ffGetFileContent(dir->chars, &result->modelName);
ffReadFileBuffer(dir->chars, &result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
ffGetFileContent(dir->chars, &result->technology);
ffReadFileBuffer(dir->chars, &result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
ffGetFileContent(dir->chars, &result->status);
ffReadFileBuffer(dir->chars, &result->status);
ffStrbufSubstrBefore(dir, dirLength);
}
static void printBattery(FFinstance* instance, const BatteryResult* result, uint8_t index)
{
if(instance->config.batteryFormat.length == 0)
if(instance->config.battery.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey);
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery.key);
bool showStatus =
result->status.length > 0 &&
@@ -114,7 +113,7 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint
}
else
{
ffPrintFormatString(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey, &instance->config.batteryFormat, NULL, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->technology},
@@ -131,8 +130,7 @@ void ffPrintBattery(FFinstance* instance)
if(instance->config.batteryDir.length > 0)
{
ffStrbufAppend(&baseDir, &instance->config.batteryDir);
if(!ffStrbufEndsWithC(&baseDir, '/'))
ffStrbufAppendC(&baseDir, '/');
ffStrbufEndsWithC(&baseDir, '/');
}
else
{
@@ -144,7 +142,7 @@ void ffPrintBattery(FFinstance* instance)
DIR* dirp = opendir(baseDir.chars);
if(dirp == NULL)
{
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "opendir(\"%s\") == NULL", baseDir.chars);
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "opendir(\"%s\") == NULL", baseDir.chars);
ffStrbufDestroy(&baseDir);
return;
}
@@ -175,7 +173,7 @@ void ffPrintBattery(FFinstance* instance)
}
if(results.length == 0)
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "%s doesn't contain any battery folder", baseDir.chars);
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "%s doesn't contain any battery folder", baseDir.chars);
ffListDestroy(&results);
ffStrbufDestroy(&baseDir);
+42 -22
View File
@@ -1,48 +1,58 @@
#include "fastfetch.h"
#include <string.h>
#include <stdlib.h>
#define FF_CPU_MODULE_NAME "CPU"
#define FF_CPU_NUM_FORMAT_ARGS 14
static double parseHz(FFstrbuf* content)
{
if(content->length == 0)
return 0;
double herz;
if(sscanf(content->chars, "%lf", &herz) != 1)
return 0;
return herz;
}
#define FF_CPU_NUM_FORMAT_ARGS 15
static double getGhz(const char* policyFile, const char* cpuFile)
{
FFstrbuf content;
ffStrbufInit(&content);
ffGetFileContent(policyFile, &content);
ffReadFileBuffer(policyFile, &content);
if(content.length == 0)
ffGetFileContent(cpuFile, &content);
ffReadFileBuffer(cpuFile, &content);
double herz = parseHz(&content);
double herz = ffStrbufToDouble(&content);
ffStrbufDestroy(&content);
//ffStrbufToDouble failed
if(herz != herz)
return 0;
herz /= 1000.0; //to MHz
return herz / 1000.0; //to GHz
}
static double detectCPUTemp(const FFinstance* instance)
{
const FFTempsResult *temps = ffDetectTemps(instance);
for(uint32_t i = 0; i < temps->values.length; i++)
{
FFTempValue* value = ffListGet(&temps->values, i);
if(
ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length ||
ffStrbufCompS(&value->name, "k10temp") == 0 ||
ffStrbufCompS(&value->name, "coretemp") == 0
) return value->value;
}
return 0.0 / 0.0; //NaN
}
void ffPrintCPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS))
return;
FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
if(cpuinfo == NULL)
{
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL");
return;
}
@@ -81,7 +91,12 @@ void ffPrintCPU(FFinstance* instance)
fclose(cpuinfo);
double procGhz = parseHz(&procGhzString) / 1000.0; //to GHz
double procGhz = ffStrbufToDouble(&procGhzString);
if(procGhz != procGhz)
procGhz = 0; //NaN
else
procGhz /= 1000.0; //To GHz
ffStrbufDestroy(&procGhzString);
double biosLimit = getGhz("/sys/devices/system/cpu/cpufreq/policy0/bios_limit", "/sys/devices/system/cpu/cpu0/cpufreq/bios_limit");
@@ -124,7 +139,7 @@ void ffPrintCPU(FFinstance* instance)
) {
ffStrbufDestroy(&name);
ffStrbufDestroy(&vendor);
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "No CPU info found in /proc/cpuinfo");
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "No CPU info found in /proc/cpuinfo");
return;
}
@@ -143,6 +158,10 @@ void ffPrintCPU(FFinstance* instance)
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
double cpuTemp;
if(instance->config.cpu.outputFormat.length > 0)
cpuTemp = detectCPUTemp(instance);
FFstrbuf cpu;
ffStrbufInitA(&cpu, 128);
@@ -164,7 +183,7 @@ void ffPrintCPU(FFinstance* instance)
if(ghz > 0)
ffStrbufAppendF(&cpu, " @ %.9gGHz", ghz);
ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &cpu, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, &cpu, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &name},
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &vendor},
@@ -172,6 +191,7 @@ void ffPrintCPU(FFinstance* instance)
{FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable},
{FF_FORMAT_ARG_TYPE_INT, &physicalCores},
{FF_FORMAT_ARG_TYPE_INT, &numProcs},
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuTemp},
{FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit},
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq},
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq},
+4 -5
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include <stdio.h>
#include <unistd.h>
#define FF_CPU_USAGE_MODULE_NAME "CPU Usage"
@@ -12,7 +11,7 @@ void ffPrintCPUUsage(FFinstance* instance)
FILE* procStat = fopen("/proc/stat", "r");
if(procStat == NULL)
{
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, FF_CPU_USAGE_NUM_FORMAT_ARGS, "fopen(\"""/proc/stat\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/stat\", \"r\") == NULL");
return;
}
if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0) goto exit;
@@ -31,15 +30,15 @@ void ffPrintCPUUsage(FFinstance* instance)
long totalOverPeriod = totalJiffies2 - totalJiffies1;
double cpuPercent = (double)workOverPeriod / (double)totalOverPeriod * 100;
if(instance->config.cpuUsageFormat.length == 0)
if(instance->config.cpuUsage.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey);
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage.key);
printf("%.2lf%%\n", cpuPercent);
}
else
{
ffPrintFormatString(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, NULL, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPercent}
});
}
+16 -8
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <stdlib.h>
#define FF_CURSOR_MODULE_NAME "Cursor"
#define FF_CURSOR_NUM_FORMAT_ARGS 2
@@ -12,9 +14,9 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr
if(cursorTheme->length == 0)
ffStrbufAppendS(cursorTheme, "default");
if(instance->config.cursorFormat.length == 0)
if(instance->config.cursor.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey);
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor.key);
ffStrbufWriteTo(cursorTheme, stdout);
if(cursorSize != NULL && cursorSize->length > 0)
@@ -28,7 +30,7 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr
}
else
{
ffPrintFormatString(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, NULL, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, cursorTheme},
{FF_FORMAT_ARG_TYPE_STRBUF, cursorSize}
});
@@ -47,7 +49,7 @@ static void printCursorGTK(FFinstance* instance)
if(gtk->cursor.length == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't detect GTK Cursor");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't detect GTK Cursor");
return;
}
@@ -69,7 +71,7 @@ static void printCursorXFCE(FFinstance* instance)
if(cursorTheme.length == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)");
return;
}
@@ -105,7 +107,7 @@ static void printCursorFromConfigFile(FFinstance* instance, const char* relative
}
if(cursorTheme.length == 0)
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find cursor in %s", relativeFilePath);
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find cursor in %s", relativeFilePath);
else
printCursor(instance, &cursorTheme, &cursorSize);
@@ -185,15 +187,21 @@ static bool printCursorFromEnv(FFinstance* instance)
void ffPrintCursor(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor detection is not supported on Android");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor detection is not supported on Android");
return;
#endif
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
if(ffStrbufCompS(&wmde->wmPrettyName, "WSLg") == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "WSLg uses native windows cursor");
return;
}
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor isn't supported in TTY");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor isn't supported in TTY");
return;
}
+3 -3
View File
@@ -4,14 +4,14 @@
void ffPrintDate(FFinstance* instance)
{
if(instance->config.dateFormat.length > 0)
if(instance->config.date.outputFormat.length > 0)
{
ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.dateKey, &instance->config.dateFormat);
ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.date);
return;
}
const FFDateTimeResult* datetime = ffDetectDateTime(instance);
ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.dateKey);
ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.date.key);
//yyyy-mm-dd
printf("%u-%s-%u\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth);
+5 -5
View File
@@ -3,10 +3,10 @@
#define FF_DATETIME_MODULE_NAME "Date & Time"
#define FF_DATETIME_NUM_FORMAT_ARGS 20
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format)
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs)
{
const FFDateTimeResult* result = ffDetectDateTime(instance);
ffPrintFormatString(instance, moduleName, 0, key, format, NULL, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, moduleName, 0, moduleArgs, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_UINT16, &result->year},
{FF_FORMAT_ARG_TYPE_UINT8, &result->yearShort},
{FF_FORMAT_ARG_TYPE_UINT8, &result->month},
@@ -32,14 +32,14 @@ void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const F
void ffPrintDateTime(FFinstance* instance)
{
if(instance->config.dateTimeFormat.length > 0)
if(instance->config.dateTime.outputFormat.length > 0)
{
ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTimeKey, &instance->config.dateTimeFormat);
ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTime);
return;
}
const FFDateTimeResult* datetime = ffDetectDateTime(instance);
ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTimeKey);
ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTime.key);
//yyyy-mm-dd hh:mm:ss
printf("%u-%s-%u %s:%s:%s\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth, datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars);
+5 -7
View File
@@ -1,14 +1,12 @@
#include "fastfetch.h"
#include <string.h>
#define FF_DE_MODULE_NAME "DE"
#define FF_DE_NUM_FORMAT_ARGS 3
void ffPrintDesktopEnvironment(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "DE detection is not supported on Android");
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "DE detection is not supported on Android");
return;
#endif
@@ -16,13 +14,13 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
if(result->dePrettyName.length == 0)
{
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "No DE found");
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "No DE found");
return;
}
if(instance->config.deFormat.length == 0)
if(instance->config.de.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey);
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.de.key);
ffStrbufWriteTo(&result->dePrettyName, stdout);
@@ -36,7 +34,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, NULL, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion}
+8 -8
View File
@@ -7,7 +7,7 @@
static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath, bool showFolderPath)
{
if(instance->config.diskKey.length == 0)
if(instance->config.disk.key.length == 0)
{
if(showFolderPath)
ffStrbufAppendF(key, FF_DISK_MODULE_NAME" (%s)", folderPath);
@@ -16,7 +16,7 @@ static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath,
}
else
{
ffParseFormatString(key, &instance->config.diskKey, NULL, 1, (FFformatarg[]){
ffParseFormatString(key, &instance->config.disk.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, folderPath}
});
}
@@ -33,14 +33,14 @@ static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs
uint32_t files = (uint32_t) (fs->f_files - fs->f_ffree);
if(instance->config.diskFormat.length == 0)
if(instance->config.disk.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, key->chars, 0, NULL);
printf("%uGiB / %uGiB (%u%%)\n", used, total, percentage);
}
else
{
ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.diskFormat, NULL, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.disk.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &used},
{FF_FORMAT_ARG_TYPE_UINT, &total},
{FF_FORMAT_ARG_TYPE_UINT, &files},
@@ -64,9 +64,9 @@ static void printFolder(FFinstance* instance, const char* folderPath)
struct statvfs fs;
int ret = statvfs(folderPath, &fs);
if(ret != 0 && instance->config.diskFormat.length == 0)
if(ret != 0 && instance->config.disk.outputFormat.length == 0)
{
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret);
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret);
ffStrbufDestroy(&key);
return;
}
@@ -89,7 +89,7 @@ void ffPrintDisk(FFinstance* instance)
{
FF_STRBUF_CREATE(key);
getKey(instance, &key, "", false);
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME);
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME);
ffStrbufDestroy(&key);
return;
}
@@ -108,7 +108,7 @@ void ffPrintDisk(FFinstance* instance)
{
FF_STRBUF_CREATE(key);
getKey(instance, &key, "", false);
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "Custom disk folders string doesn't contain any folders");
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "Custom disk folders string doesn't contain any folders");
ffStrbufDestroy(&key);
return;
}
+6 -6
View File
@@ -6,7 +6,7 @@
void ffPrintFont(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font detection is not supported on Android");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font detection is not supported on Android");
return;
#endif
@@ -14,7 +14,7 @@ void ffPrintFont(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font isn't supported in TTY");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font isn't supported in TTY");
return;
}
@@ -25,7 +25,7 @@ void ffPrintFont(FFinstance* instance)
if(plasmaRaw->length == 0 && gtk2Raw->length == 0 && gtk3Raw->length == 0 && gtk4Raw->length == 0)
{
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "No fonts found");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "No fonts found");
return;
}
@@ -45,9 +45,9 @@ void ffPrintFont(FFinstance* instance)
ffStrbufInitA(&gtk, 64);
ffParseGTK(&gtk, &gtk2.pretty, &gtk3.pretty, &gtk4.pretty);
if(instance->config.fontFormat.length == 0)
if(instance->config.font.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey);
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
if(plasma.pretty.length > 0)
{
ffStrbufWriteTo(&plasma.pretty, stdout);
@@ -60,7 +60,7 @@ void ffPrintFont(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, NULL, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, plasmaRaw},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.name},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.size},
+37 -10
View File
@@ -1,9 +1,7 @@
#include "fastfetch.h"
#include <string.h>
#define FF_GPU_MODULE_NAME "GPU"
#define FF_GPU_NUM_FORMAT_ARGS 5
#define FF_GPU_NUM_FORMAT_ARGS 6
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* result)
{
@@ -33,12 +31,13 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache,
ffStrbufAppend(&gpu, &namePretty);
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpuKey, cache, &gpu, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->vendor},
{FF_FORMAT_ARG_TYPE_STRING, vendorPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature}
});
ffStrbufDestroy(&result->vendor);
@@ -60,8 +59,10 @@ static void printGPUList(FFinstance* instance, const FFlist* list)
}
#ifdef FF_HAVE_LIBPCI
#include <pci/pci.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <pci/pci.h>
//see https://github.com/pciutils/pciutils/blob/5bdf63b6b1bc35b59c4b3f47f7ca83ca1868155b/ls-kernel.c#L220
static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get_param)(struct pci_access*, char*))
@@ -89,6 +90,26 @@ static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get
ffStrbufDestroy(&path);
}
static double pciGetTemperatur(const FFinstance* instance, uint16_t deviceClass)
{
const FFTempsResult* tempsResult = ffDetectTemps(instance);
for(uint32_t i = 0; i < tempsResult->values.length; i++)
{
FFTempValue* tempValue = ffListGet(&tempsResult->values, i);
uint32_t tempClass;
if(sscanf(tempValue->deviceClass.chars, "%x", &tempClass) != 1)
continue;
//The kernel exposes the device class multiplied by 256 for some reason
if(tempClass == deviceClass * 256)
return tempValue->value;
}
return 0.0 / 0.0; //NaN
}
static bool pciPrintGPUs(FFinstance* instance)
{
FF_LIBRARY_LOAD(pci, instance->config.libPCI, false, "libpci.so", 4)
@@ -121,16 +142,22 @@ static bool pciPrintGPUs(FFinstance* instance)
FFGPUResult* result = ffListAdd(&results);
ffStrbufInitA(&result->vendor, 256);
ffpci_lookup_name(pacc, result->vendor.chars, (int) result->vendor.allocated -1, PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
ffpci_lookup_name(pacc, result->vendor.chars, (int) ffStrbufGetFree(&result->vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->vendor);
ffStrbufInitA(&result->name, 256);
ffpci_lookup_name(pacc, result->name.chars, (int) result->name.allocated - 1, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
ffpci_lookup_name(pacc, result->name.chars, (int) ffStrbufGetFree(&result->name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->name);
ffStrbufInit(&result->driver);
if(instance->config.gpuFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed
result->temperature = 0;
//We only need it for the format string, so don't detect it if it isn't needed
if(instance->config.gpu.outputFormat.length > 0)
{
pciGetDriver(dev, &result->driver, ffpci_get_param);
result->temperature = pciGetTemperatur(instance, dev->device_class);
}
};
}
@@ -163,7 +190,7 @@ static bool vulkanPrintGPUs(FFinstance* instance)
void ffPrintGPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS))
return;
#ifdef FF_HAVE_LIBPCI
@@ -174,5 +201,5 @@ void ffPrintGPU(FFinstance* instance)
if(vulkanPrintGPUs(instance))
return;
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "No GPUs found.");
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "No GPUs found.");
}
+23 -12
View File
@@ -1,10 +1,15 @@
#include "fastfetch.h"
#include <ctype.h>
#include <stdlib.h>
#define FF_HOST_MODULE_NAME "Host"
#define FF_HOST_NUM_FORMAT_ARGS 15
#ifdef __ANDROID__
#include <ctype.h>
#endif
#ifndef __ANDROID__
static bool hostValueSet(FFstrbuf* value)
{
ffStrbufTrimRight(value, '\n');
@@ -32,19 +37,18 @@ static bool hostValueSet(FFstrbuf* value)
;
}
#ifndef __ANDROID__
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffGetFileContent(devicesPath, buffer);
ffReadFileBuffer(devicesPath, buffer);
if(buffer->length == 0)
ffGetFileContent(classPath, buffer);
ffReadFileBuffer(classPath, buffer);
}
#endif
void ffPrintHost(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, FF_HOST_NUM_FORMAT_ARGS))
return;
FFstrbuf product_family;
@@ -63,10 +67,10 @@ void ffPrintHost(FFinstance* instance)
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name);
if(product_name.length == 0)
ffGetFileContent("/sys/firmware/devicetree/base/model", &product_name);
ffReadFileBuffer("/sys/firmware/devicetree/base/model", &product_name);
if(product_name.length == 0)
ffGetFileContent("/tmp/sysinfo/model", &product_name);
ffReadFileBuffer("/tmp/sysinfo/model", &product_name);
if(ffStrbufStartsWithS(&product_name, "Standard PC"))
{
@@ -79,6 +83,13 @@ void ffPrintHost(FFinstance* instance)
if(!hostValueSet(&product_name))
ffStrbufClear(&product_name);
//On WSL, the real host can't be detected. Instead use WSL as host.
if(product_name.length == 0 && product_family.length == 0 && (
getenv("WSLENV") != NULL ||
getenv("WSL_DISTRO") != NULL ||
getenv("WSL_INTEROP") != NULL
)) ffStrbufAppendS(&product_name, "Windows Subsystem for Linux");
#else
ffSettingsGetAndroidProperty("ro.product.brand", &product_name);
if(product_name.length > 0){
@@ -96,14 +107,14 @@ void ffPrintHost(FFinstance* instance)
{
ffStrbufDestroy(&product_family);
ffStrbufDestroy(&product_name);
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, "neither product_family nor product_name is set by O.E.M.");
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, "neither product_family nor product_name is set by O.E.M.");
return;
}
#ifdef __ANDROID__
#define FF_HOST_DATA(name)
FFstrbuf product_name; \
ffStrbufInitA(&product_name, 0);
#define FF_HOST_DATA(name) \
FFstrbuf name; \
ffStrbufInitA(&name, 0);
#else
#define FF_HOST_DATA(name) \
FFstrbuf name; \
@@ -141,7 +152,7 @@ void ffPrintHost(FFinstance* instance)
ffStrbufAppend(&host, &product_version);
}
ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &host, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, &host, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &product_family},
{FF_FORMAT_ARG_TYPE_STRBUF, &product_name},
{FF_FORMAT_ARG_TYPE_STRBUF, &product_version},
+6 -6
View File
@@ -6,7 +6,7 @@
void ffPrintIcons(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons detection is not supported on Android");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons detection is not supported on Android");
return;
#endif
@@ -14,7 +14,7 @@ void ffPrintIcons(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons aren't supported in TTY");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons aren't supported in TTY");
return;
}
@@ -25,16 +25,16 @@ void ffPrintIcons(FFinstance* instance)
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "No icons could be found");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "No icons could be found");
return;
}
FF_STRBUF_CREATE(gtkPretty);
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
if(instance->config.iconsFormat.length == 0)
if(instance->config.icons.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey);
ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons.key);
if(plasma->length > 0)
{
@@ -49,7 +49,7 @@ void ffPrintIcons(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, NULL, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, plasma},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk2},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk3},
+3 -3
View File
@@ -5,14 +5,14 @@
void ffPrintKernel(FFinstance* instance)
{
if(instance->config.kernelFormat.length == 0)
if(instance->config.kernel.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey);
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key);
puts(instance->state.utsname.release);
}
else
{
ffPrintFormatString(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey, &instance->config.kernelFormat, NULL, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname},
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release},
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version}
+5 -3
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <stdlib.h>
#define FF_LOCALE_MODULE_NAME "Locale"
#define FF_LOCALE_NUM_FORMAT_ARGS 1
@@ -22,7 +24,7 @@ static void getLocaleFromEnv(FFstrbuf* locale)
void ffPrintLocale(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS))
return;
FFstrbuf locale;
@@ -45,11 +47,11 @@ void ffPrintLocale(FFinstance* instance)
if(locale.length == 0)
{
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, "No locale found");
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, "No locale found");
return;
}
ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &locale, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, &locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
});
+17 -11
View File
@@ -3,29 +3,35 @@
#define FF_LOCALIP_MODULE_NAME "Local IP"
#define FF_LOCALIP_NUM_FORMAT_ARGS 1
#include <sys/types.h>
#include <string.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
static void printValue(FFinstance* instance, const char* ifaName, const char* addressBuffer)
{
FF_STRBUF_CREATE(key);
FFstrbuf key;
ffStrbufInit(&key);
if (instance->config.localIpKey.length == 0) {
if (instance->config.localIP.key.length == 0)
{
ffStrbufAppendF(&key, FF_LOCALIP_MODULE_NAME " (%s)", ifaName);
} else {
ffParseFormatString(&key, &instance->config.localIpKey, NULL, 1, (FFformatarg[]){
}
else
{
ffParseFormatString(&key, &instance->config.localIP.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, ifaName}
});
}
if (instance->config.localIpFormat.length == 0) {
ffPrintLogoAndKey(instance, FF_LOCALIP_MODULE_NAME, 0, &key);
if (instance->config.localIP.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
puts(addressBuffer);
} else {
ffPrintFormatString(instance, FF_LOCALIP_MODULE_NAME, 0, &key, &instance->config.localIpFormat, NULL, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){
}
else
{
ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.localIP.outputFormat, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, addressBuffer}
});
}
@@ -38,7 +44,7 @@ void ffPrintLocalIp(FFinstance* instance)
struct ifaddrs* ifAddrStruct = NULL;
int ret = getifaddrs(&ifAddrStruct);
if (ret < 0) {
ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIpKey, &instance->config.localIpFormat, FF_LOCALIP_NUM_FORMAT_ARGS, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret);
ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIP, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret);
return;
}
+7 -5
View File
@@ -1,5 +1,7 @@
#include "fastfetch.h"
#include <stdlib.h>
#define FF_MEMORY_MODULE_NAME "Memory"
#define FF_MEMORY_NUM_FORMAT_ARGS 3
@@ -8,7 +10,7 @@ void ffPrintMemory(FFinstance* instance)
{
FILE* meminfo = fopen("/proc/meminfo", "r");
if(meminfo == NULL) {
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "fopen(\"""/proc/meminfo\", \"r\") == NULL");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "fopen(\"""/proc/meminfo\", \"r\") == NULL");
return;
}
@@ -42,18 +44,18 @@ void ffPrintMemory(FFinstance* instance)
if(used_mem == 0 && total_mem == 0 && percentage == 0)
{
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "/proc/meminfo could't be parsed");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "/proc/meminfo could't be parsed");
return;
}
if(instance->config.memoryFormat.length == 0)
if(instance->config.memory.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey);
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
}
else
{
ffPrintFormatString(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, NULL, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &used_mem},
{FF_FORMAT_ARG_TYPE_UINT, &total_mem},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage}
+6 -4
View File
@@ -4,6 +4,8 @@
#define FF_OPENCL_NUM_FORMAT_ARGS 3
#ifdef FF_HAVE_OPENCL
#include <dlfcn.h>
#define CL_TARGET_OPENCL_VERSION 100
#include <CL/cl.h>
@@ -44,14 +46,14 @@ static const char* openCLHandelData(FFinstance* instance, OpenCLData* data)
char vendor[32];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
if(instance->config.openCLFormat.length == 0)
if(instance->config.openCL.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey);
ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL.key);
puts(version);
}
else
{
ffPrintFormatString(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, NULL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRING, version},
{FF_FORMAT_ARG_TYPE_STRING, device},
{FF_FORMAT_ARG_TYPE_STRING, vendor}
@@ -87,5 +89,5 @@ void ffPrintOpenCL(FFinstance* instance)
#endif
if(error != NULL)
ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, FF_OPENCL_NUM_FORMAT_ARGS, error);
ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, error);
}
+5 -4
View File
@@ -7,6 +7,7 @@
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA)
#define FF_HAVE_GL 1
#include <dlfcn.h>
#include <GL/gl.h>
#define FF_OPENGL_BUFFER_WIDTH 1
@@ -27,14 +28,14 @@ static const char* glHandlePrint(FFinstance* instance, const GLData* data)
const char* vendor = (const char*) data->ffglGetString(GL_VENDOR);
const char* slv = (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION);
if(instance->config.openGLFormat.length == 0)
if(instance->config.openGL.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey);
ffPrintLogoAndKey(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL.key);
puts(version);
}
else
{
ffPrintFormatString(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey, &instance->config.openGLFormat, NULL, FF_OPENGL_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, FF_OPENGL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRING, version},
{FF_FORMAT_ARG_TYPE_STRING, renderer},
{FF_FORMAT_ARG_TYPE_STRING, vendor},
@@ -388,5 +389,5 @@ void ffPrintOpenGL(FFinstance* instance)
#endif
if(error != NULL)
ffPrintError(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey, &instance->config.openGLFormat, FF_OPENGL_NUM_FORMAT_ARGS, error);
ffPrintError(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, error);
}
+4 -4
View File
@@ -9,7 +9,7 @@ void ffPrintOS(FFinstance* instance)
if(result->name.length == 0 && result->prettyName.length == 0)
{
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS, "Could not detect OS");
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, "Could not detect OS");
return;
}
@@ -66,14 +66,14 @@ void ffPrintOS(FFinstance* instance)
ffStrbufAppendC(&os, ']');
}
if(instance->config.osFormat.length == 0)
if(instance->config.os.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey);
ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.os.key);
ffStrbufPutTo(&os, stdout);
}
else
{
ffPrintFormatString(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey, &instance->config.osFormat, NULL, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->systemName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName},
+7 -4
View File
@@ -1,7 +1,9 @@
#include "fastfetch.h"
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define FF_PACKAGES_MODULE_NAME "Packages"
#define FF_PACKAGES_NUM_FORMAT_ARGS 11
@@ -128,6 +130,7 @@ static uint32_t getNixPackages(char* path)
}
#ifdef FF_HAVE_RPM
#include <dlfcn.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmts.h>
#include <rpm/rpmdb.h>
@@ -289,13 +292,13 @@ void ffPrintPackages(FFinstance* instance)
uint32_t all = counts.dpkg + counts.emerge + counts.flatpak + counts.nixDefault + nixUser + counts.pacman + counts.rpm + counts.snap + counts.xbps;
if(all == 0)
{
ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey, &instance->config.packagesFormat, FF_PACKAGES_NUM_FORMAT_ARGS, "No packages from known package managers found");
ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, "No packages from known package managers found");
return;
}
if(instance->config.packagesFormat.length == 0)
if(instance->config.packages.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey);
ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages.key);
#define FF_PRINT_PACKAGE(name) \
if(counts.name > 0) \
@@ -344,7 +347,7 @@ void ffPrintPackages(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey, &instance->config.packagesFormat, NULL, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &all},
{FF_FORMAT_ARG_TYPE_UINT, &counts.pacman},
{FF_FORMAT_ARG_TYPE_STRBUF, &counts.pacmanBranch},
+4 -4
View File
@@ -11,7 +11,7 @@ void ffPrintPlayer(FFinstance* instance)
if(media->player.length == 0)
{
ffPrintError(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey, &instance->config.playerFormat, FF_PLAYER_NUM_FORMAT_ARGS, "No media player found");
ffPrintError(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player, "No media player found");
return;
}
@@ -50,14 +50,14 @@ void ffPrintPlayer(FFinstance* instance)
if(playerPrettyIsCustom)
ffStrbufAppendC(&playerPretty, ')');
if(instance->config.playerFormat.length == 0)
if(instance->config.player.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey);
ffPrintLogoAndKey(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player.key);
ffStrbufPutTo(&playerPretty, stdout);
}
else
{
ffPrintFormatString(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey, &instance->config.playerFormat, NULL, FF_PLAYER_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player, FF_PLAYER_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &playerPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &media->player},
{FF_FORMAT_ARG_TYPE_STRBUF, &media->busNameShort}
+3 -3
View File
@@ -5,15 +5,15 @@
void ffPrintProcesses(FFinstance* instance)
{
if(instance->config.processesFormat.length == 0)
if(instance->config.processes.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey);
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes.key);
printf("%hu\n", instance->state.sysinfo.procs);
}
else
{
ffPrintFormatString(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey, &instance->config.processesFormat, NULL, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT16, &instance->state.sysinfo.procs}
});
}
+4 -4
View File
@@ -12,18 +12,18 @@ void ffPrintPublicIp(FFinstance* instance)
if(result.length == 0)
{
ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey, &instance->config.publicIpFormat, FF_PUBLICIP_NUM_FORMAT_ARGS, "Failed to connect to an IP detection server");
ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, "Failed to connect to an IP detection server");
return;
}
if(instance->config.publicIpFormat.length == 0)
if(instance->config.publicIP.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey);
ffPrintLogoAndKey(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP.key);
ffStrbufPutTo(&result, stdout);
}
else
{
ffPrintFormatString(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey, &instance->config.publicIpFormat, NULL, FF_PUBLICIP_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, FF_PUBLICIP_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &result}
});
}
+5 -5
View File
@@ -6,7 +6,7 @@
void ffPrintResolution(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "Resolution detection is not supported on Android");
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolution, "Resolution detection is not supported on Android");
return;
#endif
@@ -17,9 +17,9 @@ void ffPrintResolution(FFinstance* instance)
FFResolutionResult* result = ffListGet(&dsResult->resolutions, i);
uint8_t moduleIndex = dsResult->resolutions.length == 1 ? 0 : (uint8_t) (i + 1);
if(instance->config.resolutionFormat.length == 0)
if(instance->config.resolution.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolutionKey);
ffPrintLogoAndKey(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolution.key);
printf("%ix%i", result->width, result->height);
if(result->refreshRate > 0)
@@ -29,7 +29,7 @@ void ffPrintResolution(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolutionKey, &instance->config.resolutionFormat, NULL, FF_RESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolution, FF_RESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_INT, &result->width},
{FF_FORMAT_ARG_TYPE_INT, &result->height},
{FF_FORMAT_ARG_TYPE_INT, &result->refreshRate}
@@ -38,5 +38,5 @@ void ffPrintResolution(FFinstance* instance)
}
if(dsResult->resolutions.length == 0)
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "Couldn't detect resolution");
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolution, "Couldn't detect resolution");
}
+4 -7
View File
@@ -1,8 +1,5 @@
#include "fastfetch.h"
#include <string.h>
#include <ctype.h>
#define FF_SHELL_MODULE_NAME "Shell"
#define FF_SHELL_NUM_FORMAT_ARGS 7
@@ -12,13 +9,13 @@ void ffPrintShell(FFinstance* instance)
if(result->shellProcessName.length == 0)
{
ffPrintError(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey, &instance->config.shellFormat, FF_SHELL_NUM_FORMAT_ARGS, "Couldn't detect shell");
ffPrintError(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell, "Couldn't detect shell");
return;
}
if(instance->config.shellFormat.length == 0)
if(instance->config.shell.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey);
ffPrintLogoAndKey(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell.key);
fputs(result->shellExeName, stdout);
if(result->shellVersion.length > 0)
@@ -31,7 +28,7 @@ void ffPrintShell(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey, &instance->config.shellFormat, NULL, FF_SHELL_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell, FF_SHELL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &result->shellProcessName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->shellExe},
{FF_FORMAT_ARG_TYPE_STRING, result->shellExeName},
+4 -11
View File
@@ -46,7 +46,7 @@ void ffPrintSong(FFinstance* instance)
if(media->song.length == 0)
{
ffPrintError(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey, &instance->config.songFormat, FF_SONG_NUM_FORMAT_ARGS, "No song detected");
ffPrintError(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song, "No song detected");
return;
}
@@ -67,7 +67,7 @@ void ffPrintSong(FFinstance* instance)
if(songPretty.length == 0)
ffStrbufAppend(&songPretty, &media->song);
if(instance->config.songFormat.length == 0)
if(instance->config.song.outputFormat.length == 0)
{
//We don't expose artistPretty to the format, as it might be empty (when the think that the artist is already in the song title)
FFstrbuf artistPretty;
@@ -79,7 +79,7 @@ void ffPrintSong(FFinstance* instance)
if(artistInSongTitle(&songPretty, &artistPretty))
ffStrbufClear(&artistPretty);
ffPrintLogoAndKey(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey);
ffPrintLogoAndKey(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song.key);
if(artistPretty.length > 0)
{
@@ -87,18 +87,11 @@ void ffPrintSong(FFinstance* instance)
fputs(" - ", stdout);
}
//Some sites (e.g. reddit) expose their url as album. We don't want to show that
if(media->album.length > 0 && !ffStrbufStartsWithIgnCaseS(&media->album, "http"))
{
ffStrbufWriteTo(&media->album, stdout);
fputs(" - ", stdout);
}
ffStrbufPutTo(&songPretty, stdout);
}
else
{
ffPrintFormatString(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey, &instance->config.songFormat, NULL, FF_SONG_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song, FF_SONG_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &songPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &media->song},
{FF_FORMAT_ARG_TYPE_STRBUF, &media->artist},
+4 -6
View File
@@ -1,8 +1,6 @@
#include "fastfetch.h"
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#define FF_TERMINAL_MODULE_NAME "Terminal"
#define FF_TERMINAL_NUM_FORMAT_ARGS 3
@@ -13,13 +11,13 @@ void ffPrintTerminal(FFinstance* instance)
if(result->terminalProcessName.length == 0)
{
ffPrintError(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey, &instance->config.terminalFormat, FF_TERMINAL_NUM_FORMAT_ARGS, "Couldn't detect terminal");
ffPrintError(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal, "Couldn't detect terminal");
return;
}
if(instance->config.terminalFormat.length == 0)
if(instance->config.terminal.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey);
ffPrintLogoAndKey(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal.key);
if(strncmp(result->terminalExeName, result->terminalProcessName.chars, result->terminalProcessName.length) == 0) // if exeName starts with processName, print it. Otherwise print processName
puts(result->terminalExeName);
@@ -28,7 +26,7 @@ void ffPrintTerminal(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey, &instance->config.terminalFormat, NULL, FF_TERMINAL_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal, FF_TERMINAL_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalProcessName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalExe},
{FF_FORMAT_ARG_TYPE_STRING, result->terminalExeName}
+14 -14
View File
@@ -7,18 +7,18 @@ static void printTerminalFont(FFinstance* instance, const char* raw, FFfont* fon
{
if(font->pretty.length == 0)
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Terminal font is an empty value");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Terminal font is an empty value");
return;
}
if(instance->config.termFontFormat.length == 0)
if(instance->config.terminalFont.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey);
ffPrintLogoAndKey(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont.key);
ffStrbufPutTo(&font->pretty, stdout);
}
else
{
ffPrintFormatString(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, NULL, FF_TERMFONT_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, FF_TERMFONT_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, raw},
{FF_FORMAT_ARG_TYPE_STRBUF, &font->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &font->size},
@@ -55,7 +55,7 @@ static void printTerminalFontFromConfigFile(FFinstance* instance, const char* co
ffParsePropFileConfig(instance, configFile, start, &fontName);
if(fontName.length == 0)
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find terminal font in \"$XDG_CONFIG_HOME/%s\"", configFile);
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find terminal font in \"$XDG_CONFIG_HOME/%s\"", configFile);
else
{
FFfont font;
@@ -72,7 +72,7 @@ static void printTerminalFontFromGSettings(FFinstance* instance, char* profilePa
const char* defaultProfile = ffSettingsGetGSettings(instance, profileList, NULL, "default", FF_VARIANT_TYPE_STRING).strValue;
if(defaultProfile == NULL)
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't get \"default\" profile from gsettings");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't get \"default\" profile from gsettings");
return;
}
@@ -88,13 +88,13 @@ static void printTerminalFontFromGSettings(FFinstance* instance, char* profilePa
{
fontName = ffSettingsGetGSettings(instance, profile, path.chars, "font", FF_VARIANT_TYPE_STRING).strValue;
if(fontName == NULL)
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't get terminal font from GSettings (%s::%s::font)", profile, path.chars);
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't get terminal font from GSettings (%s::%s::font)", profile, path.chars);
}
else // system font
{
fontName = getSystemMonospaceFont(instance);
if(fontName == NULL)
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Could't get system monospace font name from GSettings / DConf");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Could't get system monospace font name from GSettings / DConf");
}
ffStrbufDestroy(&path);
@@ -116,7 +116,7 @@ static void printKonsole(FFinstance* instance)
if(profile.length == 0)
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"DefaultProfile=%[^\\n]\" in \".config/konsolerc\"");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"DefaultProfile=%[^\\n]\" in \".config/konsolerc\"");
ffStrbufDestroy(&profile);
return;
}
@@ -131,7 +131,7 @@ static void printKonsole(FFinstance* instance)
ffParsePropFileHome(instance, profilePath.chars, "Font =", &fontName);
if(fontName.length == 0)
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars);
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars);
else
{
FFfont font;
@@ -152,7 +152,7 @@ static void printXCFETerminal(FFinstance* instance)
if(!ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem =", &useSysFont))
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"$XDG_CONFIG_HOME/xfce4/terminal/terminalrc\"");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't open \"$XDG_CONFIG_HOME/xfce4/terminal/terminalrc\"");
ffStrbufDestroy(&useSysFont);
return;
}
@@ -169,7 +169,7 @@ static void printXCFETerminal(FFinstance* instance)
const char* fontName = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/MonospaceFontName", FF_VARIANT_TYPE_STRING).strValue;
if(fontName == NULL)
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"xsettings::/Gtk/MonospaceFontName\" in XFConf");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"xsettings::/Gtk/MonospaceFontName\" in XFConf");
else
{
FFfont font;
@@ -211,7 +211,7 @@ void ffPrintTerminalFont(FFinstance* instance)
if(result->terminalProcessName.length == 0)
{
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Terminal font needs successfull terminal detection");
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Terminal font needs successfull terminal detection");
return;
}
@@ -228,5 +228,5 @@ void ffPrintTerminalFont(FFinstance* instance)
else if(ffStrbufStartsWithIgnCaseS(&result->terminalExe, "/dev/tty"))
printTTY(instance);
else
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Unknown terminal: %s", result->terminalProcessName.chars);
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Unknown terminal: %s", result->terminalProcessName.chars);
}
+6 -6
View File
@@ -6,7 +6,7 @@
void ffPrintTheme(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, FF_THEME_NUM_FORMAT_ARGS, "Theme detection is not supported on Android");
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme detection is not supported on Android");
return;
#endif
@@ -14,7 +14,7 @@ void ffPrintTheme(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_THEME_NUM_FORMAT_ARGS, "Theme isn't supported in TTY");
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme isn't supported in TTY");
return;
}
@@ -25,7 +25,7 @@ void ffPrintTheme(FFinstance* instance)
if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, FF_THEME_NUM_FORMAT_ARGS, "No themes found");
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "No themes found");
return;
}
@@ -40,9 +40,9 @@ void ffPrintTheme(FFinstance* instance)
FF_STRBUF_CREATE(gtkPretty);
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
if(instance->config.themeFormat.length == 0)
if(instance->config.theme.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey);
ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme.key);
if(plasma->widgetStyle.length > 0)
{
@@ -80,7 +80,7 @@ void ffPrintTheme(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, NULL, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma->widgetStyle},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma->colorScheme},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty},
+3 -3
View File
@@ -4,14 +4,14 @@
void ffPrintTime(FFinstance* instance)
{
if(instance->config.timeFormat.length > 0)
if(instance->config.time.outputFormat.length > 0)
{
ffPrintDateTimeFormat(instance, FF_TIME_MODULE_NAME, &instance->config.timeKey, &instance->config.timeFormat);
ffPrintDateTimeFormat(instance, FF_TIME_MODULE_NAME, &instance->config.time);
return;
}
const FFDateTimeResult* datetime = ffDetectDateTime(instance);
ffPrintLogoAndKey(instance, FF_TIME_MODULE_NAME, 0, &instance->config.timeKey);
ffPrintLogoAndKey(instance, FF_TIME_MODULE_NAME, 0, &instance->config.time.key);
//hh:mm:ss
printf("%s:%s:%s\n", datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars);
+3 -3
View File
@@ -10,9 +10,9 @@ void ffPrintUptime(FFinstance* instance)
uint32_t minutes = (uint32_t) (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
uint32_t seconds = (uint32_t) instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60);
if(instance->config.uptimeFormat.length == 0)
if(instance->config.uptime.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptimeKey);
ffPrintLogoAndKey(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptime.key);
if(days == 0 && hours == 0 && minutes == 0)
{
@@ -57,7 +57,7 @@ void ffPrintUptime(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptimeKey, &instance->config.uptimeFormat, NULL, FF_UPTIME_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptime, FF_UPTIME_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &days},
{FF_FORMAT_ARG_TYPE_UINT, &hours},
{FF_FORMAT_ARG_TYPE_UINT, &minutes},
+4 -4
View File
@@ -9,13 +9,13 @@ void ffPrintVulkan(FFinstance* instance)
if(vulkan->apiVersion.length == 0 && vulkan->driver.length == 0)
{
ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey, &instance->config.vulkanFormat, FF_VULKAN_NUM_FORMAT_ARGS, "Failed to detect vulkan");
ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, "Failed to detect vulkan");
return;
}
if(instance->config.vulkanFormat.length == 0)
if(instance->config.vulkan.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey);
ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan.key);
if(vulkan->driver.length > 0)
{
@@ -32,7 +32,7 @@ void ffPrintVulkan(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey, &instance->config.vulkanFormat, NULL, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver},
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion},
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion}
+5 -5
View File
@@ -6,7 +6,7 @@
void ffPrintWM(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, FF_WM_NUM_FORMAT_ARGS, "WM detection is not supported on Android");
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "WM detection is not supported on Android");
return;
#endif
@@ -14,13 +14,13 @@ void ffPrintWM(FFinstance* instance)
if(result->wmPrettyName.length == 0)
{
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, FF_WM_NUM_FORMAT_ARGS, "No WM found");
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "No WM found");
return;
}
if(instance->config.wmFormat.length == 0)
if(instance->config.wm.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey);
ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm.key);
ffStrbufWriteTo(&result->wmPrettyName, stdout);
@@ -35,7 +35,7 @@ void ffPrintWM(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, NULL, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}
+16 -14
View File
@@ -1,4 +1,6 @@
#include "fastfetch.h"
#include <stdlib.h>
#include <string.h>
#define FF_WMTHEME_MODULE_NAME "WM Theme"
@@ -6,14 +8,14 @@
static void printWMTheme(FFinstance* instance, const char* theme)
{
if(instance->config.wmThemeFormat.length == 0)
if(instance->config.wmTheme.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey);
ffPrintLogoAndKey(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme.key);
puts(theme);
}
else
{
ffPrintFormatString(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, NULL, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, theme}
});
}
@@ -26,7 +28,7 @@ static void printWMThemeFromConfigFile(FFinstance* instance, const char* configF
if(!ffParsePropFileConfig(instance, configFile, themeRegex, &theme))
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Config file %s doesn't exist", configFile);
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Config file %s doesn't exist", configFile);
ffStrbufDestroy(&theme);
return;
}
@@ -37,7 +39,7 @@ static void printWMThemeFromConfigFile(FFinstance* instance, const char* configF
if(defaultValue == NULL)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find WM theme in %s", configFile);
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find WM theme in %s", configFile);
return;
}
@@ -66,7 +68,7 @@ static void printWMThemeFromSettings(FFinstance* instance, const char* dconfKey,
if(!ffStrSet(theme))
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find WM theme in DConf or GSettings");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find WM theme in DConf or GSettings");
return;
}
@@ -99,7 +101,7 @@ static void printGTKThemeAsWMTheme(FFinstance* instance)
return;
}
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't detect GTK4/3/2 theme");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't detect GTK4/3/2 theme");
}
static void printMutter(FFinstance* instance)
@@ -121,7 +123,7 @@ static void printMuffin(FFinstance* instance)
if(name == NULL && theme == NULL)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find muffin theme in GSettings / DConf");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find muffin theme in GSettings / DConf");
return;
}
@@ -150,7 +152,7 @@ static void printXFWM4(FFinstance* instance)
if(theme == NULL)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find xfwm4::/general/theme in XFConf");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find xfwm4::/general/theme in XFConf");
return;
}
@@ -177,7 +179,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
FILE* file = fopen(absolutePath.chars, "r");
if(file == NULL)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars);
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't open \"%s\"", absolutePath.chars);
ffStrbufDestroy(&absolutePath);
return;
@@ -213,7 +215,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
fclose(file);
if(theme.length == 0)
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find theme name in \"%s\"", absolutePath.chars);
else
printWMTheme(instance, theme.chars);
@@ -224,7 +226,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
void ffPrintWMTheme(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "WM theme detection is not supported on Android");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "WM theme detection is not supported on Android");
return;
#endif
@@ -232,7 +234,7 @@ void ffPrintWMTheme(FFinstance* instance)
if(result->wmPrettyName.length == 0)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "WM Theme needs sucessfull WM detection");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "WM Theme needs sucessfull WM detection");
return;
}
@@ -254,5 +256,5 @@ void ffPrintWMTheme(FFinstance* instance)
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Openbox") == 0)
printOpenbox(instance, &result->dePrettyName);
else
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Unknown WM: %s", result->wmPrettyName.chars);
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Unknown WM: %s", result->wmPrettyName.chars);
}
+1 -2
View File
@@ -1,7 +1,6 @@
#include "FFlist.h"
#include <malloc.h>
#include <memory.h>
#include <stdlib.h>
void ffListInit(FFlist* list, uint32_t elementSize)
{
+16 -2
View File
@@ -1,9 +1,8 @@
#include "FFstrbuf.h"
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
static char* CHAR_NULL_PTR = "";
@@ -515,6 +514,12 @@ bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end)
return false;
}
void ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c)
{
if(!ffStrbufEndsWithC(strbuf, c))
ffStrbufAppendC(strbuf, c);
}
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file)
{
fwrite(strbuf->chars, sizeof(*strbuf->chars), strbuf->length, file);
@@ -526,6 +531,15 @@ void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file)
fputc('\n', file);
}
double ffStrbufToDouble(const FFstrbuf* strbuf)
{
double value;
if(sscanf(strbuf->chars, "%lf", &value) != 1)
return 0.0 / 0.0; //NaN
return value;
}
void ffStrbufDestroy(FFstrbuf* strbuf)
{
free(strbuf->chars);
+4
View File
@@ -90,9 +90,13 @@ uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c);
bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end);
void ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c);
void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file);
void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file);
double ffStrbufToDouble(const FFstrbuf* strbuf);
void ffStrbufDestroy(FFstrbuf* strbuf);
#endif
+3 -4
View File
@@ -1,9 +1,8 @@
#include <stdint.h>
#include <malloc.h>
#include <string.h>
#include "FFvaluestore.h"
#include <string.h>
#include <stdlib.h>
void ffValuestoreInit(FFvaluestore* vs)
{
vs->capacity = 32;
+1
View File
@@ -4,6 +4,7 @@
#define FASTFETCH_INCLUDED_FFVALUESTORE
#include <stdbool.h>
#include <stdint.h>
typedef struct FFvaluestorePair
{
-82
View File
@@ -1,82 +0,0 @@
#include "fastfetch.h"
#include <time.h>
#define FASTFETCH_TEST_PERFORMANCE(func) \
{ \
struct timespec start, end; \
clock_gettime(CLOCK_REALTIME, &start); \
func; \
clock_gettime(CLOCK_REALTIME, &end); \
long nanos = end.tv_nsec - start.tv_nsec; \
printf("\033[F"); \
for(uint8_t i = 0; i < 125; i++) printf("\033[C"); \
printf("%08ldns\n", nanos); \
} \
int main(int argc, char** argv)
{
FF_UNUSED(argc, argv);
FFinstance instance;
FASTFETCH_TEST_PERFORMANCE(
puts("Initialization");
ffInitInstance(&instance);
)
instance.config.showErrors = true;
instance.config.recache = argc == 1;
instance.config.cacheSave = false;
ffStrbufSetS(&instance.config.songFormat, "{}"); //Otherwise the line is too long
FASTFETCH_TEST_PERFORMANCE(
puts("Thread starting");
ffStartDetectionThreads(&instance);
)
FASTFETCH_TEST_PERFORMANCE(
puts("Starting");
ffStart(&instance);
)
FASTFETCH_TEST_PERFORMANCE(ffPrintTitle(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintSeparator(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintOS(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintHost(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintKernel(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintUptime(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintProcesses(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintPackages(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintShell(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintResolution(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintDesktopEnvironment(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintWM(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintWMTheme(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintTheme(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintIcons(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintFont(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintTerminal(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintTerminalFont(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintCPU(&instance))
//FASTFETCH_TEST_PERFORMANCE(ffPrintCPUUsage(&instance)) // Doesn't make sense, contains a sleep call
FASTFETCH_TEST_PERFORMANCE(ffPrintGPU(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintMemory(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintDisk(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintBattery(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintPlayer(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintSong(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintLocalIp(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintPublicIp(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintDateTime(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintLocale(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintBreak(&instance))
FASTFETCH_TEST_PERFORMANCE(ffPrintColors(&instance))
FASTFETCH_TEST_PERFORMANCE(
puts("Finishing");
ffFinish(&instance);
)
return 0;
}
-6
View File
@@ -1,6 +0,0 @@
#!/bin/env sh
mkdir -p build/
cd build
cmake ..
cmake --build . --target fastfetch-test-performance -j$(nproc)
./fastfetch-test-performance "$@"