mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +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,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFPlayerOptions
|
||||
{
|
||||
FFModuleBaseInfo moduleInfo;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFPlayerOptions;
|
||||
|
||||
static_assert(sizeof(FFPlayerOptions) <= FF_OPTION_MAX_SIZE, "FFPlayerOptions size exceeds maximum allowed size");
|
||||
|
||||
+10
-11
@@ -107,6 +107,16 @@ void ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "Player module is an alias of Media module");
|
||||
}
|
||||
|
||||
void ffInitPlayerOptions(FFPlayerOptions* options)
|
||||
{
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
}
|
||||
|
||||
void ffDestroyPlayerOptions(FFPlayerOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
FFModuleBaseInfo ffPlayerModuleInfo = {
|
||||
.name = FF_PLAYER_MODULE_NAME,
|
||||
.description = "Print music player name",
|
||||
@@ -123,14 +133,3 @@ FFModuleBaseInfo ffPlayerModuleInfo = {
|
||||
{"URL name", "url"},
|
||||
}))
|
||||
};
|
||||
|
||||
void ffInitPlayerOptions(FFPlayerOptions* options)
|
||||
{
|
||||
options->moduleInfo = ffPlayerModuleInfo;
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
}
|
||||
|
||||
void ffDestroyPlayerOptions(FFPlayerOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "option.h"
|
||||
|
||||
#define FF_PLAYER_MODULE_NAME "Player"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user