2026-01-06 09:48:38 +08:00
|
|
|
#include "common/printing.h"
|
|
|
|
|
#include "common/jsonconfig.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2023-10-05 19:06:15 +08:00
|
|
|
#include "detection/libc/libc.h"
|
2023-08-21 09:19:16 +08:00
|
|
|
#include "detection/version/version.h"
|
|
|
|
|
#include "modules/version/version.h"
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffPrintVersion(FFVersionOptions* options) {
|
2024-07-02 10:12:26 +08:00
|
|
|
FFVersionResult* result = &ffVersionResult;
|
2023-08-21 09:19:16 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (options->moduleArgs.outputFormat.length == 0) {
|
2023-08-21 09:19:16 +08:00
|
|
|
ffPrintLogoAndKey(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
2024-07-02 10:12:26 +08:00
|
|
|
printf("%s %s%s%s (%s)\n", result->projectName, result->version, result->versionTweak, result->debugMode ? "-debug" : "", result->architecture);
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2023-10-05 19:06:15 +08:00
|
|
|
FFLibcResult libcResult;
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!ffDetectLibc(&libcResult)) {
|
2023-10-05 19:06:15 +08:00
|
|
|
ffStrbufSetS(&buf, libcResult.name);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (libcResult.version) {
|
2023-10-05 19:06:15 +08:00
|
|
|
ffStrbufAppendC(&buf, ' ');
|
|
|
|
|
ffStrbufAppendS(&buf, libcResult.version);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 14:52:40 +08:00
|
|
|
const char* buildType = result->debugMode ? "debug" : "release";
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_PRINT_FORMAT_CHECKED(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
|
|
|
|
|
FF_ARG(result->projectName, "project-name"),
|
|
|
|
|
FF_ARG(result->version, "version"),
|
|
|
|
|
FF_ARG(result->versionTweak, "version-tweak"),
|
|
|
|
|
FF_ARG(buildType, "build-type"),
|
|
|
|
|
FF_ARG(result->sysName, "sysname"),
|
|
|
|
|
FF_ARG(result->architecture, "arch"),
|
|
|
|
|
FF_ARG(result->cmakeBuiltType, "cmake-built-type"),
|
|
|
|
|
FF_ARG(result->compileTime, "compile-time"),
|
|
|
|
|
FF_ARG(result->compiler, "compiler"),
|
|
|
|
|
FF_ARG(buf, "libc"),
|
|
|
|
|
}));
|
2023-08-21 09:19:16 +08:00
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
return true;
|
2023-08-21 09:19:16 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) {
|
2025-08-02 18:51:03 +08:00
|
|
|
yyjson_val *key, *val;
|
2023-08-21 09:19:16 +08:00
|
|
|
size_t idx, max;
|
2026-03-29 09:28:49 +08:00
|
|
|
yyjson_obj_foreach (module, idx, max, key, val) {
|
|
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
2023-08-21 09:19:16 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2023-08-21 09:19:16 +08:00
|
|
|
|
2025-08-02 18:51:03 +08:00
|
|
|
ffPrintError(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
2023-08-21 09:19:16 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-12 20:36:00 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffGenerateVersionJsonConfig(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-04 16:46:28 +08:00
|
|
|
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
2023-10-24 14:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 21:13:03 +08:00
|
|
|
bool ffGenerateVersionJsonResult([[maybe_unused]] FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2024-07-02 10:12:26 +08:00
|
|
|
FFVersionResult* result = &ffVersionResult;
|
2023-09-12 20:36:00 +08:00
|
|
|
|
|
|
|
|
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
2024-07-02 10:12:26 +08:00
|
|
|
yyjson_mut_obj_add_str(doc, obj, "projectName", result->projectName);
|
|
|
|
|
yyjson_mut_obj_add_str(doc, obj, "sysName", result->sysName);
|
|
|
|
|
yyjson_mut_obj_add_str(doc, obj, "architecture", result->architecture);
|
|
|
|
|
yyjson_mut_obj_add_str(doc, obj, "version", result->version);
|
2024-08-09 09:52:53 +08:00
|
|
|
yyjson_mut_obj_add_str(doc, obj, "versionGit", result->versionGit);
|
2024-07-02 10:12:26 +08:00
|
|
|
yyjson_mut_obj_add_str(doc, obj, "cmakeBuiltType", result->cmakeBuiltType);
|
|
|
|
|
yyjson_mut_obj_add_str(doc, obj, "compileTime", result->compileTime);
|
|
|
|
|
yyjson_mut_obj_add_str(doc, obj, "compiler", result->compiler);
|
|
|
|
|
yyjson_mut_obj_add_bool(doc, obj, "debugMode", result->debugMode);
|
2023-10-05 19:06:15 +08:00
|
|
|
|
|
|
|
|
FFLibcResult libcResult;
|
2026-03-29 09:28:49 +08:00
|
|
|
if (ffDetectLibc(&libcResult)) {
|
2023-10-05 19:06:15 +08:00
|
|
|
yyjson_mut_obj_add_null(doc, obj, "libc");
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2023-10-05 19:06:15 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreateS(libcResult.name);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (libcResult.version) {
|
2023-10-05 19:06:15 +08:00
|
|
|
ffStrbufAppendC(&buf, ' ');
|
|
|
|
|
ffStrbufAppendS(&buf, libcResult.version);
|
|
|
|
|
}
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "libc", &buf);
|
|
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
return true;
|
2023-09-12 20:36:00 +08:00
|
|
|
}
|
2023-10-07 13:40:40 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffInitVersionOptions(FFVersionOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs, "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffDestroyVersionOptions(FFVersionOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 22:50:56 +08:00
|
|
|
FFModuleBaseInfo ffVersionModuleInfo = {
|
2024-12-11 10:47:02 +08:00
|
|
|
.name = FF_VERSION_MODULE_NAME,
|
2026-04-16 18:27:11 +08:00
|
|
|
.description = "Print the Fastfetch version and build information",
|
2025-08-03 18:39:41 +08:00
|
|
|
.initOptions = (void*) ffInitVersionOptions,
|
|
|
|
|
.destroyOptions = (void*) ffDestroyVersionOptions,
|
2024-12-11 10:47:02 +08:00
|
|
|
.parseJsonObject = (void*) ffParseVersionJsonObject,
|
|
|
|
|
.printModule = (void*) ffPrintVersion,
|
|
|
|
|
.generateJsonResult = (void*) ffGenerateVersionJsonResult,
|
|
|
|
|
.generateJsonConfig = (void*) ffGenerateVersionJsonConfig,
|
|
|
|
|
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
2026-03-30 10:27:23 +08:00
|
|
|
{ "Project name", "project-name" },
|
|
|
|
|
{ "Version", "version" },
|
|
|
|
|
{ "Version tweak", "version-tweak" },
|
|
|
|
|
{ "Build type (debug or release)", "build-type" },
|
|
|
|
|
{ "System name", "sysname" },
|
|
|
|
|
{ "Architecture", "arch" },
|
|
|
|
|
{ "CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel)", "cmake-built-type" },
|
|
|
|
|
{ "Date time when compiling", "compile-time" },
|
|
|
|
|
{ "Compiler used when compiling", "compiler" },
|
|
|
|
|
{ "Libc used when compiling", "libc" },
|
2026-03-30 10:17:45 +08:00
|
|
|
}))
|
|
|
|
|
};
|