Global: support percent type config in module level

This commit is contained in:
李通洲
2024-11-14 13:52:02 +08:00
parent 97e1b987dd
commit c9e3f8d95c
16 changed files with 109 additions and 54 deletions
+6 -4
View File
@@ -39,24 +39,26 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
timeRemaining /= 24;
uint32_t days = timeRemaining;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
bool showStatus =
!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
result->status.length > 0 &&
ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0;
if(result->capacity >= 0)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, result->capacity, options->percent, &options->moduleArgs);
}
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
@@ -301,7 +303,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options)
ffOptionInitModuleArg(&options->moduleArgs, "");
options->temp = false;
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 20 };
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
#ifdef _WIN32
options->useSetupApi = false;
+14 -3
View File
@@ -13,9 +13,20 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
{
ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateCopy(&device->name);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
bool showBatteryLevel = device->battery > 0 && device->battery <= 100;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if (device->battery > 0 && device->battery <= 100)
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
{
ffPercentAppendBar(&buffer, device->battery, options->percent, &options->moduleArgs);
ffStrbufAppendC(&buffer, ' ');
}
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppend(&buffer, &device->name);
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT))
{
if (buffer.length)
ffStrbufAppendC(&buffer, ' ');
@@ -202,7 +213,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options)
);
ffOptionInitModuleArg(&options->moduleArgs, "");
options->showDisconnected = false;
options->percent = (FFPercentageModuleConfig) { 50, 20 };
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
}
void ffDestroyBluetoothOptions(FFBluetoothOptions* options)
+7 -5
View File
@@ -25,6 +25,8 @@ void ffPrintBrightness(FFBrightnessOptions* options)
return;
}
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if (options->compact)
{
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
@@ -48,7 +50,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
uint32_t index = 0;
FF_LIST_FOR_EACH(FFBrightnessResult, item, result)
{
if(options->moduleArgs.key.length == 0)
if (options->moduleArgs.key.length == 0)
{
ffStrbufAppendF(&key, "%s (%s)", FF_BRIGHTNESS_MODULE_NAME, item->name.chars);
}
@@ -64,17 +66,17 @@ void ffPrintBrightness(FFBrightnessOptions* options)
const double percent = (item->current - item->min) / (item->max - item->min) * 100;
if(options->moduleArgs.outputFormat.length == 0)
if (options->moduleArgs.outputFormat.length == 0)
{
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, percent, options->percent, &options->moduleArgs);
}
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
@@ -237,7 +239,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options)
ffOptionInitModuleArg(&options->moduleArgs, "󰯪");
options->ddcciSleep = 10;
options->percent = (FFPercentageModuleConfig) { 100, 100 };
options->percent = (FFPercentageModuleConfig) { 100, 100, 0 };
options->compact = false;
}
+1 -1
View File
@@ -245,7 +245,7 @@ void ffInitBtrfsOptions(FFBtrfsOptions* options)
ffGenerateBtrfsJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󱑛");
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroyBtrfsOptions(FFBtrfsOptions* options)
+5 -3
View File
@@ -44,6 +44,8 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
}
double avgValue = sumValue / (double) valueCount;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
@@ -51,9 +53,9 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if (!options->separate)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&str, avgValue, options->percent, &options->moduleArgs);
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if(str.length > 0)
ffStrbufAppendC(&str, ' ');
@@ -214,7 +216,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
);
ffOptionInitModuleArg(&options->moduleArgs, "󰓅");
options->separate = false;
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
options->waitTime = 200;
}
+6 -5
View File
@@ -51,6 +51,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
ffParseSize(disk->bytesTotal, &totalPretty);
double bytesPercentage = disk->bytesTotal > 0 ? (double) disk->bytesUsed / (double) disk->bytesTotal * 100.0 : 0;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
@@ -60,16 +61,16 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
if(disk->bytesTotal > 0)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, bytesPercentage, options->percent, &options->moduleArgs);
ffStrbufAppendC(&str, ' ');
}
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if(!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
ffPercentAppendNum(&str, bytesPercentage, options->percent, str.length > 0, &options->moduleArgs);
ffStrbufAppendC(&str, ' ');
@@ -78,7 +79,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
else
ffStrbufAppendS(&str, "Unknown ");
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if(!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
{
if(disk->filesystem.length)
ffStrbufAppendF(&str, "- %s ", disk->filesystem.chars);
@@ -473,7 +474,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 = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroyDiskOptions(FFDiskOptions* options)
+14 -3
View File
@@ -13,9 +13,20 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
{
ffPrintLogoAndKey(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateCopy(&device->name);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
bool showBatteryLevel = device->battery > 0 && device->battery <= 100;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if (device->battery > 0 && device->battery <= 100)
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
{
ffPercentAppendBar(&buffer, device->battery, options->percent, &options->moduleArgs);
ffStrbufAppendC(&buffer, ' ');
}
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppend(&buffer, &device->name);
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT))
{
if (buffer.length)
ffStrbufAppendC(&buffer, ' ');
@@ -160,7 +171,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options)
ffGenerateGamepadJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󰺵");
options->percent = (FFPercentageModuleConfig) { 50, 20 };
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
}
void ffDestroyGamepadOptions(FFGamepadOptions* options)
+1 -1
View File
@@ -439,7 +439,7 @@ void ffInitGPUOptions(FFGPUOptions* options)
options->temp = false;
options->hideType = FF_GPU_TYPE_UNKNOWN;
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroyGPUOptions(FFGPUOptions* options)
+5 -4
View File
@@ -59,18 +59,19 @@ void ffPrintLoadavg(FFLoadavgOptions* options)
ffStrbufClear(&buffer);
double percent = result[index] * 100 / cpu.coresOnline;
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&buffer, percent, options->percent, &options->moduleArgs);
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
{
if (buffer.length > 0)
ffStrbufAppendC(&buffer, ' ');
ffStrbufAppendF(&buffer, "%.*f", options->ndigits, result[index]);
}
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if (buffer.length > 0)
ffStrbufAppendC(&buffer, ' ');
@@ -204,7 +205,7 @@ void ffInitLoadavgOptions(FFLoadavgOptions* options)
);
ffOptionInitModuleArg(&options->moduleArgs, "");
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
options->ndigits = 2;
options->compact = true;
}
+5 -4
View File
@@ -37,17 +37,18 @@ void ffPrintMemory(FFMemoryOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, percentage, options->percent, &options->moduleArgs);
ffStrbufAppendC(&str, ' ');
}
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if(!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&str, percentage, options->percent, str.length > 0, &options->moduleArgs);
ffStrbufTrimRight(&str, ' ');
@@ -152,7 +153,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options)
ffGenerateMemoryJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "");
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroyMemoryOptions(FFMemoryOptions* options)
+6 -5
View File
@@ -12,14 +12,15 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppend(&str, &device->name);
if(device->volume != FF_SOUND_VOLUME_UNKNOWN)
{
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
if (str.length)
ffStrbufAppendC(&str, ' ');
@@ -27,7 +28,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
ffPercentAppendBar(&str, device->volume, options->percent, &options->moduleArgs);
}
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{
if (str.length)
ffStrbufAppendC(&str, ' ');
@@ -36,7 +37,7 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
}
}
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
{
if (device->main && index > 0)
ffStrbufAppendS(&str, " (*)");
@@ -253,7 +254,7 @@ void ffInitSoundOptions(FFSoundOptions* options)
ffOptionInitModuleArg(&options->moduleArgs, "");
options->soundType = FF_SOUND_TYPE_MAIN;
options->percent = (FFPercentageModuleConfig) { 80, 90 };
options->percent = (FFPercentageModuleConfig) { 80, 90, 0 };
}
void ffDestroySoundOptions(FFSoundOptions* options)
+8 -6
View File
@@ -33,30 +33,32 @@ void ffPrintSwap(FFSwapOptions* options)
{
ffPrintLogoAndKey(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if (storage.bytesTotal == 0)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, 0, options->percent, &options->moduleArgs);
ffStrbufAppendC(&str, ' ');
}
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if(!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendS(&str, "Disabled");
else
ffPercentAppendNum(&str, 0, options->percent, str.length > 0, &options->moduleArgs);
}
else
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&str, percentage, options->percent, &options->moduleArgs);
ffStrbufAppendC(&str, ' ');
}
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if(!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&str, percentage, options->percent, str.length > 0, &options->moduleArgs);
}
@@ -161,7 +163,7 @@ void ffInitSwapOptions(FFSwapOptions* options)
ffGenerateSwapJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󰓡");
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroySwapOptions(FFSwapOptions* options)
+6 -4
View File
@@ -22,6 +22,8 @@ void ffPrintWifi(FFWifiOptions* options)
return;
}
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
for(uint32_t index = 0; index < result.length; ++index)
{
FFWifiResult* item = FF_LIST_GET(FFWifiResult, result, index);
@@ -36,14 +38,14 @@ void ffPrintWifi(FFWifiOptions* options)
{
if(item->conn.signalQuality == item->conn.signalQuality)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffPercentAppendBar(&buffer, item->conn.signalQuality, options->percent, &options->moduleArgs);
ffStrbufAppendC(&buffer, ' ');
}
}
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
{
ffStrbufAppend(&buffer, &item->conn.ssid);
@@ -62,7 +64,7 @@ void ffPrintWifi(FFWifiOptions* options)
if(item->conn.signalQuality == item->conn.signalQuality)
{
if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&buffer, item->conn.signalQuality, options->percent, buffer.length > 0, &options->moduleArgs);
}
@@ -222,7 +224,7 @@ void ffInitWifiOptions(FFWifiOptions* options)
);
ffOptionInitModuleArg(&options->moduleArgs, "");
options->percent = (FFPercentageModuleConfig) { 50, 20 };
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
}
void ffDestroyWifiOptions(FFWifiOptions* options)
+1 -1
View File
@@ -205,7 +205,7 @@ void ffInitZpoolOptions(FFZpoolOptions* options)
ffGenerateZpoolJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs, "󱑛");
options->percent = (FFPercentageModuleConfig) { 50, 80 };
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
}
void ffDestroyZpoolOptions(FFZpoolOptions* options)