mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
Global: refactor code of -h <module>-format
This commit is contained in:
+23
-29
@@ -6,8 +6,6 @@
|
||||
#include "modules/cpu/cpu.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_CPU_NUM_FORMAT_ARGS 10
|
||||
|
||||
static int sortCores(const FFCPUCore* a, const FFCPUCore* b)
|
||||
{
|
||||
return (int)b->freq - (int)a->freq;
|
||||
@@ -104,7 +102,7 @@ void ffPrintCPU(FFCPUOptions* options)
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate();
|
||||
ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig, &options->moduleArgs);
|
||||
FF_PRINT_FORMAT_CHECKED(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPU_NUM_FORMAT_ARGS, ((FFformatarg[]){
|
||||
FF_PRINT_FORMAT_CHECKED(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(cpu.name, "name"),
|
||||
FF_FORMAT_ARG(cpu.vendor, "vendor"),
|
||||
FF_FORMAT_ARG(cpu.coresPhysical, "cores-physical"),
|
||||
@@ -241,35 +239,31 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
ffStrbufDestroy(&cpu.vendor);
|
||||
}
|
||||
|
||||
void ffPrintCPUHelpFormat(void)
|
||||
{
|
||||
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CPU_MODULE_NAME, "{1} ({5}) @ {7} GHz", FF_CPU_NUM_FORMAT_ARGS, ((const char* []) {
|
||||
"Name - name",
|
||||
"Vendor - vendor",
|
||||
"Physical core count - cores-physical",
|
||||
"Logical core count - cores-logical",
|
||||
"Online core count - cores-online",
|
||||
"Base frequency (formatted) - freq-base",
|
||||
"Max frequency (formatted) - freq-max",
|
||||
"Temperature (formatted) - temperature",
|
||||
"Logical core count grouped by frequency - core-types",
|
||||
"Processor package count - packages",
|
||||
}));
|
||||
}
|
||||
static FFModuleBaseInfo ffModuleInfo = {
|
||||
.name = FF_CPU_MODULE_NAME,
|
||||
.description = "Print CPU name, frequency, etc",
|
||||
.parseCommandOptions = (void*) ffParseCPUCommandOptions,
|
||||
.parseJsonObject = (void*) ffParseCPUJsonObject,
|
||||
.printModule = (void*) ffPrintCPU,
|
||||
.generateJsonResult = (void*) ffGenerateCPUJsonResult,
|
||||
.generateJsonConfig = (void*) ffGenerateCPUJsonConfig,
|
||||
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
||||
{"Name", "name"},
|
||||
{"Vendor", "vendor"},
|
||||
{"Physical core count", "cores-physical"},
|
||||
{"Logical core count", "cores-logical"},
|
||||
{"Online core count", "cores-online"},
|
||||
{"Base frequency (formatted)", "freq-base"},
|
||||
{"Max frequency (formatted)", "freq-max"},
|
||||
{"Temperature (formatted)", "temperature"},
|
||||
{"Logical core count grouped by frequency", "core-types"},
|
||||
{"Processor package count", "packages"},
|
||||
}))
|
||||
};
|
||||
|
||||
void ffInitCPUOptions(FFCPUOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(
|
||||
&options->moduleInfo,
|
||||
FF_CPU_MODULE_NAME,
|
||||
"Print CPU name, frequency, etc",
|
||||
ffParseCPUCommandOptions,
|
||||
ffParseCPUJsonObject,
|
||||
ffPrintCPU,
|
||||
ffGenerateCPUJsonResult,
|
||||
ffPrintCPUHelpFormat,
|
||||
ffGenerateCPUJsonConfig
|
||||
);
|
||||
options->moduleInfo = ffModuleInfo;
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
options->temp = false;
|
||||
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
|
||||
|
||||
Reference in New Issue
Block a user