mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 20:24:19 +01:00
Modules: refactor module option handling for static allocation
Moves module option structs out of global config and removes dynamic allocation, using static buffers and size assertions for safer, simpler management. Refactors module initialization and destruction to work with isolated option structs, eliminating the need for the previous modules container and related code. Unifies module option header usage and updates detection logic to leverage statically-sized option buffers, improving encapsulation and maintainability. Simplifies module function signatures and reduces coupling between modules and config. Enhances future extensibility and reliability by enforcing max size constraints and removing unnecessary indirections.
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFSeparatorOptions
|
||||
{
|
||||
FFModuleBaseInfo moduleInfo;
|
||||
|
||||
FFstrbuf string;
|
||||
FFstrbuf outputColor;
|
||||
uint32_t length;
|
||||
} FFSeparatorOptions;
|
||||
|
||||
static_assert(sizeof(FFSeparatorOptions) <= FF_OPTION_MAX_SIZE, "FFSeparatorOptions size exceeds maximum allowed size");
|
||||
|
||||
@@ -56,7 +56,7 @@ void ffPrintSeparator(FFSeparatorOptions* options)
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
mbstate_t state = {};
|
||||
bool fqdn = instance.config.modules.title.fqdn;
|
||||
bool fqdn = true; // TODO: Make this configurable
|
||||
const FFPlatform* platform = &instance.state.platform;
|
||||
|
||||
FF_AUTO_FREE wchar_t* wstr = malloc((max(
|
||||
@@ -154,19 +154,8 @@ void ffGenerateSeparatorJsonConfig(FFSeparatorOptions* options, yyjson_mut_doc*
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "string", &options->string);
|
||||
}
|
||||
|
||||
FFModuleBaseInfo ffSeparatorModuleInfo = {
|
||||
.name = FF_SEPARATOR_MODULE_NAME,
|
||||
.description = "Print a separator line",
|
||||
.initOptions = (void*) ffInitSeparatorOptions,
|
||||
.destroyOptions = (void*) ffDestroySeparatorOptions,
|
||||
.parseJsonObject = (void*) ffParseSeparatorJsonObject,
|
||||
.printModule = (void*) ffPrintSeparator,
|
||||
.generateJsonConfig = (void*) ffGenerateSeparatorJsonConfig,
|
||||
};
|
||||
|
||||
void ffInitSeparatorOptions(FFSeparatorOptions* options)
|
||||
{
|
||||
options->moduleInfo = ffSeparatorModuleInfo;
|
||||
ffStrbufInitStatic(&options->string, "-");
|
||||
ffStrbufInit(&options->outputColor);
|
||||
options->length = 0;
|
||||
@@ -176,3 +165,13 @@ void ffDestroySeparatorOptions(FFSeparatorOptions* options)
|
||||
{
|
||||
ffStrbufDestroy(&options->string);
|
||||
}
|
||||
|
||||
FFModuleBaseInfo ffSeparatorModuleInfo = {
|
||||
.name = FF_SEPARATOR_MODULE_NAME,
|
||||
.description = "Print a separator line",
|
||||
.initOptions = (void*) ffInitSeparatorOptions,
|
||||
.destroyOptions = (void*) ffDestroySeparatorOptions,
|
||||
.parseJsonObject = (void*) ffParseSeparatorJsonObject,
|
||||
.printModule = (void*) ffPrintSeparator,
|
||||
.generateJsonConfig = (void*) ffGenerateSeparatorJsonConfig,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "option.h"
|
||||
|
||||
#define FF_SEPARATOR_MODULE_NAME "Separator"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user