mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Font: add JSON printing support
This commit is contained in:
@@ -16,6 +16,12 @@ yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc,
|
||||
return yyjson_mut_obj_add_strncpy(doc, obj, _key, buf->chars, buf->length);
|
||||
}
|
||||
|
||||
yyjson_api_inline bool yyjson_mut_arr_add_strbuf(yyjson_mut_doc *doc,
|
||||
yyjson_mut_val *obj,
|
||||
const FFstrbuf* buf) {
|
||||
return yyjson_mut_arr_add_strncpy(doc, obj, buf->chars, buf->length);
|
||||
}
|
||||
|
||||
yyjson_api_inline yyjson_mut_val* yyjson_mut_obj_add_obj(yyjson_mut_doc *doc,
|
||||
yyjson_mut_val *obj,
|
||||
const char *_key) {
|
||||
|
||||
+27
-1
@@ -45,7 +45,7 @@ void ffPrintFont(FFFontOptions* options)
|
||||
|
||||
void ffInitFontOptions(FFFontOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -80,3 +80,29 @@ void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateFontJson(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFFontResult font;
|
||||
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
ffStrbufInit(&font.fonts[i]);
|
||||
ffStrbufInit(&font.display);
|
||||
|
||||
const char* error = ffDetectFont(&font);
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "display", &font.display);
|
||||
yyjson_mut_val* fontsArr = yyjson_mut_obj_add_arr(doc, obj, "fonts");
|
||||
for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
yyjson_mut_arr_add_strbuf(doc, fontsArr, &font.fonts[i]);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&font.display);
|
||||
for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
|
||||
ffStrbufDestroy(&font.fonts[i]);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitFontOptions(FFFontOptions* options);
|
||||
bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value);
|
||||
void ffDestroyFontOptions(FFFontOptions* options);
|
||||
void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module);
|
||||
void ffGenerateFontJson(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user