mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-28 15:53:51 +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:
+51
-70
@@ -7,64 +7,55 @@
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format
|
||||
|
||||
bool ffPrintUsers(FFUsersOptions* options)
|
||||
{
|
||||
bool ffPrintUsers(FFUsersOptions* options) {
|
||||
FF_LIST_AUTO_DESTROY users = ffListCreate(sizeof(FFUserResult));
|
||||
|
||||
const char* error = ffDetectUsers(options, &users);
|
||||
|
||||
if(error)
|
||||
{
|
||||
if (error) {
|
||||
ffPrintError(FF_USERS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(users.length == 0)
|
||||
{
|
||||
if (users.length == 0) {
|
||||
ffPrintError(FF_USERS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "Unable to detect any users");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
if(options->compact)
|
||||
{
|
||||
if (options->moduleArgs.outputFormat.length == 0) {
|
||||
if (options->compact) {
|
||||
ffPrintLogoAndKey(FF_USERS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
for(uint32_t i = 0; i < users.length; ++i)
|
||||
{
|
||||
if(i > 0)
|
||||
for (uint32_t i = 0; i < users.length; ++i) {
|
||||
if (i > 0) {
|
||||
ffStrbufAppendS(&result, ", ");
|
||||
}
|
||||
FFUserResult* user = FF_LIST_GET(FFUserResult, users, i);
|
||||
ffStrbufAppend(&result, &user->name);
|
||||
}
|
||||
ffStrbufPutTo(&result, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(uint32_t i = 0; i < users.length; ++i)
|
||||
{
|
||||
} else {
|
||||
for (uint32_t i = 0; i < users.length; ++i) {
|
||||
FFUserResult* user = FF_LIST_GET(FFUserResult, users, i);
|
||||
|
||||
ffPrintLogoAndKey(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateCopy(&user->name);
|
||||
if(user->hostName.length)
|
||||
if (user->hostName.length) {
|
||||
ffStrbufAppendF(&result, "@%s", user->hostName.chars);
|
||||
}
|
||||
|
||||
if(user->loginTime)
|
||||
if (user->loginTime) {
|
||||
ffStrbufAppendF(&result, " - login time %s", ffTimeToShortStr(user->loginTime));
|
||||
}
|
||||
|
||||
ffStrbufPutTo(&result, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint64_t now = ffTimeGetNow();
|
||||
for(uint32_t i = 0; i < users.length; ++i)
|
||||
{
|
||||
for (uint32_t i = 0; i < users.length; ++i) {
|
||||
FFUserResult* user = FF_LIST_GET(FFUserResult, users, i);
|
||||
|
||||
uint64_t duration = now - user->loginTime;
|
||||
@@ -80,26 +71,25 @@ bool ffPrintUsers(FFUsersOptions* options)
|
||||
|
||||
FFTimeGetAgeResult age = ffTimeGetAge(user->loginTime, ffTimeGetNow());
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
|
||||
FF_ARG(user->name, "name"),
|
||||
FF_ARG(user->hostName, "host-name"),
|
||||
FF_ARG(user->sessionName, "session-name"),
|
||||
FF_ARG(user->clientIp, "client-ip"),
|
||||
{FF_ARG_TYPE_STRING, ffTimeToShortStr(user->loginTime), "login-time"},
|
||||
FF_ARG(days, "days"),
|
||||
FF_ARG(hours, "hours"),
|
||||
FF_ARG(minutes, "minutes"),
|
||||
FF_ARG(seconds, "seconds"),
|
||||
FF_ARG(milliseconds, "milliseconds"),
|
||||
FF_ARG(age.years, "years"),
|
||||
FF_ARG(age.daysOfYear, "days-of-year"),
|
||||
FF_ARG(age.yearsFraction, "years-fraction"),
|
||||
}));
|
||||
FF_PRINT_FORMAT_CHECKED(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
|
||||
FF_ARG(user->name, "name"),
|
||||
FF_ARG(user->hostName, "host-name"),
|
||||
FF_ARG(user->sessionName, "session-name"),
|
||||
FF_ARG(user->clientIp, "client-ip"),
|
||||
{FF_ARG_TYPE_STRING, ffTimeToShortStr(user->loginTime), "login-time"},
|
||||
FF_ARG(days, "days"),
|
||||
FF_ARG(hours, "hours"),
|
||||
FF_ARG(minutes, "minutes"),
|
||||
FF_ARG(seconds, "seconds"),
|
||||
FF_ARG(milliseconds, "milliseconds"),
|
||||
FF_ARG(age.years, "years"),
|
||||
FF_ARG(age.daysOfYear, "days-of-year"),
|
||||
FF_ARG(age.yearsFraction, "years-fraction"),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFUserResult, user, users)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFUserResult, user, users) {
|
||||
ffStrbufDestroy(&user->clientIp);
|
||||
ffStrbufDestroy(&user->hostName);
|
||||
ffStrbufDestroy(&user->sessionName);
|
||||
@@ -109,26 +99,24 @@ bool ffPrintUsers(FFUsersOptions* options)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module) {
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(module, idx, max, key, val)
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "type") || unsafe_yyjson_equals_str(key, "condition"))
|
||||
yyjson_obj_foreach (module, idx, max, key, val) {
|
||||
if (unsafe_yyjson_equals_str(key, "type") || unsafe_yyjson_equals_str(key, "condition")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "compact"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "compact")) {
|
||||
options->compact = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "myselfOnly"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "myselfOnly")) {
|
||||
options->myselfOnly = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
@@ -137,8 +125,7 @@ void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module)
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateUsersJsonConfig(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateUsersJsonConfig(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
||||
|
||||
yyjson_mut_obj_add_bool(doc, module, "compact", options->compact);
|
||||
@@ -146,35 +133,32 @@ void ffGenerateUsersJsonConfig(FFUsersOptions* options, yyjson_mut_doc* doc, yyj
|
||||
yyjson_mut_obj_add_bool(doc, module, "myselfOnly", options->myselfOnly);
|
||||
}
|
||||
|
||||
bool ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
bool ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFUserResult));
|
||||
|
||||
const char* error = ffDetectUsers(options, &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(FFUserResult, user, results)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFUserResult, user, results) {
|
||||
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &user->name);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "hostName", &user->hostName);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "sessionName", &user->sessionName);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "clientIp", &user->clientIp);
|
||||
const char* pstr = ffTimeToFullStr(user->loginTime);
|
||||
if (*pstr)
|
||||
if (*pstr) {
|
||||
yyjson_mut_obj_add_strcpy(doc, obj, "loginTime", pstr);
|
||||
else
|
||||
} else {
|
||||
yyjson_mut_obj_add_null(doc, obj, "loginTime");
|
||||
}
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFUserResult, user, results)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFUserResult, user, results) {
|
||||
ffStrbufDestroy(&user->clientIp);
|
||||
ffStrbufDestroy(&user->hostName);
|
||||
ffStrbufDestroy(&user->sessionName);
|
||||
@@ -184,16 +168,14 @@ bool ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyj
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitUsersOptions(FFUsersOptions* options)
|
||||
{
|
||||
void ffInitUsersOptions(FFUsersOptions* options) {
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
options->compact = false;
|
||||
options->myselfOnly = false;
|
||||
}
|
||||
|
||||
void ffDestroyUsersOptions(FFUsersOptions* options)
|
||||
{
|
||||
void ffDestroyUsersOptions(FFUsersOptions* options) {
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -220,5 +202,4 @@ FFModuleBaseInfo ffUsersModuleInfo = {
|
||||
{"Years integer after login", "years"},
|
||||
{"Days of year after login", "days-of-year"},
|
||||
{"Years fraction after login", "years-fraction"},
|
||||
}))
|
||||
};
|
||||
}))};
|
||||
|
||||
Reference in New Issue
Block a user