Merge pull request #958 from fastfetch-cli/dev

Release v2.13.2
This commit is contained in:
Carter Li
2024-05-22 12:12:15 +00:00
committed by GitHub
30 changed files with 496 additions and 11150 deletions
+16
View File
@@ -1,3 +1,19 @@
# 2.13.2
Another hotfix release :(
Bugfixes:
* Remove DRM driver version detection feature, which caused a performance regression for nouveau drivers (#956, Display, Linux)
* Fix compatibility for old python versions. Regression of `2.13.0`
* Don't use `*-unknown` as display name for Wayland protocol (Display, Linux)
Features:
* Add new module `Editor` which prints information of the default editor, i.e. $VISUAL or $EDITOR (#430, Editor)
Logos:
* Added CuerdOS
* Remove special handling of Loc-OS
# 2.13.1
Fix a regression introduced in v2.13.0
+3 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.13.1
VERSION 2.13.2
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -291,6 +291,7 @@ set(LIBFASTFETCH_SRC
src/detection/disk/disk.c
src/detection/diskio/diskio.c
src/detection/displayserver/displayserver.c
src/detection/editor/editor.c
src/detection/font/font.c
src/detection/gpu/gpu.c
src/detection/media/media.c
@@ -330,6 +331,7 @@ set(LIBFASTFETCH_SRC
src/modules/de/de.c
src/modules/disk/disk.c
src/modules/diskio/diskio.c
src/modules/editor/editor.c
src/modules/font/font.c
src/modules/gpu/gpu.c
src/modules/host/host.c
+2 -1
View File
@@ -85,7 +85,8 @@ string match -r -a -g "^###> ?(.*)" < (status -f) | string collect | python3 | s
###> elif type == 'config':
###> print(f'{command_prefix} -x -a "(__fastfetch_complete_config)"')
###> elif type == 'enum':
###> print(f'{command_prefix} -x -a "{' '.join(flag["arg"]["enum"])}"')
###> temp: str = ' '.join(flag["arg"]["enum"])
###> print(f'{command_prefix} -x -a "{temp}"')
###> elif type == 'logo':
###> print(f'{command_prefix} -x -a "(__fastfetch_complete_logo)"')
###> elif type == 'structure':
+5
View File
@@ -695,6 +695,7 @@
"disk",
"diskio",
"de",
"editor",
"font",
"gamepad",
"gpu",
@@ -795,6 +796,10 @@
"const": "datetime",
"description": "Print current date and time"
},
{
"const": "editor",
"description": "Print information of the default editor ($VISUAL or $EDITOR)"
},
{
"const": "font",
"description": "Print system font name"
+11 -2
View File
@@ -6,6 +6,7 @@
"os",
"host",
"bios",
"bootmgr",
"board",
"chassis",
"kernel",
@@ -14,6 +15,7 @@
"processes",
"packages",
"shell",
"editor",
"display",
"brightness",
"monitor",
@@ -30,7 +32,10 @@
"terminalfont",
"terminalsize",
"terminaltheme",
"cpu",
{
"type": "cpu",
"showPeCoreCount": true
},
"cpuusage",
"gpu",
"memory",
@@ -42,7 +47,11 @@
"player",
"media",
"publicip",
"localip",
{
"type": "localip",
"showIpV6": true,
"showMac": true
},
"wifi",
"datetime",
"locale",
+11 -2
View File
@@ -13,6 +13,7 @@
"os",
"host",
"bios",
"bootmgr",
"board",
"chassis",
"kernel",
@@ -21,6 +22,7 @@
"processes",
"packages",
"shell",
"editor",
"display",
"brightness",
"monitor",
@@ -37,7 +39,10 @@
"terminalfont",
"terminalsize",
"terminaltheme",
"cpu",
{
"type": "cpu",
"showPeCoreCount": true
},
"cpuusage",
"gpu",
"memory",
@@ -49,7 +54,11 @@
"player",
"media",
"publicip",
"localip",
{
"type": "localip",
"showIpV6": true,
"showMac": true
},
"wifi",
"datetime",
"locale",
+5 -5
View File
@@ -24,24 +24,24 @@
},
{
"type": "os",
"key": "",
"key": "",
"format": "{2} {8}"
},
{
"type": "kernel",
"key": ""
"key": ""
},
{
"type": "memory",
"key": "󰻠"
"key": ""
},
{
"type": "packages",
"key": ""
"key": "󰏖"
},
{
"type": "uptime",
"key": ""
"key": "󰅐"
},
{
"type": "custom",
-11074
View File
File diff suppressed because it is too large Load Diff
-6
View File
@@ -1,6 +0,0 @@
{
"home": "https://github.com/NVIDIA/nvidia-settings/blob/main/src/nvml.h",
"license": "Embed in source",
"version": "550.54.14",
"author": "NVIDIA Corporation"
}
+1
View File
@@ -37,6 +37,7 @@ static FFModuleBaseInfo* D[] = {
};
static FFModuleBaseInfo* E[] = {
(void*) &instance.config.modules.editor,
NULL,
};
+4 -4
View File
@@ -1208,13 +1208,13 @@
{
"long": "gpu-detection-method",
"desc": "Force using a specified method to detect GPUs",
"remark": "Methods are used in this order: DRM (Linux only) -> PCI (Linux, FreeBSD and other platform specific methods) -> Vulkan -> OpenGL",
"remark": "Will fall back to next methods if the specified method fails",
"arg": {
"type": "enum",
"enum": {
"auto": "Use DRM if available, which is most feature-rich. Requires proper DRM driver installed",
"pci": "Search PCI devices, which do not requires any driver installed",
"vulkan": "Use Vulkan API. Slow and requires vulkan driver installed",
"auto": "Query platform specific graphic APIs. Requires proper GPU drivers installed. Not supported on FreeBSD",
"pci": "Search PCI devices, which do not requires GPU driver installed. Not supported on Windows and macOS",
"vulkan": "Use Vulkan API. Slow and requires vulkan driver installed. Used for Android",
"opengl": "Use OpenGL API. Slow and only detects one GPU"
},
"default": "auto"
@@ -118,7 +118,8 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist
rotation,
display.edidName.length
? &display.edidName
: display.description.length && !ffStrbufEndsWithS(&display.description, "-unknown")
// Try ignoring `eDP-1-unknown`, where `unknown` is localized
: display.description.length && !(ffStrbufStartsWithS(&display.description, display.name.chars) && display.description.chars[display.name.length] == '-')
? &display.description
: &display.name,
display.type,
+112
View File
@@ -0,0 +1,112 @@
#include "editor.h"
#include "common/processing.h"
#include "util/stringUtils.h"
#include <stdlib.h>
#if defined(MAXPATH)
#define FF_EXE_PATH_LEN MAXPATH
#elif defined(PATH_MAX)
#define FF_EXE_PATH_LEN PATH_MAX
#else
#define FF_EXE_PATH_LEN 260
#endif
#ifdef _WIN32
static inline char* realpath(const char* restrict file_name, char* restrict resolved_name)
{
char* result = _fullpath(resolved_name, file_name, _MAX_PATH);
if(result)
{
resolved_name[1] = resolved_name[0]; // Drive Name
resolved_name[0] = '/';
}
return result;
}
#endif
const char* ffDetectEditor(FFEditorResult* result)
{
ffStrbufSetS(&result->name, getenv("VISUAL"));
if (result->name.length == 0)
ffStrbufSetS(&result->name, getenv("EDITOR"));
if (result->name.length == 0)
return "$VISUAL or $EDITOR not set";
#ifndef _WIN32
if (result->name.chars[0] != '/')
{
if (ffProcessAppendStdOut(&result->path, (char* const[]){
FASTFETCH_TARGET_DIR_USR "/bin/which",
result->name.chars,
NULL,
}) != NULL || result->path.length == 0)
return NULL;
}
else
ffStrbufSet(&result->path, &result->name);
char buf[FF_EXE_PATH_LEN];
if (!realpath(result->path.chars, buf))
return NULL;
ffStrbufSetS(&result->path, buf);
const char* exe = &result->path.chars[ffStrbufLastIndexC(&result->path, '/')];
if (!*exe) return NULL;
++exe;
result->exe = exe;
const char* param = NULL;
if (
ffStrEquals(exe, "nano") ||
ffStrEquals(exe, "vim") ||
ffStrEquals(exe, "nvim") ||
ffStrEquals(exe, "micro") ||
ffStrEquals(exe, "emacs") ||
ffStrStartsWith(exe, "emacs-") || // emacs-29.3
ffStrEquals(exe, "hx") ||
ffStrEquals(exe, "code") ||
ffStrEquals(exe, "sublime_text")
) param = "--version";
else if (
ffStrEquals(exe, "kak") ||
ffStrEquals(exe, "pico")
) param = "-version";
else if (
ffStrEquals(exe, "ne")
) param = "-h";
else return NULL;
ffProcessAppendStdOut(&result->version, (char* const[]){
result->path.chars,
(char*) param,
NULL,
});
if (result->version.length == 0)
return NULL;
ffStrbufSubstrBeforeFirstC(&result->version, '\n');
for (uint32_t iStart = 0; iStart < result->version.length; ++iStart)
{
char c = result->version.chars[iStart];
if (c >= '0' && c <= '9')
{
for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd)
{
char c = result->version.chars[iEnd];
if (isspace(c))
{
ffStrbufSubstrBefore(&result->version, iEnd);
break;
}
}
if (iStart > 0)
ffStrbufSubstrAfter(&result->version, iStart - 1);
break;
}
}
#endif
return NULL;
}
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include "fastfetch.h"
typedef struct FFEditorResult
{
FFstrbuf name;
const char* exe;
FFstrbuf path;
FFstrbuf version;
} FFEditorResult;
const char* ffDetectEditor(FFEditorResult* result);
-1
View File
@@ -2,7 +2,6 @@
#include "common/io/io.h"
#include "common/properties.h"
#include "3rdparty/nvml/nvml.h"
#include "util/mallocHelper.h"
#include <dev/pci/pcireg.h>
-42
View File
@@ -33,50 +33,8 @@
#endif
#endif
#if FF_HAVE_DRM_H
static const char* drmDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, const char* drmKey)
{
ffStrbufSetS(buffer, "/dev/dri/");
ffStrbufAppendS(buffer, drmKey);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY);
if (fd < 0) return "open(/dev/dri/drm_key) failed";
ffStrbufEnsureFixedLengthFree(&gpu->driver, 128);
drm_version_t version = {
.name = gpu->driver.chars,
.name_len = gpu->driver.allocated,
};
if (ioctl(fd, DRM_IOCTL_VERSION, &version) < 0) return "ioctl(DRM_IOCTL_VERSION) failed";
gpu->driver.length = (uint32_t) version.name_len;
gpu->driver.chars[gpu->driver.length] = '\0';
if (version.version_major || version.version_minor || version.version_patchlevel)
ffStrbufAppendF(&gpu->driver, " %d.%d.%d", version.version_major, version.version_minor, version.version_patchlevel);
else
{
ffStrbufAppendS(pciDir, "/driver/module/version");
if (ffReadFileBuffer(pciDir->chars, buffer))
{
ffStrbufTrimRightSpace(buffer);
ffStrbufAppendC(&gpu->driver, ' ');
ffStrbufAppend(&gpu->driver, buffer);
}
}
return NULL;
}
#endif
static bool pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, FF_MAYBE_UNUSED const char* drmKey)
{
#if FF_HAVE_DRM_H
if (drmKey)
{
drmDetectDriver(gpu, pciDir, buffer, drmKey);
if (gpu->driver.length > 0) return true;
}
#endif
ffStrbufAppendS(pciDir, "/driver");
char pathBuf[PATH_MAX];
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
+1 -1
View File
@@ -1,7 +1,7 @@
#include "gpu_driver_specific.h"
#include "3rdparty/nvml/nvml.h"
#include "common/library.h"
#include "nvml.h"
struct FFNvmlData {
FF_LIBRARY_SYMBOL(nvmlDeviceGetCount_v2)
+120
View File
@@ -0,0 +1,120 @@
#pragma once
// DISCLAIMER:
// THIS FILE IS CREATED FROM SCRATCH, BY READING THE OFFICIAL NVML API
// DOCUMENTATION REFERENCED BELOW, IN ORDER TO MAKE FASTFETCH MIT COMPLIANT.
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceStructs.html
#define NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE 32
#define NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE 16
typedef enum { NVML_SUCCESS = 0 } nvmlReturn_t;
typedef struct nvmlDevice_t* nvmlDevice_t;
// https://docs.nvidia.com/deploy/nvml-api/structnvmlPciInfo__t.html
// PCI information about a GPU device
typedef struct {
// The legacy tuple domain:bus:device.function PCI identifier (& NULL terminator)
char busIdLegacy[NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE];
// The PCI domain on which the device's bus resides, 0 to 0xffffffff
unsigned int domain;
// The bus on which the device resides, 0 to 0xff
unsigned int bus;
// The device's id on the bus, 0 to 31
unsigned int device;
// The combined 16-bit device id and 16-bit vendor id
unsigned int pciDeviceId;
// The 32-bit Sub System Device ID
unsigned int pciSubSystemId;
// The tuple domain:bus:device.function PCI identifier (& NULL terminator)
char busId[NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE];
} nvmlPciInfo_t;
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceEnumvs.html#group__nvmlDeviceEnumvs_1g2650b526841fa38b8f293c2d509a1de0
// Temperature sensors
typedef enum {
// Temperature sensor for the GPU die
NVML_TEMPERATURE_GPU = 0,
NVML_TEMPERATURE_COUNT,
} nvmlTemperatureSensors_t;
// https://docs.nvidia.com/deploy/nvml-api/structnvmlMemory__v2__t.html#structnvmlMemory__v2__t
// Memory allocation information for a device (v2)
typedef struct {
// Structure format version (must be 2)
unsigned int version;
// Total physical device memory (in bytes)
unsigned long long total;
// Device memory (in bytes) reserved for system use (driver or firmware)
unsigned long long reserved;
// Unallocated device memory (in bytes)
unsigned long long free;
// Allocated device memory (in bytes)
unsigned long long used;
} nvmlMemory_v2_t;
enum { nvmlMemory_v2 = 2 };
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceEnumvs.html#group__nvmlDeviceEnumvs_1g805c0647be9996589fc5e3f6ff680c64
// Clock types
typedef enum {
// Graphics clock domain
NVML_CLOCK_GRAPHICS = 0,
// SM clock domain
NVML_CLOCK_SM = 1,
// Memory clock domain
NVML_CLOCK_MEM = 2,
// Video encoder/decoder clock domain
NVML_CLOCK_VIDEO = 3,
// Count of clock types
NVML_CLOCK_COUNT,
} nvmlClockType_t;
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceEnumvs.html#group__nvmlDeviceEnumvs_1gfa6b01990b212f7b49089b7158eafd2b
// The Brand of the GPU
typedef enum {
NVML_BRAND_UNKNOWN = 0,
NVML_BRAND_QUADRO = 1,
NVML_BRAND_TESLA = 2,
NVML_BRAND_NVS = 3,
NVML_BRAND_GRID = 4,
NVML_BRAND_GEFORCE = 5,
NVML_BRAND_TITAN = 6,
NVML_BRAND_NVIDIA_VAPPS = 7,
NVML_BRAND_NVIDIA_VPC = 8,
NVML_BRAND_NVIDIA_VCS = 9,
NVML_BRAND_NVIDIA_VWS = 10,
NVML_BRAND_NVIDIA_CLOUD_GAMING = 11,
NVML_BRAND_NVIDIA_VGAMING = NVML_BRAND_NVIDIA_CLOUD_GAMING,
NVML_BRAND_QUADRO_RTX = 12,
NVML_BRAND_NVIDIA_RTX = 13,
NVML_BRAND_NVIDIA = 14,
NVML_BRAND_GEFORCE_RTX = 15,
NVML_BRAND_TITAN_RTX = 16,
NVML_BRAND_COUNT,
} nvmlBrandType_t;
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlInitializationAndCleanup.html#group__nvmlInitializationAndCleanup
// Initialize NVML, but don't initialize any GPUs yet
nvmlReturn_t nvmlInit_v2(void);
// Shut down NVML by releasing all GPU resources previously allocated with nvmlInit_v2()
nvmlReturn_t nvmlShutdown(void);
// https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceQueries.html
// Retrieves the number of compute devices in the system. A compute device is a single GPU
extern nvmlReturn_t nvmlDeviceGetCount_v2(unsigned int* deviceCount);
// Acquire the handle for a particular device, based on its index
extern nvmlReturn_t nvmlDeviceGetHandleByIndex_v2(unsigned int index, nvmlDevice_t* device);
// Acquire the handle for a particular device, based on its PCI bus id
extern nvmlReturn_t nvmlDeviceGetHandleByPciBusId_v2(const char* pciBusId, nvmlDevice_t* device);
// Retrieves the PCI attributes of this device
extern nvmlReturn_t nvmlDeviceGetPciInfo_v3(nvmlDevice_t device, nvmlPciInfo_t* pci);
// Retrieves the current temperature readings for the device, in degrees C
extern nvmlReturn_t nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int* temp);
// Retrieves the amount of used, free, reserved and total memory available on the device, in bytes. The reserved amount is supported on version 2 only
extern nvmlReturn_t nvmlDeviceGetMemoryInfo_v2(nvmlDevice_t device, nvmlMemory_v2_t* memory);
// Gets the device's core count
extern nvmlReturn_t nvmlDeviceGetNumGpuCores(nvmlDevice_t device, unsigned int* numCores);
// Retrieves the maximum clock speeds for the device
extern nvmlReturn_t nvmlDeviceGetMaxClockInfo(nvmlDevice_t device, nvmlClockType_t type, unsigned int* clock);
// Retrieves the brand of this device
extern nvmlReturn_t nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t* type);
-6
View File
@@ -157,12 +157,6 @@ static bool detectDebianDerived(FFOSResult* result)
ffStrbufSetNS(&result->versionID, versionEnd - versionStart, result->prettyName.chars + versionStart);
return true;
}
else if (ffStrbufStartsWithS(&result->name, "Loc-OS"))
{
ffStrbufSetS(&result->id, "locos");
ffStrbufSetS(&result->idLike, "debian");
return true;
}
else if (ffPathExists("/usr/bin/pveversion", FF_PATHTYPE_FILE))
{
ffStrbufSetS(&result->id, "pve");
+13
View File
@@ -0,0 +1,13 @@
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣶⣾⣿⣿⣿⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⣿⣿⣿⡇
⠀⠀⡄⢀⣤⣤⣤⣤⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣤⣤⣤⣤⣤⣄⠀⣿⣿⣿⣿⣿⡇
⠀⠀⡇⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⠁
⠀⠀⣧⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃
⠀⠀⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁
⠀⠀⡇⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠁
⠀⠀⠇⠘⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠿⠿⠿⠿⠛⠛⠋⠉
⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉
____________________________________
| Optimizado hasta el último pixel |
************************************
+12 -1
View File
@@ -1066,6 +1066,17 @@ static const FFlogo C[] = {
.colorKeys = FF_COLOR_FG_GREEN,
.colorTitle = FF_COLOR_FG_YELLOW,
},
// CuerdOS
{
.names = {"CuerdOS", "CuerdOS GNU/Linux"},
.lines = FASTFETCH_DATATEXT_LOGO_CUERDOS,
.colors = {
FF_COLOR_FG_YELLOW,
FF_COLOR_FG_GREEN,
},
.colorKeys = FF_COLOR_FG_GREEN,
.colorTitle = FF_COLOR_FG_YELLOW,
},
// CutefishOS
{
.names = {"CutefishOS"},
@@ -2384,7 +2395,7 @@ static const FFlogo L[] = {
},
// Loc-OS
{
.names = {"loc-os", "Loc-OS Linux"},
.names = {"locos", "loc-os", "Loc-OS Linux"},
.lines = FASTFETCH_DATATEXT_LOGO_LOCOS,
.colors = {
FF_COLOR_FG_BLACK,
+137
View File
@@ -0,0 +1,137 @@
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "detection/libc/libc.h"
#include "detection/editor/editor.h"
#include "modules/editor/editor.h"
#include "util/stringUtils.h"
#define FF_EDITOR_NUM_FORMAT_ARGS 4
void ffPrintEditor(FFEditorOptions* options)
{
FFEditorResult result = {
.name = ffStrbufCreate(),
.path = ffStrbufCreate(),
.version = ffStrbufCreate(),
};
const char* error = ffDetectEditor(&result);
if (error)
{
ffPrintError(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
}
ffPrintLogoAndKey(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
if (result.exe)
{
fputs(result.exe, stdout);
if (result.version.length)
printf(" (%s)", result.version.chars);
}
else
{
ffStrbufWriteTo(&result.name, stdout);
}
putchar('\n');
ffStrbufDestroy(&result.name);
ffStrbufDestroy(&result.path);
ffStrbufDestroy(&result.version);
}
bool ffParseEditorCommandOptions(FFEditorOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_EDITOR_MODULE_NAME);
if (!subKey) return false;
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
return false;
}
void ffParseEditorJsonObject(FFEditorOptions* 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_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
void ffGenerateEditorJsonConfig(FFEditorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
__attribute__((__cleanup__(ffDestroyEditorOptions))) FFEditorOptions defaultOptions;
ffInitEditorOptions(&defaultOptions);
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
}
void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFEditorResult result = {
.name = ffStrbufCreate(),
.path = ffStrbufCreate(),
.version = ffStrbufCreate(),
};
const char* error = ffDetectEditor(&result);
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "name", &result.name);
yyjson_mut_obj_add_strbuf(doc, obj, "path", &result.path);
if (result.exe)
yyjson_mut_obj_add_strcpy(doc, obj, "exe", result.exe);
else
yyjson_mut_obj_add_null(doc, obj, "exe");
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
ffStrbufDestroy(&result.name);
ffStrbufDestroy(&result.path);
ffStrbufDestroy(&result.version);
}
void ffPrintEditorHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_EDITOR_MODULE_NAME, "{2} ({4})", FF_EDITOR_NUM_FORMAT_ARGS, ((const char* []) {
"Name",
"Exe name",
"Full path",
"Version",
}));
}
void ffInitEditorOptions(FFEditorOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_EDITOR_MODULE_NAME,
"Print information of the default editor ($VISUAL or $EDITOR)",
ffParseEditorCommandOptions,
ffParseEditorJsonObject,
ffPrintEditor,
ffGenerateEditorJsonResult,
ffPrintEditorHelpFormat,
ffGenerateEditorJsonConfig
);
ffOptionInitModuleArg(&options->moduleArgs);
}
void ffDestroyEditorOptions(FFEditorOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include "fastfetch.h"
#define FF_EDITOR_MODULE_NAME "Editor"
void ffPrintEditor(FFEditorOptions* options);
void ffInitEditorOptions(FFEditorOptions* options);
void ffDestroyEditorOptions(FFEditorOptions* options);
+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 FFEditorOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFEditorOptions;
+1
View File
@@ -22,6 +22,7 @@
#include "modules/diskio/diskio.h"
#include "modules/display/display.h"
#include "modules/de/de.h"
#include "modules/editor/editor.h"
#include "modules/font/font.h"
#include "modules/gamepad/gamepad.h"
#include "modules/gpu/gpu.h"
+1
View File
@@ -22,6 +22,7 @@
#include "modules/disk/option.h"
#include "modules/diskio/option.h"
#include "modules/display/option.h"
#include "modules/editor/option.h"
#include "modules/font/option.h"
#include "modules/host/option.h"
#include "modules/gamepad/option.h"
+2
View File
@@ -23,6 +23,7 @@ void ffOptionsInitModules(FFOptionsModules* options)
ffInitDiskOptions(&options->disk);
ffInitDiskIOOptions(&options->diskIo);
ffInitDisplayOptions(&options->display);
ffInitEditorOptions(&options->editor);
ffInitFontOptions(&options->font);
ffInitGPUOptions(&options->gpu);
ffInitGamepadOptions(&options->gamepad);
@@ -90,6 +91,7 @@ void ffOptionsDestroyModules(FFOptionsModules* options)
ffDestroyDiskOptions(&options->disk);
ffDestroyDiskIOOptions(&options->diskIo);
ffDestroyDisplayOptions(&options->display);
ffDestroyEditorOptions(&options->editor);
ffDestroyFontOptions(&options->font);
ffDestroyGPUOptions(&options->gpu);
ffDestroyGamepadOptions(&options->gamepad);
+1
View File
@@ -24,6 +24,7 @@ typedef struct FFOptionsModules
FFDiskOptions disk;
FFDiskIOOptions diskIo;
FFDisplayOptions display;
FFEditorOptions editor;
FFFontOptions font;
FFGPUOptions gpu;
FFGamepadOptions gamepad;
+2 -2
View File
@@ -389,8 +389,8 @@ void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index)
if(strbuf->allocated == 0)
{
//static string
strbuf->length -= index;
strbuf->chars += index;
strbuf->length -= index + 1;
strbuf->chars += index + 1;
return;
}
+1 -1
View File
@@ -68,7 +68,7 @@ FF_C_NODISCARD uint32_t ffStrbufPreviousIndexC(const FFstrbuf* strbuf, uint32_t
void ffStrbufReplaceAllC(FFstrbuf* strbuf, char find, char replace);
void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);
void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index);
void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index); // Not including the index
void ffStrbufSubstrAfterFirstC(FFstrbuf* strbuf, char c);
void ffStrbufSubstrAfterFirstS(FFstrbuf* strbuf, const char* str);
void ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, char c);