Files
fastfetch/src/modules/users.c
T

53 lines
1.3 KiB
C
Raw Normal View History

2022-09-26 14:57:27 +08:00
#include "fastfetch.h"
#include "common/printing.h"
2022-10-06 17:47:49 +08:00
#include "detection/users/users.h"
2022-09-26 14:57:27 +08:00
#define FF_USERS_MODULE_NAME "Users"
#define FF_USERS_NUM_FORMAT_ARGS 1
void ffPrintUsers(FFinstance* instance)
{
FFlist users;
2022-10-06 17:47:49 +08:00
ffListInit(&users, sizeof(FFstrbuf));
2022-09-26 14:57:27 +08:00
2022-10-06 17:47:49 +08:00
FFstrbuf error;
ffStrbufInit(&error);
2022-09-29 15:53:28 +02:00
2022-10-06 17:47:49 +08:00
ffDetectUsers(&users, &error);
2022-09-26 14:57:27 +08:00
2022-10-06 17:47:49 +08:00
if(error.length > 0)
2022-09-26 23:45:46 +08:00
{
2022-10-06 17:47:49 +08:00
ffPrintError(instance, FF_USERS_MODULE_NAME, 0, &instance->config.users, "%*s", error.length, error.chars);
2022-09-26 23:45:46 +08:00
ffListDestroy(&users);
2022-10-06 17:47:49 +08:00
ffStrbufDestroy(&error);
2022-09-26 23:45:46 +08:00
return;
}
2022-09-26 14:57:27 +08:00
FFstrbuf result;
ffStrbufInit(&result);
for(uint32_t i = 0; i < users.length; ++i)
{
if(i > 0)
ffStrbufAppendS(&result, ", ");
2022-10-06 17:47:49 +08:00
FFstrbuf* user = (FFstrbuf*)ffListGet(&users, i);
ffStrbufAppend(&result, user);
ffStrbufDestroy(user);
2022-09-26 14:57:27 +08:00
}
2022-10-06 17:47:49 +08:00
2022-09-26 14:57:27 +08:00
ffListDestroy(&users);
2022-09-26 23:45:46 +08:00
if(instance->config.users.outputFormat.length == 0)
2022-09-26 14:57:27 +08:00
{
2022-09-26 23:45:46 +08:00
ffPrintLogoAndKey(instance, FF_USERS_MODULE_NAME, 0, &instance->config.users.key);
2022-09-26 14:57:27 +08:00
puts(result.chars);
}
else
{
2022-09-26 23:45:46 +08:00
ffPrintFormat(instance, FF_USERS_MODULE_NAME, 0, &instance->config.users, FF_USERS_NUM_FORMAT_ARGS, (FFformatarg[]){
2022-09-26 14:57:27 +08:00
{FF_FORMAT_ARG_TYPE_STRBUF, &result},
});
}
ffStrbufDestroy(&result);
}