Version: add new module

This commit is contained in:
李通洲
2023-08-21 09:19:16 +08:00
parent 970863e7df
commit f23384725f
19 changed files with 174 additions and 2 deletions
+1
View File
@@ -14,6 +14,7 @@ Features:
* Add `--key-width` for aligning the left edge of values, supported both for global `--key-width` and specific module `--module-key-width`
* Add `--bar-char-elapsed`, `--bar-char-total`, `--bar-width` and `--bar-border` options
* Add CMake option `ENABLE_SYSTEM_YYJSON`, which allow building fastfetch with system-provided yyjson (for package managers)
* Add new module `Version`, which prints fastfetch version (like `fastfetch --version`)
Bugfixes:
* Fix label detection. Use `--disk-key 'Disk ({2})'` to display it (Disk, Linux)
+2
View File
@@ -279,6 +279,7 @@ set(LIBFASTFETCH_SRC
src/detection/packages/packages.c
src/detection/terminalfont/terminalfont.c
src/detection/terminalshell/terminalshell.c
src/detection/version/version.c
src/detection/vulkan/vulkan.c
src/logo/builtin.c
src/logo/image/im6.c
@@ -334,6 +335,7 @@ set(LIBFASTFETCH_SRC
src/modules/title/title.c
src/modules/uptime/uptime.c
src/modules/users/users.c
src/modules/version/version.c
src/modules/vulkan/vulkan.c
src/modules/wallpaper/wallpaper.c
src/modules/weather/weather.c
+1 -1
View File
@@ -96,7 +96,7 @@ All categories not listed here should work without needing a specific implementa
##### Available Modules
```
Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme
Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Version, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme
```
##### Builtin logos
+2
View File
@@ -558,6 +558,7 @@
"theme",
"uptime",
"users",
"version",
"vulkan",
"wallpaper",
"weather",
@@ -626,6 +627,7 @@
"theme",
"uptime",
"users",
"version",
"vulkan",
"wallpaper",
"wm",
+1 -1
View File
@@ -1 +1 @@
--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:Break:Colors
--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:Version:Break:Colors
+1
View File
@@ -51,6 +51,7 @@
"sound",
"gamepad",
"weather",
"version",
"break",
"colors"
]
+2
View File
@@ -123,6 +123,7 @@ static void defaultConfig(void)
ffInitTitleOptions(&instance.config.title);
ffInitUptimeOptions(&instance.config.uptime);
ffInitUsersOptions(&instance.config.users);
ffInitVersionOptions(&instance.config.version);
ffInitVulkanOptions(&instance.config.vulkan);
ffInitWMOptions(&instance.config.wm);
ffInitWMThemeOptions(&instance.config.wmTheme);
@@ -335,6 +336,7 @@ static void destroyConfig(void)
ffDestroyTitleOptions(&instance.config.title);
ffDestroyUptimeOptions(&instance.config.uptime);
ffDestroyUsersOptions(&instance.config.users);
ffDestroyVersionOptions(&instance.config.version);
ffDestroyVulkanOptions(&instance.config.vulkan);
ffDestroyWMOptions(&instance.config.wm);
ffDestroyWMThemeOptions(&instance.config.wmTheme);
+1
View File
@@ -133,6 +133,7 @@ static FFModuleBaseInfo* U[] = {
};
static FFModuleBaseInfo* V[] = {
(void*) &instance.config.version,
(void*) &instance.config.vulkan,
NULL,
};
+3
View File
@@ -376,6 +376,7 @@
#--player-key Media Player
#--media-key Media
#--datetime-key Date Time
#--version-key Version
#--vulkan-key Vulkan
#--opengl-key OpenGL
#--opencl-key OpenCL
@@ -426,6 +427,7 @@
#--player-format
#--media-format
#--datetime-format
#--version-format
#--vulkan-format
#--opengl-format
#--opencl-format
@@ -473,6 +475,7 @@
#--player-key-color
#--media-key-color
#--datetime-key-color
#--version-key-color
#--vulkan-key-color
#--opengl-key-color
#--opencl-key-color
+35
View File
@@ -0,0 +1,35 @@
#include "version.h"
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64)
#define FF_ARCHITECTURE "x86_64"
#elif defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(__i586__) || defined(__i586) || defined(__i686__) || defined(__i686)
#define FF_ARCHITECTURE "i386"
#elif defined(__aarch64__)
#define FF_ARCHITECTURE "aarch64"
#elif defined(__arm__)
#define FF_ARCHITECTURE "arm"
#elif defined(__mips__)
#define FF_ARCHITECTURE "mips"
#elif defined(__powerpc__) || defined(__powerpc)
#define FF_ARCHITECTURE "powerpc"
#elif defined(__riscv__) || defined(__riscv)
#define FF_ARCHITECTURE "riscv"
#elif defined(__s390x__)
#define FF_ARCHITECTURE "s390x"
#else
#define FF_ARCHITECTURE "unknown"
#endif
void ffDetectVersion(FFVersionResult* version)
{
version->projectName = FASTFETCH_PROJECT_NAME;
version->architecture = FF_ARCHITECTURE;
version->version = FASTFETCH_PROJECT_VERSION;
version->versionTweak = FASTFETCH_PROJECT_VERSION_TWEAK;
version->cmakeBuiltType = FASTFETCH_PROJECT_CMAKE_BUILD_TYPE;
#ifndef NDEBUG
version->debugMode = true;
#else
version->debugMode = false;
#endif
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#ifndef FF_INCLUDED_detection_version_version
#define FF_INCLUDED_detection_version_version
#include "fastfetch.h"
typedef struct FFVersionResult
{
const char* projectName;
const char* architecture;
const char* version;
const char* versionTweak;
const char* cmakeBuiltType;
bool debugMode;
} FFVersionResult;
void ffDetectVersion(FFVersionResult* version);
#endif
+11
View File
@@ -456,6 +456,17 @@ static inline void printCommandHelp(const char* command)
"second with leading zero"
);
}
else if(ffStrEqualsIgnCase(command, "version-format"))
{
constructAndPrintCommandHelpFormat("version", "{1} {2}{3} (5)", 6,
"Project name",
"Version",
"Version tweak",
"Build type (debug or release)",
"Architecture",
"CMake build type (Debug, Release, RelWithDebInfo, MinSizeRel)"
);
}
else if(ffStrEqualsIgnCase(command, "vulkan-format"))
{
constructAndPrintCommandHelpFormat("vulkan", "{} (driver), {} (api version)", 3,
+1
View File
@@ -126,6 +126,7 @@ typedef struct FFconfig
FFTitleOptions title;
FFUptimeOptions uptime;
FFUsersOptions users;
FFVersionOptions version;
FFVulkanOptions vulkan;
FFWMOptions wm;
FFWMThemeOptions wmTheme;
+1
View File
@@ -10,6 +10,7 @@
#define FASTFETCH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@"
#define FASTFETCH_PROJECT_VERSION_TWEAK_NUM @PROJECT_VERSION_TWEAK_NUM@
#define FASTFETCH_PROJECT_CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
#define FASTFETCH_PROJECT_HOMEPAGE_URL "@PROJECT_HOMEPAGE_URL@"
#define FASTFETCH_PROJECT_DESCRIPTION "@PROJECT_DESCRIPTION@"
#define FASTFETCH_PROJECT_LICENSE "@PROJECT_LICENSE@"
+1
View File
@@ -50,6 +50,7 @@
#include "modules/title/title.h"
#include "modules/uptime/uptime.h"
#include "modules/users/users.h"
#include "modules/version/version.h"
#include "modules/vulkan/vulkan.h"
#include "modules/wallpaper/wallpaper.h"
#include "modules/weather/weather.h"
+1
View File
@@ -50,6 +50,7 @@
#include "modules/title/option.h"
#include "modules/uptime/option.h"
#include "modules/users/option.h"
#include "modules/version/option.h"
#include "modules/vulkan/option.h"
#include "modules/wallpaper/option.h"
#include "modules/weather/option.h"
+11
View File
@@ -0,0 +1,11 @@
#pragma once
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
#include "common/option.h"
typedef struct FFVersionOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFVersionOptions;
+68
View File
@@ -0,0 +1,68 @@
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "detection/version/version.h"
#include "modules/version/version.h"
#include "util/stringUtils.h"
#define FF_VERSION_NUM_FORMAT_ARGS 6
void ffPrintVersion(FFVersionOptions* options)
{
FFVersionResult result = {};
ffDetectVersion(&result);
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
printf("%s %s%s%s (%s)\n", result.projectName, result.version, result.versionTweak, result.debugMode ? "-debug" : "", result.architecture);
}
else
{
ffPrintFormat(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_VERSION_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, result.projectName},
{FF_FORMAT_ARG_TYPE_STRING, result.version},
{FF_FORMAT_ARG_TYPE_STRING, result.versionTweak},
{FF_FORMAT_ARG_TYPE_STRING, result.debugMode ? "debug" : "release"},
{FF_FORMAT_ARG_TYPE_STRING, result.architecture},
{FF_FORMAT_ARG_TYPE_STRING, result.cmakeBuiltType},
});
}
}
void ffInitVersionOptions(FFVersionOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion);
ffOptionInitModuleArg(&options->moduleArgs);
}
bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_VERSION_MODULE_NAME);
if (!subKey) return false;
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
return false;
}
void ffDestroyVersionOptions(FFVersionOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
ffPrintError(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include "fastfetch.h"
#define FF_VERSION_MODULE_NAME "Version"
void ffPrintVersion(FFVersionOptions* options);
void ffInitVersionOptions(FFVersionOptions* options);
bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value);
void ffDestroyVersionOptions(FFVersionOptions* options);
void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module);