Skip to content

Commit 782af25

Browse files
committed
Percent: in custom format, only set num and bar string if enabled in percent config
Also fix `percentage-bar` printing in Brightness module
1 parent 6801fe3 commit 782af25

File tree

12 files changed

+82
-40
lines changed

12 files changed

+82
-40
lines changed

src/modules/battery/battery.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
9797
else
9898
{
9999
FF_STRBUF_AUTO_DESTROY capacityNum = ffStrbufCreate();
100-
ffPercentAppendNum(&capacityNum, result->capacity, options->percent, false, &options->moduleArgs);
100+
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
101+
ffPercentAppendNum(&capacityNum, result->capacity, options->percent, false, &options->moduleArgs);
101102
FF_STRBUF_AUTO_DESTROY capacityBar = ffStrbufCreate();
102-
ffPercentAppendBar(&capacityBar, result->capacity, options->percent, &options->moduleArgs);
103+
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
104+
ffPercentAppendBar(&capacityBar, result->capacity, options->percent, &options->moduleArgs);
103105
FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate();
104106
ffTempsAppendNum(result->temperature, &tempStr, options->tempConfig, &options->moduleArgs);
107+
105108
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BATTERY_NUM_FORMAT_ARGS, ((FFformatarg[]) {
106109
FF_FORMAT_ARG(result->manufacturer, "manufacturer"),
107110
FF_FORMAT_ARG(result->modelName, "model-name"),

src/modules/bluetooth/bluetooth.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index)
1111
{
12+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1213
if(options->moduleArgs.outputFormat.length == 0)
1314
{
1415
ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
1516

1617
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
1718
bool showBatteryLevel = device->battery > 0 && device->battery <= 100;
18-
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1919

2020
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
2121
{
@@ -41,9 +41,11 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
4141
else
4242
{
4343
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
44-
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
44+
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
45+
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
4546
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
46-
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
47+
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
48+
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
4749

4850
FF_PRINT_FORMAT_CHECKED(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BLUETOOTH_NUM_FORMAT_ARGS, ((FFformatarg[]) {
4951
FF_FORMAT_ARG(device->name, "name"),

src/modules/brightness/brightness.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ void ffPrintBrightness(FFBrightnessOptions* options)
8989
else
9090
{
9191
FF_STRBUF_AUTO_DESTROY valueNum = ffStrbufCreate();
92-
ffPercentAppendNum(&valueNum, percent, options->percent, false, &options->moduleArgs);
92+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
93+
ffPercentAppendNum(&valueNum, percent, options->percent, false, &options->moduleArgs);
9394
FF_STRBUF_AUTO_DESTROY valueBar = ffStrbufCreate();
94-
ffPercentAppendBar(&valueBar, percent, options->percent, &options->moduleArgs);
95+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
96+
ffPercentAppendBar(&valueBar, percent, options->percent, &options->moduleArgs);
97+
9598
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, ((FFformatarg[]) {
9699
FF_FORMAT_ARG(valueNum, "percentage"),
97100
FF_FORMAT_ARG(item->name, "name"),
98101
FF_FORMAT_ARG(item->max, "max"),
99102
FF_FORMAT_ARG(item->min, "min"),
100103
FF_FORMAT_ARG(item->current, "current"),
101-
FF_FORMAT_ARG(item->current, "percentage-bar"),
104+
FF_FORMAT_ARG(valueBar, "percentage-bar"),
102105
}));
103106
}
104107

src/modules/btrfs/btrfs.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
4545
double usedPercentage = total > 0 ? (double) used / (double) total * 100.0 : 0;
4646
double allocatedPercentage = total > 0 ? (double) allocated / (double) total * 100.0 : 0;
4747

48+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
49+
4850
if(options->moduleArgs.outputFormat.length == 0)
4951
{
5052
ffPrintLogoAndKey(buffer.chars, index, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
@@ -60,14 +62,18 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
6062
else
6163
{
6264
FF_STRBUF_AUTO_DESTROY usedPercentageNum = ffStrbufCreate();
63-
ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs);
65+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
66+
ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs);
6467
FF_STRBUF_AUTO_DESTROY usedPercentageBar = ffStrbufCreate();
65-
ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs);
68+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
69+
ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs);
6670

6771
FF_STRBUF_AUTO_DESTROY allocatedPercentageNum = ffStrbufCreate();
68-
ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs);
72+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
73+
ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs);
6974
FF_STRBUF_AUTO_DESTROY allocatedPercentageBar = ffStrbufCreate();
70-
ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs);
75+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
76+
ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs);
7177

7278
FF_STRBUF_AUTO_DESTROY nodeSizePretty = ffStrbufCreate();
7379
ffParseSize(result->nodeSize, &nodeSizePretty);

src/modules/cpuusage/cpuusage.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,24 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
7676
else
7777
{
7878
FF_STRBUF_AUTO_DESTROY avgNum = ffStrbufCreate();
79-
ffPercentAppendNum(&avgNum, avgValue, options->percent, false, &options->moduleArgs);
79+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
80+
ffPercentAppendNum(&avgNum, avgValue, options->percent, false, &options->moduleArgs);
8081
FF_STRBUF_AUTO_DESTROY avgBar = ffStrbufCreate();
81-
ffPercentAppendBar(&avgBar, avgValue, options->percent, &options->moduleArgs);
82+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
83+
ffPercentAppendBar(&avgBar, avgValue, options->percent, &options->moduleArgs);
8284
FF_STRBUF_AUTO_DESTROY minNum = ffStrbufCreate();
83-
ffPercentAppendNum(&minNum, minValue, options->percent, false, &options->moduleArgs);
85+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
86+
ffPercentAppendNum(&minNum, minValue, options->percent, false, &options->moduleArgs);
8487
FF_STRBUF_AUTO_DESTROY minBar = ffStrbufCreate();
85-
ffPercentAppendBar(&minBar, minValue, options->percent, &options->moduleArgs);
88+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
89+
ffPercentAppendBar(&minBar, minValue, options->percent, &options->moduleArgs);
8690
FF_STRBUF_AUTO_DESTROY maxNum = ffStrbufCreate();
87-
ffPercentAppendNum(&maxNum, maxValue, options->percent, false, &options->moduleArgs);
91+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
92+
ffPercentAppendNum(&maxNum, maxValue, options->percent, false, &options->moduleArgs);
8893
FF_STRBUF_AUTO_DESTROY maxBar = ffStrbufCreate();
89-
ffPercentAppendBar(&maxBar, maxValue, options->percent, &options->moduleArgs);
94+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
95+
ffPercentAppendBar(&maxBar, maxValue, options->percent, &options->moduleArgs);
96+
9097
FF_PRINT_FORMAT_CHECKED(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPUUSAGE_NUM_FORMAT_ARGS, ((FFformatarg[]){
9198
FF_FORMAT_ARG(avgNum, "avg"),
9299
FF_FORMAT_ARG(maxNum, "max"),

src/modules/disk/disk.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,19 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
108108
else
109109
{
110110
FF_STRBUF_AUTO_DESTROY bytesPercentageNum = ffStrbufCreate();
111-
ffPercentAppendNum(&bytesPercentageNum, bytesPercentage, options->percent, false, &options->moduleArgs);
111+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
112+
ffPercentAppendNum(&bytesPercentageNum, bytesPercentage, options->percent, false, &options->moduleArgs);
112113
FF_STRBUF_AUTO_DESTROY bytesPercentageBar = ffStrbufCreate();
113-
ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs);
114+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
115+
ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs);
114116

115117
double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0;
116118
FF_STRBUF_AUTO_DESTROY filesPercentageNum = ffStrbufCreate();
117-
ffPercentAppendNum(&filesPercentageNum, filesPercentage, options->percent, false, &options->moduleArgs);
119+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
120+
ffPercentAppendNum(&filesPercentageNum, filesPercentage, options->percent, false, &options->moduleArgs);
118121
FF_STRBUF_AUTO_DESTROY filesPercentageBar = ffStrbufCreate();
119-
ffPercentAppendBar(&filesPercentageBar, filesPercentage, options->percent, &options->moduleArgs);
122+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
123+
ffPercentAppendBar(&filesPercentageBar, filesPercentage, options->percent, &options->moduleArgs);
120124

121125
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
122126
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);

src/modules/gamepad/gamepad.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device, uint8_t index)
1111
{
12+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1213
if(options->moduleArgs.outputFormat.length == 0)
1314
{
1415
ffPrintLogoAndKey(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
1516

1617
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
1718
bool showBatteryLevel = device->battery > 0 && device->battery <= 100;
18-
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1919

2020
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
2121
{
@@ -37,9 +37,11 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
3737
else
3838
{
3939
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
40-
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
40+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
41+
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
4142
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
42-
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
43+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
44+
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
4345

4446
FF_PRINT_FORMAT_CHECKED(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_GAMEPAD_NUM_FORMAT_ARGS, ((FFformatarg[]) {
4547
FF_FORMAT_ARG(device->name, "name"),

src/modules/memory/memory.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void ffPrintMemory(FFMemoryOptions* options)
2929
? 0
3030
: (double) storage.bytesUsed / (double) storage.bytesTotal * 100.0;
3131

32+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
3233
if(options->moduleArgs.outputFormat.length == 0)
3334
{
3435
ffPrintLogoAndKey(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
@@ -37,7 +38,6 @@ void ffPrintMemory(FFMemoryOptions* options)
3738
else
3839
{
3940
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
40-
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
4141

4242
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
4343
{
@@ -58,9 +58,12 @@ void ffPrintMemory(FFMemoryOptions* options)
5858
else
5959
{
6060
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
61-
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
61+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
62+
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
6263
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
63-
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
64+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
65+
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
66+
6467
FF_PRINT_FORMAT_CHECKED(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_MEMORY_NUM_FORMAT_ARGS, ((FFformatarg[]){
6568
FF_FORMAT_ARG(usedPretty, "used"),
6669
FF_FORMAT_ARG(totalPretty, "total"),

src/modules/sound/sound.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, uint8_t index)
1111
{
12+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1213
if(options->moduleArgs.outputFormat.length == 0)
1314
{
1415
ffPrintLogoAndKey(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
15-
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
1616

1717
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
1818
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
@@ -48,9 +48,11 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
4848
else
4949
{
5050
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
51-
ffPercentAppendNum(&percentageNum, device->volume, options->percent, false, &options->moduleArgs);
51+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
52+
ffPercentAppendNum(&percentageNum, device->volume, options->percent, false, &options->moduleArgs);
5253
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
53-
ffPercentAppendBar(&percentageBar, device->volume, options->percent, &options->moduleArgs);
54+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
55+
ffPercentAppendBar(&percentageBar, device->volume, options->percent, &options->moduleArgs);
5456

5557
FF_PRINT_FORMAT_CHECKED(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SOUND_NUM_FORMAT_ARGS, ((FFformatarg[]) {
5658
FF_FORMAT_ARG(device->main, "is-main"),

src/modules/swap/swap.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ void ffPrintSwap(FFSwapOptions* options)
2929
? 0
3030
: (double) storage.bytesUsed / (double) storage.bytesTotal * 100.0;
3131

32+
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
3233
if(options->moduleArgs.outputFormat.length == 0)
3334
{
3435
ffPrintLogoAndKey(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
3536
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
36-
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
3737

3838
if (storage.bytesTotal == 0)
3939
{
@@ -68,9 +68,11 @@ void ffPrintSwap(FFSwapOptions* options)
6868
else
6969
{
7070
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
71-
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
71+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
72+
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
7273
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
73-
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
74+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
75+
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
7476
FF_PRINT_FORMAT_CHECKED(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SWAP_NUM_FORMAT_ARGS, ((FFformatarg[]){
7577
FF_FORMAT_ARG(usedPretty, "used"),
7678
FF_FORMAT_ARG(totalPretty, "total"),

src/modules/wifi/wifi.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ void ffPrintWifi(FFWifiOptions* options)
7979
else
8080
{
8181
FF_STRBUF_AUTO_DESTROY percentNum = ffStrbufCreate();
82-
ffPercentAppendNum(&percentNum, item->conn.signalQuality, options->percent, false, &options->moduleArgs);
82+
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
83+
ffPercentAppendNum(&percentNum, item->conn.signalQuality, options->percent, false, &options->moduleArgs);
8384
FF_STRBUF_AUTO_DESTROY percentBar = ffStrbufCreate();
84-
ffPercentAppendBar(&percentBar, item->conn.signalQuality, options->percent, &options->moduleArgs);
85+
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
86+
ffPercentAppendBar(&percentBar, item->conn.signalQuality, options->percent, &options->moduleArgs);
87+
8588
FF_PRINT_FORMAT_CHECKED(FF_WIFI_MODULE_NAME, moduleIndex, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WIFI_NUM_FORMAT_ARGS, ((FFformatarg[]){
8689
FF_FORMAT_ARG(item->inf.description, "inf-desc"),
8790
FF_FORMAT_ARG(item->inf.status, "inf-status"),

0 commit comments

Comments
 (0)