mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 09:58:03 +02:00
LM: add JSON format support
This commit is contained in:
@@ -86,3 +86,34 @@ void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_LM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateLMJson(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFLMResult result;
|
||||
ffStrbufInit(&result.service);
|
||||
ffStrbufInit(&result.type);
|
||||
ffStrbufInit(&result.version);
|
||||
const char* error = ffDetectLM(&result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.service.length == 0)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", "No LM service found");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "service", &result.service);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "type", &result.type);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
|
||||
|
||||
exit:
|
||||
ffStrbufDestroy(&result.service);
|
||||
ffStrbufDestroy(&result.type);
|
||||
ffStrbufDestroy(&result.version);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitLMOptions(FFLMOptions* options);
|
||||
bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* value);
|
||||
void ffDestroyLMOptions(FFLMOptions* options);
|
||||
void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module);
|
||||
void ffGenerateLMJson(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user