mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Memory: JSON format support
This commit is contained in:
@@ -68,7 +68,7 @@ void ffPrintMemory(FFMemoryOptions* options)
|
||||
|
||||
void ffInitMemoryOptions(FFMemoryOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -103,3 +103,19 @@ void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateMemoryJson(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFMemoryResult storage;
|
||||
const char* error = ffDetectMemory(&storage);
|
||||
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
yyjson_mut_obj_add_uint(doc, obj, "total", storage.bytesTotal);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "used", storage.bytesUsed);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitMemoryOptions(FFMemoryOptions* options);
|
||||
bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, const char* value);
|
||||
void ffDestroyMemoryOptions(FFMemoryOptions* options);
|
||||
void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module);
|
||||
void ffGenerateMemoryJson(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user