mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +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:
+67
-82
@@ -7,38 +7,32 @@
|
||||
|
||||
#define FF_NETIO_DISPLAY_NAME "Network IO"
|
||||
|
||||
static int sortInfs(const FFNetIOResult* left, const FFNetIOResult* right)
|
||||
{
|
||||
static int sortInfs(const FFNetIOResult* left, const FFNetIOResult* right) {
|
||||
return ffStrbufComp(&left->name, &right->name);
|
||||
}
|
||||
|
||||
static void formatKey(const FFNetIOOptions* options, FFNetIOResult* inf, uint32_t index, FFstrbuf* key)
|
||||
{
|
||||
if(options->moduleArgs.key.length == 0)
|
||||
{
|
||||
if(!inf->name.length)
|
||||
static void formatKey(const FFNetIOOptions* options, FFNetIOResult* inf, uint32_t index, FFstrbuf* key) {
|
||||
if (options->moduleArgs.key.length == 0) {
|
||||
if (!inf->name.length) {
|
||||
ffStrbufSetF(&inf->name, "unknown %u", (unsigned) index);
|
||||
}
|
||||
|
||||
ffStrbufSetF(key, FF_NETIO_DISPLAY_NAME " (%s)", inf->name.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ffStrbufClear(key);
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, ((FFformatarg[]){
|
||||
FF_ARG(index, "index"),
|
||||
FF_ARG(inf->name, "name"),
|
||||
FF_ARG(options->moduleArgs.keyIcon, "icon"),
|
||||
}));
|
||||
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, ((FFformatarg[]) {
|
||||
FF_ARG(index, "index"),
|
||||
FF_ARG(inf->name, "name"),
|
||||
FF_ARG(options->moduleArgs.keyIcon, "icon"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
bool ffPrintNetIO(FFNetIOOptions* options)
|
||||
{
|
||||
bool ffPrintNetIO(FFNetIOOptions* options) {
|
||||
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
|
||||
const char* error = ffDetectNetIO(&result, options);
|
||||
|
||||
if(error)
|
||||
{
|
||||
if (error) {
|
||||
ffPrintError(FF_NETIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
@@ -50,90 +44,89 @@ bool ffPrintNetIO(FFNetIOOptions* options)
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY buffer2 = ffStrbufCreate();
|
||||
|
||||
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFNetIOResult, inf, result) {
|
||||
formatKey(options, inf, result.length == 1 ? 0 : index + 1, &key);
|
||||
ffStrbufClear(&buffer);
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
if (options->moduleArgs.outputFormat.length == 0) {
|
||||
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
|
||||
|
||||
ffSizeAppendNum(inf->rxBytes, &buffer);
|
||||
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
|
||||
if (!options->detectTotal) {
|
||||
ffStrbufAppendS(&buffer, "/s");
|
||||
}
|
||||
ffStrbufAppendS(&buffer, " (IN) - ");
|
||||
|
||||
ffSizeAppendNum(inf->txBytes, &buffer);
|
||||
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
|
||||
if (!options->detectTotal) {
|
||||
ffStrbufAppendS(&buffer, "/s");
|
||||
}
|
||||
ffStrbufAppendS(&buffer, " (OUT)");
|
||||
|
||||
if (inf->defaultRoute && !options->defaultRouteOnly)
|
||||
if (inf->defaultRoute && !options->defaultRouteOnly) {
|
||||
ffStrbufAppendS(&buffer, " *");
|
||||
}
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ffStrbufClear(&buffer2);
|
||||
ffSizeAppendNum(inf->rxBytes, &buffer);
|
||||
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
|
||||
if (!options->detectTotal) {
|
||||
ffStrbufAppendS(&buffer, "/s");
|
||||
}
|
||||
ffSizeAppendNum(inf->txBytes, &buffer2);
|
||||
if (!options->detectTotal) ffStrbufAppendS(&buffer2, "/s");
|
||||
if (!options->detectTotal) {
|
||||
ffStrbufAppendS(&buffer2, "/s");
|
||||
}
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]){
|
||||
FF_ARG(buffer, "rx-size"),
|
||||
FF_ARG(buffer2, "tx-size"),
|
||||
FF_ARG(inf->name, "ifname"),
|
||||
FF_ARG(inf->defaultRoute, "is-default-route"),
|
||||
FF_ARG(inf->txBytes, "tx-bytes"),
|
||||
FF_ARG(inf->rxBytes, "rx-bytes"),
|
||||
FF_ARG(inf->txPackets, "tx-packets"),
|
||||
FF_ARG(inf->rxPackets, "rx-packets"),
|
||||
FF_ARG(inf->rxErrors, "rx-errors"),
|
||||
FF_ARG(inf->txErrors, "tx-errors"),
|
||||
FF_ARG(inf->rxDrops, "rx-drops"),
|
||||
FF_ARG(inf->txDrops, "tx-drops"),
|
||||
}));
|
||||
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]) {
|
||||
FF_ARG(buffer, "rx-size"),
|
||||
FF_ARG(buffer2, "tx-size"),
|
||||
FF_ARG(inf->name, "ifname"),
|
||||
FF_ARG(inf->defaultRoute, "is-default-route"),
|
||||
FF_ARG(inf->txBytes, "tx-bytes"),
|
||||
FF_ARG(inf->rxBytes, "rx-bytes"),
|
||||
FF_ARG(inf->txPackets, "tx-packets"),
|
||||
FF_ARG(inf->rxPackets, "rx-packets"),
|
||||
FF_ARG(inf->rxErrors, "rx-errors"),
|
||||
FF_ARG(inf->txErrors, "tx-errors"),
|
||||
FF_ARG(inf->rxDrops, "rx-drops"),
|
||||
FF_ARG(inf->txDrops, "tx-drops"),
|
||||
}));
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFNetIOResult, inf, result) {
|
||||
ffStrbufDestroy(&inf->name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseNetIOJsonObject(FFNetIOOptions* 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, "namePrefix"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "namePrefix")) {
|
||||
ffStrbufSetJsonVal(&options->namePrefix, val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "defaultRouteOnly"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "defaultRouteOnly")) {
|
||||
options->defaultRouteOnly = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "detectTotal"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "detectTotal")) {
|
||||
options->detectTotal = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "waitTime"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "waitTime")) {
|
||||
options->waitTime = (uint32_t) yyjson_get_uint(val);
|
||||
continue;
|
||||
}
|
||||
@@ -142,8 +135,7 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
||||
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix);
|
||||
@@ -155,20 +147,17 @@ void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
|
||||
yyjson_mut_obj_add_uint(doc, module, "waitTime", options->waitTime);
|
||||
}
|
||||
|
||||
bool ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
bool ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
|
||||
const char* error = ffDetectNetIO(&result, options);
|
||||
|
||||
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(FFNetIOResult, counter, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFNetIOResult, counter, result) {
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &counter->name);
|
||||
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", counter->defaultRoute);
|
||||
@@ -182,32 +171,29 @@ bool ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
|
||||
yyjson_mut_obj_add_uint(doc, obj, "txDrops", counter->txDrops);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFNetIOResult, inf, result) {
|
||||
ffStrbufDestroy(&inf->name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitNetIOOptions(FFNetIOOptions* options)
|
||||
{
|
||||
void ffInitNetIOOptions(FFNetIOOptions* options) {
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
ffStrbufInit(&options->namePrefix);
|
||||
options->defaultRouteOnly =
|
||||
#if __ANDROID__
|
||||
false
|
||||
#else
|
||||
true
|
||||
#endif
|
||||
;
|
||||
#if __ANDROID__
|
||||
false
|
||||
#else
|
||||
true
|
||||
#endif
|
||||
;
|
||||
options->detectTotal = false;
|
||||
options->waitTime = 1000;
|
||||
}
|
||||
|
||||
void ffDestroyNetIOOptions(FFNetIOOptions* options)
|
||||
{
|
||||
void ffDestroyNetIOOptions(FFNetIOOptions* options) {
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
ffStrbufDestroy(&options->namePrefix);
|
||||
}
|
||||
@@ -234,5 +220,4 @@ FFModuleBaseInfo ffNetIOModuleInfo = {
|
||||
{"Number of errors sent [per second]", "tx-errors"},
|
||||
{"Number of packets dropped when receiving [per second]", "rx-drops"},
|
||||
{"Number of packets dropped when sending [per second]", "tx-drops"},
|
||||
}))
|
||||
};
|
||||
}))};
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFNetIOOptions
|
||||
{
|
||||
typedef struct FFNetIOOptions {
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFstrbuf namePrefix;
|
||||
|
||||
Reference in New Issue
Block a user