mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Bluetooth / Gamepad / Sound: support percentage number formatting
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "common/percent.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "detection/bluetooth/bluetooth.h"
|
||||
@@ -11,23 +12,29 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
ffStrbufWriteTo(&device->name, stdout);
|
||||
|
||||
if(device->battery > 0)
|
||||
printf(" (%d%%)", device->battery);
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateCopy(&device->name);
|
||||
|
||||
if(!device->connected)
|
||||
puts(" [disconnected]");
|
||||
else
|
||||
putchar('\n');
|
||||
if (device->battery > 0 && device->battery <= 100)
|
||||
{
|
||||
if (buffer.length)
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
ffAppendPercentNum(&buffer, device->battery, 50, 20, buffer.length > 0);
|
||||
}
|
||||
|
||||
if (!device->connected)
|
||||
ffStrbufAppendS(&buffer, " [disconnected]");
|
||||
}
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
|
||||
ffAppendPercentNum(&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},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->address},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->type},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &device->battery}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,27 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
|
||||
{
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateCopy(&device->name);
|
||||
ffPrintLogoAndKey(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateCopy(&device->name);
|
||||
|
||||
if (device->battery > 0 && device->battery <= 100)
|
||||
{
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
ffAppendPercentNum(&buffer, device->battery, 51, 21, true);
|
||||
if (buffer.length)
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
ffAppendPercentNum(&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);
|
||||
|
||||
ffPrintFormat(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->serial},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &device->battery},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -130,7 +136,7 @@ void ffPrintGamepadHelpFormat(void)
|
||||
ffPrintModuleFormatHelp(FF_GAMEPAD_MODULE_NAME, "{1}", FF_GAMEPAD_NUM_FORMAT_ARGS, (const char* []) {
|
||||
"Name",
|
||||
"Serial number",
|
||||
"Battery",
|
||||
"Battery percentage",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "common/percent.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "detection/sound/sound.h"
|
||||
@@ -11,27 +12,47 @@ 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);
|
||||
ffStrbufWriteTo(&device->name, stdout);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
|
||||
ffStrbufAppend(&str, &device->name);
|
||||
|
||||
if(device->volume != FF_SOUND_VOLUME_UNKNOWN)
|
||||
{
|
||||
if(device->volume > 0)
|
||||
printf(" (%d%%)", device->volume);
|
||||
else
|
||||
fputs(" (muted)", stdout);
|
||||
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
if (str.length)
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
|
||||
ffAppendPercentBar(&str, device->volume, 80, 90);
|
||||
}
|
||||
|
||||
if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
{
|
||||
if (str.length)
|
||||
ffStrbufAppendC(&str, ' ');
|
||||
|
||||
ffAppendPercentNum(&str, device->volume, 80, 90, str.length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(device->main && index > 0)
|
||||
fputs(" (*)", stdout);
|
||||
if (!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
|
||||
{
|
||||
if (device->main && index > 0)
|
||||
ffStrbufAppendS(&str, " (*)");
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate();
|
||||
ffAppendPercentNum(&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},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &device->volume},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ void ffPrintSwap(FFSwapOptions* options)
|
||||
}
|
||||
if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
|
||||
ffStrbufAppendS(&str, "Disabled");
|
||||
else
|
||||
ffAppendPercentNum(&str, 0, 50, 80, str.length > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user