mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-31 10:02:49 +01:00
JsonConfig: support Logo config (WIP)
This commit is contained in:
@@ -331,6 +331,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
static void destroyState(FFinstance* instance)
|
||||
{
|
||||
ffPlatformDestroy(&instance->state.platform);
|
||||
yyjson_doc_free(instance->state.configDoc);
|
||||
}
|
||||
|
||||
void ffDestroyInstance(FFinstance* instance)
|
||||
|
||||
+2
-7
@@ -105,19 +105,14 @@ bool ffOptionParseBoolean(const char* str)
|
||||
);
|
||||
}
|
||||
|
||||
void ffOptionParseColor(const char* key, const char* value, FFstrbuf* buffer)
|
||||
void ffOptionParseColor(const char* value, FFstrbuf* buffer)
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error: usage: %s <str>\n", key);
|
||||
exit(477);
|
||||
}
|
||||
ffStrbufEnsureFree(buffer, 63);
|
||||
|
||||
while(*value != '\0')
|
||||
{
|
||||
#define FF_APPEND_COLOR_CODE_COND(prefix, code) \
|
||||
if(strncasecmp(value, #prefix, strlen(#prefix))) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); }
|
||||
if(strncasecmp(value, #prefix, strlen(#prefix)) == 0) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); }
|
||||
|
||||
FF_APPEND_COLOR_CODE_COND(reset_, "0;")
|
||||
else FF_APPEND_COLOR_CODE_COND(bright_, "1;")
|
||||
|
||||
+1
-1
@@ -21,6 +21,6 @@ void ffOptionParseString(const char* argumentKey, const char* value, FFstrbuf* b
|
||||
FF_C_NODISCARD uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value);
|
||||
FF_C_NODISCARD int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]);
|
||||
FF_C_NODISCARD bool ffOptionParseBoolean(const char* str);
|
||||
void ffOptionParseColor(const char* key, const char* value, FFstrbuf* buffer);
|
||||
void ffOptionParseColor(const char* value, FFstrbuf* buffer);
|
||||
void ffOptionInitModuleArg(FFModuleArgs* args);
|
||||
void ffOptionDestroyModuleArg(FFModuleArgs* args);
|
||||
|
||||
+63
-46
@@ -496,8 +496,16 @@ static void listConfigPaths(FFinstance* instance)
|
||||
{
|
||||
FF_LIST_FOR_EACH(FFstrbuf, folder, instance->state.platform.configDirs)
|
||||
{
|
||||
ffStrbufAppendS(folder, "fastfetch/config.conf");
|
||||
printf("%s%s\n", folder->chars, ffPathExists(folder->chars, FF_PATHTYPE_FILE) ? " (*)" : "");
|
||||
bool exists = false;
|
||||
ffStrbufAppendS(folder, "fastfetch/config.jsonc");
|
||||
exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE);
|
||||
if (!exists)
|
||||
{
|
||||
ffStrbufSubstrBefore(folder, folder->length - (uint32_t) strlen("jsonc"));
|
||||
ffStrbufAppendS(folder, "conf");
|
||||
exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE);
|
||||
}
|
||||
printf("%s%s\n", folder->chars, exists ? " (*)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,6 +520,23 @@ static void listDataPaths(FFinstance* instance)
|
||||
|
||||
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value);
|
||||
|
||||
static bool parseJsoncFile(FFinstance* instance, const char* path)
|
||||
{
|
||||
yyjson_doc* doc = yyjson_read_file(path, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, NULL);
|
||||
if (doc)
|
||||
{
|
||||
instance->state.configDoc = doc;
|
||||
const char* error = ffParseLogoJsonConfig(instance);
|
||||
if (error)
|
||||
{
|
||||
fputs(error, stderr);
|
||||
exit(477);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool parseConfigFile(FFinstance* instance, FFdata* data, const char* path)
|
||||
{
|
||||
FILE* file = fopen(path, "r");
|
||||
@@ -662,35 +687,6 @@ static inline bool startsWith(const char* str, const char* compareTo)
|
||||
return strncasecmp(str, compareTo, strlen(compareTo)) == 0;
|
||||
}
|
||||
|
||||
static void optionParseColor(const char* key, const char* value, FFstrbuf* buffer)
|
||||
{
|
||||
optionCheckString(key, value, buffer);
|
||||
|
||||
while(*value != '\0')
|
||||
{
|
||||
#define FF_APPEND_COLOR_CODE_COND(prefix, code) \
|
||||
if(startsWith(value, #prefix)) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); }
|
||||
|
||||
FF_APPEND_COLOR_CODE_COND(reset_, "0;")
|
||||
else FF_APPEND_COLOR_CODE_COND(bright_, "1;")
|
||||
else FF_APPEND_COLOR_CODE_COND(black, "30")
|
||||
else FF_APPEND_COLOR_CODE_COND(red, "31")
|
||||
else FF_APPEND_COLOR_CODE_COND(green, "32")
|
||||
else FF_APPEND_COLOR_CODE_COND(yellow, "33")
|
||||
else FF_APPEND_COLOR_CODE_COND(blue, "34")
|
||||
else FF_APPEND_COLOR_CODE_COND(magenta, "35")
|
||||
else FF_APPEND_COLOR_CODE_COND(cyan, "36")
|
||||
else FF_APPEND_COLOR_CODE_COND(white, "37")
|
||||
else
|
||||
{
|
||||
ffStrbufAppendC(buffer, *value);
|
||||
++value;
|
||||
}
|
||||
|
||||
#undef FF_APPEND_COLOR_CODE_COND
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t optionParseUInt32(const char* key, const char* value)
|
||||
{
|
||||
if(value == NULL)
|
||||
@@ -914,12 +910,19 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(strcasecmp(key, "--separator") == 0)
|
||||
optionParseString(key, value, &instance->config.keyValueSeparator);
|
||||
else if(strcasecmp(key, "--color-keys") == 0)
|
||||
optionParseColor(key, value, &instance->config.colorKeys);
|
||||
{
|
||||
optionCheckString(key, value, &instance->config.colorKeys);
|
||||
ffOptionParseColor(value, &instance->config.colorKeys);
|
||||
}
|
||||
else if(strcasecmp(key, "--color-title") == 0)
|
||||
optionParseColor(key, value, &instance->config.colorTitle);
|
||||
{
|
||||
optionCheckString(key, value, &instance->config.colorTitle);
|
||||
ffOptionParseColor(value, &instance->config.colorTitle);
|
||||
}
|
||||
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
|
||||
{
|
||||
optionParseColor(key, value, &instance->config.colorKeys);
|
||||
optionCheckString(key, value, &instance->config.colorKeys);
|
||||
ffOptionParseColor(value, &instance->config.colorKeys);
|
||||
ffStrbufSet(&instance->config.colorTitle, &instance->config.colorKeys);
|
||||
}
|
||||
else if(strcasecmp(key, "--binary-prefix") == 0)
|
||||
@@ -1066,6 +1069,17 @@ error:
|
||||
|
||||
static void parseConfigFiles(FFinstance* instance, FFdata* data)
|
||||
{
|
||||
for(uint32_t i = instance->state.platform.configDirs.length; i > 0; --i)
|
||||
{
|
||||
FFstrbuf* dir = ffListGet(&instance->state.platform.configDirs, i - 1);
|
||||
uint32_t dirLength = dir->length;
|
||||
|
||||
ffStrbufAppendS(dir, "fastfetch/config.jsonc");
|
||||
bool success = parseJsoncFile(instance, dir->chars);
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
if (success) return;
|
||||
}
|
||||
|
||||
for(uint32_t i = instance->state.platform.configDirs.length; i > 0; --i)
|
||||
{
|
||||
if(!data->loadUserConfig)
|
||||
@@ -1225,20 +1239,23 @@ int main(int argc, const char** argv)
|
||||
parseConfigFiles(&instance, &data);
|
||||
parseArguments(&instance, &data, argc, argv);
|
||||
|
||||
//If we don't have a custom structure, use the default one
|
||||
if(data.structure.length == 0)
|
||||
ffStrbufAppendS(&data.structure, FASTFETCH_DATATEXT_STRUCTURE);
|
||||
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_CPUUSAGE_MODULE_NAME))
|
||||
ffPrepareCPUUsage();
|
||||
|
||||
if(instance.config.multithreading)
|
||||
if(!instance.state.configDoc)
|
||||
{
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_PUBLICIP_MODULE_NAME))
|
||||
ffPreparePublicIp(&instance.config.publicIP);
|
||||
//If we don't have a custom structure, use the default one
|
||||
if(data.structure.length == 0)
|
||||
ffStrbufAppendS(&data.structure, FASTFETCH_DATATEXT_STRUCTURE);
|
||||
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_WEATHER_MODULE_NAME))
|
||||
ffPrepareWeather(&instance.config.weather);
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_CPUUSAGE_MODULE_NAME))
|
||||
ffPrepareCPUUsage();
|
||||
|
||||
if(instance.config.multithreading)
|
||||
{
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_PUBLICIP_MODULE_NAME))
|
||||
ffPreparePublicIp(&instance.config.publicIP);
|
||||
|
||||
if(ffStrbufContainIgnCaseS(&data.structure, FF_WEATHER_MODULE_NAME))
|
||||
ffPrepareWeather(&instance.config.weather);
|
||||
}
|
||||
}
|
||||
|
||||
ffStart(&instance);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <yyjson.h>
|
||||
|
||||
#include "util/FFstrbuf.h"
|
||||
#include "util/FFlist.h"
|
||||
@@ -135,6 +136,7 @@ typedef struct FFstate
|
||||
uint32_t titleLength;
|
||||
|
||||
FFPlatform platform;
|
||||
yyjson_doc* configDoc;
|
||||
} FFstate;
|
||||
|
||||
typedef struct FFinstance
|
||||
|
||||
@@ -30,5 +30,6 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type, bool printE
|
||||
void ffInitLogoOptions(FFLogoOptions* options);
|
||||
bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value);
|
||||
void ffDestroyLogoOptions(FFLogoOptions* options);
|
||||
const char* ffParseLogoJsonConfig(FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
+152
-2
@@ -1,5 +1,7 @@
|
||||
#include "logo/logo.h"
|
||||
|
||||
#include "common/jsonconfig.h"
|
||||
|
||||
void ffInitLogoOptions(FFLogoOptions* options)
|
||||
{
|
||||
ffStrbufInit(&options->source);
|
||||
@@ -72,8 +74,12 @@ logoType:
|
||||
fprintf(stderr, "Error: invalid --color-[1-9] index: %c\n", key[13]);
|
||||
exit(472);
|
||||
}
|
||||
|
||||
ffOptionParseColor(key, value, &options->colors[index]);
|
||||
if(value == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error: usage: %s <str>\n", key);
|
||||
exit(477);
|
||||
}
|
||||
ffOptionParseColor(value, &options->colors[index]);
|
||||
}
|
||||
else if(strcasecmp(subKey, "width") == 0)
|
||||
options->width = ffOptionParseUInt32(key, value);
|
||||
@@ -181,3 +187,147 @@ void ffDestroyLogoOptions(FFLogoOptions* options)
|
||||
for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
|
||||
ffStrbufDestroy(&options->colors[i]);
|
||||
}
|
||||
|
||||
const char* ffParseLogoJsonConfig(FFinstance* instance)
|
||||
{
|
||||
FFLogoOptions* options = &instance->config.logo;
|
||||
|
||||
yyjson_val* const root = yyjson_doc_get_root(instance->state.configDoc);
|
||||
assert(root);
|
||||
|
||||
if (!yyjson_is_obj(root))
|
||||
return "Invalid JSON config format. Root value must be an object";
|
||||
|
||||
yyjson_val* object = yyjson_obj_get(root, "logo");
|
||||
if (!object) return NULL;
|
||||
if (!yyjson_is_obj(object)) return "Property 'logo' must be an object";
|
||||
|
||||
yyjson_val *key_, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(object, idx, max, key_, val)
|
||||
{
|
||||
const char* key = yyjson_get_str(key_);
|
||||
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
{
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "auto", FF_LOGO_TYPE_AUTO },
|
||||
{ "builtin", FF_LOGO_TYPE_BUILTIN },
|
||||
{ "file", FF_LOGO_TYPE_FILE },
|
||||
{ "file-raw", FF_LOGO_TYPE_FILE_RAW },
|
||||
{ "data", FF_LOGO_TYPE_DATA },
|
||||
{ "data-raw", FF_LOGO_TYPE_DATA_RAW },
|
||||
{ "sixel", FF_LOGO_TYPE_IMAGE_SIXEL },
|
||||
{ "kitty", FF_LOGO_TYPE_IMAGE_KITTY },
|
||||
{ "iterm", FF_LOGO_TYPE_IMAGE_ITERM },
|
||||
{ "chafa", FF_LOGO_TYPE_IMAGE_CHAFA },
|
||||
{ "raw", FF_LOGO_TYPE_IMAGE_RAW },
|
||||
{ "none", FF_LOGO_TYPE_NONE },
|
||||
{},
|
||||
});
|
||||
|
||||
if (error) return error;
|
||||
options->type = (FFLogoType) value;
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "source") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options->source, yyjson_get_str(val));
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "color") == 0)
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
return "Property 'color' must be an object";
|
||||
|
||||
yyjson_val *key_c, *valc;
|
||||
size_t idxc, maxc;
|
||||
yyjson_obj_foreach(val, idxc, maxc, key_c, valc)
|
||||
{
|
||||
const char* keyc = yyjson_get_str(key_c);
|
||||
uint32_t index = (uint32_t) strtoul(keyc, NULL, 10);
|
||||
if (index < 1 || index > 9)
|
||||
return "Keys of property 'color' must be a number between 1 to 9";
|
||||
|
||||
ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "width") == 0)
|
||||
{
|
||||
uint32_t value = (uint32_t) yyjson_get_uint(val);
|
||||
if (value == 0)
|
||||
return "Logo width must be a possitive integer";
|
||||
options->width = value;
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "height") == 0)
|
||||
{
|
||||
uint32_t value = (uint32_t) yyjson_get_uint(val);
|
||||
if (value == 0)
|
||||
return "Logo height must be a possitive integer";
|
||||
options->height = value;
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "padding") == 0)
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
return "Logo padding must be an object";
|
||||
|
||||
#define FF_PARSE_PADDING_POSITON(pos, paddingPos) \
|
||||
yyjson_val* pos = yyjson_obj_get(val, #pos); \
|
||||
if (pos) \
|
||||
{ \
|
||||
if (!yyjson_is_uint(pos)) \
|
||||
return "Logo padding values must be possitive integers"; \
|
||||
options->paddingPos = (uint32_t) yyjson_get_uint(pos); \
|
||||
}
|
||||
FF_PARSE_PADDING_POSITON(left, paddingLeft);
|
||||
FF_PARSE_PADDING_POSITON(top, paddingTop);
|
||||
FF_PARSE_PADDING_POSITON(right, paddingRight);
|
||||
#undef FF_PARSE_PADDING_POSITON
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "printRemaining"))
|
||||
{
|
||||
options->printRemaining = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "preserveAspectRadio"))
|
||||
{
|
||||
options->preserveAspectRadio = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
else if (strcasecmp(key, "chafa"))
|
||||
{
|
||||
if (!yyjson_is_obj(val))
|
||||
return "Chafa config must be an object";
|
||||
|
||||
yyjson_val* fgOnly = yyjson_obj_get(val, "fgOnly");
|
||||
if (fgOnly)
|
||||
options->chafaFgOnly = yyjson_get_bool(fgOnly);
|
||||
|
||||
yyjson_val* symbols = yyjson_obj_get(val, "symbols");
|
||||
if (symbols)
|
||||
ffStrbufAppendS(&options->chafaSymbols, yyjson_get_str(symbols));
|
||||
|
||||
yyjson_val* canvasMode = yyjson_obj_get(val, "canvasMode");
|
||||
if (canvasMode)
|
||||
options->chafaCanvasMode = (uint32_t) yyjson_get_uint(canvasMode);
|
||||
|
||||
yyjson_val* colorSpace = yyjson_obj_get(val, "colorSpace");
|
||||
if (colorSpace)
|
||||
options->chafaColorSpace = (uint32_t) yyjson_get_uint(colorSpace);
|
||||
|
||||
yyjson_val* ditherMode = yyjson_obj_get(val, "ditherMode");
|
||||
if (ditherMode)
|
||||
options->chafaDitherMode = (uint32_t) yyjson_get_uint(ditherMode);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return "Unknown logo key";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BATTERY_MODULE_NAME "Battery"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BIOS_MODULE_NAME "Bios"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BLUETOOTH_MODULE_NAME "Bluetooth"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BOARD_MODULE_NAME "Board"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BREAK_MODULE_NAME "Break"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_BRIGHTNESS_MODULE_NAME "Brightness"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_CHASSIS_MODULE_NAME "Chassis"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_COLORS_MODULE_NAME "Colors"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_COMMAND_MODULE_NAME "Command"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_CPU_MODULE_NAME "CPU"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_CPUUSAGE_MODULE_NAME "CPUUsage"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_CURSOR_MODULE_NAME "Cursor"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_CUSTOM_MODULE_NAME "Custom"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_DATETIME_MODULE_NAME "DateTime"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_DE_MODULE_NAME "DE"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_DISK_MODULE_NAME "Disk"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_DISPLAY_MODULE_NAME "Display"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_FONT_MODULE_NAME "Font"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_GAMEPAD_MODULE_NAME "Gamepad"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_GPU_MODULE_NAME "GPU"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_HOST_MODULE_NAME "Host"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_ICONS_MODULE_NAME "Icons"
|
||||
|
||||
|
||||
@@ -162,30 +162,9 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, yyjson
|
||||
}
|
||||
}
|
||||
|
||||
static inline void wrapYyjsonFree(yyjson_doc** doc)
|
||||
{
|
||||
assert(doc);
|
||||
if (*doc)
|
||||
yyjson_doc_free(*doc);
|
||||
}
|
||||
|
||||
static const char* printJsonConfig(FFinstance* instance)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
FF_LIST_FOR_EACH(FFstrbuf, filename, instance->state.platform.configDirs)
|
||||
{
|
||||
uint32_t oldLength = filename->length;
|
||||
ffStrbufAppendS(filename, "fastfetch/config.jsonc");
|
||||
bool success = ffAppendFileBuffer(filename->chars, &content);
|
||||
ffStrbufSubstrBefore(filename, oldLength);
|
||||
if (success) break;
|
||||
}
|
||||
|
||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonFree))) doc = yyjson_read_opts(content.chars, content.length, YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INF_AND_NAN, NULL, NULL);
|
||||
if (!doc)
|
||||
return "Failed to parse JSON config file";
|
||||
|
||||
yyjson_val* const root = yyjson_doc_get_root(doc);
|
||||
yyjson_val* const root = yyjson_doc_get_root(instance->state.configDoc);
|
||||
assert(root);
|
||||
|
||||
if (!yyjson_is_obj(root))
|
||||
@@ -193,7 +172,7 @@ static const char* printJsonConfig(FFinstance* instance)
|
||||
|
||||
yyjson_val* modules = yyjson_obj_get(root, "modules");
|
||||
if (!modules) return "Property 'modules' is not found";
|
||||
if (!yyjson_is_arr(modules)) return "modules must be an array of strings or objects";
|
||||
if (!yyjson_is_arr(modules)) return "Property 'modules' must be an array of strings or objects";
|
||||
|
||||
yyjson_val* item;
|
||||
size_t idx, max;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_KERNEL_MODULE_NAME "Kernel"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_LOCALE_MODULE_NAME "Locale"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_LOCALIP_MODULE_NAME "LocalIp"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_MEDIA_MODULE_NAME "Media"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_MEMORY_MODULE_NAME "Memory"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_OPENCL_MODULE_NAME "OpenCL"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_OPENGL_MODULE_NAME "OpenGL"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_OS_MODULE_NAME "OS"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_PACKAGES_MODULE_NAME "Packages"
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_PLAYER_MODULE_NAME "Player"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_POWERADAPTER_MODULE_NAME "PowerAdapter"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_PROCESSES_MODULE_NAME "Processes"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_PUBLICIP_MODULE_NAME "PublicIp"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_SEPARATOR_MODULE_NAME "Separator"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_SHELL_MODULE_NAME "Shell"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_SOUND_MODULE_NAME "Sound"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_SWAP_MODULE_NAME "Swap"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_TERMINAL_MODULE_NAME "Terminal"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_TERMINALFONT_MODULE_NAME "TerminalFont"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_THEME_MODULE_NAME "Theme"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_TITLE_MODULE_NAME "Title"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_UPTIME_MODULE_NAME "Uptime"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_USERS_MODULE_NAME "Users"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_VULKAN_MODULE_NAME "Vulkan"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_WALLPAPER_MODULE_NAME "Wallpaper"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_WEATHER_MODULE_NAME "Weather"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_WIFI_MODULE_NAME "Wifi"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_WM_MODULE_NAME "WM"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include <yyjson.h>
|
||||
|
||||
#define FF_WMTHEME_MODULE_NAME "WMTheme"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user