mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
CPUUsage: add JSON printing support
This commit is contained in:
@@ -46,7 +46,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
|
||||
|
||||
void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -81,3 +81,16 @@ void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_CPUUSAGE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateCPUUsageJson(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
double percentage = 0.0/0.0;
|
||||
const char* error = ffGetCpuUsageResult(&percentage);
|
||||
|
||||
if(error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
}
|
||||
yyjson_mut_obj_add_real(doc, module, "result", percentage);
|
||||
}
|
||||
|
||||
@@ -11,3 +11,4 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options);
|
||||
bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value);
|
||||
void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options);
|
||||
void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module);
|
||||
void ffGenerateCPUUsageJson(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user