mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 08:13:44 +01:00
Refactor package detection code
This commit is contained in:
+35
-58
@@ -7,11 +7,9 @@
|
||||
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
FFPackageCounts counts = {0};
|
||||
ffStrbufInit(&counts.pacmanBranch);
|
||||
ffDetectPackages(instance, &counts);
|
||||
const FFPackagesResult* counts = ffDetectPackages(instance);
|
||||
uint32_t all = counts->all; //Copy it, so we can substract from it in FF_PRINT_PACKAGE
|
||||
|
||||
uint32_t all = counts.pacman + counts.dpkg + counts.rpm + counts.emerge + counts.xbps + counts.nixSystem + counts.nixUser + counts.nixDefault + counts.apk + counts.pkg + counts.flatpak + counts.snap + counts.brew + counts.port + counts.scoop;
|
||||
if(all == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, "No packages from known package managers found");
|
||||
@@ -22,20 +20,22 @@ void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages.key);
|
||||
|
||||
#define FF_PRINT_PACKAGE(name) \
|
||||
if(counts.name > 0) \
|
||||
{ \
|
||||
printf("%u ("#name")", counts.name); \
|
||||
if((all = all - counts.name) > 0) \
|
||||
printf(", "); \
|
||||
};
|
||||
#define FF_PRINT_PACKAGE_NAME(var, name) \
|
||||
if(counts->var > 0) \
|
||||
{ \
|
||||
printf("%u ("name")", counts->var); \
|
||||
if((all -= counts->var) > 0) \
|
||||
printf(", "); \
|
||||
};
|
||||
|
||||
if(counts.pacman > 0)
|
||||
#define FF_PRINT_PACKAGE(name) FF_PRINT_PACKAGE_NAME(name, #name)
|
||||
|
||||
if(counts->pacman > 0)
|
||||
{
|
||||
printf("%u (pacman)", counts.pacman);
|
||||
if(counts.pacmanBranch.length > 0)
|
||||
printf("[%s]", counts.pacmanBranch.chars);
|
||||
if((all = all - counts.pacman) > 0)
|
||||
printf("%u (pacman)", counts->pacman);
|
||||
if(counts->pacmanBranch.length > 0)
|
||||
printf("[%s]", counts->pacmanBranch.chars);
|
||||
if((all -= counts->pacman) > 0)
|
||||
printf(", ");
|
||||
};
|
||||
|
||||
@@ -43,28 +43,9 @@ void ffPrintPackages(FFinstance* instance)
|
||||
FF_PRINT_PACKAGE(rpm)
|
||||
FF_PRINT_PACKAGE(emerge)
|
||||
FF_PRINT_PACKAGE(xbps)
|
||||
|
||||
if(counts.nixSystem > 0)
|
||||
{
|
||||
printf("%u (nix-system)", counts.nixSystem);
|
||||
if((all = all - counts.nixSystem) > 0)
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
if(counts.nixUser > 0)
|
||||
{
|
||||
printf("%u (nix-user)", counts.nixUser);
|
||||
if((all = all - counts.nixUser) > 0)
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
if(counts.nixDefault > 0)
|
||||
{
|
||||
printf("%u (nix-default)", counts.nixDefault);
|
||||
if((all = all - counts.nixDefault) > 0)
|
||||
printf(", ");
|
||||
}
|
||||
|
||||
FF_PRINT_PACKAGE_NAME(nixSystem, "nix-system")
|
||||
FF_PRINT_PACKAGE_NAME(nixUser, "nix-user")
|
||||
FF_PRINT_PACKAGE_NAME(nixDefault, "nix-default")
|
||||
FF_PRINT_PACKAGE(apk)
|
||||
FF_PRINT_PACKAGE(pkg)
|
||||
FF_PRINT_PACKAGE(flatpak)
|
||||
@@ -76,32 +57,28 @@ void ffPrintPackages(FFinstance* instance)
|
||||
//Fix linter warning of unused value of all
|
||||
(void) all;
|
||||
|
||||
#undef FF_PRINT_PACKAGE
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &all},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.pacman},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &counts.pacmanBranch},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.dpkg},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.rpm},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.emerge},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.xbps},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixSystem},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixUser},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixDefault},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.apk},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.pkg},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.flatpak},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.snap},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.brew},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.port},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts.scoop}
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->pacman},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &counts->pacmanBranch},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->dpkg},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->rpm},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->emerge},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->xbps},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->nixSystem},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->nixUser},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->nixDefault},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->apk},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->pkg},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->flatpak},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->snap},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->brew},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->port},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &counts->scoop}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&counts.pacmanBranch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user