mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Icons: add JSON formatting support
This commit is contained in:
@@ -32,7 +32,7 @@ void ffPrintIcons(FFIconsOptions* options)
|
||||
|
||||
void ffInitIconsOptions(FFIconsOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -67,3 +67,17 @@ void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_ICONS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateIconsJson(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate();
|
||||
const char* error = ffDetectIcons(&icons);
|
||||
|
||||
if (error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "result", &icons);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitIconsOptions(FFIconsOptions* options);
|
||||
bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const char* value);
|
||||
void ffDestroyIconsOptions(FFIconsOptions* options);
|
||||
void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module);
|
||||
void ffGenerateIconsJson(FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user