mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 00:03:58 +01:00
Global: refactor code of -h <module>-format
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_CPUUSAGE_DISPLAY_NAME "CPU Usage"
|
||||
#define FF_CPUUSAGE_NUM_FORMAT_ARGS 8
|
||||
|
||||
void ffPrintCPUUsage(FFCPUUsageOptions* options)
|
||||
{
|
||||
@@ -94,7 +93,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
ffPercentAppendBar(&maxBar, maxValue, options->percent, &options->moduleArgs);
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPUUSAGE_NUM_FORMAT_ARGS, ((FFformatarg[]){
|
||||
FF_PRINT_FORMAT_CHECKED(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(avgNum, "avg"),
|
||||
FF_FORMAT_ARG(maxNum, "max"),
|
||||
FF_FORMAT_ARG(maxIndex, "max-index"),
|
||||
@@ -194,33 +193,29 @@ void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* do
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintCPUUsageHelpFormat(void)
|
||||
{
|
||||
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CPUUSAGE_MODULE_NAME, "{1}", FF_CPUUSAGE_NUM_FORMAT_ARGS, ((const char* []) {
|
||||
"CPU usage (percentage num, average) - avg",
|
||||
"CPU usage (percentage num, maximum) - max",
|
||||
"CPU core index of maximum usage - max-index",
|
||||
"CPU usage (percentage num, minimum) - min",
|
||||
"CPU core index of minimum usage - min-index",
|
||||
"CPU usage (percentage bar, average) - avg-bar",
|
||||
"CPU usage (percentage bar, maximum) - max-bar",
|
||||
"CPU usage (percentage bar, minimum) - min-bar",
|
||||
}));
|
||||
}
|
||||
static FFModuleBaseInfo ffModuleInfo = {
|
||||
.name = FF_CPUUSAGE_MODULE_NAME,
|
||||
.description = "Print CPU usage. Costs some time to collect data",
|
||||
.parseCommandOptions = (void*) ffParseCPUUsageCommandOptions,
|
||||
.parseJsonObject = (void*) ffParseCPUUsageJsonObject,
|
||||
.printModule = (void*) ffPrintCPUUsage,
|
||||
.generateJsonResult = (void*) ffGenerateCPUUsageJsonResult,
|
||||
.generateJsonConfig = (void*) ffGenerateCPUUsageJsonConfig,
|
||||
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
||||
{"CPU usage (percentage num, average)", "avg"},
|
||||
{"CPU usage (percentage num, maximum)", "max"},
|
||||
{"CPU core index of maximum usage", "max-index"},
|
||||
{"CPU usage (percentage num, minimum)", "min"},
|
||||
{"CPU core index of minimum usage", "min-index"},
|
||||
{"CPU usage (percentage bar, average)", "avg-bar"},
|
||||
{"CPU usage (percentage bar, maximum)", "max-bar"},
|
||||
{"CPU usage (percentage bar, minimum)", "min-bar"},
|
||||
}))
|
||||
};
|
||||
|
||||
void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(
|
||||
&options->moduleInfo,
|
||||
FF_CPUUSAGE_MODULE_NAME,
|
||||
"Print CPU usage. Costs some time to collect data",
|
||||
ffParseCPUUsageCommandOptions,
|
||||
ffParseCPUUsageJsonObject,
|
||||
ffPrintCPUUsage,
|
||||
ffGenerateCPUUsageJsonResult,
|
||||
ffPrintCPUUsageHelpFormat,
|
||||
ffGenerateCPUUsageJsonConfig
|
||||
);
|
||||
options->moduleInfo = ffModuleInfo;
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
options->separate = false;
|
||||
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
|
||||
|
||||
Reference in New Issue
Block a user