2021-11-24 16:16:25 +08:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-10-18 22:55:28 +08:00
|
|
|
#include "common/bar.h"
|
2022-09-21 10:47:15 +08:00
|
|
|
#include "detection/cpuUsage/cpuUsage.h"
|
2022-10-07 16:52:52 +08:00
|
|
|
|
2021-11-24 16:16:25 +08:00
|
|
|
#define FF_CPU_USAGE_MODULE_NAME "CPU Usage"
|
|
|
|
|
#define FF_CPU_USAGE_NUM_FORMAT_ARGS 1
|
|
|
|
|
|
|
|
|
|
void ffPrintCPUUsage(FFinstance* instance)
|
|
|
|
|
{
|
2022-10-18 22:55:28 +08:00
|
|
|
double percentage = 0.0/0.0;
|
|
|
|
|
const char* error = ffGetCpuUsageResult(&percentage);
|
2022-09-21 10:47:15 +08:00
|
|
|
|
|
|
|
|
if(error)
|
2021-11-24 16:16:25 +08:00
|
|
|
{
|
2022-09-21 10:47:15 +08:00
|
|
|
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpu, "%s", error);
|
2021-11-24 16:16:25 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 18:15:36 +02:00
|
|
|
if(instance->config.cpuUsage.outputFormat.length == 0)
|
2021-11-24 16:16:25 +08:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage.key);
|
2021-11-24 16:16:25 +08:00
|
|
|
|
2023-04-15 10:23:32 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY str;
|
2022-10-18 22:55:28 +08:00
|
|
|
ffStrbufInit(&str);
|
|
|
|
|
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
|
|
|
|
ffAppendPercentBar(instance, &str, (uint8_t)percentage, 0, 5, 8);
|
|
|
|
|
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
|
|
|
|
{
|
|
|
|
|
if(str.length > 0)
|
|
|
|
|
ffStrbufAppendC(&str, ' ');
|
2023-01-31 19:42:02 +08:00
|
|
|
ffAppendPercentNum(instance, &str, (uint8_t) percentage, 50, 80, str.length > 0);
|
2022-10-18 22:55:28 +08:00
|
|
|
}
|
|
|
|
|
ffStrbufPutTo(&str, stdout);
|
2021-11-24 16:16:25 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintFormat(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2022-10-18 22:55:28 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_DOUBLE, &percentage}
|
2021-11-24 16:16:25 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|