Global: make FFinstance instance a global variable

As discussed in https://github.com/fastfetch-cli/fastfetch/discussions/473
This commit is contained in:
李通洲
2023-06-24 10:59:53 +08:00
parent 48b01c9665
commit d0f093c567
255 changed files with 2020 additions and 2064 deletions
+11 -11
View File
@@ -8,35 +8,35 @@
#define FF_CPUUSAGE_DISPLAY_NAME "CPU Usage"
#define FF_CPUUSAGE_NUM_FORMAT_ARGS 1
void ffPrintCPUUsage(FFinstance* instance, FFCPUUsageOptions* options)
void ffPrintCPUUsage(FFCPUUsageOptions* options)
{
double percentage = 0.0/0.0;
const char* error = ffGetCpuUsageResult(&percentage);
if(error)
{
ffPrintError(instance, FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error);
ffPrintError(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error);
return;
}
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
ffPrintLogoAndKey(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
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(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffAppendPercentBar(&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);
ffAppendPercentNum(&str, (uint8_t) percentage, 50, 80, str.length > 0);
}
ffStrbufPutTo(&str, stdout);
}
else
{
ffPrintFormat(instance, FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_CPUUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_CPUUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &percentage}
});
}
@@ -63,7 +63,7 @@ void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseCPUUsageJsonObject(FFinstance* instance, yyjson_val* module)
void ffParseCPUUsageJsonObject(yyjson_val* module)
{
FFCPUUsageOptions __attribute__((__cleanup__(ffDestroyCPUUsageOptions))) options;
ffInitCPUUsageOptions(&options);
@@ -81,9 +81,9 @@ void ffParseCPUUsageJsonObject(FFinstance* instance, yyjson_val* module)
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_CPUUSAGE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
ffPrintError(FF_CPUUSAGE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
}
ffPrintCPUUsage(instance, &options);
ffPrintCPUUsage(&options);
}