Percentage: refactor function names

This commit is contained in:
李通洲
2024-01-20 13:49:04 +08:00
parent 24cb83dd18
commit e7974a7cea
12 changed files with 36 additions and 36 deletions
+2 -2
View File
@@ -3,7 +3,7 @@
#include "common/color.h"
#include "util/textModifier.h"
void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow)
void ffPercentAppendBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow)
{
assert(green <= 100 && yellow <= 100);
@@ -56,7 +56,7 @@ void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t
ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET);
}
void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses)
void ffPercentAppendNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses)
{
assert(green <= 100 && yellow <= 100);
+2 -2
View File
@@ -20,5 +20,5 @@ enum
// [yellow, green): print yellow
// [0, yellow): print red
void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow);
void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses);
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);
+3 -3
View File
@@ -24,7 +24,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, result->capacity, 50, 20);
ffPercentAppendBar(&str, result->capacity, 50, 20);
}
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, ' ');
ffAppendPercentNum(&str, result->capacity, 50, 20, str.length > 0);
ffPercentAppendNum(&str, result->capacity, 50, 20, str.length > 0);
}
}
@@ -57,7 +57,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
else
{
FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate();
ffAppendPercentNum(&capacityStr, result->capacity, 51, 21, false);
ffPercentAppendNum(&capacityStr, result->capacity, 51, 21, 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},
+2 -2
View File
@@ -19,7 +19,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
{
if (buffer.length)
ffStrbufAppendC(&buffer, ' ');
ffAppendPercentNum(&buffer, device->battery, 50, 20, buffer.length > 0);
ffPercentAppendNum(&buffer, device->battery, 50, 20, 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();
ffAppendPercentNum(&percentageStr, device->battery, 50, 20, false);
ffPercentAppendNum(&percentageStr, device->battery, 50, 20, false);
ffPrintFormat(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_BLUETOOTH_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
+3 -3
View File
@@ -52,7 +52,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, percent, 100, 100);
ffPercentAppendBar(&str, percent, 100, 100);
}
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
@@ -60,7 +60,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, percent, 100, 100, str.length > 0);
ffPercentAppendNum(&str, percent, 100, 100, str.length > 0);
}
ffStrbufPutTo(&str, stdout);
@@ -68,7 +68,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate();
ffAppendPercentNum(&valueStr, percent, 10, 10, false);
ffPercentAppendNum(&valueStr, percent, 10, 10, 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},
+6 -6
View File
@@ -52,12 +52,12 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
if (!options->separate)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffAppendPercentBar(&str, avgValue, 50, 80);
ffPercentAppendBar(&str, avgValue, 50, 80);
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, avgValue, 50, 80, str.length > 0);
ffPercentAppendNum(&str, avgValue, 50, 80, str.length > 0);
}
}
else
@@ -66,7 +66,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, *percent, 50, 80, false);
ffPercentAppendNum(&str, *percent, 50, 80, false);
}
}
ffStrbufPutTo(&str, stdout);
@@ -74,11 +74,11 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY avgStr = ffStrbufCreate();
ffAppendPercentNum(&avgStr, avgValue, 50, 80, false);
ffPercentAppendNum(&avgStr, avgValue, 50, 80, false);
FF_STRBUF_AUTO_DESTROY minStr = ffStrbufCreate();
ffAppendPercentNum(&minStr, minValue, 50, 80, false);
ffPercentAppendNum(&minStr, minValue, 50, 80, false);
FF_STRBUF_AUTO_DESTROY maxStr = ffStrbufCreate();
ffAppendPercentNum(&maxStr, maxValue, 50, 80, false);
ffPercentAppendNum(&maxStr, maxValue, 50, 80, 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},
+4 -4
View File
@@ -59,7 +59,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, bytesPercentage, 50, 80);
ffPercentAppendBar(&str, bytesPercentage, 50, 80);
ffStrbufAppendC(&str, ' ');
}
@@ -68,7 +68,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
ffAppendPercentNum(&str, bytesPercentage, 50, 80, str.length > 0);
ffPercentAppendNum(&str, bytesPercentage, 50, 80, str.length > 0);
ffStrbufAppendC(&str, ' ');
}
}
@@ -104,10 +104,10 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
else
{
FF_STRBUF_AUTO_DESTROY bytesPercentageStr = ffStrbufCreate();
ffAppendPercentNum(&bytesPercentageStr, bytesPercentage, 50, 80, false);
ffPercentAppendNum(&bytesPercentageStr, bytesPercentage, 50, 80, false);
FF_STRBUF_AUTO_DESTROY filesPercentageStr = ffStrbufCreate();
double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0;
ffAppendPercentNum(&filesPercentageStr, filesPercentage, 50, 80, false);
ffPercentAppendNum(&filesPercentageStr, filesPercentage, 50, 80, false);
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
+2 -2
View File
@@ -19,14 +19,14 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
{
if (buffer.length)
ffStrbufAppendC(&buffer, ' ');
ffAppendPercentNum(&buffer, device->battery, 50, 20, buffer.length > 0);
ffPercentAppendNum(&buffer, device->battery, 50, 20, buffer.length > 0);
}
ffStrbufPutTo(&buffer, stdout);
}
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, device->battery, 50, 20, false);
ffPercentAppendNum(&percentageStr, device->battery, 50, 20, false);
ffPrintFormat(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
+1 -1
View File
@@ -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, ", ");
ffAppendPercentNum(&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, 50, 80, false);
}
ffStrbufAppendC(&output, ')');
}
+3 -3
View File
@@ -40,7 +40,7 @@ void ffPrintMemory(FFMemoryOptions* options)
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, percentage, 50, 80);
ffPercentAppendBar(&str, percentage, 50, 80);
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)
ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0);
ffPercentAppendNum(&str, percentage, 50, 80, str.length > 0);
ffStrbufTrimRight(&str, ' ');
ffStrbufPutTo(&str, stdout);
@@ -57,7 +57,7 @@ void ffPrintMemory(FFMemoryOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, percentage, 50, 80, false);
ffPercentAppendNum(&percentageStr, percentage, 50, 80, 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},
+3 -3
View File
@@ -24,7 +24,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
if (str.length)
ffStrbufAppendC(&str, ' ');
ffAppendPercentBar(&str, device->volume, 80, 90);
ffPercentAppendBar(&str, device->volume, 80, 90);
}
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, ' ');
ffAppendPercentNum(&str, device->volume, 80, 90, str.length > 0);
ffPercentAppendNum(&str, device->volume, 80, 90, str.length > 0);
}
}
@@ -47,7 +47,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, device->volume, 80, 90, false);
ffPercentAppendNum(&percentageStr, device->volume, 80, 90, false);
ffPrintFormat(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_SOUND_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_BOOL, &device->main},
+5 -5
View File
@@ -37,19 +37,19 @@ void ffPrintSwap(FFSwapOptions* options)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, 0, 50, 80);
ffPercentAppendBar(&str, 0, 50, 80);
ffStrbufAppendC(&str, ' ');
}
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendS(&str, "Disabled");
else
ffAppendPercentNum(&str, 0, 50, 80, str.length > 0);
ffPercentAppendNum(&str, 0, 50, 80, str.length > 0);
}
else
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, percentage, 50, 80);
ffPercentAppendBar(&str, percentage, 50, 80);
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)
ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0);
ffPercentAppendNum(&str, percentage, 50, 80, str.length > 0);
}
ffStrbufTrimRight(&str, ' ');
@@ -66,7 +66,7 @@ void ffPrintSwap(FFSwapOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
ffAppendPercentNum(&percentageStr, percentage, 50, 80, false);
ffPercentAppendNum(&percentageStr, percentage, 50, 80, 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},