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"
|
2023-03-24 17:47:03 +08:00
|
|
|
#define FF_PACKAGES_NUM_FORMAT_ARGS 21
|
2022-09-15 14:17:33 -06:00
|
|
|
|
2022-05-24 13:36:33 +02:00
|
|
|
void ffPrintPackages(FFinstance* instance)
|
|
|
|
|
{
|
2022-10-13 21:43:31 +02:00
|
|
|
const FFPackagesResult* counts = ffDetectPackages(instance);
|
|
|
|
|
uint32_t all = counts->all; //Copy it, so we can substract from it in FF_PRINT_PACKAGE
|
2022-04-21 17:59:26 +02:00
|
|
|
|
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
|
|
|
|
2022-10-13 21:43:31 +02:00
|
|
|
#define FF_PRINT_PACKAGE_NAME(var, name) \
|
|
|
|
|
if(counts->var > 0) \
|
|
|
|
|
{ \
|
2023-03-24 17:47:03 +08:00
|
|
|
printf("%u (%s)", counts->var, (name)); \
|
2022-10-13 21:43:31 +02:00
|
|
|
if((all -= counts->var) > 0) \
|
|
|
|
|
printf(", "); \
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define FF_PRINT_PACKAGE(name) FF_PRINT_PACKAGE_NAME(name, #name)
|
2021-03-11 19:40:46 +01:00
|
|
|
|
2022-10-13 21:43:31 +02:00
|
|
|
if(counts->pacman > 0)
|
2021-05-15 17:21:02 +02:00
|
|
|
{
|
2022-10-13 21:43:31 +02:00
|
|
|
printf("%u (pacman)", counts->pacman);
|
|
|
|
|
if(counts->pacmanBranch.length > 0)
|
|
|
|
|
printf("[%s]", counts->pacmanBranch.chars);
|
|
|
|
|
if((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-12-27 17:36:58 +08:00
|
|
|
FF_PRINT_PACKAGE(eopkg)
|
2022-08-12 09:40:02 +02:00
|
|
|
FF_PRINT_PACKAGE(xbps)
|
2022-10-13 21:43:31 +02:00
|
|
|
FF_PRINT_PACKAGE_NAME(nixSystem, "nix-system")
|
|
|
|
|
FF_PRINT_PACKAGE_NAME(nixUser, "nix-user")
|
|
|
|
|
FF_PRINT_PACKAGE_NAME(nixDefault, "nix-default")
|
2022-08-18 22:02:21 +02:00
|
|
|
FF_PRINT_PACKAGE(apk)
|
2022-09-20 11:16:08 +02:00
|
|
|
FF_PRINT_PACKAGE(pkg)
|
2023-03-24 17:47:03 +08:00
|
|
|
FF_PRINT_PACKAGE_NAME(flatpakSystem, counts->flatpakUser ? "flatpak-system" : "flatpak")
|
|
|
|
|
FF_PRINT_PACKAGE_NAME(flatpakUser, "flatpak-user")
|
2021-05-01 21:22:07 +02:00
|
|
|
FF_PRINT_PACKAGE(snap)
|
2022-09-05 05:15:19 -07:00
|
|
|
FF_PRINT_PACKAGE(brew)
|
2022-12-13 10:57:40 +08:00
|
|
|
FF_PRINT_PACKAGE_NAME(brewCask, "brew-cask")
|
2022-09-15 14:17:33 -06:00
|
|
|
FF_PRINT_PACKAGE(port)
|
2022-10-08 17:41:25 +08:00
|
|
|
FF_PRINT_PACKAGE(scoop)
|
2022-10-23 22:16:12 +08:00
|
|
|
FF_PRINT_PACKAGE(choco)
|
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
|
|
|
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-10-13 21:43:31 +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},
|
2022-12-27 17:36:58 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->eopkg},
|
2022-10-13 21:43:31 +02:00
|
|
|
{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},
|
2023-03-24 17:47:03 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->flatpakSystem},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->flatpakUser},
|
2022-10-13 21:43:31 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->snap},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->brew},
|
2022-12-13 10:57:40 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->brewCask},
|
2022-10-13 21:43:31 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->port},
|
2022-12-13 10:57:40 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->scoop},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT, &counts->choco},
|
2021-04-15 18:59:26 +02:00
|
|
|
});
|
2021-03-27 15:39:56 +01:00
|
|
|
}
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|