Skip to content

Commit

Permalink
Percent: in custom format, only set num and bar string if enabled in …
Browse files Browse the repository at this point in the history
…percent config

Also fix `percentage-bar` printing in Brightness module
  • Loading branch information
CarterLi committed Nov 14, 2024
1 parent 6801fe3 commit 782af25
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 40 deletions.
7 changes: 5 additions & 2 deletions src/modules/battery/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
else
{
FF_STRBUF_AUTO_DESTROY capacityNum = ffStrbufCreate();
ffPercentAppendNum(&capacityNum, result->capacity, options->percent, false, &options->moduleArgs);
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&capacityNum, result->capacity, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY capacityBar = ffStrbufCreate();
ffPercentAppendBar(&capacityBar, result->capacity, options->percent, &options->moduleArgs);
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BATTERY_NUM_FORMAT_ARGS, ((FFformatarg[]) {
FF_FORMAT_ARG(result->manufacturer, "manufacturer"),
FF_FORMAT_ARG(result->modelName, "model-name"),
Expand Down
8 changes: 5 additions & 3 deletions src/modules/bluetooth/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

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

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 (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
{
Expand All @@ -41,9 +41,11 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
else
{
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(device->name, "name"),
Expand Down
9 changes: 6 additions & 3 deletions src/modules/brightness/brightness.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ void ffPrintBrightness(FFBrightnessOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY valueNum = ffStrbufCreate();
ffPercentAppendNum(&valueNum, percent, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&valueNum, percent, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY valueBar = ffStrbufCreate();
ffPercentAppendBar(&valueBar, percent, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(valueNum, "percentage"),
FF_FORMAT_ARG(item->name, "name"),
FF_FORMAT_ARG(item->max, "max"),
FF_FORMAT_ARG(item->min, "min"),
FF_FORMAT_ARG(item->current, "current"),
FF_FORMAT_ARG(item->current, "percentage-bar"),
FF_FORMAT_ARG(valueBar, "percentage-bar"),
}));
}

Expand Down
14 changes: 10 additions & 4 deletions src/modules/btrfs/btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
double usedPercentage = total > 0 ? (double) used / (double) total * 100.0 : 0;
double allocatedPercentage = total > 0 ? (double) allocated / (double) total * 100.0 : 0;

FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;

if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(buffer.chars, index, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
Expand All @@ -60,14 +62,18 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
else
{
FF_STRBUF_AUTO_DESTROY usedPercentageNum = ffStrbufCreate();
ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY usedPercentageBar = ffStrbufCreate();
ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs);

FF_STRBUF_AUTO_DESTROY allocatedPercentageNum = ffStrbufCreate();
ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY allocatedPercentageBar = ffStrbufCreate();
ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs);

FF_STRBUF_AUTO_DESTROY nodeSizePretty = ffStrbufCreate();
ffParseSize(result->nodeSize, &nodeSizePretty);
Expand Down
19 changes: 13 additions & 6 deletions src/modules/cpuusage/cpuusage.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,24 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY avgNum = ffStrbufCreate();
ffPercentAppendNum(&avgNum, avgValue, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&avgNum, avgValue, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY avgBar = ffStrbufCreate();
ffPercentAppendBar(&avgBar, avgValue, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&avgBar, avgValue, options->percent, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY minNum = ffStrbufCreate();
ffPercentAppendNum(&minNum, minValue, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&minNum, minValue, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY minBar = ffStrbufCreate();
ffPercentAppendBar(&minBar, minValue, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&minBar, minValue, options->percent, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY maxNum = ffStrbufCreate();
ffPercentAppendNum(&maxNum, maxValue, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&maxNum, maxValue, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY maxBar = ffStrbufCreate();
ffPercentAppendBar(&maxBar, maxValue, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(avgNum, "avg"),
FF_FORMAT_ARG(maxNum, "max"),
Expand Down
12 changes: 8 additions & 4 deletions src/modules/disk/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
else
{
FF_STRBUF_AUTO_DESTROY bytesPercentageNum = ffStrbufCreate();
ffPercentAppendNum(&bytesPercentageNum, bytesPercentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&bytesPercentageNum, bytesPercentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY bytesPercentageBar = ffStrbufCreate();
ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs);

double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0;
FF_STRBUF_AUTO_DESTROY filesPercentageNum = ffStrbufCreate();
ffPercentAppendNum(&filesPercentageNum, filesPercentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&filesPercentageNum, filesPercentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY filesPercentageBar = ffStrbufCreate();
ffPercentAppendBar(&filesPercentageBar, filesPercentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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);
Expand Down
8 changes: 5 additions & 3 deletions src/modules/gamepad/gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

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

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 (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
{
Expand All @@ -37,9 +37,11 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
else
{
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(device->name, "name"),
Expand Down
9 changes: 6 additions & 3 deletions src/modules/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void ffPrintMemory(FFMemoryOptions* options)
? 0
: (double) storage.bytesUsed / (double) storage.bytesTotal * 100.0;

FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
Expand All @@ -37,7 +38,6 @@ 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(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
Expand All @@ -58,9 +58,12 @@ void ffPrintMemory(FFMemoryOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(usedPretty, "used"),
FF_FORMAT_ARG(totalPretty, "total"),
Expand Down
8 changes: 5 additions & 3 deletions src/modules/sound/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, uint8_t index)
{
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
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 (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
Expand Down Expand Up @@ -48,9 +48,11 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui
else
{
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
ffPercentAppendNum(&percentageNum, device->volume, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentageNum, device->volume, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
ffPercentAppendBar(&percentageBar, device->volume, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(device->main, "is-main"),
Expand Down
8 changes: 5 additions & 3 deletions src/modules/swap/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ void ffPrintSwap(FFSwapOptions* options)
? 0
: (double) storage.bytesUsed / (double) storage.bytesTotal * 100.0;

FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
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)
{
Expand Down Expand Up @@ -68,9 +68,11 @@ void ffPrintSwap(FFSwapOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentageNum, percentage, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
ffPercentAppendBar(&percentageBar, percentage, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
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(usedPretty, "used"),
FF_FORMAT_ARG(totalPretty, "total"),
Expand Down
7 changes: 5 additions & 2 deletions src/modules/wifi/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ void ffPrintWifi(FFWifiOptions* options)
else
{
FF_STRBUF_AUTO_DESTROY percentNum = ffStrbufCreate();
ffPercentAppendNum(&percentNum, item->conn.signalQuality, options->percent, false, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
ffPercentAppendNum(&percentNum, item->conn.signalQuality, options->percent, false, &options->moduleArgs);
FF_STRBUF_AUTO_DESTROY percentBar = ffStrbufCreate();
ffPercentAppendBar(&percentBar, item->conn.signalQuality, options->percent, &options->moduleArgs);
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffPercentAppendBar(&percentBar, item->conn.signalQuality, options->percent, &options->moduleArgs);

FF_PRINT_FORMAT_CHECKED(FF_WIFI_MODULE_NAME, moduleIndex, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WIFI_NUM_FORMAT_ARGS, ((FFformatarg[]){
FF_FORMAT_ARG(item->inf.description, "inf-desc"),
FF_FORMAT_ARG(item->inf.status, "inf-status"),
Expand Down
Loading

0 comments on commit 782af25

Please sign in to comment.