Files
fastfetch/src/modules/cpuUsage.c
T

43 lines
1.3 KiB
C
Raw Normal View History

2021-11-24 16:16:25 +08:00
#include "fastfetch.h"
#include "common/printing.h"
#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)
{
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;
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, ' ');
ffAppendPercentNum(instance, &str, (uint8_t) percentage, 50, 80, str.length > 0);
}
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[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &percentage}
2021-11-24 16:16:25 +08:00
});
}
}