mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 14:10:11 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
@@ -5,105 +5,91 @@
|
||||
#include "detection/gamepad/gamepad.h"
|
||||
#include "modules/gamepad/gamepad.h"
|
||||
|
||||
static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device, uint8_t index)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
|
||||
{
|
||||
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))
|
||||
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) {
|
||||
ffStrbufAppend(&buffer, &device->name);
|
||||
}
|
||||
|
||||
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT))
|
||||
{
|
||||
if (buffer.length)
|
||||
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)) {
|
||||
if (buffer.length) {
|
||||
ffStrbufAppendC(&buffer, ' ');
|
||||
}
|
||||
ffPercentAppendNum(&buffer, device->battery, options->percent, buffer.length > 0, &options->moduleArgs);
|
||||
}
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT) {
|
||||
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
|
||||
}
|
||||
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
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, ((FFformatarg[]) {
|
||||
FF_ARG(device->name, "name"),
|
||||
FF_ARG(device->serial, "serial"),
|
||||
FF_ARG(percentageNum, "battery-percentage"),
|
||||
FF_ARG(percentageBar, "battery-percentage-bar"),
|
||||
}));
|
||||
FF_ARG(device->name, "name"),
|
||||
FF_ARG(device->serial, "serial"),
|
||||
FF_ARG(percentageNum, "battery-percentage"),
|
||||
FF_ARG(percentageBar, "battery-percentage-bar"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
bool ffPrintGamepad(FFGamepadOptions* options)
|
||||
{
|
||||
bool ffPrintGamepad(FFGamepadOptions* options) {
|
||||
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice));
|
||||
|
||||
const char* error = ffDetectGamepad(&result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
if (error) {
|
||||
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!result.length)
|
||||
{
|
||||
if (!result.length) {
|
||||
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFGamepadDevice*));
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFGamepadDevice, device, result) {
|
||||
bool ignored = false;
|
||||
FF_LIST_FOR_EACH(FFstrbuf, ignore, options->ignores)
|
||||
{
|
||||
if(ffStrbufStartsWithIgnCase(&device->name, ignore))
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFstrbuf, ignore, options->ignores) {
|
||||
if (ffStrbufStartsWithIgnCase(&device->name, ignore)) {
|
||||
ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!ignored)
|
||||
{
|
||||
if (!ignored) {
|
||||
FFGamepadDevice** ptr = ffListAdd(&filtered);
|
||||
*ptr = device;
|
||||
}
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
if(!filtered.length)
|
||||
{
|
||||
if (!filtered.length) {
|
||||
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "All devices are ignored");
|
||||
ret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint8_t index = 0;
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice*, pdevice, filtered)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFGamepadDevice*, pdevice, filtered) {
|
||||
FFGamepadDevice* device = *pdevice;
|
||||
printDevice(options, device, filtered.length > 1 ? ++index : 0);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFGamepadDevice, device, result) {
|
||||
ffStrbufDestroy(&device->serial);
|
||||
ffStrbufDestroy(&device->name);
|
||||
}
|
||||
@@ -112,23 +98,19 @@ bool ffPrintGamepad(FFGamepadOptions* options)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module) {
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(module, idx, max, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
||||
yyjson_obj_foreach (module, idx, max, key, val) {
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "ignores"))
|
||||
{
|
||||
yyjson_val *elem;
|
||||
if (unsafe_yyjson_equals_str(key, "ignores")) {
|
||||
yyjson_val* elem;
|
||||
size_t eidx, emax;
|
||||
yyjson_arr_foreach(val, eidx, emax, elem)
|
||||
{
|
||||
if (yyjson_is_str(elem))
|
||||
{
|
||||
yyjson_arr_foreach (val, eidx, emax, elem) {
|
||||
if (yyjson_is_str(elem)) {
|
||||
FFstrbuf* strbuf = ffListAdd(&options->ignores);
|
||||
ffStrbufInitJsonVal(strbuf, elem);
|
||||
}
|
||||
@@ -136,50 +118,45 @@ void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ffPercentParseJsonObject(key, val, &options->percent))
|
||||
if (ffPercentParseJsonObject(key, val, &options->percent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
||||
|
||||
if (options->ignores.length > 0)
|
||||
{
|
||||
if (options->ignores.length > 0) {
|
||||
yyjson_mut_val* ignores = yyjson_mut_obj_add_arr(doc, module, "ignores");
|
||||
FF_LIST_FOR_EACH(FFstrbuf, strbuf, options->ignores)
|
||||
FF_LIST_FOR_EACH (FFstrbuf, strbuf, options->ignores) {
|
||||
yyjson_mut_arr_append(ignores, yyjson_mut_strncpy(doc, strbuf->chars, strbuf->length));
|
||||
}
|
||||
}
|
||||
ffPercentGenerateJsonConfig(doc, module, options->percent);
|
||||
}
|
||||
|
||||
bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice));
|
||||
|
||||
const char* error = ffDetectGamepad(&result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
if (error) {
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFGamepadDevice, device, result) {
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &device->serial);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &device->name);
|
||||
|
||||
bool ignored = false;
|
||||
FF_LIST_FOR_EACH(FFstrbuf, ignore, options->ignores)
|
||||
{
|
||||
if(ffStrbufStartsWithIgnCase(&device->name, ignore))
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFstrbuf, ignore, options->ignores) {
|
||||
if (ffStrbufStartsWithIgnCase(&device->name, ignore)) {
|
||||
ignored = true;
|
||||
break;
|
||||
}
|
||||
@@ -187,8 +164,7 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
|
||||
yyjson_mut_obj_add_bool(doc, obj, "ignored", ignored);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFGamepadDevice, device, result) {
|
||||
ffStrbufDestroy(&device->serial);
|
||||
ffStrbufDestroy(&device->name);
|
||||
}
|
||||
@@ -196,20 +172,19 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitGamepadOptions(FFGamepadOptions* options)
|
||||
{
|
||||
void ffInitGamepadOptions(FFGamepadOptions* options) {
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
ffListInit(&options->ignores, sizeof(FFstrbuf));
|
||||
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
|
||||
options->percent = (FFPercentageModuleConfig) {50, 20, 0};
|
||||
}
|
||||
|
||||
void ffDestroyGamepadOptions(FFGamepadOptions* options)
|
||||
{
|
||||
void ffDestroyGamepadOptions(FFGamepadOptions* options) {
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, str, options->ignores)
|
||||
FF_LIST_FOR_EACH (FFstrbuf, str, options->ignores) {
|
||||
ffStrbufDestroy(str);
|
||||
}
|
||||
ffListDestroy(&options->ignores);
|
||||
}
|
||||
|
||||
@@ -227,5 +202,4 @@ FFModuleBaseInfo ffGamepadModuleInfo = {
|
||||
{"Serial number", "serial"},
|
||||
{"Battery percentage num", "battery-percentage"},
|
||||
{"Battery percentage bar", "battery-percentage-bar"},
|
||||
}))
|
||||
};
|
||||
}))};
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "common/option.h"
|
||||
#include "common/FFlist.h"
|
||||
|
||||
typedef struct FFGamepadOptions
|
||||
{
|
||||
typedef struct FFGamepadOptions {
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFlist ignores; // List of FFstrbuf
|
||||
|
||||
Reference in New Issue
Block a user