2023-03-20 15:46:00 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-03-20 15:46:00 +08:00
|
|
|
#include "modules/custom/custom.h"
|
|
|
|
|
#include "util/textModifier.h"
|
|
|
|
|
|
|
|
|
|
void ffPrintCustom(FFinstance* instance, FFCustomOptions* options)
|
|
|
|
|
{
|
|
|
|
|
if (options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, "output format must be set for custom module");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 12:32:47 +08:00
|
|
|
ffPrintLogoAndKey(instance, options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
|
2023-03-20 15:46:00 +08:00
|
|
|
ffPrintUserString(options->moduleArgs.outputFormat.chars);
|
|
|
|
|
puts(FASTFETCH_TEXT_MODIFIER_RESET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitCustomOptions(FFCustomOptions* options)
|
|
|
|
|
{
|
|
|
|
|
options->moduleName = FF_CUSTOM_MODULE_NAME;
|
|
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_CUSTOM_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyCustomOptions(FFCustomOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-10 15:01:54 +08:00
|
|
|
void ffParseCustomJsonObject(FFinstance* instance, yyjson_val* module)
|
2023-03-20 15:46:00 +08:00
|
|
|
{
|
|
|
|
|
FFCustomOptions __attribute__((__cleanup__(ffDestroyCustomOptions))) options;
|
|
|
|
|
ffInitCustomOptions(&options);
|
|
|
|
|
|
|
|
|
|
if (module)
|
|
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-03-20 15:46:00 +08:00
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
|
|
|
|
if(strcasecmp(key, "type") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-03-20 15:46:00 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ffPrintError(instance, FF_CUSTOM_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffPrintCustom(instance, &options);
|
|
|
|
|
}
|