mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 14:10:11 +01:00
Custom: support JSON module
Note: old command options `--set` and `--set-keyless` were removed. To reuse custom module, JSON config must be used.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#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;
|
||||
}
|
||||
|
||||
ffPrintLogoAndKey(instance, options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseCustomJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFCustomOptions __attribute__((__cleanup__(ffDestroyCustomOptions))) options;
|
||||
ffInitCustomOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_CUSTOM_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintCustom(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_CUSTOM_MODULE_NAME "Custom"
|
||||
|
||||
void ffPrintCustom(FFinstance* instance, FFCustomOptions* options);
|
||||
void ffInitCustomOptions(FFCustomOptions* options);
|
||||
bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value);
|
||||
void ffDestroyCustomOptions(FFCustomOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseCustomJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFCustomOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFCustomOptions;
|
||||
Reference in New Issue
Block a user