mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
Global: refactor code of -h <module>-format
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_PHYSICALDISK_DISPLAY_NAME "Physical Disk"
|
||||
#define FF_PHYSICALDISK_NUM_FORMAT_ARGS 10
|
||||
|
||||
static int sortDevices(const FFPhysicalDiskResult* left, const FFPhysicalDiskResult* right)
|
||||
{
|
||||
@@ -23,7 +22,7 @@ static void formatKey(const FFPhysicalDiskOptions* options, FFPhysicalDiskResult
|
||||
else
|
||||
{
|
||||
ffStrbufClear(key);
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 4, ((FFformatarg[]){
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(index, "index"),
|
||||
FF_FORMAT_ARG(dev->name, "name"),
|
||||
FF_FORMAT_ARG(dev->devPath, "dev-path"),
|
||||
@@ -108,13 +107,13 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
|
||||
ffTempsAppendNum(dev->temperature, &tempStr, options->tempConfig, &options->moduleArgs);
|
||||
if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE)
|
||||
readOnlyType = "Read-write";
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_PHYSICALDISK_NUM_FORMAT_ARGS, ((FFformatarg[]){
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]){
|
||||
FF_FORMAT_ARG(buffer, "size"),
|
||||
FF_FORMAT_ARG(dev->name, "name"),
|
||||
FF_FORMAT_ARG(dev->interconnect, "interconnect"),
|
||||
FF_FORMAT_ARG(physicalType, "type"),
|
||||
FF_FORMAT_ARG(dev->devPath, "dev-path"),
|
||||
FF_FORMAT_ARG(dev->serial, "serial"),
|
||||
FF_FORMAT_ARG(physicalType, "physical-type"),
|
||||
FF_FORMAT_ARG(removableType, "removable-type"),
|
||||
FF_FORMAT_ARG(readOnlyType, "readonly-type"),
|
||||
FF_FORMAT_ARG(dev->revision, "revision"),
|
||||
@@ -250,35 +249,31 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintPhysicalDiskHelpFormat(void)
|
||||
{
|
||||
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PHYSICALDISK_MODULE_NAME, "{1} [{6}, {7}, {8}]", FF_PHYSICALDISK_NUM_FORMAT_ARGS, ((const char* []) {
|
||||
"Device size (formatted) - ",
|
||||
"Device name",
|
||||
"Device interconnect type",
|
||||
"Device raw file path",
|
||||
"Serial number",
|
||||
"Device kind (SSD or HDD)",
|
||||
"Device kind (Removable or Fixed)",
|
||||
"Device kind (Read-only or Read-write)",
|
||||
"Product revision",
|
||||
"Device temperature (formatted)",
|
||||
}));
|
||||
}
|
||||
static FFModuleBaseInfo ffModuleInfo = {
|
||||
.name = FF_PHYSICALDISK_MODULE_NAME,
|
||||
.description = "Print physical disk information",
|
||||
.parseCommandOptions = (void*) ffParsePhysicalDiskCommandOptions,
|
||||
.parseJsonObject = (void*) ffParsePhysicalDiskJsonObject,
|
||||
.printModule = (void*) ffPrintPhysicalDisk,
|
||||
.generateJsonResult = (void*) ffGeneratePhysicalDiskJsonResult,
|
||||
.generateJsonConfig = (void*) ffGeneratePhysicalDiskJsonConfig,
|
||||
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
||||
{"Device size (formatted)", "size"},
|
||||
{"Device name", "name"},
|
||||
{"Device interconnect type", "interconnect"},
|
||||
{"Device raw file path", "dev-path"},
|
||||
{"Serial number", "serial"},
|
||||
{"Device kind (SSD or HDD)", "physical-type"},
|
||||
{"Device kind (Removable or Fixed)", "removable-type"},
|
||||
{"Device kind (Read-only or Read-write)", "readonly-type"},
|
||||
{"Product revision", "revision"},
|
||||
{"Device temperature (formatted)", "temperature"},
|
||||
}))
|
||||
};
|
||||
|
||||
void ffInitPhysicalDiskOptions(FFPhysicalDiskOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(
|
||||
&options->moduleInfo,
|
||||
FF_PHYSICALDISK_MODULE_NAME,
|
||||
"Print physical disk information",
|
||||
ffParsePhysicalDiskCommandOptions,
|
||||
ffParsePhysicalDiskJsonObject,
|
||||
ffPrintPhysicalDisk,
|
||||
ffGeneratePhysicalDiskJsonResult,
|
||||
ffPrintPhysicalDiskHelpFormat,
|
||||
ffGeneratePhysicalDiskJsonConfig
|
||||
);
|
||||
options->moduleInfo = ffModuleInfo;
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
ffStrbufInit(&options->namePrefix);
|
||||
|
||||
Reference in New Issue
Block a user