diff --git a/src/common/percent.c b/src/common/percent.c index 766f610f7..0dff8b169 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -3,8 +3,9 @@ #include "common/color.h" #include "util/textModifier.h" -void ffPercentAppendBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow) +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config) { + uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); const FFOptionsDisplay* options = &instance.config.display; @@ -56,8 +57,9 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } -void ffPercentAppendNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses) +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses) { + uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); const FFOptionsDisplay* options = &instance.config.display; diff --git a/src/common/percent.h b/src/common/percent.h index f97fcb1c8..190c8a374 100644 --- a/src/common/percent.h +++ b/src/common/percent.h @@ -1,6 +1,6 @@ #pragma once -#include "fastfetch.h" +#include "util/FFstrbuf.h" enum { @@ -10,6 +10,12 @@ 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 @@ -20,5 +26,5 @@ enum // [yellow, green): print yellow // [0, yellow): print red -void ffPercentAppendBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow); -void ffPercentAppendNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses); +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentConfig config); +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentConfig config, bool parentheses); diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index b811bdb3e..d667ea846 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -24,7 +24,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin { if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, result->capacity, 50, 20); + ffPercentAppendBar(&str, result->capacity, options->percent); } if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) @@ -32,7 +32,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffPercentAppendNum(&str, result->capacity, 50, 20, str.length > 0); + ffPercentAppendNum(&str, result->capacity, options->percent, str.length > 0); } } @@ -57,7 +57,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin else { FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); - ffPercentAppendNum(&capacityStr, result->capacity, 51, 21, false); + ffPercentAppendNum(&capacityStr, result->capacity, options->percent, false); ffPrintFormat(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, @@ -240,6 +240,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; + options->percent = (FFPercentConfig) { 50, 20 }; #ifdef _WIN32 options->useSetupApi = false; diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index 401816ae7..c03537a37 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFBatteryOptions { @@ -10,6 +11,7 @@ typedef struct FFBatteryOptions FFModuleArgs moduleArgs; bool temp; + FFPercentConfig percent; #ifdef _WIN32 bool useSetupApi; diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 078759831..cd0692746 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -19,7 +19,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de { if (buffer.length) ffStrbufAppendC(&buffer, ' '); - ffPercentAppendNum(&buffer, device->battery, 50, 20, buffer.length > 0); + ffPercentAppendNum(&buffer, device->battery, options->percent, buffer.length > 0); } if (!device->connected) @@ -28,7 +28,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de else { FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->battery, 50, 20, false); + ffPercentAppendNum(&percentageStr, device->battery, options->percent, false); ffPrintFormat(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_BLUETOOTH_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, @@ -188,6 +188,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; + options->percent = (FFPercentConfig) { 50, 20 }; } void ffDestroyBluetoothOptions(FFBluetoothOptions* options) diff --git a/src/modules/bluetooth/option.h b/src/modules/bluetooth/option.h index bbe9e1c54..bab9cce67 100644 --- a/src/modules/bluetooth/option.h +++ b/src/modules/bluetooth/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFBluetoothOptions { @@ -10,4 +11,5 @@ typedef struct FFBluetoothOptions FFModuleArgs moduleArgs; bool showDisconnected; + FFPercentConfig percent; } FFBluetoothOptions; diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 80ceb0cfd..4dd295a36 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -52,7 +52,7 @@ void ffPrintBrightness(FFBrightnessOptions* options) if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, percent, 100, 100); + ffPercentAppendBar(&str, percent, options->percent); } if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) @@ -60,7 +60,7 @@ void ffPrintBrightness(FFBrightnessOptions* options) if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffPercentAppendNum(&str, percent, 100, 100, str.length > 0); + ffPercentAppendNum(&str, percent, options->percent, str.length > 0); } ffStrbufPutTo(&str, stdout); @@ -68,7 +68,7 @@ void ffPrintBrightness(FFBrightnessOptions* options) else { FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate(); - ffPercentAppendNum(&valueStr, percent, 10, 10, false); + ffPercentAppendNum(&valueStr, percent, options->percent, false); ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &valueStr}, {FF_FORMAT_ARG_TYPE_STRBUF, &item->name}, @@ -197,6 +197,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->ddcciSleep = 10; + options->percent = (FFPercentConfig) { 100, 100 }; } void ffDestroyBrightnessOptions(FFBrightnessOptions* options) diff --git a/src/modules/brightness/option.h b/src/modules/brightness/option.h index cad3e7ac8..89d08a8ed 100644 --- a/src/modules/brightness/option.h +++ b/src/modules/brightness/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFBrightnessOptions { @@ -10,4 +11,5 @@ typedef struct FFBrightnessOptions FFModuleArgs moduleArgs; uint32_t ddcciSleep; // ms + FFPercentConfig percent; } FFBrightnessOptions; diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index ea1a0ffeb..38738fabb 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -52,12 +52,12 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) if (!options->separate) { if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) - ffPercentAppendBar(&str, avgValue, 50, 80); + ffPercentAppendBar(&str, avgValue, options->percent); if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffPercentAppendNum(&str, avgValue, 50, 80, str.length > 0); + ffPercentAppendNum(&str, avgValue, options->percent, str.length > 0); } } else @@ -66,7 +66,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) { if(str.length > 0) ffStrbufAppendC(&str, ' '); - ffPercentAppendNum(&str, *percent, 50, 80, false); + ffPercentAppendNum(&str, *percent, options->percent, false); } } ffStrbufPutTo(&str, stdout); @@ -74,11 +74,11 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) else { FF_STRBUF_AUTO_DESTROY avgStr = ffStrbufCreate(); - ffPercentAppendNum(&avgStr, avgValue, 50, 80, false); + ffPercentAppendNum(&avgStr, avgValue, options->percent, false); FF_STRBUF_AUTO_DESTROY minStr = ffStrbufCreate(); - ffPercentAppendNum(&minStr, minValue, 50, 80, false); + ffPercentAppendNum(&minStr, minValue, options->percent, false); FF_STRBUF_AUTO_DESTROY maxStr = ffStrbufCreate(); - ffPercentAppendNum(&maxStr, maxValue, 50, 80, false); + ffPercentAppendNum(&maxStr, maxValue, options->percent, false); ffPrintFormat(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_CPUUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &avgStr}, {FF_FORMAT_ARG_TYPE_STRBUF, &maxStr}, @@ -182,6 +182,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); options->separate = false; + options->percent = (FFPercentConfig) { 50, 80 }; } void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options) diff --git a/src/modules/cpuusage/option.h b/src/modules/cpuusage/option.h index d7fea247d..380fc9b56 100644 --- a/src/modules/cpuusage/option.h +++ b/src/modules/cpuusage/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFCPUUsageOptions { @@ -10,4 +11,5 @@ typedef struct FFCPUUsageOptions FFModuleArgs moduleArgs; bool separate; + FFPercentConfig percent; } FFCPUUsageOptions; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 3bf539359..fae7e3501 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -59,7 +59,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) { if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, bytesPercentage, 50, 80); + ffPercentAppendBar(&str, bytesPercentage, options->percent); ffStrbufAppendC(&str, ' '); } @@ -68,7 +68,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { - ffPercentAppendNum(&str, bytesPercentage, 50, 80, str.length > 0); + ffPercentAppendNum(&str, bytesPercentage, options->percent, str.length > 0); ffStrbufAppendC(&str, ' '); } } @@ -104,10 +104,10 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) else { FF_STRBUF_AUTO_DESTROY bytesPercentageStr = ffStrbufCreate(); - ffPercentAppendNum(&bytesPercentageStr, bytesPercentage, 50, 80, false); + ffPercentAppendNum(&bytesPercentageStr, bytesPercentage, options->percent, false); FF_STRBUF_AUTO_DESTROY filesPercentageStr = ffStrbufCreate(); double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0; - ffPercentAppendNum(&filesPercentageStr, filesPercentage, 50, 80, false); + ffPercentAppendNum(&filesPercentageStr, filesPercentage, options->percent, false); bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT); bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT); @@ -476,6 +476,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 }; } void ffDestroyDiskOptions(FFDiskOptions* options) diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index 9b727e542..a02505d5e 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef enum FFDiskVolumeType { @@ -29,4 +30,5 @@ typedef struct FFDiskOptions FFstrbuf folders; FFDiskVolumeType showTypes; FFDiskCalcType calcType; + FFPercentConfig percent; } FFDiskOptions; diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 34d79978d..76de33845 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -19,14 +19,14 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device { if (buffer.length) ffStrbufAppendC(&buffer, ' '); - ffPercentAppendNum(&buffer, device->battery, 50, 20, buffer.length > 0); + ffPercentAppendNum(&buffer, device->battery, options->percent, buffer.length > 0); } ffStrbufPutTo(&buffer, stdout); } else { FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->battery, 50, 20, false); + ffPercentAppendNum(&percentageStr, device->battery, options->percent, false); ffPrintFormat(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, @@ -133,7 +133,7 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs void ffPrintGamepadHelpFormat(void) { - ffPrintModuleFormatHelp(FF_GAMEPAD_MODULE_NAME, "{1}", FF_GAMEPAD_NUM_FORMAT_ARGS, (const char* []) { + ffPrintModuleFormatHelp(FF_GAMEPAD_MODULE_NAME, "{1} ({3})", FF_GAMEPAD_NUM_FORMAT_ARGS, (const char* []) { "Name", "Serial number", "Battery percentage", @@ -154,6 +154,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options) ffGenerateGamepadJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + options->percent = (FFPercentConfig) { 50, 20 }; } void ffDestroyGamepadOptions(FFGamepadOptions* options) diff --git a/src/modules/gamepad/option.h b/src/modules/gamepad/option.h index f455b3a42..bc49128e8 100644 --- a/src/modules/gamepad/option.h +++ b/src/modules/gamepad/option.h @@ -8,4 +8,6 @@ typedef struct FFGamepadOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + FFPercentConfig percent; } FFGamepadOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index dd19e8614..f1b348d18 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -60,7 +60,7 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu if(gpu->dedicated.used != FF_GPU_VMEM_SIZE_UNSET) { ffStrbufAppendS(&output, ", "); - ffPercentAppendNum(&output, (double) gpu->dedicated.used / (double) gpu->dedicated.total * 100.0, 50, 80, false); + ffPercentAppendNum(&output, (double) gpu->dedicated.used / (double) gpu->dedicated.total * 100.0, options->percent, false); } ffStrbufAppendC(&output, ')'); } @@ -363,6 +363,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; + options->percent = (FFPercentConfig) { 50, 80 }; } void ffDestroyGPUOptions(FFGPUOptions* options) diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 77babf437..e251f834e 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef enum FFGPUType { @@ -20,4 +21,5 @@ typedef struct FFGPUOptions bool temp; bool driverSpecific; bool forceVulkan; + FFPercentConfig percent; } FFGPUOptions; diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index ac2eea94f..c71ca9167 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -40,7 +40,7 @@ void ffPrintMemory(FFMemoryOptions* options) if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, percentage, 50, 80); + ffPercentAppendBar(&str, percentage, options->percent); ffStrbufAppendC(&str, ' '); } @@ -48,7 +48,7 @@ void ffPrintMemory(FFMemoryOptions* options) ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) - ffPercentAppendNum(&str, percentage, 50, 80, str.length > 0); + ffPercentAppendNum(&str, percentage, options->percent, str.length > 0); ffStrbufTrimRight(&str, ' '); ffStrbufPutTo(&str, stdout); @@ -57,7 +57,7 @@ void ffPrintMemory(FFMemoryOptions* options) else { FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, percentage, 50, 80, false); + ffPercentAppendNum(&percentageStr, percentage, options->percent, false); ffPrintFormat(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, @@ -140,6 +140,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options) ffGenerateMemoryJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + options->percent = (FFPercentConfig) { 50, 80 }; } void ffDestroyMemoryOptions(FFMemoryOptions* options) diff --git a/src/modules/memory/option.h b/src/modules/memory/option.h index b908943e4..a63153264 100644 --- a/src/modules/memory/option.h +++ b/src/modules/memory/option.h @@ -3,9 +3,12 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFMemoryOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + FFPercentConfig percent; } FFMemoryOptions; diff --git a/src/modules/sound/option.h b/src/modules/sound/option.h index 11f652602..dae67bb49 100644 --- a/src/modules/sound/option.h +++ b/src/modules/sound/option.h @@ -3,6 +3,7 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef enum FFSoundType { @@ -17,4 +18,5 @@ typedef struct FFSoundOptions FFModuleArgs moduleArgs; FFSoundType soundType; + FFPercentConfig percent; } FFSoundOptions; diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index a7665865b..d7fbebf99 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -24,7 +24,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui if (str.length) ffStrbufAppendC(&str, ' '); - ffPercentAppendBar(&str, device->volume, 80, 90); + ffPercentAppendBar(&str, device->volume, options->percent); } if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) @@ -32,7 +32,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui if (str.length) ffStrbufAppendC(&str, ' '); - ffPercentAppendNum(&str, device->volume, 80, 90, str.length > 0); + ffPercentAppendNum(&str, device->volume, options->percent, str.length > 0); } } @@ -47,7 +47,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui else { FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->volume, 80, 90, false); + ffPercentAppendNum(&percentageStr, device->volume, options->percent, false); ffPrintFormat(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_SOUND_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_BOOL, &device->main}, @@ -247,6 +247,7 @@ void ffInitSoundOptions(FFSoundOptions* options) ffOptionInitModuleArg(&options->moduleArgs); options->soundType = FF_SOUND_TYPE_MAIN; + options->percent = (FFPercentConfig) { 80, 90 }; } void ffDestroySoundOptions(FFSoundOptions* options) diff --git a/src/modules/swap/option.h b/src/modules/swap/option.h index 52fea1733..6940a39e1 100644 --- a/src/modules/swap/option.h +++ b/src/modules/swap/option.h @@ -3,9 +3,12 @@ // This file will be included in "fastfetch.h", do NOT put unnecessary things here #include "common/option.h" +#include "common/percent.h" typedef struct FFSwapOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + FFPercentConfig percent; } FFSwapOptions; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index cfc1e36cb..b4103bf6b 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -37,19 +37,19 @@ void ffPrintSwap(FFSwapOptions* options) { if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, 0, 50, 80); + ffPercentAppendBar(&str, 0, options->percent); ffStrbufAppendC(&str, ' '); } if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendS(&str, "Disabled"); else - ffPercentAppendNum(&str, 0, 50, 80, str.length > 0); + ffPercentAppendNum(&str, 0, options->percent, str.length > 0); } else { if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { - ffPercentAppendBar(&str, percentage, 50, 80); + ffPercentAppendBar(&str, percentage, options->percent); ffStrbufAppendC(&str, ' '); } @@ -57,7 +57,7 @@ void ffPrintSwap(FFSwapOptions* options) ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) - ffPercentAppendNum(&str, percentage, 50, 80, str.length > 0); + ffPercentAppendNum(&str, percentage, options->percent, str.length > 0); } ffStrbufTrimRight(&str, ' '); @@ -66,7 +66,7 @@ void ffPrintSwap(FFSwapOptions* options) else { FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, percentage, 50, 80, false); + ffPercentAppendNum(&percentageStr, percentage, options->percent, false); ffPrintFormat(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_SWAP_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, @@ -149,6 +149,7 @@ void ffInitSwapOptions(FFSwapOptions* options) ffGenerateSwapJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + options->percent = (FFPercentConfig) { 50, 80 }; } void ffDestroySwapOptions(FFSwapOptions* options)