mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 12:14:19 +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:
+56
-73
@@ -6,29 +6,25 @@
|
||||
#include "detection/btrfs/btrfs.h"
|
||||
#include "modules/btrfs/btrfs.h"
|
||||
|
||||
static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t index)
|
||||
{
|
||||
static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t index) {
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
if (options->moduleArgs.key.length == 0)
|
||||
{
|
||||
if (result->name.length > 0)
|
||||
if (options->moduleArgs.key.length == 0) {
|
||||
if (result->name.length > 0) {
|
||||
ffStrbufSetF(&buffer, "%s (%s)", FF_BTRFS_MODULE_NAME, result->name.chars);
|
||||
else
|
||||
} else {
|
||||
ffStrbufSetS(&buffer, FF_BTRFS_MODULE_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
} else {
|
||||
ffStrbufClear(&buffer);
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(&buffer, &options->moduleArgs.key, ((FFformatarg[]) {
|
||||
FF_ARG(index, "index"),
|
||||
FF_ARG(result->name, "name"),
|
||||
FF_ARG(options->moduleArgs.keyIcon, "icon"),
|
||||
}));
|
||||
FF_ARG(index, "index"),
|
||||
FF_ARG(result->name, "name"),
|
||||
FF_ARG(options->moduleArgs.keyIcon, "icon"),
|
||||
}));
|
||||
}
|
||||
|
||||
uint64_t used = 0, allocated = 0, total = result->totalSize;
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(result->allocation); ++i)
|
||||
{
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(result->allocation); ++i) {
|
||||
uint64_t times = result->allocation[i].copies;
|
||||
used += result->allocation[i].used * times;
|
||||
allocated += result->allocation[i].total * times;
|
||||
@@ -46,8 +42,7 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
|
||||
|
||||
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(buffer.chars, index, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
|
||||
|
||||
ffStrbufClear(&buffer);
|
||||
@@ -57,22 +52,24 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
|
||||
ffPercentAppendNum(&buffer, allocatedPercentage, options->percent, false, &options->moduleArgs);
|
||||
ffStrbufAppendF(&buffer, " allocated)");
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
FF_STRBUF_AUTO_DESTROY usedPercentageNum = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT) {
|
||||
ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs);
|
||||
}
|
||||
FF_STRBUF_AUTO_DESTROY usedPercentageBar = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT) {
|
||||
ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs);
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY allocatedPercentageNum = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT) {
|
||||
ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs);
|
||||
}
|
||||
FF_STRBUF_AUTO_DESTROY allocatedPercentageBar = ffStrbufCreate();
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT) {
|
||||
ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs);
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY nodeSizePretty = ffStrbufCreate();
|
||||
ffSizeAppendNum(result->nodeSize, &nodeSizePretty);
|
||||
@@ -80,49 +77,44 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
|
||||
ffSizeAppendNum(result->sectorSize, §orSizePretty);
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(buffer.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]) {
|
||||
FF_ARG(result->name, "name"),
|
||||
FF_ARG(result->uuid, "uuid"),
|
||||
FF_ARG(result->devices, "devices"),
|
||||
FF_ARG(result->features, "features"),
|
||||
FF_ARG(usedPretty, "used"),
|
||||
FF_ARG(allocatedPretty, "allocated"),
|
||||
FF_ARG(totalPretty, "total"),
|
||||
FF_ARG(usedPercentageNum, "used-percentage"),
|
||||
FF_ARG(allocatedPercentageNum, "allocated-percentage"),
|
||||
FF_ARG(usedPercentageBar, "used-percentage-bar"),
|
||||
FF_ARG(allocatedPercentageBar, "allocated-percentage-bar"),
|
||||
FF_ARG(nodeSizePretty, "node-size"),
|
||||
FF_ARG(sectorSizePretty, "sector-size"),
|
||||
}));
|
||||
FF_ARG(result->name, "name"),
|
||||
FF_ARG(result->uuid, "uuid"),
|
||||
FF_ARG(result->devices, "devices"),
|
||||
FF_ARG(result->features, "features"),
|
||||
FF_ARG(usedPretty, "used"),
|
||||
FF_ARG(allocatedPretty, "allocated"),
|
||||
FF_ARG(totalPretty, "total"),
|
||||
FF_ARG(usedPercentageNum, "used-percentage"),
|
||||
FF_ARG(allocatedPercentageNum, "allocated-percentage"),
|
||||
FF_ARG(usedPercentageBar, "used-percentage-bar"),
|
||||
FF_ARG(allocatedPercentageBar, "allocated-percentage-bar"),
|
||||
FF_ARG(nodeSizePretty, "node-size"),
|
||||
FF_ARG(sectorSizePretty, "sector-size"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
bool ffPrintBtrfs(FFBtrfsOptions* options)
|
||||
{
|
||||
bool ffPrintBtrfs(FFBtrfsOptions* options) {
|
||||
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult));
|
||||
|
||||
const char* error = ffDetectBtrfs(&results);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
if(results.length == 0)
|
||||
{
|
||||
if (results.length == 0) {
|
||||
ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No btrfs drive found");
|
||||
return false;
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < results.length; i++)
|
||||
{
|
||||
for (uint32_t i = 0; i < results.length; i++) {
|
||||
FFBtrfsResult* result = FF_LIST_GET(FFBtrfsResult, results, i);
|
||||
uint8_t index = results.length == 1 ? 0 : (uint8_t) (i + 1);
|
||||
printBtrfs(options, result, index);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFBtrfsResult, result, results)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFBtrfsResult, result, results) {
|
||||
ffStrbufDestroy(&result->name);
|
||||
ffStrbufDestroy(&result->uuid);
|
||||
ffStrbufDestroy(&result->devices);
|
||||
@@ -132,44 +124,40 @@ bool ffPrintBtrfs(FFBtrfsOptions* options)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseBtrfsJsonObject(FFBtrfsOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseBtrfsJsonObject(FFBtrfsOptions* 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 (ffPercentParseJsonObject(key, val, &options->percent))
|
||||
if (ffPercentParseJsonObject(key, val, &options->percent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateBtrfsJsonConfig(FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateBtrfsJsonConfig(FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
||||
|
||||
ffPercentGenerateJsonConfig(doc, module, options->percent);
|
||||
}
|
||||
|
||||
bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult));
|
||||
|
||||
const char* error = ffDetectBtrfs(&results);
|
||||
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(FFBtrfsResult, btrfs, results)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFBtrfsResult, btrfs, results) {
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &btrfs->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "uuid", &btrfs->uuid);
|
||||
@@ -180,8 +168,7 @@ bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
|
||||
yyjson_mut_obj_add_uint(doc, obj, "sectorSize", btrfs->sectorSize);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "totalSize", btrfs->totalSize);
|
||||
yyjson_mut_val* allocation = yyjson_mut_obj_add_arr(doc, obj, "allocation");
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(btrfs->allocation); ++i)
|
||||
{
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(btrfs->allocation); ++i) {
|
||||
yyjson_mut_val* item = yyjson_mut_arr_add_obj(doc, allocation);
|
||||
yyjson_mut_obj_add_str(doc, item, "type", btrfs->allocation[i].type);
|
||||
yyjson_mut_obj_add_str(doc, item, "profile", btrfs->allocation[i].profile);
|
||||
@@ -191,8 +178,7 @@ bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
|
||||
}
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFBtrfsResult, btrfs, results)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFBtrfsResult, btrfs, results) {
|
||||
ffStrbufDestroy(&btrfs->name);
|
||||
ffStrbufDestroy(&btrfs->uuid);
|
||||
ffStrbufDestroy(&btrfs->devices);
|
||||
@@ -202,14 +188,12 @@ bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitBtrfsOptions(FFBtrfsOptions* options)
|
||||
{
|
||||
void ffInitBtrfsOptions(FFBtrfsOptions* options) {
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };
|
||||
options->percent = (FFPercentageModuleConfig) {50, 80, 0};
|
||||
}
|
||||
|
||||
void ffDestroyBtrfsOptions(FFBtrfsOptions* options)
|
||||
{
|
||||
void ffDestroyBtrfsOptions(FFBtrfsOptions* options) {
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -236,5 +220,4 @@ FFModuleBaseInfo ffBtrfsModuleInfo = {
|
||||
{"Allocated percentage bar", "allocated-percentage-bar"},
|
||||
{"Node size", "node-size"},
|
||||
{"Sector size", "sector-size"},
|
||||
}))
|
||||
};
|
||||
}))};
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include "common/option.h"
|
||||
#include "common/percent.h"
|
||||
|
||||
typedef struct FFBtrfsOptions
|
||||
{
|
||||
typedef struct FFBtrfsOptions {
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFPercentageModuleConfig percent;
|
||||
|
||||
Reference in New Issue
Block a user