2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-10-08 17:41:25 +08:00
|
|
|
#include "detection/packages/packages.h"
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_PACKAGES_MODULE_NAME "Packages"
|
2022-10-08 17:41:25 +08:00
|
|
|
#define FF_PACKAGES_NUM_FORMAT_ARGS 17
|
2022-09-15 14:17:33 -06:00
|
|
|
|
2022-05-24 13:36:33 +02:00
|
|
|
void ffPrintPackages(FFinstance* instance)
|
|
|
|
|
{
|
2022-10-08 17:41:25 +08:00
|
|
|
FFPackageCounts counts = {0};
|
2022-06-02 22:58:19 +02:00
|
|
|
ffStrbufInit(&counts.pacmanBranch);
|
2022-10-08 17:41:25 +08:00
|
|
|
ffDetectPackages(instance, &counts);
|
2022-04-21 17:59:26 +02:00
|
|
|
|
2022-10-08 17:41:25 +08:00
|
|
|
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;
|
2021-04-03 21:51:50 +02:00
|
|
|
if(all == 0)
|
2021-03-11 19:54:34 +01:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, "No packages from known package managers found");
|
2021-04-03 21:51:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-05-15 18:17:34 +02:00
|
|
|
|
2022-06-17 18:15:36 +02:00
|
|
|
if(instance->config.packages.outputFormat.length == 0)
|
2021-04-03 21:51:50 +02:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages.key);
|
2021-03-11 19:40:46 +01:00
|
|
|
|
|
|
|
|
#define FF_PRINT_PACKAGE(name) \
|
2022-06-02 22:58:19 +02:00
|
|
|
if(counts.name > 0) \
|
2021-03-19 20:57:07 +01:00
|
|
|
{ \
|
2022-06-02 22:58:19 +02:00
|
|
|
printf("%u ("#name")", counts.name); \
|
|
|
|
|
if((all = all - counts.name) > 0) \
|
2021-03-19 20:57:07 +01:00
|
|
|
printf(", "); \
|
|
|
|
|
};
|
2021-03-11 19:40:46 +01:00
|
|
|
|
2022-06-02 22:58:19 +02:00
|
|
|
if(counts.pacman > 0)
|
2021-05-15 17:21:02 +02:00
|
|
|
{
|
2022-06-02 22:58:19 +02:00
|
|
|
printf("%u (pacman)", counts.pacman);
|
|
|
|
|
if(counts.pacmanBranch.length > 0)
|
|
|
|
|
printf("[%s]", counts.pacmanBranch.chars);
|
|
|
|
|
if((all = all - counts.pacman) > 0)
|
2021-05-15 17:21:02 +02:00
|
|
|
printf(", ");
|
|
|
|
|
};
|
2021-05-15 18:12:10 +02:00
|
|
|
|
2021-05-01 21:22:07 +02:00
|
|
|
FF_PRINT_PACKAGE(dpkg)
|
2021-06-08 20:01:29 +02:00
|
|
|
FF_PRINT_PACKAGE(rpm)
|
2022-02-12 12:13:02 +01:00
|
|
|
FF_PRINT_PACKAGE(emerge)
|
2022-08-12 09:40:02 +02:00
|
|
|
FF_PRINT_PACKAGE(xbps)
|
2022-04-21 17:59:26 +02:00
|
|
|
|
2022-07-26 19:15:00 +02:00
|
|
|
if(counts.nixSystem > 0)
|
2022-04-21 17:59:26 +02:00
|
|
|
{
|
2022-07-26 19:15:00 +02:00
|
|
|
printf("%u (nix-system)", counts.nixSystem);
|
|
|
|
|
if((all = all - counts.nixSystem) > 0)
|
2022-04-21 17:59:26 +02:00
|
|
|
printf(", ");
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 17:41:25 +08:00
|
|
|
if(counts.nixUser > 0)
|
2022-07-26 19:03:15 +02:00
|
|
|
{
|
2022-10-08 17:41:25 +08:00
|
|
|
printf("%u (nix-user)", counts.nixUser);
|
|
|
|
|
if((all = all - counts.nixUser) > 0)
|
2022-07-26 19:03:15 +02:00
|
|
|
printf(", ");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 22:58:19 +02:00
|
|
|
if(counts.nixDefault > 0)
|
2022-04-21 17:59:26 +02:00
|
|
|
{
|
2022-06-02 22:58:19 +02:00
|
|
|
printf("%u (nix-default)", counts.nixDefault);
|
|
|
|
|
if((all = all - counts.nixDefault) > 0)
|
2022-04-21 17:59:26 +02:00
|
|
|
printf(", ");
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-18 22:02:21 +02:00
|
|
|
FF_PRINT_PACKAGE(apk)
|
2022-09-20 11:16:08 +02:00
|
|
|
FF_PRINT_PACKAGE(pkg)
|
2021-05-01 21:22:07 +02:00
|
|
|
FF_PRINT_PACKAGE(flatpak)
|
|
|
|
|
FF_PRINT_PACKAGE(snap)
|
2022-09-05 05:15:19 -07:00
|
|
|
FF_PRINT_PACKAGE(brew)
|
2022-09-15 14:17:33 -06:00
|
|
|
FF_PRINT_PACKAGE(port)
|
2022-10-08 17:41:25 +08:00
|
|
|
FF_PRINT_PACKAGE(scoop)
|
2021-03-11 19:40:46 +01:00
|
|
|
|
2021-05-13 12:27:44 +02:00
|
|
|
//Fix linter warning of unused value of all
|
|
|
|
|
(void) all;
|
|
|
|
|
|
2021-03-11 19:40:46 +01:00
|
|
|
#undef FF_PRINT_PACKAGE
|
|
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
}
|
2021-03-27 15:39:56 +01:00
|
|
|
else
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintFormat(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2021-04-15 18:59:26 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &all},
|
2022-06-02 22:58:19 +02:00
|
|
|
{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},
|
2022-07-26 19:03:15 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixSystem},
|
2022-10-08 17:41:25 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixUser},
|
2022-06-02 22:58:19 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.nixDefault},
|
2022-08-18 22:02:21 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.apk},
|
2022-09-20 11:16:08 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.pkg},
|
2022-06-02 22:58:19 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.flatpak},
|
2022-09-05 05:15:19 -07:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.snap},
|
2022-09-15 14:17:33 -06:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.brew},
|
2022-10-08 17:41:25 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.port},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts.scoop}
|
2021-04-15 18:59:26 +02:00
|
|
|
});
|
2021-03-27 15:39:56 +01:00
|
|
|
}
|
2021-05-15 18:17:34 +02:00
|
|
|
|
2022-06-02 22:58:19 +02:00
|
|
|
ffStrbufDestroy(&counts.pacmanBranch);
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|