From 545267bb7ed27927c27126864ba92396bb52c834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 8 Jul 2024 15:21:12 +0800 Subject: [PATCH] Percentage: support percent bar in custom formatting Fix #1075 --- src/modules/battery/battery.c | 14 +++++++---- src/modules/bluetooth/bluetooth.c | 14 +++++++---- src/modules/brightness/brightness.c | 14 +++++++---- src/modules/cpuusage/cpuusage.c | 38 +++++++++++++++++++---------- src/modules/disk/disk.c | 27 +++++++++++++------- src/modules/gamepad/gamepad.c | 14 +++++++---- src/modules/memory/memory.c | 14 +++++++---- src/modules/sound/sound.c | 14 +++++++---- src/modules/swap/swap.c | 14 +++++++---- 9 files changed, 106 insertions(+), 57 deletions(-) diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 02a3a475d..f098bf6ec 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -7,7 +7,7 @@ #include "modules/battery/battery.h" #include "util/stringUtils.h" -#define FF_BATTERY_NUM_FORMAT_ARGS 9 +#define FF_BATTERY_NUM_FORMAT_ARGS 10 static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uint8_t index) { @@ -57,20 +57,23 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin } else { - FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); - ffPercentAppendNum(&capacityStr, result->capacity, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY capacityNum = ffStrbufCreate(); + ffPercentAppendNum(&capacityNum, result->capacity, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY capacityBar = ffStrbufCreate(); + ffPercentAppendBar(&capacityBar, result->capacity, options->percent, &options->moduleArgs); FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); ffTempsAppendNum(result->temperature, &tempStr, options->tempConfig, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BATTERY_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer, "manufacturer"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName, "model-name"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology, "technology"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr, "capacity"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &capacityNum, "capacity"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->status, "status"}, {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr, "temperature"}, {FF_FORMAT_ARG_TYPE_UINT, &result->cycleCount, "cycle-count"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial, "serial"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufactureDate, "manufacture-date"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &capacityBar, "capacity-bar"}, })); } } @@ -225,12 +228,13 @@ void ffPrintBatteryHelpFormat(void) "Battery manufacturer - manufacturer", "Battery model name - model-name", "Battery technology - technology", - "Battery capacity (percentage) - capacity", + "Battery capacity (percentage num) - capacity", "Battery status - status", "Battery temperature (formatted) - temperature", "Battery cycle count - cycle-count", "Battery serial number - serial", "Battery manufactor date - manufacture-date", + "Battery capacity (percentage bar) - capacity-bar", })); } diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 578a201bf..d3c089df4 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -5,7 +5,7 @@ #include "modules/bluetooth/bluetooth.h" #include "util/stringUtils.h" -#define FF_BLUETOOTH_NUM_FORMAT_ARGS 5 +#define FF_BLUETOOTH_NUM_FORMAT_ARGS 6 static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index) { @@ -29,15 +29,18 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de } else { - FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->battery, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate(); + ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate(); + ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BLUETOOTH_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->address, "address"}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->type, "type"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "battery-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageNum, "battery-percentage"}, {FF_FORMAT_ARG_TYPE_BOOL, &device->connected, "connected"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageBar, "battery-percentage-bar"}, })); } } @@ -178,8 +181,9 @@ void ffPrintBluetoothHelpFormat(void) "Name - name", "Address - address", "Type - type", - "Battery percentage - battery-percentage", + "Battery percentage number - battery-percentage", "Is connected - connected", + "Battery percentage bar - battery-percentage-bar", })); } diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 01d0beb8f..8030c6bef 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -5,7 +5,7 @@ #include "modules/brightness/brightness.h" #include "util/stringUtils.h" -#define FF_BRIGHTNESS_NUM_FORMAT_ARGS 5 +#define FF_BRIGHTNESS_NUM_FORMAT_ARGS 6 void ffPrintBrightness(FFBrightnessOptions* options) { @@ -67,14 +67,17 @@ void ffPrintBrightness(FFBrightnessOptions* options) } else { - FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate(); - ffPercentAppendNum(&valueStr, percent, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY valueNum = ffStrbufCreate(); + ffPercentAppendNum(&valueNum, percent, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY valueBar = ffStrbufCreate(); + ffPercentAppendBar(&valueBar, percent, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &valueStr, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &valueNum, "percentage"}, {FF_FORMAT_ARG_TYPE_STRBUF, &item->name, "name"}, {FF_FORMAT_ARG_TYPE_DOUBLE, &item->max, "max"}, {FF_FORMAT_ARG_TYPE_DOUBLE, &item->min, "min"}, {FF_FORMAT_ARG_TYPE_DOUBLE, &item->current, "current"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->current, "percentage-bar"}, })); } @@ -175,11 +178,12 @@ void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options void ffPrintBrightnessHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BRIGHTNESS_MODULE_NAME, "{1}", FF_BRIGHTNESS_NUM_FORMAT_ARGS, ((const char* []) { - "Screen brightness (percentage) - percentage", + "Screen brightness (percentage num) - percentage", "Screen name - name", "Maximum brightness value - max", "Minimum brightness value - min", "Current brightness value - current", + "Screen brightness (percentage bar) - percentage-bar", })); } diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index b90e475bc..1629e237a 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -6,7 +6,7 @@ #include "util/stringUtils.h" #define FF_CPUUSAGE_DISPLAY_NAME "CPU Usage" -#define FF_CPUUSAGE_NUM_FORMAT_ARGS 5 +#define FF_CPUUSAGE_NUM_FORMAT_ARGS 8 void ffPrintCPUUsage(FFCPUUsageOptions* options) { @@ -73,18 +73,27 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) } else { - FF_STRBUF_AUTO_DESTROY avgStr = ffStrbufCreate(); - ffPercentAppendNum(&avgStr, avgValue, options->percent, false, &options->moduleArgs); - FF_STRBUF_AUTO_DESTROY minStr = ffStrbufCreate(); - ffPercentAppendNum(&minStr, minValue, options->percent, false, &options->moduleArgs); - FF_STRBUF_AUTO_DESTROY maxStr = ffStrbufCreate(); - ffPercentAppendNum(&maxStr, maxValue, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY avgNum = ffStrbufCreate(); + ffPercentAppendNum(&avgNum, avgValue, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY avgBar = ffStrbufCreate(); + ffPercentAppendBar(&avgBar, avgValue, options->percent, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY minNum = ffStrbufCreate(); + ffPercentAppendNum(&minNum, minValue, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY minBar = ffStrbufCreate(); + ffPercentAppendBar(&minBar, minValue, options->percent, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY maxNum = ffStrbufCreate(); + ffPercentAppendNum(&maxNum, maxValue, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY maxBar = ffStrbufCreate(); + ffPercentAppendBar(&maxBar, maxValue, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPUUSAGE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &avgStr, "avg"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &maxStr, "max"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &avgNum, "avg"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &maxNum, "max"}, {FF_FORMAT_ARG_TYPE_UINT, &maxIndex, "max-index"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &minStr, "min"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &minNum, "min"}, {FF_FORMAT_ARG_TYPE_UINT, &minIndex, "min-index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &avgBar, "avg-bar"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &maxBar, "max-bar"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &minBar, "min-bar"}, })); } } @@ -167,11 +176,14 @@ void ffGenerateCPUUsageJsonResult(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yy void ffPrintCPUUsageHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CPUUSAGE_MODULE_NAME, "{1}", FF_CPUUSAGE_NUM_FORMAT_ARGS, ((const char* []) { - "CPU usage (percentage, average) - avg", - "CPU usage (percentage, maximum) - max", + "CPU usage (percentage num, average) - avg", + "CPU usage (percentage num, maximum) - max", "CPU core index of maximum usage - max-index", - "CPU usage (percentage, minimum) - min", + "CPU usage (percentage num, minimum) - min", "CPU core index of minimum usage - min-index", + "CPU usage (percentage bar, average) - avg-bar", + "CPU usage (percentage bar, maximum) - max-bar", + "CPU usage (percentage bar, minimum) - min-bar", })); } diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 48b494efe..3996ff647 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -7,7 +7,7 @@ #include "modules/disk/disk.h" #include "util/stringUtils.h" -#define FF_DISK_NUM_FORMAT_ARGS 12 +#define FF_DISK_NUM_FORMAT_ARGS 14 #pragma GCC diagnostic ignored "-Wsign-conversion" static void printDisk(FFDiskOptions* options, const FFDisk* disk) @@ -104,11 +104,16 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) } else { - FF_STRBUF_AUTO_DESTROY bytesPercentageStr = ffStrbufCreate(); - ffPercentAppendNum(&bytesPercentageStr, bytesPercentage, options->percent, false, &options->moduleArgs); - FF_STRBUF_AUTO_DESTROY filesPercentageStr = ffStrbufCreate(); + FF_STRBUF_AUTO_DESTROY bytesPercentageNum = ffStrbufCreate(); + ffPercentAppendNum(&bytesPercentageNum, bytesPercentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY bytesPercentageBar = ffStrbufCreate(); + ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs); + double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0; - ffPercentAppendNum(&filesPercentageStr, filesPercentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY filesPercentageNum = ffStrbufCreate(); + ffPercentAppendNum(&filesPercentageNum, filesPercentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY filesPercentageBar = ffStrbufCreate(); + ffPercentAppendBar(&filesPercentageBar, filesPercentage, options->percent, &options->moduleArgs); bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT); bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT); @@ -117,16 +122,18 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "size-used"}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "size-total"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageStr, "size-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageNum, "size-percentage"}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed, "files-used"}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal, "files-total"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageStr, "files-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageNum, "files-percentage"}, {FF_FORMAT_ARG_TYPE_BOOL, &isExternal, "is-external"}, {FF_FORMAT_ARG_TYPE_BOOL, &isHidden, "is-hidden"}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem, "filesystem"}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name, "name"}, {FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly, "is-readonly"}, {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(disk->createTime), "create-time"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageBar, "size-percentage-bar"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageBar, "files-percentage-bar"}, })); } } @@ -430,16 +437,18 @@ void ffPrintDiskHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DISK_MODULE_NAME, "{1} / {2} ({3}) - {9}", FF_DISK_NUM_FORMAT_ARGS, ((const char* []) { "Size used - size-used", "Size total - size-total", - "Size percentage - size-percentage", + "Size percentage num - size-percentage", "Files used - files-used", "Files total - files-total", - "Files percentage - files-percentage", + "Files percentage num - files-percentage", "True if external volume - is-external", "True if hidden volume - is-hidden", "Filesystem - filesystem", "Label / name - name", "True if read-only - is-readonly", "Create time in local timezone - create-time", + "Size percentage bar - size-percentage-bar", + "Files percentage bar - files-percentage-bar", })); } diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 062e375b8..e6fff3622 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -5,7 +5,7 @@ #include "modules/gamepad/gamepad.h" #include "util/stringUtils.h" -#define FF_GAMEPAD_NUM_FORMAT_ARGS 3 +#define FF_GAMEPAD_NUM_FORMAT_ARGS 4 static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device, uint8_t index) { @@ -25,13 +25,16 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device } else { - FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->battery, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate(); + ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate(); + ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_GAMEPAD_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->serial, "serial"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "battery-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageNum, "battery-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageBar, "battery-percentage-bar"}, })); } } @@ -138,7 +141,8 @@ void ffPrintGamepadHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_GAMEPAD_MODULE_NAME, "{1} ({3})", FF_GAMEPAD_NUM_FORMAT_ARGS, ((const char* []) { "Name - name", "Serial number - serial", - "Battery percentage - battery-percentage", + "Battery percentage num - battery-percentage", + "Battery percentage bar - battery-percentage-bar", })); } diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index df623e8c5..832fecf20 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -6,7 +6,7 @@ #include "modules/memory/memory.h" #include "util/stringUtils.h" -#define FF_MEMORY_NUM_FORMAT_ARGS 3 +#define FF_MEMORY_NUM_FORMAT_ARGS 4 void ffPrintMemory(FFMemoryOptions* options) { @@ -56,12 +56,15 @@ void ffPrintMemory(FFMemoryOptions* options) } else { - FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, percentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate(); + ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate(); + ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_MEMORY_NUM_FORMAT_ARGS, ((FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "used"}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "total"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageNum, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageBar, "percentage-bar"}, })); } } @@ -130,7 +133,8 @@ void ffPrintMemoryHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MEMORY_MODULE_NAME, "{1} / {2} ({3})", FF_MEMORY_NUM_FORMAT_ARGS, ((const char* []) { "Used size - used", "Total size - total", - "Percentage used - percentage", + "Percentage used (num) - percentage", + "Percentage used (bar) - percentage-bar", })); } diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 0b1c39cbf..3ca23491a 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -5,7 +5,7 @@ #include "modules/sound/sound.h" #include "util/stringUtils.h" -#define FF_SOUND_NUM_FORMAT_ARGS 4 +#define FF_SOUND_NUM_FORMAT_ARGS 5 static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, uint8_t index) { @@ -46,14 +46,17 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui } else { - FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, device->volume, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate(); + ffPercentAppendNum(&percentageNum, device->volume, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate(); + ffPercentAppendBar(&percentageBar, device->volume, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SOUND_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_BOOL, &device->main, "is-main"}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "volume-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageNum, "volume-percentage"}, {FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier, "identifier"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageBar, "volume-percentage-bar"}, })); } } @@ -228,8 +231,9 @@ void ffPrintSoundHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_SOUND_MODULE_NAME, "{2} ({3}%)", FF_SOUND_NUM_FORMAT_ARGS, ((const char* []) { "Is main sound device - is-main", "Device name - name", - "Volume (in percentage) - volume-percentage", + "Volume (in percentage num) - volume-percentage", "Identifier - identifier", + "Volume (in percentage bar) - volume-percentage-bar", })); } diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index ac2b277b0..7b823f671 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -6,7 +6,7 @@ #include "modules/swap/swap.h" #include "util/stringUtils.h" -#define FF_SWAP_NUM_FORMAT_ARGS 3 +#define FF_SWAP_NUM_FORMAT_ARGS 4 void ffPrintSwap(FFSwapOptions* options) { @@ -65,12 +65,15 @@ void ffPrintSwap(FFSwapOptions* options) } else { - FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); - ffPercentAppendNum(&percentageStr, percentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate(); + ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate(); + ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SWAP_NUM_FORMAT_ARGS, ((FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "used"}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "total"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageNum, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageBar, "percentage-bar"}, })); } } @@ -139,7 +142,8 @@ void ffPrintSwapHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_SWAP_MODULE_NAME, "{1} / {2} ({3})", FF_SWAP_NUM_FORMAT_ARGS, ((const char* []) { "Used size - used", "Total size - total", - "Percentage used - percentage", + "Percentage used (num) - percentage", + "Percentage used (bar) - percentage-bar", })); }