From 8f205b8c30cf0a13190b9aca5e2136fc90e112bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 26 Feb 2024 15:12:04 +0800 Subject: [PATCH] Percent: rename FFPercentConfig to FFColorRangeConfig --- src/common/parsing.h | 8 +++++++- src/common/percent.c | 10 +++++----- src/common/percent.h | 17 ++++++----------- src/modules/battery/battery.c | 2 +- src/modules/battery/option.h | 2 +- src/modules/bluetooth/bluetooth.c | 2 +- src/modules/bluetooth/option.h | 2 +- src/modules/brightness/brightness.c | 2 +- src/modules/brightness/option.h | 2 +- src/modules/cpuusage/cpuusage.c | 2 +- src/modules/cpuusage/option.h | 2 +- src/modules/disk/disk.c | 2 +- src/modules/disk/option.h | 2 +- src/modules/gamepad/gamepad.c | 2 +- src/modules/gamepad/option.h | 2 +- src/modules/gpu/gpu.c | 2 +- src/modules/gpu/option.h | 2 +- src/modules/memory/memory.c | 2 +- src/modules/memory/option.h | 2 +- src/modules/sound/option.h | 2 +- src/modules/sound/sound.c | 2 +- src/modules/swap/option.h | 2 +- src/modules/swap/swap.c | 2 +- 23 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/common/parsing.h b/src/common/parsing.h index e98883b06..24fd13528 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -1,6 +1,6 @@ #pragma once -#include "fastfetch.h" +#include "util/FFstrbuf.h" #include @@ -11,6 +11,12 @@ typedef struct FFVersion uint32_t patch; } FFVersion; +typedef struct FFColorRangeConfig +{ + uint8_t green; + uint8_t yellow; +} FFColorRangeConfig; + #define FF_VERSION_INIT ((FFVersion) {0}) void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* minor, const FFstrbuf* patch); diff --git a/src/common/percent.c b/src/common/percent.c index 9c52970ed..a80f3ed10 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -6,7 +6,7 @@ #include "util/textModifier.h" #include "util/stringUtils.h" -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config) +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -75,7 +75,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses) +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -126,7 +126,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config ffStrbufAppendC(buffer, ')'); } -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentConfig* config) +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config) { if (!ffStrStartsWithIgnCase(subkey, "percent-")) return false; @@ -160,7 +160,7 @@ bool ffPercentParseCommandOptions(const char* key, const char* subkey, const cha return false; } -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfig* config) +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config) { if (!ffStrEqualsIgnCase(key, "percent")) return false; @@ -198,7 +198,7 @@ bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfi return true; } -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentConfig defaultConfig, FFPercentConfig config) +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config) { if (config.green == defaultConfig.green && config.yellow == defaultConfig.yellow) return; diff --git a/src/common/percent.h b/src/common/percent.h index e3e83b4a4..6d7c6b2e8 100644 --- a/src/common/percent.h +++ b/src/common/percent.h @@ -1,6 +1,7 @@ #pragma once #include "util/FFstrbuf.h" +#include "common/parsing.h" enum { @@ -10,12 +11,6 @@ enum FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, }; -typedef struct FFPercentConfig -{ - uint8_t green; - uint8_t yellow; -} FFPercentConfig; - // if (green <= yellow) // [0, green]: print green // (green, yellow]: print yellow @@ -26,12 +21,12 @@ typedef struct FFPercentConfig // [yellow, green): print yellow // [0, yellow): print red -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config); -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses); +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config); +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses); typedef struct yyjson_val yyjson_val; typedef struct yyjson_mut_doc yyjson_mut_doc; typedef struct yyjson_mut_val yyjson_mut_val; -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentConfig* config); -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentConfig* config); -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentConfig defaultConfig, FFPercentConfig config); +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config); +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config); +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config); diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index bab7d5db0..ccfed5d09 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -250,7 +250,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; #ifdef _WIN32 options->useSetupApi = false; diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index c03537a37..4fa9e8f5c 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -11,7 +11,7 @@ typedef struct FFBatteryOptions FFModuleArgs moduleArgs; bool temp; - FFPercentConfig percent; + FFColorRangeConfig percent; #ifdef _WIN32 bool useSetupApi; diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 79a7539c1..02c14975c 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -198,7 +198,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; } void ffDestroyBluetoothOptions(FFBluetoothOptions* options) diff --git a/src/modules/bluetooth/option.h b/src/modules/bluetooth/option.h index bab9cce67..7938e77f0 100644 --- a/src/modules/bluetooth/option.h +++ b/src/modules/bluetooth/option.h @@ -11,5 +11,5 @@ typedef struct FFBluetoothOptions FFModuleArgs moduleArgs; bool showDisconnected; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFBluetoothOptions; diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 49283474f..454a580d6 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -205,7 +205,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->ddcciSleep = 10; - options->percent = (FFPercentConfig) { 100, 100 }; + options->percent = (FFColorRangeConfig) { 100, 100 }; } void ffDestroyBrightnessOptions(FFBrightnessOptions* options) diff --git a/src/modules/brightness/option.h b/src/modules/brightness/option.h index 89d08a8ed..2623d0aea 100644 --- a/src/modules/brightness/option.h +++ b/src/modules/brightness/option.h @@ -11,5 +11,5 @@ typedef struct FFBrightnessOptions FFModuleArgs moduleArgs; uint32_t ddcciSleep; // ms - FFPercentConfig percent; + FFColorRangeConfig percent; } FFBrightnessOptions; diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index e8787dd33..be852f076 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -190,7 +190,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->separate = false; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options) diff --git a/src/modules/cpuusage/option.h b/src/modules/cpuusage/option.h index 380fc9b56..92d298f30 100644 --- a/src/modules/cpuusage/option.h +++ b/src/modules/cpuusage/option.h @@ -11,5 +11,5 @@ typedef struct FFCPUUsageOptions FFModuleArgs moduleArgs; bool separate; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFCPUUsageOptions; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index a874cc892..ea209dcea 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -484,7 +484,7 @@ void ffInitDiskOptions(FFDiskOptions* options) ffStrbufInit(&options->folders); options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyDiskOptions(FFDiskOptions* options) diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index a02505d5e..7c2abdcaa 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -30,5 +30,5 @@ typedef struct FFDiskOptions FFstrbuf folders; FFDiskVolumeType showTypes; FFDiskCalcType calcType; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFDiskOptions; diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 2c5341333..e50fb22d7 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -162,7 +162,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options) ffGenerateGamepadJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 20 }; + options->percent = (FFColorRangeConfig) { 50, 20 }; } void ffDestroyGamepadOptions(FFGamepadOptions* options) diff --git a/src/modules/gamepad/option.h b/src/modules/gamepad/option.h index bc49128e8..b4ecaf94d 100644 --- a/src/modules/gamepad/option.h +++ b/src/modules/gamepad/option.h @@ -9,5 +9,5 @@ typedef struct FFGamepadOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFGamepadOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 270872127..c933d7832 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -373,7 +373,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyGPUOptions(FFGPUOptions* options) diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index e251f834e..438e4d309 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -21,5 +21,5 @@ typedef struct FFGPUOptions bool temp; bool driverSpecific; bool forceVulkan; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFGPUOptions; diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 485b62130..e7bd5c105 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -148,7 +148,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options) ffGenerateMemoryJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroyMemoryOptions(FFMemoryOptions* options) diff --git a/src/modules/memory/option.h b/src/modules/memory/option.h index a63153264..4936b252b 100644 --- a/src/modules/memory/option.h +++ b/src/modules/memory/option.h @@ -10,5 +10,5 @@ typedef struct FFMemoryOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFMemoryOptions; diff --git a/src/modules/sound/option.h b/src/modules/sound/option.h index dae67bb49..ad659a557 100644 --- a/src/modules/sound/option.h +++ b/src/modules/sound/option.h @@ -18,5 +18,5 @@ typedef struct FFSoundOptions FFModuleArgs moduleArgs; FFSoundType soundType; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFSoundOptions; diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 0d0950011..31a9d32ea 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -255,7 +255,7 @@ void ffInitSoundOptions(FFSoundOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->soundType = FF_SOUND_TYPE_MAIN; - options->percent = (FFPercentConfig) { 80, 90 }; + options->percent = (FFColorRangeConfig) { 80, 90 }; } void ffDestroySoundOptions(FFSoundOptions* options) diff --git a/src/modules/swap/option.h b/src/modules/swap/option.h index 6940a39e1..1c96ce41f 100644 --- a/src/modules/swap/option.h +++ b/src/modules/swap/option.h @@ -10,5 +10,5 @@ typedef struct FFSwapOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFPercentConfig percent; + FFColorRangeConfig percent; } FFSwapOptions; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index bf7c7481a..cb4cad7f2 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -157,7 +157,7 @@ void ffInitSwapOptions(FFSwapOptions* options) ffGenerateSwapJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); - options->percent = (FFPercentConfig) { 50, 80 }; + options->percent = (FFColorRangeConfig) { 50, 80 }; } void ffDestroySwapOptions(FFSwapOptions* options)