From b4cd47cbc492ae804075a0f19e81a44ffdd35db8 Mon Sep 17 00:00:00 2001 From: Mohammed Keyvanzadeh Date: Wed, 8 Nov 2023 15:46:44 +0330 Subject: [PATCH 001/118] src: end va_list before returning (#618) Explicitly end the `va_list` before returning in the `ffStrbufSetF()` function as `va_list`s are not ended implicitly. --- src/util/FFstrbuf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 221a98fc3..dc941a7ef 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -167,8 +167,11 @@ void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...) va_list arguments; va_start(arguments, format); - if(strbuf->allocated == 0) - return ffStrbufInitVF(strbuf, format, arguments); + if(strbuf->allocated == 0) { + ffStrbufInitVF(strbuf, format, arguments); + va_end(arguments); + return; + } ffStrbufClear(strbuf); ffStrbufAppendVF(strbuf, format, arguments); From f9597eba39d6afd278eeca2f2972f73a7e54f111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 8 Nov 2023 14:21:18 +0800 Subject: [PATCH 002/118] Global: remove `#ifndef FF_INCLUDED_*` guards --- src/common/bar.h | 5 ----- src/common/commandoption.h | 5 ----- src/common/dbus.h | 4 ---- src/common/font.h | 5 ----- src/common/format.h | 5 ----- src/common/io/io.h | 5 ----- src/common/library.h | 5 ----- src/common/networking.h | 5 ----- src/common/parsing.h | 5 ----- src/common/printing.h | 5 ----- src/common/processing.h | 5 ----- src/common/properties.h | 5 ----- src/common/settings.h | 5 ----- src/common/sysctl.h | 5 ----- src/common/thread.h | 5 ----- src/common/time.h | 5 ----- src/detection/battery/battery.h | 5 ----- src/detection/bios/bios.h | 5 ----- src/detection/bluetooth/bluetooth.h | 5 ----- src/detection/board/board.h | 5 ----- src/detection/brightness/brightness.h | 5 ----- src/detection/chassis/chassis.h | 5 ----- src/detection/cpu/cpu.h | 5 ----- src/detection/cpuusage/cpuusage.h | 5 ----- src/detection/cursor/cursor.h | 5 ----- src/detection/disk/disk.h | 5 ----- src/detection/displayserver/displayserver.h | 5 ----- src/detection/font/font.h | 5 ----- src/detection/gamepad/gamepad.h | 5 ----- src/detection/gpu/gpu.h | 5 ----- src/detection/gtk_qt/gtk_qt.h | 5 ----- src/detection/host/host.h | 5 ----- src/detection/icons/icons.h | 5 ----- src/detection/internal.h | 5 ----- src/detection/libc/libc.h | 5 ----- src/detection/lm/lm.h | 5 ----- src/detection/locale/locale.h | 5 ----- src/detection/localip/localip.h | 5 ----- src/detection/media/media.h | 5 ----- src/detection/memory/memory.h | 5 ----- src/detection/opencl/opencl.h | 5 ----- src/detection/opengl/opengl.h | 5 ----- src/detection/os/os.h | 5 ----- src/detection/packages/packages.h | 5 ----- src/detection/poweradapter/poweradapter.h | 5 ----- src/detection/processes/processes.h | 5 ----- src/detection/publicip/publicip.h | 5 ----- src/detection/sound/sound.h | 5 ----- src/detection/swap/swap.h | 5 ----- src/detection/temps/temps_apple.h | 5 ----- src/detection/temps/temps_bsd.h | 5 ----- src/detection/temps/temps_linux.h | 5 ----- src/detection/temps/temps_windows.h | 5 ----- src/detection/terminalfont/terminalfont.h | 5 ----- src/detection/terminalshell/terminalshell.h | 5 ----- src/detection/terminalsize/terminalsize.h | 5 ----- src/detection/theme/theme.h | 5 ----- src/detection/uptime/uptime.h | 5 ----- src/detection/users/users.h | 5 ----- src/detection/version/version.h | 5 ----- src/detection/vulkan/vulkan.h | 5 ----- src/detection/wallpaper/wallpaper.h | 15 +++++---------- src/detection/weather/weather.h | 5 ----- src/detection/wifi/wifi.h | 5 ----- src/logo/image/image.h | 5 ----- src/util/FFlist.h | 5 ----- src/util/edidHelper.h | 5 ----- src/util/platform/FFPlatform.h | 5 ----- src/util/platform/FFPlatform_private.h | 5 ----- src/util/stringUtils.h | 5 ----- src/util/wcwidth.h | 5 ----- src/util/windows/com.hpp | 5 ----- src/util/windows/wmi.hpp | 5 ----- 73 files changed, 5 insertions(+), 369 deletions(-) diff --git a/src/common/bar.h b/src/common/bar.h index d35276cef..c77234ae6 100644 --- a/src/common/bar.h +++ b/src/common/bar.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_bar -#define FF_INCLUDED_common_bar - #include "fastfetch.h" enum @@ -15,5 +12,3 @@ enum void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, uint8_t red); void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses); - -#endif diff --git a/src/common/commandoption.h b/src/common/commandoption.h index c20d0f81f..276477b91 100644 --- a/src/common/commandoption.h +++ b/src/common/commandoption.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_commandoption -#define FF_INCLUDED_common_commandoption - #include "fastfetch.h" typedef struct FFCustomValue @@ -24,5 +21,3 @@ bool ffParseModuleOptions(const char* key, const char* value); void ffPrepareCommandOption(FFdata* data); void ffPrintCommandOption(FFdata* data, yyjson_mut_doc* jsonDoc); void ffMigrateCommandOptionToJsonc(FFdata* data, yyjson_mut_doc* jsonDoc); - -#endif diff --git a/src/common/dbus.h b/src/common/dbus.h index bf112e244..8c9be36c2 100644 --- a/src/common/dbus.h +++ b/src/common/dbus.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_dbus -#define FF_INCLUDED_common_dbus - #ifdef FF_HAVE_DBUS #include @@ -54,4 +51,3 @@ DBusMessage* ffDBusGetProperty(FFDBusData* dbus, const char* busName, const char void ffDBusGetPropertyString(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property, FFstrbuf* result); #endif // FF_HAVE_DBUS -#endif // FF_INCLUDED_common_dbus diff --git a/src/common/font.h b/src/common/font.h index 58b3841ae..5ececb2f6 100644 --- a/src/common/font.h +++ b/src/common/font.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_font -#define FF_INCLUDED_common_font - #include "util/FFstrbuf.h" #include "util/FFlist.h" @@ -21,5 +18,3 @@ void ffFontInitCopy(FFfont* font, const char* name); void ffFontInitValues(FFfont* font, const char* name, const char* size); void ffFontInitWithSpace(FFfont* font, const char* rawName); void ffFontDestroy(FFfont* font); - -#endif diff --git a/src/common/format.h b/src/common/format.h index 3e7c751f2..969de6c36 100644 --- a/src/common/format.h +++ b/src/common/format.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_format -#define FF_INCLUDED_common_format - typedef enum FFformatargtype { FF_FORMAT_ARG_TYPE_NULL = 0, @@ -27,5 +24,3 @@ typedef struct FFformatarg void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg); void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments); - -#endif diff --git a/src/common/io/io.h b/src/common/io/io.h index 78c94ad9f..f25381e51 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_io_io -#define FF_INCLUDED_common_io_io - #include "util/FFstrbuf.h" #ifdef _WIN32 @@ -153,5 +150,3 @@ static inline bool wrapClosedir(HANDLE* pdir) } #endif #define FF_AUTO_CLOSE_DIR __attribute__((__cleanup__(wrapClosedir))) - -#endif // FF_INCLUDED_common_io_io diff --git a/src/common/library.h b/src/common/library.h index 1721ea8d3..5a283bc2e 100644 --- a/src/common/library.h +++ b/src/common/library.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_library -#define FF_INCLUDED_common_library - #include "fastfetch.h" #include "util/FFcheckmacros.h" @@ -74,5 +71,3 @@ static inline void ffLibraryUnload(void** handle) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue); void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...); - -#endif diff --git a/src/common/networking.h b/src/common/networking.h index f27850477..1fb4589d9 100644 --- a/src/common/networking.h +++ b/src/common/networking.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_networking -#define FF_INCLUDED_common_networking - #include "common/thread.h" #include "util/FFstrbuf.h" @@ -35,5 +32,3 @@ static inline bool ffNetworkingGetHttp(const char* host, const char* path, uint3 return ffNetworkingRecvHttpResponse(&state, buffer, timeout); return false; } - -#endif diff --git a/src/common/parsing.h b/src/common/parsing.h index deb555c01..e98883b06 100644 --- a/src/common/parsing.h +++ b/src/common/parsing.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_parsing_h -#define FF_INCLUDED_parsing_h - #include "fastfetch.h" #include @@ -24,5 +21,3 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2); void ffParseSize(uint64_t bytes, FFstrbuf* result); void ffParseTemperature(double celsius, FFstrbuf* buffer); - -#endif diff --git a/src/common/printing.h b/src/common/printing.h index d9925757c..5b8d1b6ad 100644 --- a/src/common/printing.h +++ b/src/common/printing.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_printing -#define FF_INCLUDED_common_printing - #include "fastfetch.h" #include "common/format.h" @@ -26,5 +23,3 @@ void ffPrintColor(const FFstrbuf* colorValue); void ffPrintCharTimes(char c, uint32_t times); void ffPrintModuleFormatHelp(const char* name, const char* def, uint32_t numArgs, const char* args[]); - -#endif diff --git a/src/common/processing.h b/src/common/processing.h index 380c2a36e..98b9fe09f 100644 --- a/src/common/processing.h +++ b/src/common/processing.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_processing -#define FF_INCLUDED_common_processing - #include "util/FFstrbuf.h" const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool useStdErr); @@ -28,5 +25,3 @@ static inline const char* ffProcessAppendStdErr(FFstrbuf* buffer, char* const ar } return error; } - -#endif diff --git a/src/common/properties.h b/src/common/properties.h index 8b65e419c..69ea5ddf4 100644 --- a/src/common/properties.h +++ b/src/common/properties.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_properties -#define FF_INCLUDED_common_properties - #include "fastfetch.h" typedef struct FFpropquery @@ -51,5 +48,3 @@ static inline bool ffParsePropFileData(const char* relativeFile, const char* sta { return ffParsePropFileDataValues(relativeFile, 1, (FFpropquery[]){{start, buffer}}); } - -#endif diff --git a/src/common/settings.h b/src/common/settings.h index 212727fe9..0b87bb33e 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_settings -#define FF_INCLUDED_common_settings - #include "fastfetch.h" typedef enum FFvarianttype @@ -38,5 +35,3 @@ bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result); #elif defined(__FreeBSD__) bool ffSettingsGetFreeBSDKenv(const char* propName, FFstrbuf* result); #endif - -#endif diff --git a/src/common/sysctl.h b/src/common/sysctl.h index 562e625d5..2a210de86 100644 --- a/src/common/sysctl.h +++ b/src/common/sysctl.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_sysctl -#define FF_INCLUDED_common_sysctl - #include "fastfetch.h" #include "util/FFcheckmacros.h" @@ -13,5 +10,3 @@ const char* ffSysctlGetString(const char* propName, FFstrbuf* result); FF_C_NODISCARD int ffSysctlGetInt(const char* propName, int defaultValue); FF_C_NODISCARD int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue); FF_C_NODISCARD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength); - -#endif diff --git a/src/common/thread.h b/src/common/thread.h index 55b4c5be7..2fd328cf4 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_thread -#define FF_INCLUDED_common_thread - #include "fastfetch.h" #ifdef FF_HAVE_THREADS @@ -82,5 +79,3 @@ static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { FF_UNUSED(mutex) } #define FF_THREAD_ENTRY_DECL_WRAPPER(fn, paramType) #endif //FF_HAVE_THREADS - -#endif diff --git a/src/common/time.h b/src/common/time.h index 8da249448..4dd00f0e3 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_common_time -#define FF_INCLUDED_common_time - #include #ifdef _WIN32 #include @@ -48,5 +45,3 @@ static inline void ffTimeSleep(uint32_t msec) nanosleep(&(struct timespec){ msec / 1000, (msec % 1000) * 1000000 }, NULL); #endif } - -#endif diff --git a/src/detection/battery/battery.h b/src/detection/battery/battery.h index 8f94e93a8..6dfe6466b 100644 --- a/src/detection/battery/battery.h +++ b/src/detection/battery/battery.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_battery_battery -#define FF_INCLUDED_detection_battery_battery - #include "fastfetch.h" #define FF_BATTERY_TEMP_UNSET (0/0.0) @@ -19,5 +16,3 @@ typedef struct FFBatteryResult } FFBatteryResult; const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results); - -#endif diff --git a/src/detection/bios/bios.h b/src/detection/bios/bios.h index 04d55811c..5272c5ca1 100644 --- a/src/detection/bios/bios.h +++ b/src/detection/bios/bios.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_bios_bios -#define FF_INCLUDED_detection_bios_bios - #include "fastfetch.h" typedef struct FFBiosResult @@ -15,5 +12,3 @@ typedef struct FFBiosResult } FFBiosResult; const char* ffDetectBios(FFBiosResult* bios); - -#endif diff --git a/src/detection/bluetooth/bluetooth.h b/src/detection/bluetooth/bluetooth.h index a9c07b161..0702abbdb 100644 --- a/src/detection/bluetooth/bluetooth.h +++ b/src/detection/bluetooth/bluetooth.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_bluetooth_bluetooth -#define FF_INCLUDED_detection_bluetooth_bluetooth - #include "fastfetch.h" typedef struct FFBluetoothResult @@ -15,5 +12,3 @@ typedef struct FFBluetoothResult } FFBluetoothResult; const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */); - -#endif diff --git a/src/detection/board/board.h b/src/detection/board/board.h index bc232e244..c847436b5 100644 --- a/src/detection/board/board.h +++ b/src/detection/board/board.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_board_board -#define FF_INCLUDED_detection_board_board - #include "fastfetch.h" typedef struct FFBoardResult @@ -13,5 +10,3 @@ typedef struct FFBoardResult } FFBoardResult; const char* ffDetectBoard(FFBoardResult* result); - -#endif diff --git a/src/detection/brightness/brightness.h b/src/detection/brightness/brightness.h index b32e5d15c..f0adf329d 100644 --- a/src/detection/brightness/brightness.h +++ b/src/detection/brightness/brightness.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_brightness_brightness -#define FF_INCLUDED_detection_brightness_brightness - #include "fastfetch.h" #include "util/FFlist.h" @@ -13,5 +10,3 @@ typedef struct FFBrightnessResult } FFBrightnessResult; const char* ffDetectBrightness(FFBrightnessOptions* options, FFlist* result); // list of FFBrightnessResult - -#endif diff --git a/src/detection/chassis/chassis.h b/src/detection/chassis/chassis.h index 534141666..60befc83e 100644 --- a/src/detection/chassis/chassis.h +++ b/src/detection/chassis/chassis.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_chassis_chassis -#define FF_INCLUDED_detection_chassis_chassis - #include "fastfetch.h" typedef struct FFChassisResult @@ -14,5 +11,3 @@ typedef struct FFChassisResult const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options); const char* ffChassisTypeToString(uint32_t type); - -#endif diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index 7dd1c29d2..9ae364808 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_cpu_cpu -#define FF_INCLUDED_detection_cpu_cpu - #include "fastfetch.h" #define FF_CPU_TEMP_UNSET (0/0.0) @@ -23,5 +20,3 @@ typedef struct FFCPUResult } FFCPUResult; const char* ffDetectCPU(const FFCPUOptions* options, FFCPUResult* cpu); - -#endif diff --git a/src/detection/cpuusage/cpuusage.h b/src/detection/cpuusage/cpuusage.h index 655239350..839902e6e 100644 --- a/src/detection/cpuusage/cpuusage.h +++ b/src/detection/cpuusage/cpuusage.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_cpuusage_cpuusage -#define FF_INCLUDED_detection_cpuusage_cpuusage - #include "fastfetch.h" typedef struct FFCpuUsageInfo { @@ -12,5 +9,3 @@ typedef struct FFCpuUsageInfo { const char* ffGetCpuUsageInfo(FFlist* cpuTimes); const char* ffGetCpuUsageResult(FFlist* result); // list of double - -#endif diff --git a/src/detection/cursor/cursor.h b/src/detection/cursor/cursor.h index 793721f0b..3e3ff6d40 100644 --- a/src/detection/cursor/cursor.h +++ b/src/detection/cursor/cursor.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_cursor_cursor -#define FF_INCLUDED_detection_cursor_cursor - #include "fastfetch.h" typedef struct FFCursorResult @@ -13,5 +10,3 @@ typedef struct FFCursorResult } FFCursorResult; void ffDetectCursor(FFCursorResult* result); - -#endif diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index 3ccab52c4..72ea82f2c 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_disk_disk -#define FF_INCLUDED_detection_disk_disk - #include "fastfetch.h" typedef struct FFDisk @@ -27,5 +24,3 @@ typedef struct FFDisk * If error is not set, disks contains at least one disk. */ const char* ffDetectDisks(FFDiskOptions* options, FFlist* result /* list of FFDisk */); - -#endif diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index 4ae40320f..7a5ebb8f8 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_displayserver -#define FF_INCLUDED_detection_displayserver - #include "fastfetch.h" #define FF_DE_PRETTY_PLASMA "KDE Plasma" @@ -85,5 +82,3 @@ bool ffdsAppendDisplay( FFDisplayType type, bool primary, uint64_t id); - -#endif diff --git a/src/detection/font/font.h b/src/detection/font/font.h index 22e402652..411efde7a 100644 --- a/src/detection/font/font.h +++ b/src/detection/font/font.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_font_font -#define FF_INCLUDED_detection_font_font - #include "fastfetch.h" #define FF_DETECT_FONT_NUM_FONTS 4 @@ -20,5 +17,3 @@ typedef struct FFFontResult } FFFontResult; const char* ffDetectFont(FFFontResult* font); - -#endif diff --git a/src/detection/gamepad/gamepad.h b/src/detection/gamepad/gamepad.h index 59519bb16..be63e9dea 100644 --- a/src/detection/gamepad/gamepad.h +++ b/src/detection/gamepad/gamepad.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_gamepad_gamepad -#define FF_INCLUDED_detection_gamepad_gamepad - #include "fastfetch.h" typedef struct FFGamepadDevice @@ -12,5 +9,3 @@ typedef struct FFGamepadDevice } FFGamepadDevice; const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */); - -#endif diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 70ccd96b2..9c73637cc 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_gpu_gpu -#define FF_INCLUDED_detection_gpu_gpu - #include "fastfetch.h" #define FF_GPU_TEMP_UNSET (0/0.0) @@ -42,5 +39,3 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result); const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus); const char* ffGetGPUVendorString(unsigned vendorId); - -#endif diff --git a/src/detection/gtk_qt/gtk_qt.h b/src/detection/gtk_qt/gtk_qt.h index ef329f03a..58b373b8e 100644 --- a/src/detection/gtk_qt/gtk_qt.h +++ b/src/detection/gtk_qt/gtk_qt.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_gtkqt_gtkqt -#define FF_INCLUDED_detection_gtkqt_gtkqt - #include "fastfetch.h" typedef struct FFGTKResult @@ -28,5 +25,3 @@ const FFGTKResult* ffDetectGTK2(void); const FFGTKResult* ffDetectGTK4(void); const FFGTKResult* ffDetectGTK3(void); const FFQtResult* ffDetectQt(void); - -#endif diff --git a/src/detection/host/host.h b/src/detection/host/host.h index a0fd66511..f3b1011f2 100644 --- a/src/detection/host/host.h +++ b/src/detection/host/host.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_host_host -#define FF_INCLUDED_detection_host_host - #include "fastfetch.h" typedef struct FFHostResult @@ -15,5 +12,3 @@ typedef struct FFHostResult } FFHostResult; const char* ffDetectHost(FFHostResult* result); - -#endif diff --git a/src/detection/icons/icons.h b/src/detection/icons/icons.h index 744dc3f5f..3e2096e09 100644 --- a/src/detection/icons/icons.h +++ b/src/detection/icons/icons.h @@ -1,10 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_icons -#define FF_INCLUDED_detection_icons - #include "fastfetch.h" const char* ffDetectIcons(FFstrbuf* result); - -#endif diff --git a/src/detection/internal.h b/src/detection/internal.h index 19ec8d1a2..a25f8fee6 100644 --- a/src/detection/internal.h +++ b/src/detection/internal.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_internal -#define FF_INCLUDED_detection_internal - #include "common/thread.h" #define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \ @@ -13,5 +10,3 @@ init = true; \ __VA_ARGS__; \ return &result; \ - -#endif diff --git a/src/detection/libc/libc.h b/src/detection/libc/libc.h index dc89cc2be..ea7bb8013 100644 --- a/src/detection/libc/libc.h +++ b/src/detection/libc/libc.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_libc_libc -#define FF_INCLUDED_detection_libc_libc - #include "fastfetch.h" typedef struct FFLibcResult @@ -12,5 +9,3 @@ typedef struct FFLibcResult } FFLibcResult; const char* ffDetectLibc(FFLibcResult* result); - -#endif diff --git a/src/detection/lm/lm.h b/src/detection/lm/lm.h index e118419a5..4cbaf7c13 100644 --- a/src/detection/lm/lm.h +++ b/src/detection/lm/lm.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_lm_lm -#define FF_INCLUDED_detection_lm_lm - #include "fastfetch.h" typedef struct FFLMResult @@ -13,5 +10,3 @@ typedef struct FFLMResult } FFLMResult; const char* ffDetectLM(FFLMResult* result); - -#endif diff --git a/src/detection/locale/locale.h b/src/detection/locale/locale.h index 6ca84ab6f..2fe9cd0bf 100644 --- a/src/detection/locale/locale.h +++ b/src/detection/locale/locale.h @@ -1,10 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_locale_locale -#define FF_INCLUDED_detection_locale_locale - #include "fastfetch.h" void ffDetectLocale(FFstrbuf* result); - -#endif diff --git a/src/detection/localip/localip.h b/src/detection/localip/localip.h index 8d0fe84bf..fe50575ad 100644 --- a/src/detection/localip/localip.h +++ b/src/detection/localip/localip.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_localip_localip -#define FF_INCLUDED_detection_localip_localip - #include "fastfetch.h" typedef struct FFLocalIpResult @@ -15,5 +12,3 @@ typedef struct FFLocalIpResult } FFLocalIpResult; const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results); - -#endif diff --git a/src/detection/media/media.h b/src/detection/media/media.h index 8043e0d93..5c97da471 100644 --- a/src/detection/media/media.h +++ b/src/detection/media/media.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_media -#define FF_INCLUDED_detection_media - #include "fastfetch.h" typedef struct FFMediaResult @@ -18,5 +15,3 @@ typedef struct FFMediaResult } FFMediaResult; const FFMediaResult* ffDetectMedia(); - -#endif diff --git a/src/detection/memory/memory.h b/src/detection/memory/memory.h index bc140e689..9e88c6118 100644 --- a/src/detection/memory/memory.h +++ b/src/detection/memory/memory.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_memory_memory -#define FF_INCLUDED_detection_memory_memory - #include "fastfetch.h" typedef struct FFMemoryResult @@ -12,5 +9,3 @@ typedef struct FFMemoryResult } FFMemoryResult; const char* ffDetectMemory(FFMemoryResult* result); - -#endif diff --git a/src/detection/opencl/opencl.h b/src/detection/opencl/opencl.h index 56a96c98f..5daaacbda 100644 --- a/src/detection/opencl/opencl.h +++ b/src/detection/opencl/opencl.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_opencl_opencl -#define FF_INCLUDED_detection_opencl_opencl - #include "fastfetch.h" typedef struct FFOpenCLResult @@ -13,5 +10,3 @@ typedef struct FFOpenCLResult } FFOpenCLResult; const char* ffDetectOpenCL(FFOpenCLResult* result); - -#endif diff --git a/src/detection/opengl/opengl.h b/src/detection/opengl/opengl.h index fbd9e897d..3c878f97c 100644 --- a/src/detection/opengl/opengl.h +++ b/src/detection/opengl/opengl.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_opengl_opengl -#define FF_INCLUDED_detection_opengl_opengl - #include "fastfetch.h" typedef struct FFOpenGLResult @@ -14,5 +11,3 @@ typedef struct FFOpenGLResult } FFOpenGLResult; const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result); - -#endif diff --git a/src/detection/os/os.h b/src/detection/os/os.h index 87af406a9..e1b7828fe 100644 --- a/src/detection/os/os.h +++ b/src/detection/os/os.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_os_os -#define FF_INCLUDED_detection_os_os - #include "fastfetch.h" typedef struct FFOSResult @@ -20,5 +17,3 @@ typedef struct FFOSResult } FFOSResult; const FFOSResult* ffDetectOS(); - -#endif diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 1fb5e0d85..b7d7520b5 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_packages_packages -#define FF_INCLUDED_detection_packages_packages - #include "fastfetch.h" typedef struct FFPackagesResult @@ -37,5 +34,3 @@ typedef struct FFPackagesResult } FFPackagesResult; const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options); - -#endif diff --git a/src/detection/poweradapter/poweradapter.h b/src/detection/poweradapter/poweradapter.h index 0c60d4d9f..21c93b64a 100644 --- a/src/detection/poweradapter/poweradapter.h +++ b/src/detection/poweradapter/poweradapter.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_poweradapter_poweradapter -#define FF_INCLUDED_detection_poweradapter_poweradapter - #include "fastfetch.h" typedef struct FFPowerAdapterResult @@ -18,5 +15,3 @@ const char* ffDetectPowerAdapterImpl(FFlist* results); #define FF_POWERADAPTER_UNSET -2 #define FF_POWERADAPTER_NOT_CONNECTED -1 - -#endif diff --git a/src/detection/processes/processes.h b/src/detection/processes/processes.h index 3feaaed87..69cf46381 100644 --- a/src/detection/processes/processes.h +++ b/src/detection/processes/processes.h @@ -1,10 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_processes_processes -#define FF_INCLUDED_detection_processes_processes - #include "fastfetch.h" const char* ffDetectProcesses(uint32_t* result); - -#endif diff --git a/src/detection/publicip/publicip.h b/src/detection/publicip/publicip.h index 1313cc46a..463514762 100644 --- a/src/detection/publicip/publicip.h +++ b/src/detection/publicip/publicip.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_publicip_publicip -#define FF_INCLUDED_detection_publicip_publicip - #include "fastfetch.h" typedef struct FFPublicIpResult @@ -13,5 +10,3 @@ typedef struct FFPublicIpResult void ffPreparePublicIp(FFPublicIpOptions* options); const char* ffDetectPublicIp(FFPublicIpOptions* options, FFPublicIpResult* result); - -#endif diff --git a/src/detection/sound/sound.h b/src/detection/sound/sound.h index 350a4f3e6..6ad811044 100644 --- a/src/detection/sound/sound.h +++ b/src/detection/sound/sound.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_sound_sound -#define FF_INCLUDED_detection_sound_sound - #include "fastfetch.h" #define FF_SOUND_VOLUME_UNKNOWN 255 @@ -17,5 +14,3 @@ typedef struct FFSoundDevice } FFSoundDevice; const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */); - -#endif diff --git a/src/detection/swap/swap.h b/src/detection/swap/swap.h index 18e74c7ba..f52654ca4 100644 --- a/src/detection/swap/swap.h +++ b/src/detection/swap/swap.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_swap_swap -#define FF_INCLUDED_detection_swap_swap - #include "fastfetch.h" typedef struct FFSwapResult @@ -12,5 +9,3 @@ typedef struct FFSwapResult } FFSwapResult; const char* ffDetectSwap(FFSwapResult* result); - -#endif diff --git a/src/detection/temps/temps_apple.h b/src/detection/temps/temps_apple.h index 0fe4b0174..7d340ba22 100644 --- a/src/detection/temps/temps_apple.h +++ b/src/detection/temps/temps_apple.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_temps_apple -#define FF_INCLUDED_detection_temps_apple - #include "fastfetch.h" #include "util/FFlist.h" @@ -31,5 +28,3 @@ enum FFTempType }; const char *ffDetectCoreTemps(enum FFTempType type, double* result); - -#endif diff --git a/src/detection/temps/temps_bsd.h b/src/detection/temps/temps_bsd.h index b126811a0..36789740b 100644 --- a/src/detection/temps/temps_bsd.h +++ b/src/detection/temps/temps_bsd.h @@ -1,9 +1,4 @@ #pragma once -#ifndef FF_INCLUDED_detection_temps_windows -#define FF_INCLUDED_detection_temps_windows - const char* ffDetectCpuTemp(double* current); const char* ffDetectThermalTemp(double* current); - -#endif diff --git a/src/detection/temps/temps_linux.h b/src/detection/temps/temps_linux.h index f99dd4138..0d153ccfd 100644 --- a/src/detection/temps/temps_linux.h +++ b/src/detection/temps/temps_linux.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_temps_linux -#define FF_INCLUDED_detection_temps_linux - #include "fastfetch.h" typedef struct FFTempValue @@ -13,5 +10,3 @@ typedef struct FFTempValue } FFTempValue; const FFlist* /* List of FFTempValue */ ffDetectTemps(); - -#endif diff --git a/src/detection/temps/temps_windows.h b/src/detection/temps/temps_windows.h index 57e27ba5a..501cc0aa7 100644 --- a/src/detection/temps/temps_windows.h +++ b/src/detection/temps/temps_windows.h @@ -1,8 +1,3 @@ #pragma once -#ifndef FF_INCLUDED_detection_temps_windows -#define FF_INCLUDED_detection_temps_windows - const char* ffDetectSmbiosTemp(double* current, double* critical); - -#endif diff --git a/src/detection/terminalfont/terminalfont.h b/src/detection/terminalfont/terminalfont.h index 936cdeb4f..0cb33b71d 100644 --- a/src/detection/terminalfont/terminalfont.h +++ b/src/detection/terminalfont/terminalfont.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_terminalfont_terminalfont -#define FF_INCLUDED_detection_terminalfont_terminalfont - #include "fastfetch.h" #include "common/font.h" @@ -14,5 +11,3 @@ typedef struct FFTerminalFontResult } FFTerminalFontResult; bool ffDetectTerminalFont(FFTerminalFontResult* result); - -#endif diff --git a/src/detection/terminalshell/terminalshell.h b/src/detection/terminalshell/terminalshell.h index 41e31700f..3dbb0633f 100644 --- a/src/detection/terminalshell/terminalshell.h +++ b/src/detection/terminalshell/terminalshell.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_terminalshell -#define FF_INCLUDED_detection_terminalshell - #include "fastfetch.h" typedef struct FFTerminalShellResult @@ -23,5 +20,3 @@ typedef struct FFTerminalShellResult } FFTerminalShellResult; const FFTerminalShellResult* ffDetectTerminalShell(); - -#endif diff --git a/src/detection/terminalsize/terminalsize.h b/src/detection/terminalsize/terminalsize.h index b1b51ebe5..f8b116d73 100644 --- a/src/detection/terminalsize/terminalsize.h +++ b/src/detection/terminalsize/terminalsize.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_terminalsize_terminalsize -#define FF_INCLUDED_detection_terminalsize_terminalsize - #include "fastfetch.h" typedef struct FFTerminalSizeResult @@ -14,5 +11,3 @@ typedef struct FFTerminalSizeResult } FFTerminalSizeResult; bool ffDetectTerminalSize(FFTerminalSizeResult* result); - -#endif diff --git a/src/detection/theme/theme.h b/src/detection/theme/theme.h index ec4c596e8..2536c6fb7 100644 --- a/src/detection/theme/theme.h +++ b/src/detection/theme/theme.h @@ -1,10 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_theme -#define FF_INCLUDED_detection_theme - #include "fastfetch.h" const char* ffDetectTheme(FFstrbuf* result); - -#endif diff --git a/src/detection/uptime/uptime.h b/src/detection/uptime/uptime.h index 105e1bfa5..6f0696d39 100644 --- a/src/detection/uptime/uptime.h +++ b/src/detection/uptime/uptime.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_uptime_uptime -#define FF_INCLUDED_detection_uptime_uptime - #include "fastfetch.h" typedef struct FFUptimeResult @@ -12,5 +9,3 @@ typedef struct FFUptimeResult } FFUptimeResult; const char* ffDetectUptime(FFUptimeResult* result); - -#endif diff --git a/src/detection/users/users.h b/src/detection/users/users.h index 38b3cf204..67be7f1fd 100644 --- a/src/detection/users/users.h +++ b/src/detection/users/users.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_users_users -#define FF_INCLUDED_detection_users_users - #include "fastfetch.h" typedef struct FFUserResult @@ -15,5 +12,3 @@ typedef struct FFUserResult } FFUserResult; const char* ffDetectUsers(FFlist* users); - -#endif diff --git a/src/detection/version/version.h b/src/detection/version/version.h index 4cb7b9ac6..5227561e0 100644 --- a/src/detection/version/version.h +++ b/src/detection/version/version.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_version_version -#define FF_INCLUDED_detection_version_version - #include "fastfetch.h" typedef struct FFVersionResult @@ -18,5 +15,3 @@ typedef struct FFVersionResult } FFVersionResult; void ffDetectVersion(FFVersionResult* version); - -#endif diff --git a/src/detection/vulkan/vulkan.h b/src/detection/vulkan/vulkan.h index 560fcdc53..9ac051cbc 100644 --- a/src/detection/vulkan/vulkan.h +++ b/src/detection/vulkan/vulkan.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_vulkan -#define FF_INCLUDED_detection_vulkan - #include "fastfetch.h" typedef struct FFVulkanResult @@ -15,5 +12,3 @@ typedef struct FFVulkanResult } FFVulkanResult; FFVulkanResult* ffDetectVulkan(); - -#endif diff --git a/src/detection/wallpaper/wallpaper.h b/src/detection/wallpaper/wallpaper.h index f75ad77dd..96fead922 100644 --- a/src/detection/wallpaper/wallpaper.h +++ b/src/detection/wallpaper/wallpaper.h @@ -1,10 +1,5 @@ -#pragma once - -#ifndef FF_INCLUDED_detection_wallpaper -#define FF_INCLUDED_detection_wallpaper - -#include "fastfetch.h" - -const char* ffDetectWallpaper(FFstrbuf* result); - -#endif +#pragma once + +#include "fastfetch.h" + +const char* ffDetectWallpaper(FFstrbuf* result); diff --git a/src/detection/weather/weather.h b/src/detection/weather/weather.h index c15f1ea3a..55a578628 100644 --- a/src/detection/weather/weather.h +++ b/src/detection/weather/weather.h @@ -1,11 +1,6 @@ #pragma once -#ifndef FF_INCLUDED_detection_weather_weather -#define FF_INCLUDED_detection_weather_weather - #include "common/networking.h" void ffPrepareWeather(FFWeatherOptions* options); const char* ffDetectWeather(FFWeatherOptions* options, FFstrbuf* result); - -#endif diff --git a/src/detection/wifi/wifi.h b/src/detection/wifi/wifi.h index d3257a9ef..2e292439d 100644 --- a/src/detection/wifi/wifi.h +++ b/src/detection/wifi/wifi.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_detection_wifi_wifi -#define FF_INCLUDED_detection_wifi_wifi - #include "fastfetch.h" struct FFWifiInterface @@ -30,5 +27,3 @@ typedef struct FFWifiResult } FFWifiResult; const char* ffDetectWifi(FFlist* result /*list of FFWifiItem*/); - -#endif diff --git a/src/logo/image/image.h b/src/logo/image/image.h index 7d54edd8a..608286392 100644 --- a/src/logo/image/image.h +++ b/src/logo/image/image.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_LOGO_SIXEL_sixel -#define FF_INCLUDED_LOGO_SIXEL_sixel - #include "../logo.h" #if defined(FF_HAVE_IMAGEMAGICK7) || defined(FF_HAVE_IMAGEMAGICK6) @@ -47,5 +44,3 @@ FFLogoImageResult ffLogoPrintImageIM7(FFLogoRequestData* requestData); #include FFLogoImageResult ffLogoPrintImageIM6(FFLogoRequestData* requestData); #endif - -#endif diff --git a/src/util/FFlist.h b/src/util/FFlist.h index 0f71b1bff..c3fd451e5 100644 --- a/src/util/FFlist.h +++ b/src/util/FFlist.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_FFLIST -#define FF_INCLUDED_FFLIST - #include "FFcheckmacros.h" #include @@ -109,5 +106,3 @@ static inline void ffListClear(FFlist* list) assert((listVar).capacity > (index)); \ (itemType*)(listVar).data + (index); \ }) - -#endif diff --git a/src/util/edidHelper.h b/src/util/edidHelper.h index 75fa6ce8c..2fc8d591d 100644 --- a/src/util/edidHelper.h +++ b/src/util/edidHelper.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_EDID_HELPER_H -#define FF_INCLUDED_EDID_HELPER_H - #include #include "util/FFstrbuf.h" @@ -11,5 +8,3 @@ bool ffEdidGetName(const uint8_t edid[128], FFstrbuf* name); void ffEdidGetPhysicalResolution(const uint8_t edid[128], uint32_t* width, uint32_t* height); void ffEdidGetPhysicalSize(const uint8_t edid[128], uint32_t* width, uint32_t* height); // in mm bool ffEdidGetHdrCompatible(const uint8_t* edid, uint32_t length); - -#endif diff --git a/src/util/platform/FFPlatform.h b/src/util/platform/FFPlatform.h index 6386cf479..8594e2039 100644 --- a/src/util/platform/FFPlatform.h +++ b/src/util/platform/FFPlatform.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_util_platform_FFPlatform -#define FF_INCLUDED_util_platform_FFPlatform - #include "util/FFstrbuf.h" #include "util/FFlist.h" @@ -28,5 +25,3 @@ typedef struct FFPlatform { void ffPlatformInit(FFPlatform* platform); void ffPlatformDestroy(FFPlatform* platform); - -#endif diff --git a/src/util/platform/FFPlatform_private.h b/src/util/platform/FFPlatform_private.h index d81e6f9cf..bb0247e6a 100644 --- a/src/util/platform/FFPlatform_private.h +++ b/src/util/platform/FFPlatform_private.h @@ -1,13 +1,8 @@ #pragma once -#ifndef FF_INCLUDED_util_platform_FFPlatform_private -#define FF_INCLUDED_util_platform_FFPlatform_private - #include "FFPlatform.h" void ffPlatformInitImpl(FFPlatform* platform); void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path); void ffPlatformPathAddHome(FFlist* dirs, const FFPlatform* platform, const char* suffix); - -#endif diff --git a/src/util/stringUtils.h b/src/util/stringUtils.h index d3ff894c6..e67298224 100644 --- a/src/util/stringUtils.h +++ b/src/util/stringUtils.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_util_stringUtils_h -#define FF_INCLUDED_util_stringUtils_h - #include #include #include @@ -47,5 +44,3 @@ static inline bool ffStrEquals(const char* str, const char* compareTo) { return strcmp(str, compareTo) == 0; } - -#endif diff --git a/src/util/wcwidth.h b/src/util/wcwidth.h index eaeceed22..4252e0f36 100644 --- a/src/util/wcwidth.h +++ b/src/util/wcwidth.h @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_UTIL_WCWIDTH_H -#define FF_INCLUDED_UTIL_WCWIDTH_H - #include #ifdef FF_HAVE_WCWIDTH @@ -17,5 +14,3 @@ static inline int mk_wcswidth(const wchar_t *pwcs, size_t n) { int mk_wcwidth(wchar_t ucs); int mk_wcswidth(const wchar_t *pwcs, size_t n); #endif - -#endif diff --git a/src/util/windows/com.hpp b/src/util/windows/com.hpp index e0f1051ae..3714d79dc 100644 --- a/src/util/windows/com.hpp +++ b/src/util/windows/com.hpp @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_util_windows_com -#define FF_INCLUDED_util_windows_com - #ifdef __cplusplus #include @@ -21,5 +18,3 @@ static inline void ffReleaseComObject(void* ppUnknown) // Win32 COM headers requires C++ compiler #error Must be included in C++ source file #endif - -#endif diff --git a/src/util/windows/wmi.hpp b/src/util/windows/wmi.hpp index 5e8d57a32..561f1ff5e 100644 --- a/src/util/windows/wmi.hpp +++ b/src/util/windows/wmi.hpp @@ -1,8 +1,5 @@ #pragma once -#ifndef FF_INCLUDED_util_windows_wmi -#define FF_INCLUDED_util_windows_wmi - #ifdef __cplusplus extern "C" { @@ -215,5 +212,3 @@ struct FFWmiQuery // Win32 COM headers requires C++ compiler #error Must be included in C++ source file #endif //__cplusplus - -#endif //FF_INCLUDED_util_windows_wmi From 41aaaa34298e8f4369d207295d89b0c38f49ce05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 9 Nov 2023 13:46:29 +0800 Subject: [PATCH 003/118] Global: silence compiler warnings --- src/detection/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/internal.h b/src/detection/internal.h index a25f8fee6..ef691f734 100644 --- a/src/detection/internal.h +++ b/src/detection/internal.h @@ -9,4 +9,4 @@ return &result; \ init = true; \ __VA_ARGS__; \ - return &result; \ + return &result; From 2af338f42581f3aa38aa3ea9156fd7c55e4ee7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 9 Nov 2023 14:15:23 +0800 Subject: [PATCH 004/118] CI (Linux): build with ddcutil and remove unused deps --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d046a3e5e..4f2946110 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: run: uname -a - name: install required packages - run: sudo apt-get update && sudo apt-get install -y musl-dev musl-tools linux-headers-generic libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev directx-headers-dev + run: sudo apt-get update && sudo apt-get install -y musl-dev musl-tools linux-headers-generic libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev directx-headers-dev - name: configure project env: @@ -74,12 +74,12 @@ jobs: run: uname -a - name: install required packages - run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev directx-headers-dev + run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev librpm-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev libnm-dev libpulse-dev directx-headers-dev - name: install linuxbrew packages run: | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - /home/linuxbrew/.linuxbrew/bin/brew install imagemagick --ignore-dependencies + /home/linuxbrew/.linuxbrew/bin/brew install imagemagick ddcutil --ignore-dependencies - name: Initialize CodeQL uses: github/codeql-action/init@v2 From f2fc92dbf7ef82a84458c2ff6684c72f9da01c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 12 Nov 2023 10:47:04 +0800 Subject: [PATCH 005/118] Brightness (Linux): better ddcutil 2.x compatibility --- src/detection/brightness/brightness_linux.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/detection/brightness/brightness_linux.c b/src/detection/brightness/brightness_linux.c index ff3843c06..55ad47643 100644 --- a/src/detection/brightness/brightness_linux.c +++ b/src/detection/brightness/brightness_linux.c @@ -96,6 +96,8 @@ static const char* detectWithBacklight(FFlist* result) // Try to be compatible with ddcutil 2.0 #if DDCUTIL_VMAJOR >= 2 double ddca_set_default_sleep_multiplier(double multiplier); // ddcutil 1.4 +#else +DDCA_Status ddca_init(const char *libopts, int syslog_level, int opts); #endif static const char* detectWithDdcci(FFBrightnessOptions* options, FFlist* result) @@ -107,11 +109,22 @@ static const char* detectWithDdcci(FFBrightnessOptions* options, FFlist* result) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_free_any_vcp_value) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_close_display) - __typeof__(&ddca_set_default_sleep_multiplier) ffddca_set_default_sleep_multiplier = dlsym(libddcutil, "ddca_set_default_sleep_multiplier"); - if (ffddca_set_default_sleep_multiplier) - ffddca_set_default_sleep_multiplier(options->ddcciSleep / 40.0); + __typeof__(&ddca_init) ffddca_init = dlsym(libddcutil, "ddca_init"); + if (ffddca_init) + { + FF_SUPPRESS_IO(); + // Ref: https://github.com/rockowitz/ddcutil/issues/344 + if (ffddca_init("--disable-watch-displays", -1 /*DDCA_SYSLOG_NOT_SET*/, 1 /*DDCA_INIT_OPTIONS_DISABLE_CONFIG_FILE*/) < 0) + return "ddca_init() failed"; + } + else + { + __typeof__(&ddca_set_default_sleep_multiplier) ffddca_set_default_sleep_multiplier = dlsym(libddcutil, "ddca_set_default_sleep_multiplier"); + if (ffddca_set_default_sleep_multiplier) + ffddca_set_default_sleep_multiplier(options->ddcciSleep / 40.0); - libddcutil = NULL; // Don't dlclose libddcutil. See https://github.com/rockowitz/ddcutil/issues/330 + libddcutil = NULL; // Don't dlclose libddcutil. See https://github.com/rockowitz/ddcutil/issues/330 + } FF_AUTO_FREE DDCA_Display_Info_List* infoList = NULL; if (ffddca_get_display_info_list2(false, &infoList) < 0) From 84a5a4033ee7fe964c89c0a56dec6c55bd98eb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 10 Nov 2023 15:05:09 +0800 Subject: [PATCH 006/118] Fastfetch: parse some switches in advance --- src/fastfetch.c | 167 ++++++++++++++++++++---------------------------- 1 file changed, 70 insertions(+), 97 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 3480af0c7..44653b0bd 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -353,7 +353,6 @@ static void generateConfigFile(bool force, const char* type) isJsonc ? strlen(FASTFETCH_DATATEXT_CONFIG_USER_JSONC) : strlen(FASTFETCH_DATATEXT_CONFIG_USER), isJsonc ? FASTFETCH_DATATEXT_CONFIG_USER_JSONC : FASTFETCH_DATATEXT_CONFIG_USER); printf("A sample config file has been written in `%s`\n", filename->chars); - exit(0); } } @@ -428,12 +427,8 @@ static void printVersion() printf("%s %s%s%s (%s)\n", result.projectName, result.version, result.versionTweak, result.debugMode ? "-debug" : "", result.architecture); } -static void parseOption(FFdata* data, const char* key, const char* value) +static void parseCommand(FFdata* data, char* key, char* value) { - /////////////////////// - //Informative options// - /////////////////////// - if(ffStrEqualsIgnCase(key, "-h") || ffStrEqualsIgnCase(key, "--help")) { printCommandHelp(value); @@ -453,121 +448,62 @@ static void parseOption(FFdata* data, const char* key, const char* value) { const char* subkey = key + strlen("--print-"); if(ffStrEqualsIgnCase(subkey, "config-system")) - { puts(FASTFETCH_DATATEXT_CONFIG_SYSTEM); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "config-user")) - { puts(FASTFETCH_DATATEXT_CONFIG_USER); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "structure")) - { puts(FASTFETCH_DATATEXT_STRUCTURE); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "logos")) - { ffLogoBuiltinPrint(); - exit(0); - } else - goto error; + { + fprintf(stderr, "Error: unsupported print option: %s\n", key); + exit(415); + } + exit(0); } else if(ffStrStartsWithIgnCase(key, "--list-")) { const char* subkey = key + strlen("--list-"); if(ffStrEqualsIgnCase(subkey, "modules")) - { listModules(); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "presets")) - { listAvailablePresets(); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "config-paths")) - { listConfigPaths(); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "data-paths")) - { listDataPaths(); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "features")) - { ffListFeatures(); - exit(0); - } else if(ffStrEqualsIgnCase(subkey, "logos")) { puts("Builtin logos:"); ffLogoBuiltinList(); puts("\nCustom logos:"); listAvailableLogos(); - exit(0); } else if(ffStrEqualsIgnCase(subkey, "logos-autocompletion")) - { ffLogoBuiltinListAutocompletion(); - exit(0); - } else - goto error; - } - else if(ffStrEqualsIgnCase(key, "--set") || ffStrEqualsIgnCase(key, "--set-keyless")) - { - FF_STRBUF_AUTO_DESTROY customValueStr = ffStrbufCreate(); - ffOptionParseString(key, value, &customValueStr); - uint32_t index = ffStrbufFirstIndexC(&customValueStr, '='); - if(index == 0 || index == customValueStr.length) { - fprintf(stderr, "Error: usage: %s =\n", key); - exit(477); + fprintf(stderr, "Error: unsupported list option: %s\n", key); + exit(415); } - FF_STRBUF_AUTO_DESTROY customKey = ffStrbufCreateNS(index, customValueStr.chars); - - FFCustomValue* customValue = NULL; - FF_LIST_FOR_EACH(FFCustomValue, x, data->customValues) - { - if(ffStrbufEqual(&x->key, &customKey)) - { - ffStrbufDestroy(&x->key); - ffStrbufDestroy(&x->value); - customValue = x; - break; - } - } - if(!customValue) customValue = (FFCustomValue*) ffListAdd(&data->customValues); - ffStrbufInitMove(&customValue->key, &customKey); - ffStrbufSubstrAfter(&customValueStr, index); - ffStrbufInitMove(&customValue->value, &customValueStr); - customValue->printKey = key[5] == '\0'; + exit(0); } - - //////////// - //Switches// - //////////// - - else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config")) - optionParseConfigFile(data, key, value); else if(ffStrEqualsIgnCase(key, "--gen-config")) + { generateConfigFile(false, value); + exit(0); + } else if(ffStrEqualsIgnCase(key, "--gen-config-force")) + { generateConfigFile(true, value); + exit(0); + } else if (ffStrEqualsIgnCase(key, "--migrate-config")) { - if (instance.state.configDoc) - { - fputs("Error: existing jsonc config detected. Aborting\n", stderr); - exit(477); - } - if (!value) { ffStrbufSet(&instance.state.migrateConfigPath, (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0)); @@ -608,13 +544,54 @@ static void parseOption(FFdata* data, const char* key, const char* value) break; } } + else + return; + + // Don't parse it again in parseOption. + // This is necessary because parseOption doesn't understand this option and will result in an unknown option error. + key[0] = '\0'; + if (value) value[0] = '\0'; +} + +static void parseOption(FFdata* data, const char* key, const char* value) +{ + if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config")) + optionParseConfigFile(data, key, value); + + else if(ffStrEqualsIgnCase(key, "--set") || ffStrEqualsIgnCase(key, "--set-keyless")) + { + FF_STRBUF_AUTO_DESTROY customValueStr = ffStrbufCreate(); + ffOptionParseString(key, value, &customValueStr); + uint32_t index = ffStrbufFirstIndexC(&customValueStr, '='); + if(index == 0 || index == customValueStr.length) + { + fprintf(stderr, "Error: usage: %s =\n", key); + exit(477); + } + + FF_STRBUF_AUTO_DESTROY customKey = ffStrbufCreateNS(index, customValueStr.chars); + + FFCustomValue* customValue = NULL; + FF_LIST_FOR_EACH(FFCustomValue, x, data->customValues) + { + if(ffStrbufEqual(&x->key, &customKey)) + { + ffStrbufDestroy(&x->key); + ffStrbufDestroy(&x->value); + customValue = x; + break; + } + } + if(!customValue) customValue = (FFCustomValue*) ffListAdd(&data->customValues); + ffStrbufInitMove(&customValue->key, &customKey); + ffStrbufSubstrAfter(&customValueStr, index); + ffStrbufInitMove(&customValue->value, &customValueStr); + customValue->printKey = key[5] == '\0'; + } + else if(ffStrEqualsIgnCase(key, "-s") || ffStrEqualsIgnCase(key, "--structure")) ffOptionParseString(key, value, &data->structure); - /////////// - //Options// - /////////// - else if( ffOptionsParseGeneralCommandLine(&instance.config.general, key, value) || ffOptionsParseLogoCommandLine(&instance.config.logo, key, value) || @@ -623,13 +600,8 @@ static void parseOption(FFdata* data, const char* key, const char* value) ffParseModuleOptions(key, value) ) {} - ////////////////// - //Unknown option// - ////////////////// - else { -error: fprintf(stderr, "Error: unknown option: %s\n", key); exit(400); } @@ -664,14 +636,14 @@ static void parseConfigFiles(FFdata* data) } } -static void parseArguments(FFdata* data, int argc, const char** argv) +static void parseArguments(FFdata* data, int argc, char** argv, void (*parser)(FFdata* data, char* key, char* value)) { - if(!data->loadUserConfig) - return; - for(int i = 1; i < argc; i++) { const char* key = argv[i]; + if(*key == '\0') + continue; // has been handled by parseCommand + if(*key != '-') { fprintf(stderr, "Error: invalid option: %s. An option must start with `-`\n", key); @@ -683,11 +655,11 @@ static void parseArguments(FFdata* data, int argc, const char** argv) argv[i + 1][1] != '\0' && // `-` is used as an alias for `/dev/stdin` strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a - )) { - parseOption(data, argv[i], NULL); + parser(data, argv[i], NULL); } else { - parseOption(data, argv[i], argv[i + 1]); + parser(data, argv[i], argv[i + 1]); ++i; } } @@ -769,7 +741,7 @@ static void migrateConfig(FFdata* data, const FFstrbuf* filename) yyjson_mut_doc_free(doc); } -int main(int argc, const char** argv) +int main(int argc, char** argv) { ffInitInstance(); @@ -780,9 +752,10 @@ int main(int argc, const char** argv) .loadUserConfig = true, }; - if(!getenv("NO_CONFIG")) + parseArguments(&data, argc, argv, parseCommand); + if(!getenv("NO_CONFIG") && data.loadUserConfig) parseConfigFiles(&data); - parseArguments(&data, argc, argv); + parseArguments(&data, argc, argv, (void*) parseOption); if (__builtin_expect(instance.state.migrateConfigPath.length == 0, true)) run(&data); From a44b8264af51284817ea96bcea0ff3f4fc5351f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 10 Nov 2023 15:47:09 +0800 Subject: [PATCH 007/118] Fastfetch: remove the old function of `--gen-config` The file `config_user.txt` has not been maintained for long. Let's remove it. --- CHANGELOG.md | 8 +- CMakeLists.txt | 3 - src/common/init.c | 2 +- src/data/config_system.txt | 16 -- src/data/config_user.jsonc | 41 --- src/data/config_user.txt | 519 ------------------------------------- src/data/help.txt | 5 +- src/fastfetch.c | 79 ++---- src/fastfetch.h | 2 +- 9 files changed, 32 insertions(+), 643 deletions(-) delete mode 100644 src/data/config_system.txt delete mode 100644 src/data/config_user.jsonc delete mode 100644 src/data/config_user.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index bab497143..8b9ecdc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.3.0 + +Changes: +* The deprecated flag `--gen-config conf` is removed +* Flag `--gen-config` now does the same thing as `--migrate-config`, which can be used as config migration and default config file generation. Flag `--migrate-config` is removed + # 2.2.3 Features: @@ -8,7 +14,7 @@ Bugfixes: * Fix terminal detection on NixOS (Terminal) # 2.2.2 - +g Changes: * `--percent-type` now defaults to 9 (colored percentage numbers) * `fastfetch` now prints LocalIp module by default diff --git a/CMakeLists.txt b/CMakeLists.txt index 06e5e4f59..b6362afd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,9 +214,6 @@ function(fastfetch_load_text FILENAME OUTVAR) endfunction(fastfetch_load_text) fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE) -fastfetch_load_text(src/data/config_system.txt DATATEXT_CONFIG_SYSTEM) -fastfetch_load_text(src/data/config_user.txt DATATEXT_CONFIG_USER) -fastfetch_load_text(src/data/config_user.jsonc DATATEXT_CONFIG_USER_JSONC) fastfetch_load_text(src/data/help.txt DATATEXT_HELP) fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR) fastfetch_load_text(src/data/help_format.txt DATATEXT_HELP_FORMAT) diff --git a/src/common/init.c b/src/common/init.c index 5c5b2307a..0ebb4b144 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -144,7 +144,7 @@ static void destroyState(void) ffPlatformDestroy(&instance.state.platform); yyjson_doc_free(instance.state.configDoc); yyjson_mut_doc_free(instance.state.resultDoc); - ffStrbufDestroy(&instance.state.migrateConfigPath); + ffStrbufDestroy(&instance.state.genConfigPath); } void ffDestroyInstance(void) diff --git a/src/data/config_system.txt b/src/data/config_system.txt deleted file mode 100644 index 46f58c043..000000000 --- a/src/data/config_system.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Fastfetch system configuration -# This file sets the default config for all users of the system. - -# For more information about how configuration files work, -# see ~/.config/fastfetch/config.conf. -# All options that can be put there (or passed as argument) can be put here too. - -# Use fastfetch --print-config-system > /etc/fastfetch/config.conf -# to overwrite this file with the current default file. - -# User config option -# Sets if fastfetch should load user provided configuration. -# If this is off, fastfetch ignores the user config file and any passed arguments -# Must be true or false -# Default is true. -#--load-user-config true diff --git a/src/data/config_user.jsonc b/src/data/config_user.jsonc deleted file mode 100644 index 029f768e5..000000000 --- a/src/data/config_user.jsonc +++ /dev/null @@ -1,41 +0,0 @@ -// ~/.config/fastfetch/config.jsonc -// See https://github.com/fastfetch-cli/fastfetch/wiki/Configuration for more details -// See *.jsonc in https://github.com/fastfetch-cli/fastfetch/tree/dev/presets/examples for more examples -{ - "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", - "logo": { - "padding": { - "top": 2 - } - }, - "modules": [ - "title", - "separator", - "os", - "host", - "kernel", - "uptime", - "packages", - "shell", - "display", - "de", - "wm", - "wmtheme", - "theme", - "icons", - "font", - "cursor", - "terminal", - "terminalfont", - "cpu", - "gpu", - "memory", - "disk", - "localip", - "battery", - "poweradapter", - "locale", - "break", - "colors" - ] -} diff --git a/src/data/config_user.txt b/src/data/config_user.txt deleted file mode 100644 index c8a257ec5..000000000 --- a/src/data/config_user.txt +++ /dev/null @@ -1,519 +0,0 @@ -# Fastfetch configuration -# Write every argument in different lines. -# Direct arguments will overwrite the corresponding ones in this file. -# Argument keys are not case sensitive. -# Whitespaces are trimmed at the beginning and the end. -# Empty lines or lines starting with # are ignored. - -# This file was shipped with $" FASTFETCH_PROJECT_VERSION $". -# Use fastfetch --gen-config-force to overwrite this file with the current defaults - -# Below some often usefull options are listed. Uncomment and modify them so they take affect. -# Note that there are a lot more options than the ones listed here, take a look at "fastfetch --help". -# Of course all of them can be made persistent here too. - -# Config option: -# Load additional config files. -# Some are shipped with fastfetch, list them with "fastfetch --list-presets". -# Must be a path to a config file or the name of a shipped preset. -# The config file is completely loaded before continuing in the current file, so the placement of this option matters, as later options overwrite already set ones. -# Can be used multiple times to load multiple config files / presets. -#--load-config /path/to/config.txt - -# Structure option: -# Sets the modules to use and their order. -# Must be a list of module names, separated by colons. -# List available modules with "fastfetch --list-modules". -# Get the default structure with "fastfetch --print-structure". -#--structure $" FASTFETCH_DATATEXT_STRUCTURE $" - -# Multithreading option: -# Sets if fastfetch should use multiple threads to detect the values. -# Must be true or false. -# Default is true. -#--multithreading true - -# Print stat option: -# Sets if fastfetch should print time usage (in ms) for individual modules -# If true, it will also enable --show-errors -# Must be true or false. -# Default is false. -#--stat true - -# Slow operations option: -# Sets if fastfetch is allowed to use known slow operations to detect more / better values. -# Must be true or false. -# Default is false. -#--allow-slow-operations false - -# Linewrap option: -# Sets if fastfetch should disable linewrap during the run. -# Must be true or false. -# Default is true. -#--disable-linewrap true - -# Cursor option: -# Sets if fastfetch should hide the console cursor during the run. -# Must be true or false. -# Default is true. -#--hide-cursor true - -# Processing timeout option: -# Sets the timeout (ms) when waiting for child processes -# Must be an integer. -# Default is 1000 -#--processing-timeout 1000 - -# WMI timeout option: -# Sets the timeout (ms) for WMI queries. Windows only -# Must be an integer. -# Default is 5000 -#--wmi-timeout 5000 - -# Logo option: -# Sets the logo to use. -# List available logos with "fastfetch --list-logos". -# Print available logos with "fastfetch --print-logos". -# Must be the name of an available logo or a path to a text file containing a custom logo. -# Default is the current distribution. -#--logo arch - -# Logo type option: -# Sets the logo type to use. -# Must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty or chafa. -# Default is auto. -#--logo-type auto - -# Logo width option: -# Sets the width of the logo (in characters) if the logo is an image. -# Must be a positive integer. -# Default is 65. -#--logo-width 65 - -# Logo height option: -# Sets the height of the logo (in characters) if the logo is an image. -# Must be a positive integer. -# Default is 0 (keeps aspect ration). -#--logo-height 0 - -# Logo color options: -# Overwrite a color in the logo. Also works for user provided logos. -# In the user logo, they replace $[1-9]. Use $$ to print a single $ sign. -# Must be linux console color codes or the name of a color. -# Default is the one specified by the logo. -# Use "fastfetch --help color" to learn more and see examples. -# Valid index range is [1-9]. -#--logo-color-1 red -#--logo-color-2 32 -# [...] -#--logo-color-9 yellow - -# Logo padding option: -# Adds a padding to the left and the right side of the logo. -# Must be a positive integer. -# Default is 0. -#--logo-padding 0 - -# Logo padding left option: -# Adds a padding to the left side of the logo. -# Must be a positive integer. -# Default is 0. -#--logo-padding-left 0 - -# Logo padding right option: -# Adds a padding to the right side of the logo. -# Must be a positive integer. -# Default is 0. -#--logo-padding-right 0 - -# Logo padding top option: -# Adds a padding to the top side of the logo. -# Must be a positive integer. -# Default is 0. -#--logo-padding-top 0 - -# Logo print remaining option: -# Sets if the remaining logo should be printed, it is has more lines than modules to show. -# Must be true or false. -# Default is true. -#--logo-print-remaining true - -# Color keys option: -# Sets the color of the keys. -# Must be linux console color codes or the name of a color. -# Default is the key color of the logo. -# Use "fastfetch --help color" to learn more and see examples. -#--color-keys magenta - -# Color title option: -# Sets the color of the title. -# Must be linux console color codes or the name of a color. -# Default is the title color of the logo. -# Use "fastfetch --help color" to learn more and see examples. -#--color-title magenta - -# Binary prefix option: -# Sets the binary prefix to use. -# Must be a IEC, SI or JEDEC. -# Default is IEC. -#--binary-prefix IEC - -# Size number of digits option: -# Sets the number of digits to keep after the decimal point when formatting sizes. -# Must be an possitive integer. -# Default is 2. -#--size-ndigits 2 - -# Size max prefix option: -# Sets the largest binary prefix to use when formatting sizes. -# Must be one of B, kB, MB, GB, TB, PB, EB, ZB, YB -# Default is YB. -#--size-max-prefix YB - -# Disable output buffer option: -# Sets if the stdout application buffer should be disabled. -# Must be true or false. -# Default is false. -#--no-buffer false - -# Title FQDN option: -# Sets if the title should use the fully qualified domain name. -# Must be true or false. -# Default is false. -#--title-fqdn false - -# Title user color option: -# Sets color of the user name (left part). -# Default is empty (use color of `--color-title`). -#--title-color-user - -# Title at color option: -# Sets color of the @ symbol (middle part). -# Default is empty (use color of `--color-title`). -#--title-color-at - -# Title host color option: -# Sets color of the host name (right part). -# Default is empty (use color of `--color-title`). -#--title-color-host - -# Separator option: -# Sets the string placed between a key and its value. -# Can be any string. -# Default is ": ". -#--separator ": " - -# Separator string option: -# Sets the string printed by the "separator" module (usually between title and rest of output) -# Must be any string. It is repated / cut to fit perfectly. -# Default is "-" -#--separator-string - - -# Public IP URL option: -# Sets the URL of public IP detection server to be used. -# Only HTTP protocol is supported, and the value should not contain "http://" prefix. -# Default is "ipinfo.io/ip". -#--publicip-url "ipinfo.io/ip" - -# Public IP timeout option: -# Sets the time to wait for the public ip server to respond. -# Must be a positive integer. -# Default is 0 (disabled). -#--publicip-timeout 0 - -# Weather location option: -# Sets the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). -# Default is empty (guessing by public IP) -#--weather-location "Location" - -# Weather output format option: -# Sets the weather format to be used. It must be URI encoded. -# See: https://github.com/chubin/wttr.in#one-line-output -# Default is "%t+-+%C+(%l)". -#--weather-output-format "%t+-+%C+(%l)" - -# Weather timeout option: -# Sets the time to wait for the weather server (wttr.in) to respond. -# Must be a positive integer. -# Default is 0 (disabled). -#--weather-timeout 0 - -# OS file option -# Sets the path to the file containing the operating system information. -# Should be a valid path to an existing file. -# Default is /etc/os-release. -#--os-file /etc/os-release - -# Player name option -# Sets the name of the player. This is also used in song detection -# Must be the exact name of the player or a dbus address (e.g. org.mpris.MediaPlayer2.spotify) -# Default is the first match starting with org.mpris.MediaPlayer2. -#--player-name spotify - -# Display server force DRM option -# Sets if fastfetch should only use `/sys/class/drm` to detect displays if you get issues with the default behavior. -# Note DRM doesn't support refresh rate or scaled resolution detection. -# Only supported on Linux. -# Must be true or false. -# Default is false. -#--ds-force-drm false - -# Escape bedrock option -# Sets if fastfetch should escape the bedrock jail, if it detectes that it is running in one -# Must be true or false. -# Default is true. -#--escape-bedrock true - -# OpenGL option -# Sets with opengl context creation library to use -# Must be either auto, egl, glx or osmesa -# Default is auto. -#--opengl-library auto - -# GPU hide options -# Sets whether to hide certain gpu types -# Must be either true or false -# Default is false. -#--gpu-hide-integrated -#--gpu-hide-discrete - -# GPU detection options -# Forces using vulkan to detect GPUs -# which support video memory usage detection with `--allow-slow-operations` -# Must be either true or false -# Default is false. -#--gpu-force-vulkan - -# Disk show options -# Sets if certain types of disk should be printed -# Must be either true or false -# Default is false except for --disk-show-external. -#--disk-show-external true -#--disk-show-hidden false -#--disk-show-subvolumes false -#--disk-show-unknown false - -# Disk option -# A colon (semicolon on Windows) separated list of folder paths for the disk output -# This option override `--disk-show-*` options above -# Must be a string -# Default is "/:/home" ("C:\\;D:\\ ..." on Windows). -#--disk-folders /:/home - -# Bluetooth show disconnected option -# Sets if disconnected bluetooth devices should be printed -# Must be either true or false -# Default is false. -#--bluetooth-show-disconnected false - -# Display compact output option -# Sets if all displays should be printed in one line -# Must be either original (print pixel resolution) or scaled (print scaled resolution) -# Default is none. -#--display-compact-type none - -# Display detect name option -# Sets if display name should be detected and printed (if supported) -# Must be either true of false -# Default is false. -#--display-detect-name none - -# Display precise refresh rate option -# Sets if decimal refresh rates should not be rounded into integers when printing -# Must be either true (keep decimals) of false (round into integers) -# Default is false. -#--display-precise-refresh-rate false - -# Sound show all option -# Sets if all sound devices should be printed -# Must be either main, active or all. Default is main -# Default is main. -#--sound-type main - -# Percentage output type option -# Applies to all modules that prints percentage values. Currently memory, swap, disk, battery and CPU usage are supported. -# Only works with default format ( without --module-format option ). -# 0: prints none; 1: prints percent number only; 2: prints bar only; 3: prints both percent number and bar; 6: prints bar and hide other texts; 9: prints colored number -#--percent-type 1 - -# Key options: -# Sets the displayed key of a module -# Can be any string. Some of theme take an argument like a format string. See "fastfetch --help format" for help. -#--os-key OS -#--host-key Host -#--chassis-key Chassis -#--kernel-key Kernel -#--uptime-key Uptime -#--processes-key Processes -#--packages-key Packages -#--shell-key Shell -#--display-key Display {1} -#--brightness-key Brightness ({1}) -#--monitor-key Monitor -#--de-key DE -#--wm-key WM -#--wmtheme-key WM Theme -#--theme-key Theme -#--icons-key Icons -#--font-key Font -#--cursor-key Cursor -#--terminal-key Terminal -#--terminalfont-key Terminal Font -#--cpu-key CPU -#--cpuusage-key CPU Usage -#--gpu-key GPU {1} -#--memory-key Memory -#--swap-key Swap -#--disk-key Disk ({1}) -#--battery-key Battery {1} -#--poweradapter-key Power Adapter {1} -#--lm-key LM -#--locale-key Locale -#--localip-key Local IP ({1}) -#--netio-key Network IO ({1}) -#--publicip-key Public IP -#--wifi-key Wifi -#--weather-key Weather -#--player-key Media Player -#--media-key Media -#--datetime-key Date Time -#--version-key Version -#--vulkan-key Vulkan -#--opengl-key OpenGL -#--opencl-key OpenCL -#--users-key Users -#--bluetooth-key Bluetooth -#--sound-key Sound -#--gamepad-key Gamepad -#--wallpaper-key Wallpaper - -# Format options: -# Sets the format string for module values. -# For information on format strings, see "fastfetch --help format". -# To see the parameter they take and their default value, see "fastfetch --help *-format", e.g. "fastfetch --help os-format". -# An empty format string (As they are currently below) will behave as if it was not set. -#--title-format -#--os-format -#--host-format -#--chassis-format -#--kernel-format -#--uptime-format -#--processes-format -#--packages-format -#--shell-format -#--display-format -#--brightness-format -#--de-format -#--wm-format -#--wmtheme-format -#--theme-format -#--icons-format -#--font-format -#--cursor-format -#--terminal-format -#--terminalfont-format -#--cpu-format -#--cpuusage-format -#--gpu-format -#--memory-format -#--swap-format -#--disk-format -#--battery-format -#--poweradapter-format -#--lm-format -#--locale-format -#--localip-format -#--netio-format -#--publicip-format -#--weather-format -#--monitor-format -#--player-format -#--media-format -#--datetime-format -#--version-format -#--vulkan-format -#--opengl-format -#--opencl-format -#--users-format -#--bluetooth-format -#--sound-format -#--gamepad-format -#--wallpaper-format - -# Key color options: -# Overrides the global `--color-keys` for one specified module -#--title-key-color -#--os-key-color -#--host-key-color -#--chassis-key-color -#--kernel-key-color -#--uptime-key-color -#--processes-key-color -#--packages-key-color -#--shell-key-color -#--display-key-color -#--brightness-key-color -#--de-key-color -#--wm-key-color -#--wmtheme-key-color -#--theme-key-color -#--icons-key-color -#--font-key-color -#--cursor-key-color -#--terminal-key-color -#--terminalfont-key-color -#--cpu-key-color -#--cpuusage-key-color -#--gpu-key-color -#--memory-key-color -#--swap-key-color -#--disk-key-color -#--battery-key-color -#--poweradapter-key-color -#--lm-key-color -#--locale-key-color -#--localip-key-color -#--netio-key-color -#--publicip-key-color -#--weather-key-color -#--monitor-key-color -#--player-key-color -#--media-key-color -#--datetime-key-color -#--version-key-color -#--vulkan-key-color -#--opengl-key-color -#--opencl-key-color -#--users-key-color -#--bluetooth-key-color -#--sound-key-color -#--gamepad-key-color -#--wallpaper-key-color - -# Library options: -# Sets an user specific path to a library to load. -# Must be a valid path to a library. -#--lib-PCI /usr/lib/libpci.so -#--lib-vulkan /usr/lib/libvulkan.so (libMoltenVK.dylib on macOS) -#--lib-wayland /usr/lib/libwayland-client.so -#--lib-xcb-randr /usr/lib/libxcb-randr.so -#--lib-xcb /usr/lib/libxcb.so -#--lib-Xrandr /usr/lib/libXrandr.so -#--lib-X11 /usr/lib/libX11.so -#--lib-gio /usr/lib/libgio-2.0.so -#--lib-DConf /usr/lib/libdconf.so -#--lib-DBus /usr/lib/libdbus-1.so -#--lib-XFConf /usr/lib/libxfconf-0.so -#--lib-sqlite3 /usr/lib/libsqlite3.so -#--lib-rpm /usr/lib/librpm.so -#--lib-imagemagick /usr/lib/libMagickCore-7.Q16HDRI.so -#--lib-z /usr/lib/libz.so -#--lib-chafa /usr/lib/libchafa.so -#--lib-egl /usr/lib/libEGL.so -#--lib-glx /usr/lib/libGLX.so -#--lib-osmesa /usr/lib/libOSMesa.so -#--lib-opencl /usr/lib/libOpenCL.so -#--lib-freetype /data/data/com.termux/files/usr/lib -#--lib-pulse /usr/lib/libpulse.so -#--lib-ddcutil /usr/lib/libddcutil.so -#--lib-nm /usr/lib/libnm.so diff --git a/src/data/help.txt b/src/data/help.txt index 7d5d1b9c6..0c4aa46c4 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -19,9 +19,8 @@ Informative options: Config options: -c, --load-config : Load a config file or preset (+) - --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf` - --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one - --migrate-config : Migrate old flag based config file to new JSONC format. Optional param `path` is the file path that new file should be write to + --gen-config : Generate a config file (or print the file if is `-`), with options specified in the command line (if any) + --gen-config-force : Generate a config file. Overwrite the existing one General options: --thread : Use separate threads to send HTTP requests diff --git a/src/fastfetch.c b/src/fastfetch.c index 44653b0bd..89ee82491 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -317,42 +317,27 @@ static bool parseConfigFile(FFdata* data, const char* path) return true; } -static void generateConfigFile(bool force, const char* type) +static void generateConfigFile(bool force, const char* filePath) { - if (!type) + if (!filePath) { - fputs("Error: the config type (`jsonc` or `conf`) must be specified\n", stderr); - exit(1); - } - - FFstrbuf* filename = (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0); - // Paths generated in `init.c/initConfigDirs` end with `/` - bool isJsonc = ffStrEqualsIgnCase(type, "jsonc"); - if (!isJsonc) - { - if (!ffStrEqualsIgnCase(type, "conf")) - { - fputs("Error: config type can only be `jsonc` or `conf`\n", stderr); - exit(1); - } - else - fputs("Warning: support of flag based config type `conf` is deprecated, and may be removed in the future\n", stderr); - } - - ffStrbufAppendS(filename, isJsonc ? "fastfetch/config.jsonc" : "fastfetch/config.conf"); - - if (!force && ffPathExists(filename->chars, FF_PATHTYPE_FILE)) - { - fprintf(stderr, "Config file exists in `%s`, use `--gen-config-force` to overwrite\n", filename->chars); - exit(1); + ffStrbufSet(&instance.state.genConfigPath, (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0)); + ffStrbufAppendS(&instance.state.genConfigPath, "fastfetch/config.jsonc"); } else { - ffWriteFileData( - filename->chars, - isJsonc ? strlen(FASTFETCH_DATATEXT_CONFIG_USER_JSONC) : strlen(FASTFETCH_DATATEXT_CONFIG_USER), - isJsonc ? FASTFETCH_DATATEXT_CONFIG_USER_JSONC : FASTFETCH_DATATEXT_CONFIG_USER); - printf("A sample config file has been written in `%s`\n", filename->chars); + if (ffStrEqualsIgnCase(filePath, "conf") || ffStrEqualsIgnCase(filePath, "jsonc")) + { + fputs("Error: specifying file type is no longer supported\n", stderr); + exit(477); + } + ffStrbufSetS(&instance.state.genConfigPath, filePath); + } + + if (!force && ffPathExists(instance.state.genConfigPath.chars, FF_PATHTYPE_ANY)) + { + fprintf(stderr, "Error: file `%s` exists. Use `--gen-config-force` to overwrite\n", instance.state.genConfigPath.chars); + exit(477); } } @@ -493,31 +478,9 @@ static void parseCommand(FFdata* data, char* key, char* value) exit(0); } else if(ffStrEqualsIgnCase(key, "--gen-config")) - { generateConfigFile(false, value); - exit(0); - } else if(ffStrEqualsIgnCase(key, "--gen-config-force")) - { generateConfigFile(true, value); - exit(0); - } - else if (ffStrEqualsIgnCase(key, "--migrate-config")) - { - if (!value) - { - ffStrbufSet(&instance.state.migrateConfigPath, (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0)); - ffStrbufAppendS(&instance.state.migrateConfigPath, "fastfetch/config.jsonc"); - } - else - ffStrbufSetS(&instance.state.migrateConfigPath, value); - - if (ffPathExists(instance.state.migrateConfigPath.chars, FF_PATHTYPE_ANY)) - { - fprintf(stderr, "Error: file `%s` exists. Aborting\n", instance.state.migrateConfigPath.chars); - exit(477); - } - } else if(ffStrEqualsIgnCase(key, "--load-user-config")) data->loadUserConfig = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--format")) @@ -609,7 +572,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) static void parseConfigFiles(FFdata* data) { - if (__builtin_expect(instance.state.migrateConfigPath.length == 0, true)) + if (__builtin_expect(instance.state.genConfigPath.length == 0, true)) { for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) { @@ -712,7 +675,7 @@ static void run(FFdata* data) ffFinish(); } -static void migrateConfig(FFdata* data, const FFstrbuf* filename) +static void writeConfigFile(FFdata* data, const FFstrbuf* filename) { yyjson_mut_doc* doc = yyjson_mut_doc_new(NULL); yyjson_mut_val* root = yyjson_mut_obj(doc); @@ -730,7 +693,7 @@ static void migrateConfig(FFdata* data, const FFstrbuf* filename) else { if (yyjson_mut_write_file(filename->chars, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL)) - printf("The migrated config file has been written in `%s`\nYou may remove the old config file if everything works fine\n", filename->chars); + printf("The generated config file has been written in `%s`\n", filename->chars); else { printf("Error: failed to write file in `%s`\n", filename->chars); @@ -757,10 +720,10 @@ int main(int argc, char** argv) parseConfigFiles(&data); parseArguments(&data, argc, argv, (void*) parseOption); - if (__builtin_expect(instance.state.migrateConfigPath.length == 0, true)) + if (__builtin_expect(instance.state.genConfigPath.length == 0, true)) run(&data); else - migrateConfig(&data, &instance.state.migrateConfigPath); + writeConfigFile(&data, &instance.state.genConfigPath); ffStrbufDestroy(&data.structure); FF_LIST_FOR_EACH(FFCustomValue, customValue, data.customValues) diff --git a/src/fastfetch.h b/src/fastfetch.h index 502a48d40..b7c136501 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -47,7 +47,7 @@ typedef struct FFstate FFPlatform platform; yyjson_doc* configDoc; yyjson_mut_doc* resultDoc; - FFstrbuf migrateConfigPath; + FFstrbuf genConfigPath; } FFstate; typedef struct FFinstance From 8e9c5712931a81a03b1d79e1125163eb91bb2b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 13 Nov 2023 16:36:25 +0800 Subject: [PATCH 008/118] Flashfetch: simplify implementation --- src/flashfetch.c | 81 ++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/src/flashfetch.c b/src/flashfetch.c index e35b84c93..bb5bb1c59 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -17,54 +17,39 @@ int main(void) ffStart(); //Printing - ffPrintTitle(&options->title); - ffPrintSeparator(&options->separator); - ffPrintOS(&options->os); - ffPrintHost(&options->host); - //ffPrintBios(&options->bios); - //ffPrintBoard(&options->board); - //ffPrintChassis(&options->chassis); - ffPrintKernel(&options->kernel); - //ffPrintProcesses(&options->processes); - ffPrintUptime(&options->uptime); - ffPrintPackages(&options->packages); - ffPrintShell(&options->shell); - ffPrintDisplay(&options->display); - // ffPrintBrightness(&options->brightness); - ffPrintDE(&options->de); - ffPrintWM(&options->wm); - ffPrintWMTheme(&options->wmTheme); - ffPrintTheme(&options->theme); - ffPrintIcons(&options->icons); - ffPrintFont(&options->font); - ffPrintCursor(&options->cursor); - ffPrintTerminal(&options->terminal); - ffPrintTerminalFont(&options->terminalFont); - ffPrintCPU(&options->cpu); - ffPrintGPU(&options->gpu); - ffPrintMemory(&options->memory); - ffPrintSwap(&options->swap); - ffPrintDisk(&options->disk); - ffPrintLocalIp(&options->localIP); - // ffPrintPublicIp(&options->publicIP); - //ffPrintWifi(&options->wifi); - ffPrintBattery(&options->battery); - ffPrintPowerAdapter(&options->powerAdapter); - //ffPrintPlayer(&options->player); - //ffPrintMedia(&options->media); - //ffPrintCPUUsage(&options->cpuUsage); - ffPrintLocale(&options->locale); - //ffPrintDateTime(&options->dateTime); - //ffPrintVulkan(&options->vulkan); - //ffPrintOpenGL(&options->openGL); - //ffPrintOpenCL(&options->openCL); - //ffPrintUsers(&options->users); - //ffPrintWeather(&options->weather); - //ffPrintBluetooth(&options->bluetooth); - //ffPrintSound(&options->sound); - //ffPrintGamepad(&options->gamepad); - ffPrintBreak(&options->break_); - ffPrintColors(&options->colors); + void* const modules[] = { + &options->title, + &options->separator, + &options->os, + &options->kernel, + &options->uptime, + &options->packages, + &options->shell, + &options->display, + &options->de, + &options->wm, + &options->wmTheme, + &options->theme, + &options->icons, + &options->font, + &options->cursor, + &options->terminal, + &options->terminalFont, + &options->cpu, + &options->gpu, + &options->memory, + &options->swap, + &options->disk, + &options->localIP, + &options->battery, + &options->powerAdapter, + &options->locale, + &options->break_, + &options->colors, + }; + + for (size_t i = 0; i < sizeof(modules) / sizeof(modules[0]); i++) + ((const FFModuleBaseInfo*) modules[i])->printModule(modules[i]); ffFinish(); ffDestroyInstance(); From ee7d3d471ea3f20feab5bc0022c0cdb0a3f6d13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 13 Nov 2023 16:41:10 +0800 Subject: [PATCH 009/118] Completions (Fish): inital support --- completions/fish | 53 +++++++++++++++++ src/common/io/io.h | 2 +- src/common/io/io_unix.c | 25 +++++--- src/common/io/io_windows.c | 26 ++++++--- src/data/help.txt | 117 ++++++++++++++++++------------------- src/fastfetch.c | 10 ++-- 6 files changed, 153 insertions(+), 80 deletions(-) create mode 100755 completions/fish diff --git a/completions/fish b/completions/fish new file mode 100755 index 000000000..3a8b833fc --- /dev/null +++ b/completions/fish @@ -0,0 +1,53 @@ +#!/usr/bin/env fish + +set -l whole_text (fastfetch --pipe --help) +set -l modules (string lower (string sub -s 5 (fastfetch --list-modules))) + +complete -c fastfetch -f + +for line in (string match -- ' -*' $whole_text) + set -l kv (string split -n ':' $line -m1) + set -l args (string trim -- $kv[1]) + set -l desc (string trim -- $kv[2]) + + set -l res -c fastfetch + + switch (string match -r -- '<\??\w+>' $args) + case '<\?command>' + set -l modules_format $modules-format"\tModule_format" + set res $res -x -a "color\tSupported_colors format\tCustom_format config\tConfiguration $modules_format" + case '<\?bool>' + set res $res -x -a "true\tBool false\tBool" + case '' + set res $res -F -r + case '' + if string match -q -- '*--config*' $args + set -l presets (fastfetch --list-presets false)"\tPreset" + set res $res -r -a "$presets" + else + set res $res -F -r + end + case '' + set res $res -x -a "0\tNumber 1\tNumber 2\tNumber 3\tNumber 4\tNumber 5\tNumber 6\tNumber 7\tNumber 8\tNumber 9\tNumber" + case '<\?num>' + set res $res -x -a "0\tNumber 1\tNumber 2\tNumber 3\tNumber 4\tNumber 5\tNumber 6\tNumber 7\tNumber 8\tNumber 9\tNumber" + case '' + set temp $modules"\tModule" + set res $res -x -a "$temp" + case '' + set res $res -x -a "none\tNone small\tSmall" + case '<*>' + set res $res -x + end + + set args (string trim -- (string split -- ',' (string replace -r -- '<\??\w+>' '' $args))) + + for arg in $args + if string match -q -- '--*' $arg + set res $res -l (string sub -s 3 -- $arg) + else + set res $res -o (string sub -s 2 -- $arg) + end + end + complete $res -d (string replace -- ' (+)' '' $desc) +end diff --git a/src/common/io/io.h b/src/common/io/io.h index f25381e51..0ea5cf411 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -99,7 +99,7 @@ static inline void ffUnsuppressIO(bool* suppressed) #define FF_SUPPRESS_IO() bool __attribute__((__cleanup__(ffUnsuppressIO), __unused__)) io_suppressed__ = ffSuppressIO(true) -void ffListFilesRecursively(const char* path); +void ffListFilesRecursively(const char* path, bool pretty); static inline bool wrapClose(FFNativeFD* pfd) { diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index db5f3c65b..018af9fa7 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -199,7 +199,7 @@ bool ffSuppressIO(bool suppress) return true; } -void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* folderName) +void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty) { DIR* dir = opendir(folder->chars); if(dir == NULL) @@ -207,8 +207,12 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol uint32_t folderLength = folder->length; - if(folderName != NULL) + if(pretty && folderName != NULL) + { + for(uint8_t i = 0; i < indentation - 1; i++) + fputs(" | ", stdout); printf("%s/\n", folderName); + } struct dirent* entry; @@ -221,13 +225,20 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol ffStrbufAppendS(folder, entry->d_name); ffStrbufAppendC(folder, '/'); - listFilesRecursively(folder, (uint8_t) (indentation + 1), entry->d_name); + listFilesRecursively(baseLength, folder, (uint8_t) (indentation + 1), entry->d_name, pretty); ffStrbufSubstrBefore(folder, folderLength); continue; } - for(uint8_t i = 0; i < indentation; i++) - fputs(" | ", stdout); + if (pretty) + { + for(uint8_t i = 0; i < indentation; i++) + fputs(" | ", stdout); + } + else + { + fputs(folder->chars + baseLength, stdout); + } puts(entry->d_name); } @@ -235,9 +246,9 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol closedir(dir); } -void ffListFilesRecursively(const char* path) +void ffListFilesRecursively(const char* path, bool pretty) { FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path); ffStrbufEnsureEndsWithC(&folder, '/'); - listFilesRecursively(&folder, 0, NULL); + listFilesRecursively(folder.length, &folder, 0, NULL, pretty); } diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index c4c26145b..1917bc3ed 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -114,16 +114,21 @@ bool ffSuppressIO(bool suppress) return false; } -void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* folderName) +void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty) { uint32_t folderLength = folder->length; - if(folderName != NULL) + if(pretty && folderName != NULL) + { + for(uint8_t i = 0; i < indentation - 1; i++) + fputs(" | ", stdout); printf("%s/\n", folderName); + } ffStrbufAppendC(folder, '*'); WIN32_FIND_DATAA entry; HANDLE hFind = FindFirstFileA(folder->chars, &entry); + ffStrbufTrimRight(folder, '*'); if(hFind == INVALID_HANDLE_VALUE) return; @@ -137,24 +142,31 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol ffStrbufSubstrBefore(folder, folderLength); ffStrbufAppendS(folder, entry.cFileName); ffStrbufAppendC(folder, '/'); - listFilesRecursively(folder, (uint8_t) (indentation + 1), entry.cFileName); + listFilesRecursively(baseLength, folder, (uint8_t) (indentation + 1), entry.cFileName, pretty); ffStrbufSubstrBefore(folder, folderLength); continue; } - for(uint8_t i = 0; i < indentation; i++) - fputs(" | ", stdout); + if (pretty) + { + for(uint8_t i = 0; i < indentation; i++) + fputs(" | ", stdout); + } + else + { + fputs(folder->chars + baseLength, stdout); + } puts(entry.cFileName); } while (FindNextFileA(hFind, &entry)); FindClose(hFind); } -void ffListFilesRecursively(const char* path) +void ffListFilesRecursively(const char* path, bool pretty) { FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path); ffStrbufEnsureEndsWithC(&folder, '/'); - listFilesRecursively(&folder, 0, NULL); + listFilesRecursively(folder.length, &folder, 0, NULL, pretty); } const char* ffGetTerminalResponse(const char* request, const char* format, ...) diff --git a/src/data/help.txt b/src/data/help.txt index 0c4aa46c4..bc2682db1 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -3,8 +3,7 @@ Fastfetch is a neofetch-like tool for fetching system information and displaying Usage: fastfetch Informative options: - -h, --help: Show this message - -h, --help : Show help for a specific command + -h, --help : Show this message, or help for a specific command -v, --version: Show the version of fastfetch --list-config-paths: List search paths of config files --list-data-paths: List search paths of presets and logos @@ -18,31 +17,31 @@ Informative options: --print-structure: Print the default structure Config options: - -c, --load-config : Load a config file or preset (+) + -c, --config : Load a config file or preset (+) --gen-config : Generate a config file (or print the file if is `-`), with options specified in the command line (if any) --gen-config-force : Generate a config file. Overwrite the existing one General options: - --thread : Use separate threads to send HTTP requests - --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail + --thread : Use separate threads to send HTTP requests + --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail --wmi-timeout : Set the timeout (ms) for WMI queries. Windows only. Default is 5000 --processing-timeout : Set the timeout (ms) when waiting for child processes. Default is 1000 - --ds-force-drm : Set if only DRM should be used to detect displays. Default is false. Linux only + --ds-force-drm : Set if only DRM should be used to detect displays. Default is false. Linux only Logo options: -l, --logo : Set the logo; if default, the name of a builtin logo or a path to a file --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa --logo-width : Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol --logo-height : Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol - --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol + --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol --logo-color-[1-9] : Overwrite a color in the logo - --logo-padding : Set the padding on the left and the right of the logo - --logo-padding-left : Set the padding on the left of the logo - --logo-padding-right : Set the padding on the right of the logo - --logo-padding-top : Set the padding on the top of the logo - --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display - --logo-separate : If true, print modules at bottom of the logo - --logo-recache : If true, regenerate image logo cache + --logo-padding : Set the padding on the left and the right of the logo + --logo-padding-left : Set the padding on the left of the logo + --logo-padding-right : Set the padding on the right of the logo + --logo-padding-top : Set the padding on the top of the logo + --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display + --logo-separate : If true, print modules at bottom of the logo + --logo-recache : If true, regenerate image logo cache --file : Short for --logo-type file --logo --file-raw : Short for --logo-type file-raw --logo --data : Short for --logo-type data --logo @@ -51,36 +50,36 @@ Logo options: --kitty : Short for --logo-type kitty --logo --iterm : Short for --logo-type iterm --logo --chafa : Short for --logo-type chafa --logo - --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail + --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail --chafa-symbols : Specify character symbols to employ in final output. See chafa document for detail - --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail + --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail --chafa-color-space : Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail - --chafa-dither-mode : Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail + --chafa-dither-mode : Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail Display options: - -s,--structure : Set the structure of the fetch. Must be a colon separated list of keys. Use `fastfetch --list-modules` to see the ones available. - --stat : Show time usage (in ms) for individual modules - --pipe : Disable logo and all escape sequences + -s, --structure : Set the structure of the fetch. Must be a colon separated list of keys. Use `fastfetch --list-modules` to see the ones available. + --stat : Show time usage (in ms) for individual modules + --pipe : Disable logo and all escape sequences --color-keys : Set the color of the keys --color-title : Set the color of the title --color : Set the color of both the keys and title --key-width : Align the width of keys to characters - --bright-color : Set if the keys, title and ASCII logo should be printed in bright color. Default is true + --bright-color : Set if the keys, title and ASCII logo should be printed in bright color. Default is true --separator : Set the separator between key and value. Default is a colon with a space --set : Hard set the value of a key --set-keyless : Hard set the value of a key, but don't print the key or the separator - --show-errors : Print occurring errors - --disable-linewrap : Whether to disable line wrap during the run - --hide-cursor : Whether to hide the cursor during the run + --show-errors : Print occurring errors + --disable-linewrap : Whether to disable line wrap during the run + --hide-cursor : Whether to hide the cursor during the run --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 9 - --percent-ndigits : Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0 + --percent-ndigits : Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0 --bar-char-elapsed : Set the character to use in elapsed part. Default is '■' --bar-char-total : Set the character to use in total part. Default is '-' --bar-width : Set the width of the bar, in number of characters. Default is 10 - --bar-border : Whether to show a border around the bar. Default is true - --no-buffer : Set if the stdout application buffer should be disabled. Default is false - --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes + --bar-border : Whether to show a border around the bar. Default is true + --no-buffer : Set if the stdout application buffer should be disabled. Default is false + --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB --temperature-unit : Set the unit of the temperature. Must be one of C, F and K. Default is C @@ -122,62 +121,62 @@ Library options: Set the path of a library to load --lib-ddcutil : Used for brightness detection of external displays Module specific options: - --title-fqdn : Set if the title should use fully qualified domain name. Default is false + --title-fqdn : Set if the title should use fully qualified domain name. Default is false --title-color-user : Set color of the user name (left part). Default is empty (use color of `--color-title`). --title-color-at : Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`) --title-color-host : Set color of the host name (right part). Default is empty (use color of `--color-title`) - --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false + --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false --separator-string : Set the string printed by the separator module --os-file : Set the path to the file containing OS information. Linux only --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) - --disk-show-regular : Set if regular volume should be printed. Default is true - --disk-show-external : Set if external volume should be printed. Default is true - --disk-show-hidden : Set if hidden volumes should be printed. Default is false - --disk-show-subvolumes : Set if subvolumes should be printed. Default is false - --disk-show-readonly : Set if read only volumes should be printed. Default is false - --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false - --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false + --disk-show-regular : Set if regular volume should be printed. Default is true + --disk-show-external : Set if external volume should be printed. Default is true + --disk-show-hidden : Set if hidden volumes should be printed. Default is false + --disk-show-subvolumes : Set if subvolumes should be printed. Default is false + --disk-show-readonly : Set if read only volumes should be printed. Default is false + --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false + --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false --diskio-name-prefix : Show disks with given name prefix only. Default is empty - --bluetooth-show-disconnected : Set if disconnected bluetooth devices should be printed. Default is false - --packages-winget : Set if winget package count should be detected. Default is false + --bluetooth-show-disconnected : Set if disconnected bluetooth devices should be printed. Default is false + --packages-winget : Set if winget package count should be detected. Default is false --display-compact-type : Set if all displays should be printed in one line. Default is none - --display-detect-name : Set if display name should be detected and printed (if supported). Default is false - --display-precise-refresh-rate : Set if decimal refresh rates should not be rounded into integers when printing. Default is true + --display-detect-name : Set if display name should be detected and printed (if supported). Default is false + --display-precise-refresh-rate : Set if decimal refresh rates should not be rounded into integers when printing. Default is true --brightness-ddcci-sleep : Set the sleep times (in ms) when sending DDC/CI requests. See for detail. Default is 10 --sound-type : Set what type of sound devices should be printed. Should be either main, active or all. Default is main --battery-dir : The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only - --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only - --cpu-temp : Detect and display CPU temperature if supported. Default is false + --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only + --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 - --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false - --de-slow-version-detection : Set if DE version should be detected with slow operations. Default is false - --gpu-temp : Detect and display GPU temperature if supported. Default is false - --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false - --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false - --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none - --battery-temp : Detect and display Battery temperature if supported. Default is false - --localip-show-ipv4 : Show IPv4 addresses in local ip module. Default is true - --localip-show-ipv6 : Show IPv6 addresses in local ip module. Default is false - --localip-show-mac : Show mac addresses in local ip module. Default is false - --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false + --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false + --de-slow-version-detection : Set if DE version should be detected with slow operations. Default is false + --gpu-temp : Detect and display GPU temperature if supported. Default is false + --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false + --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false + --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none + --battery-temp : Detect and display Battery temperature if supported. Default is false + --localip-show-ipv4 : Show IPv4 addresses in local ip module. Default is true + --localip-show-ipv6 : Show IPv6 addresses in local ip module. Default is false + --localip-show-mac : Show mac addresses in local ip module. Default is false + --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false --localip-name-prefix : Show interfaces with given interface name prefix only. Default is empty - --localip-default-route-only : Show the interface that is used for default routing only. Default is true on non-android platforms - --localip-compact : Show all IPs in one line. Default is false + --localip-default-route-only : Show the interface that is used for default routing only. Default is true on non-android platforms + --localip-compact : Show all IPs in one line. Default is false --netio-name-prefix : Show interfaces with given name prefix only. Default is empty - --netio-default-route-only : Show the interfac that is used for default routing only. Default is true on non-android platforms + --netio-default-route-only : Show the interfac that is used for default routing only. Default is true on non-android platforms --publicip-timeout : Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --publicip-url : The URL of public IP detection server to be used. --weather-location : Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). --weather-timeout : Time in milliseconds to wait for the weather server to respond. Default is disabled (0) --weather-output-format : The output weather format to be used. It must be URI encoded. - --wm-detect-plugin : Set if window manager plugin should be detected on supported platforms. Default is false + --wm-detect-plugin : Set if window manager plugin should be detected on supported platforms. Default is false --player-name : The name of the player to use for module Media and Player. Linux only --opengl-library : Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix --command-key : Set the module key to display --command-text : Set the command text to be executed --colors-symbol : Set the symbol to be printed by Colors module. Default is block - --colors-padding-left : Set the number of white spaces to print before the symbol. Default is 0 + --colors-padding-left : Set the number of white spaces to print before the symbol. Default is 0 Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci" If a value starts with a ?, it is optional. "true" will be used if not set. diff --git a/src/fastfetch.c b/src/fastfetch.c index 89ee82491..103f0b109 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -19,8 +19,6 @@ #include "util/windows/getline.h" #endif -#include "modules/modules.h" - static void printCommandFormatHelp(const char* command) { FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command); @@ -139,12 +137,12 @@ static void printCommandHelp(const char* command) fprintf(stderr, "Error: No specific help for command '%s' provided\n", command); } -static void listAvailablePresets(void) +static void listAvailablePresets(bool pretty) { FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs) { ffStrbufAppendS(path, "fastfetch/presets/"); - ffListFilesRecursively(path->chars); + ffListFilesRecursively(path->chars, pretty); } } @@ -153,7 +151,7 @@ static void listAvailableLogos(void) FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs) { ffStrbufAppendS(path, "fastfetch/logos/"); - ffListFilesRecursively(path->chars); + ffListFilesRecursively(path->chars, true); } } @@ -453,7 +451,7 @@ static void parseCommand(FFdata* data, char* key, char* value) if(ffStrEqualsIgnCase(subkey, "modules")) listModules(); else if(ffStrEqualsIgnCase(subkey, "presets")) - listAvailablePresets(); + listAvailablePresets(ffOptionParseBoolean(value)); else if(ffStrEqualsIgnCase(subkey, "config-paths")) listConfigPaths(); else if(ffStrEqualsIgnCase(subkey, "data-paths")) From fceb19affe590d0e5636305f226f1acf65ae5c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 14 Nov 2023 09:58:42 +0800 Subject: [PATCH 010/118] Fastfetch: change the order of loading config files --- CHANGELOG.md | 2 ++ src/data/help.txt | 1 + src/fastfetch.c | 21 +++++++++------------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9ecdc2c..24ed5857d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Changes: * The deprecated flag `--gen-config conf` is removed * Flag `--gen-config` now does the same thing as `--migrate-config`, which can be used as config migration and default config file generation. Flag `--migrate-config` is removed +* Fastfetch now searchs for config files in the order of `fastfetch --list-config-paths`, and won't load other config if one is found. +* Flag `--load-user-config` now works in command line flags, but not in config file. # 2.2.3 diff --git a/src/data/help.txt b/src/data/help.txt index bc2682db1..1e1df2107 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -20,6 +20,7 @@ Config options: -c, --config : Load a config file or preset (+) --gen-config : Generate a config file (or print the file if is `-`), with options specified in the command line (if any) --gen-config-force : Generate a config file. Overwrite the existing one + --load-user-config : Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set General options: --thread : Use separate threads to send HTTP requests diff --git a/src/fastfetch.c b/src/fastfetch.c index 103f0b109..837eae772 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -160,6 +160,7 @@ static void listConfigPaths(void) FF_LIST_FOR_EACH(FFstrbuf, folder, instance.state.platform.configDirs) { bool exists = false; + uint32_t length = folder->length + sizeof("fastfetch"); ffStrbufAppendS(folder, "fastfetch/config.jsonc"); exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE); if (!exists) @@ -168,6 +169,7 @@ static void listConfigPaths(void) ffStrbufAppendS(folder, "conf"); exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE); } + ffStrbufSubstrBefore(folder, length); printf("%s%s\n", folder->chars, exists ? " (*)" : ""); } } @@ -218,7 +220,7 @@ static bool parseJsoncFile(const char* path) static bool parseConfigFile(FFdata* data, const char* path) { - FILE* file = fopen(path, "r"); + FF_AUTO_CLOSE_FILE FILE* file = fopen(path, "r"); if(file == NULL) return false; @@ -311,7 +313,6 @@ static bool parseConfigFile(FFdata* data, const char* path) if(line != NULL) free(line); - fclose(file); return true; } @@ -572,9 +573,8 @@ static void parseConfigFiles(FFdata* data) { if (__builtin_expect(instance.state.genConfigPath.length == 0, true)) { - for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) + FF_LIST_FOR_EACH(FFstrbuf, dir, instance.state.platform.configDirs) { - FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1); uint32_t dirLength = dir->length; ffStrbufAppendS(dir, "fastfetch/config.jsonc"); @@ -583,17 +583,14 @@ static void parseConfigFiles(FFdata* data) if (success) return; } } - for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) + FF_LIST_FOR_EACH(FFstrbuf, dir, instance.state.platform.configDirs) { - if (!data->loadUserConfig) - return; - - FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1); uint32_t dirLength = dir->length; ffStrbufAppendS(dir, "fastfetch/config.conf"); - parseConfigFile(data, dir->chars); + bool success = parseConfigFile(data, dir->chars); ffStrbufSubstrBefore(dir, dirLength); + if (success) return; } } @@ -710,11 +707,11 @@ int main(int argc, char** argv) FFdata data = { .structure = ffStrbufCreate(), .customValues = ffListCreate(sizeof(FFCustomValue)), - .loadUserConfig = true, + .loadUserConfig = !getenv("NO_CONFIG"), }; parseArguments(&data, argc, argv, parseCommand); - if(!getenv("NO_CONFIG") && data.loadUserConfig) + if(data.loadUserConfig) parseConfigFiles(&data); parseArguments(&data, argc, argv, (void*) parseOption); From 6ad83af2b5b62a01485dbb918236d479d0c56b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 14 Nov 2023 09:59:15 +0800 Subject: [PATCH 011/118] Host: clean up --- src/modules/host/host.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/host/host.c b/src/modules/host/host.c index 182954de1..d758edddb 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -39,10 +39,8 @@ void ffPrintHost(FFHostOptions* options) else ffStrbufAppend(&output, &host.productFamily); - if(host.productVersion.length > 0 && !ffStrbufIgnCaseEqualS(&host.productVersion, "none")) - { + if(host.productVersion.length > 0) ffStrbufAppendF(&output, " (%s)", host.productVersion.chars); - } ffStrbufPutTo(&output, stdout); } From 5d44efbf62561c6a71895ab942e03838e9eb04c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 14 Nov 2023 10:01:29 +0800 Subject: [PATCH 012/118] Colors: don't use background color It causes some weird behavior on some old terminals. Ref: https://www.reddit.com/r/HomeServer/comments/16ys32a/guess_the_power_consumption_of_ryzen57600x/ --- src/modules/colors/colors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 239e2ec8b..8692c2cac 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -19,7 +19,7 @@ void ffPrintColors(FFColorsOptions* options) // 4%d: Set the background color // 3%d: Set the foreground color for(uint8_t i = 0; i < 8; i++) - printf("\033[4%d;3%dm███", i, i); + printf("\033[3%dm███", i); puts(FASTFETCH_TEXT_MODIFIER_RESET); @@ -34,7 +34,7 @@ void ffPrintColors(FFColorsOptions* options) // 10%d: Set the background to the bright color // 9%d: Set the foreground to the bright color for(uint8_t i = 0; i < 8; i++) - printf("\033[1;4%d;3%d;10%d;9%dm███", i, i, i, i); + printf("\033[1;3%d;9%dm███", i, i); } else { From 2a53b012ea487dd4569cf79ce4119c49feb48e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 14 Nov 2023 16:36:08 +0800 Subject: [PATCH 013/118] Completion (Fish): clean up --- completions/fish | 31 ++++++++++++++++++++----------- src/data/help.txt | 46 +++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/completions/fish b/completions/fish index 3a8b833fc..0c61e2500 100755 --- a/completions/fish +++ b/completions/fish @@ -1,7 +1,11 @@ #!/usr/bin/env fish +if not test -x fastfetch + return +end + set -l whole_text (fastfetch --pipe --help) -set -l modules (string lower (string sub -s 5 (fastfetch --list-modules))) +set -l modules (fastfetch --list-modules | string sub -s 5 | string lower) complete -c fastfetch -f @@ -10,23 +14,24 @@ for line in (string match -- ' -*' $whole_text) set -l args (string trim -- $kv[1]) set -l desc (string trim -- $kv[2]) - set -l res -c fastfetch + if string match -q -- '--<*' $args # ignore ---* + continue + end - switch (string match -r -- '<\??\w+>' $args) + set -l res -c fastfetch + set -l regexp '<\??[\w=]+>' + + switch (string match -r -- $regexp $args) case '<\?command>' set -l modules_format $modules-format"\tModule_format" set res $res -x -a "color\tSupported_colors format\tCustom_format config\tConfiguration $modules_format" case '<\?bool>' set res $res -x -a "true\tBool false\tBool" + case '' + set -l presets (fastfetch --list-presets false)"\tPreset" + set res $res -r -a "$presets" case '' set res $res -F -r - case '' - if string match -q -- '*--config*' $args - set -l presets (fastfetch --list-presets false)"\tPreset" - set res $res -r -a "$presets" - else - set res $res -F -r - end case '' set res $res -x -a "0\tNumber 1\tNumber 2\tNumber 3\tNumber 4\tNumber 5\tNumber 6\tNumber 7\tNumber 8\tNumber 9\tNumber" case '<\?num>' @@ -36,11 +41,15 @@ for line in (string match -- ' -*' $whole_text) set res $res -x -a "$temp" case '' set res $res -x -a "none\tNone small\tSmall" + case '' + set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor" case '<*>' set res $res -x + case '*' + set res $res -f end - set args (string trim -- (string split -- ',' (string replace -r -- '<\??\w+>' '' $args))) + set args (string replace -r -- $regexp '' $args | string split ',' | string trim) for arg in $args if string match -q -- '--*' $arg diff --git a/src/data/help.txt b/src/data/help.txt index 1e1df2107..6fab811c5 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -17,9 +17,9 @@ Informative options: --print-structure: Print the default structure Config options: - -c, --config : Load a config file or preset (+) - --gen-config : Generate a config file (or print the file if is `-`), with options specified in the command line (if any) - --gen-config-force : Generate a config file. Overwrite the existing one + -c, --config : Load a config file or preset (+) + --gen-config : Generate a config file (or print it if is `-`), with options specified in the command line (if any) + --gen-config-force : Generate a config file. Overwrite the existing one --load-user-config : Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set General options: @@ -31,9 +31,9 @@ General options: Logo options: -l, --logo : Set the logo; if default, the name of a builtin logo or a path to a file - --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa - --logo-width : Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol - --logo-height : Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol + --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa + --logo-width : Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol + --logo-height : Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol --logo-color-[1-9] : Overwrite a color in the logo --logo-padding : Set the padding on the left and the right of the logo @@ -43,18 +43,18 @@ Logo options: --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display --logo-separate : If true, print modules at bottom of the logo --logo-recache : If true, regenerate image logo cache - --file : Short for --logo-type file --logo - --file-raw : Short for --logo-type file-raw --logo + --file : Short for --logo-type file --logo + --file-raw : Short for --logo-type file-raw --logo --data : Short for --logo-type data --logo --data-raw : Short for --logo-type data-raw --logo - --sixel : Short for --logo-type sixel --logo - --kitty : Short for --logo-type kitty --logo - --iterm : Short for --logo-type iterm --logo - --chafa : Short for --logo-type chafa --logo + --sixel : Short for --logo-type sixel --logo + --kitty : Short for --logo-type kitty --logo + --iterm : Short for --logo-type iterm --logo + --chafa : Short for --logo-type chafa --logo --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail --chafa-symbols : Specify character symbols to employ in final output. See chafa document for detail --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail - --chafa-color-space : Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail + --chafa-color-space : Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail --chafa-dither-mode : Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail Display options: @@ -72,8 +72,8 @@ Display options: --show-errors : Print occurring errors --disable-linewrap : Whether to disable line wrap during the run --hide-cursor : Whether to hide the cursor during the run - --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC - --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 9 + --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC + --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 9 --percent-ndigits : Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0 --bar-char-elapsed : Set the character to use in elapsed part. Default is '■' --bar-char-total : Set the character to use in total part. Default is '-' @@ -81,8 +81,8 @@ Display options: --bar-border : Whether to show a border around the bar. Default is true --no-buffer : Set if the stdout application buffer should be disabled. Default is false --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes - --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB - --temperature-unit : Set the unit of the temperature. Must be one of C, F and K. Default is C + --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB + --temperature-unit : Set the unit of the temperature. Must be one of C, F and K. Default is C General module options: ---format : Set the format string to use for each specific module. @@ -117,7 +117,7 @@ Library options: Set the path of a library to load --lib-osmesa : Needed by the OpenGL module for gl context creation --lib-opencl : OpenCL module --lib-pulse : Pulseaudio. Used for Sound detection - --lib-nm: NetworkManager. Used for Wifi detection + --lib-nm : NetworkManager. Used for Wifi detection --lib-freetype : Used for Termux font detection --lib-ddcutil : Used for brightness detection of external displays @@ -128,8 +128,8 @@ Module specific options: --title-color-host : Set color of the host name (right part). Default is empty (use color of `--color-title`) --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false --separator-string : Set the string printed by the separator module - --os-file : Set the path to the file containing OS information. Linux only - --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) + --os-file : Set the file path which containing OS information. Linux only + --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) --disk-show-regular : Set if regular volume should be printed. Default is true --disk-show-external : Set if external volume should be printed. Default is true --disk-show-hidden : Set if hidden volumes should be printed. Default is false @@ -140,12 +140,12 @@ Module specific options: --diskio-name-prefix : Show disks with given name prefix only. Default is empty --bluetooth-show-disconnected : Set if disconnected bluetooth devices should be printed. Default is false --packages-winget : Set if winget package count should be detected. Default is false - --display-compact-type : Set if all displays should be printed in one line. Default is none + --display-compact-type : Set if all displays should be printed in one line. Must be one of `none`, `original` and `scaled`. Default is none --display-detect-name : Set if display name should be detected and printed (if supported). Default is false --display-precise-refresh-rate : Set if decimal refresh rates should not be rounded into integers when printing. Default is true --brightness-ddcci-sleep : Set the sleep times (in ms) when sending DDC/CI requests. See for detail. Default is 10 - --sound-type : Set what type of sound devices should be printed. Should be either main, active or all. Default is main - --battery-dir : The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only + --sound-type : Set what type of sound devices should be printed. Should be either main, active or all. Default is main + --battery-dir : The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 From 1ba5e6e8f76ec5e2c631521f13db56c8f3ebf9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 15 Nov 2023 10:38:32 +0800 Subject: [PATCH 014/118] Doc: better document for logo types --- src/data/help.txt | 20 +++++++++++--------- src/options/logo.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/data/help.txt b/src/data/help.txt index 6fab811c5..c0069ca1d 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -31,7 +31,7 @@ General options: Logo options: -l, --logo : Set the logo; if default, the name of a builtin logo or a path to a file - --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty, iterm or chafa + --logo-type : Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, raw, sixel, kitty, kitty-direct, iterm or chafa --logo-width : Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol --logo-height : Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol --logo-preserve-aspect-ratio : Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol @@ -43,14 +43,16 @@ Logo options: --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display --logo-separate : If true, print modules at bottom of the logo --logo-recache : If true, regenerate image logo cache - --file : Short for --logo-type file --logo - --file-raw : Short for --logo-type file-raw --logo - --data : Short for --logo-type data --logo - --data-raw : Short for --logo-type data-raw --logo - --sixel : Short for --logo-type sixel --logo - --kitty : Short for --logo-type kitty --logo - --iterm : Short for --logo-type iterm --logo - --chafa : Short for --logo-type chafa --logo + --file : Short for --logo-type file --logo . Text file, printed with color code replacement + --file-raw : Short for --logo-type file-raw --logo . Text file, printed as is (with escaped chars replacement) + --data : Short for --logo-type data --logo . Text data, printed with color code replacement + --data-raw : Short for --logo-type data-raw --logo . Text data, printed as is (with escaped chars replacement) + --raw : Short for --logo-type raw --logo . Image file, printed as raw binary string + --sixel : Short for --logo-type sixel --logo . Image file, printed as sixel codes + --kitty : Short for --logo-type kitty --logo . Image file, printed as kitty graphics protocol + --kitty-direct : Short for --logo-type kitty-direct --logo . Image file, tell the terminal emulator to read image data from the specified file + --iterm : Short for --logo-type iterm --logo . Image file, printed as iterm graphics protocol + --chafa : Short for --logo-type chafa --logo . Image file, printed as ascii art using libchafa --chafa-fg-only : Produce character-cell output using foreground colors only. See chafa document for detail --chafa-symbols : Specify character symbols to employ in final output. See chafa document for detail --chafa-canvas-mode : Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail diff --git a/src/options/logo.h b/src/options/logo.h index c5bb6fb3e..b93d0ef8a 100644 --- a/src/options/logo.h +++ b/src/options/logo.h @@ -14,7 +14,7 @@ typedef enum FFLogoType FF_LOGO_TYPE_FILE_RAW, //text file, printed as is FF_LOGO_TYPE_DATA, //text data, printed with color code replacement FF_LOGO_TYPE_DATA_RAW, //text data, printed as is - FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes. + FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol FF_LOGO_TYPE_IMAGE_KITTY_DIRECT, //image file, tell the terminal emulator to read image data from the specified file (Supported by kitty and wezterm) FF_LOGO_TYPE_IMAGE_ITERM, //image file, printed as iterm graphics protocol From 5aab0e2dd90705a0ad69b1fb6b17657d1dd6b08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 15 Nov 2023 16:21:07 +0800 Subject: [PATCH 015/118] Completion (Fish): built-in logos auto-completion --- completions/fish | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/fish b/completions/fish index 0c61e2500..1515ff223 100755 --- a/completions/fish +++ b/completions/fish @@ -40,7 +40,9 @@ for line in (string match -- ' -*' $whole_text) set temp $modules"\tModule" set res $res -x -a "$temp" case '' - set res $res -x -a "none\tNone small\tSmall" + set -l builtin_logos (fastfetch --list-logos-autocompletion) + set -l temp $builtin_logos"\tBuiltin" + set res $res -x -a "none\tNone small\tSmall $temp" case '' set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor" case '<*>' From 413984963ef8bc679847adae2b98cbee01732f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 15 Nov 2023 16:30:46 +0800 Subject: [PATCH 016/118] TerminalShell: support oils and elvish --- CHANGELOG.md | 3 +++ src/detection/terminalshell/terminalshell.c | 19 +++++++++++++++++++ .../terminalshell/terminalshell_linux.c | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ed5857d..12abd719c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Changes: * Fastfetch now searchs for config files in the order of `fastfetch --list-config-paths`, and won't load other config if one is found. * Flag `--load-user-config` now works in command line flags, but not in config file. +Features: +* Support Oils and elvish shell version detection (Shell) + # 2.2.3 Features: diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index c0444047d..0fe89f3aa 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -128,6 +128,21 @@ static bool getShellVersionOksh(FFstrbuf* exe, FFstrbuf* version) return true; } +static bool getShellVersionOils(FFstrbuf* exe, FFstrbuf* version) +{ + if(ffProcessAppendStdOut(version, (char* const[]) { + exe->chars, + "--version", + NULL + }) != NULL) + return false; + + // Oils 0.18.0 https://www.oilshell.org/... + ffStrbufSubstrAfterFirstC(version, ' '); + ffStrbufSubstrBeforeFirstC(version, '\t'); + return true; +} + static bool getShellVersionNushell(FFstrbuf* exe, FFstrbuf* version) { ffStrbufSetS(version, getenv("NU_VERSION")); @@ -170,6 +185,10 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version) return getShellVersionKsh(exe, version); if(strcasecmp(exeName, "oksh") == 0) return getShellVersionOksh(exe, version); + if(strcasecmp(exeName, "oil.ovm") == 0) + return getShellVersionOils(exe, version); + if(strcasecmp(exeName, "elvish") == 0) + return getExeVersionRaw(exe, version); if(strcasecmp(exeName, "python") == 0 && getenv("XONSH_VERSION")) { ffStrbufSetS(version, getenv("XONSH_VERSION")); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index ce4d3dea5..91394faea 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -164,6 +164,8 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid) strcasecmp(name, "pwsh") == 0 || strcasecmp(name, "nu") == 0 || strcasecmp(name, "git-shell") == 0 || + strcasecmp(name, "elvish") == 0 || + strcasecmp(name, "oil.ovm") == 0 || (strcasecmp(name, "python") == 0 && getenv("XONSH_VERSION")) ) { if (result->shellProcessName.length == 0) @@ -355,6 +357,8 @@ const FFTerminalShellResult* ffDetectTerminalShell() ffStrbufInitStatic(&result.shellPrettyName, "nushell"); else if(ffStrbufIgnCaseEqualS(&result.shellProcessName, "python") && getenv("XONSH_VERSION")) ffStrbufInitStatic(&result.shellPrettyName, "xonsh"); + else if(ffStrbufIgnCaseEqualS(&result.shellProcessName, "oil.ovm")) + ffStrbufInitStatic(&result.shellPrettyName, "Oils"); else { // https://github.com/fastfetch-cli/fastfetch/discussions/280#discussioncomment-3831734 From 3f9462d7c81ccf991e624655071faf560b34ea9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 16 Nov 2023 10:04:17 +0800 Subject: [PATCH 017/118] Package (macOS): try supporting nix --- src/detection/packages/packages_apple.c | 47 ++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/detection/packages/packages_apple.c b/src/detection/packages/packages_apple.c index d49944d84..c25459193 100644 --- a/src/detection/packages/packages_apple.c +++ b/src/detection/packages/packages_apple.c @@ -1,12 +1,12 @@ #include "packages.h" +#include "common/io/io.h" #include "common/parsing.h" +#include "common/processing.h" #include "util/stringUtils.h" -#include - static uint32_t getNumElements(const char* dirname, unsigned char type) { - DIR* dirp = opendir(dirname); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(dirname); if(dirp == NULL) return 0; @@ -21,8 +21,6 @@ static uint32_t getNumElements(const char* dirname, unsigned char type) if(type == DT_DIR) num_elements -= 2; // accounting for . and .. - closedir(dirp); - return num_elements; } @@ -68,8 +66,47 @@ static uint32_t getMacPortsPackages() return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/local"); } +static uint32_t getNixPackagesImpl(char* path) +{ + //Nix detection is kinda slow, so we only do it if the dir exists + if(!ffPathExists(path, FF_PATHTYPE_DIRECTORY)) + return 0; + + FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(128); + + //https://github.com/fastfetch-cli/fastfetch/issues/195#issuecomment-1191748222 + FF_STRBUF_AUTO_DESTROY command = ffStrbufCreateA(255); + ffStrbufAppendS(&command, "for x in $(nix-store --query --requisites "); + ffStrbufAppendS(&command, path); + ffStrbufAppendS(&command, "); do if [ -d $x ]; then echo $x ; fi ; done | cut -d- -f2- | egrep '([0-9]{1,}\\.)+[0-9]{1,}' | egrep -v '\\-doc$|\\-man$|\\-info$|\\-dev$|\\-bin$|^nixos-system-nixos-' | uniq | wc -l"); + + ffProcessAppendStdOut(&output, (char* const[]) { + "/bin/sh", + "-c", + command.chars, + NULL + }); + + return (uint32_t) strtol(output.chars, NULL, 10); +} + +static uint32_t getNixPackages(FFstrbuf* baseDir, const char* dirname) +{ + uint32_t baseDirLength = baseDir->length; + ffStrbufAppendS(baseDir, dirname); + uint32_t num_elements = getNixPackagesImpl(baseDir->chars); + ffStrbufSubstrBefore(baseDir, baseDirLength); + return num_elements; +} + void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { getBrewPackages(result); result->port = getMacPortsPackages(); + + FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(FASTFETCH_TARGET_DIR_ROOT); + result->nixDefault += getNixPackages(&baseDir, "/nix/var/nix/profiles/default"); + result->nixSystem += getNixPackages(&baseDir, "/run/current-system"); + ffStrbufSet(&baseDir, &instance.state.platform.homeDir); + result->nixUser = getNixPackages(&baseDir, "/.nix-profile"); } From f8ba138b8d3dfc7af79df18a44c72d46e9ef5a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 16 Nov 2023 14:21:24 +0800 Subject: [PATCH 018/118] Completion: tidy --- completions/bash | 10 +++++----- completions/fish | 14 ++++++++------ src/data/help_color.txt | 2 +- src/fastfetch.c | 38 ++++++++++++++++++++++++++++---------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/completions/bash b/completions/bash index 9a59d7116..c730d177d 100644 --- a/completions/bash +++ b/completions/bash @@ -5,7 +5,7 @@ __fastfetch_complete_help() local __ff_helps=( "color" "format" - "load-config" + "config" "os-format" "host-format" "kernel-format" @@ -66,7 +66,7 @@ __fastfetch_complete_path() __fastfetch_complete_logo() { - COMPREPLY=($(compgen -W "$(fastfetch --list-logos-autocompletion)" -- "$CURRENT_WORD")) + COMPREPLY=($(compgen -W "$(fastfetch --list-logos autocompletion)" -- "$CURRENT_WORD")) } __fastfetch_complete_logo_type() @@ -218,10 +218,9 @@ __fastfetch_completion() "--logo-color-6" "--logo-color-7" "--logo-color-8" + "--logo-color-9" "--logo-width" "--logo-height" - "--logo-color-9" - "-c" "--color" "--color-keys" "--color-title" @@ -360,7 +359,8 @@ __fastfetch_completion() ) local FF_OPTIONS_PATH=( - "--load-config" + "-c" + "--config" "--os-file" "--lib-pci" "--lib-vulkan" diff --git a/completions/fish b/completions/fish index 1515ff223..1edf0a38c 100755 --- a/completions/fish +++ b/completions/fish @@ -5,7 +5,7 @@ if not test -x fastfetch end set -l whole_text (fastfetch --pipe --help) -set -l modules (fastfetch --list-modules | string sub -s 5 | string lower) +set -l modules (fastfetch --list-modules autocompletion) complete -c fastfetch -f @@ -23,12 +23,13 @@ for line in (string match -- ' -*' $whole_text) switch (string match -r -- $regexp $args) case '<\?command>' - set -l modules_format $modules-format"\tModule_format" - set res $res -x -a "color\tSupported_colors format\tCustom_format config\tConfiguration $modules_format" + set -l temp (string lower $modules) + set -l temp $temp-format"\tModule\\ format" + set res $res -x -a "color\tSupported\\ colors format\tCustom\\ format config\tConfiguration $temp" case '<\?bool>' set res $res -x -a "true\tBool false\tBool" case '' - set -l presets (fastfetch --list-presets false)"\tPreset" + set -l presets (fastfetch --list-presets autocompletion)"\tPreset" set res $res -r -a "$presets" case '' set res $res -F -r @@ -40,8 +41,9 @@ for line in (string match -- ' -*' $whole_text) set temp $modules"\tModule" set res $res -x -a "$temp" case '' - set -l builtin_logos (fastfetch --list-logos-autocompletion) - set -l temp $builtin_logos"\tBuiltin" + set -l temp (fastfetch --list-logos autocompletion) + set -l temp (string replace -- ' ' '\\ ' $temp) + set -l temp $temp"\tBuiltin" set res $res -x -a "none\tNone small\tSmall $temp" case '' set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor" diff --git a/src/data/help_color.txt b/src/data/help_color.txt index defeab6d6..a28d89eb6 100644 --- a/src/data/help_color.txt +++ b/src/data/help_color.txt @@ -3,7 +3,7 @@ Usage: fastfetch --color must be a color encoding as ANSI escape sequences. It is inserted between "ESC[" and "m". Infos about them can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters. Examples: - --color 35: sets the color to pink + --color 35: sets the color to magenta. `--color magenta` is also supported --color 4;92: sets the color to bright Green with underline --color 5;104: blinking text on a blue background If no color is set, the main color of the logo will be used. diff --git a/src/fastfetch.c b/src/fastfetch.c index 837eae772..cd2972eaa 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -183,7 +183,7 @@ static void listDataPaths(void) } } -static void listModules() +static void listModules(bool pretty) { unsigned count = 0; for (int i = 0; i <= 'Z' - 'A'; ++i) @@ -191,7 +191,10 @@ static void listModules() for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules) { ++count; - printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name); + if (pretty) + printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name); + else + puts((*modules)->name); } } } @@ -450,9 +453,9 @@ static void parseCommand(FFdata* data, char* key, char* value) { const char* subkey = key + strlen("--list-"); if(ffStrEqualsIgnCase(subkey, "modules")) - listModules(); + listModules(!value || !ffStrEqualsIgnCase(value, "autocompletion")); else if(ffStrEqualsIgnCase(subkey, "presets")) - listAvailablePresets(ffOptionParseBoolean(value)); + listAvailablePresets(!value || !ffStrEqualsIgnCase(value, "autocompletion")); else if(ffStrEqualsIgnCase(subkey, "config-paths")) listConfigPaths(); else if(ffStrEqualsIgnCase(subkey, "data-paths")) @@ -461,13 +464,28 @@ static void parseCommand(FFdata* data, char* key, char* value) ffListFeatures(); else if(ffStrEqualsIgnCase(subkey, "logos")) { - puts("Builtin logos:"); - ffLogoBuiltinList(); - puts("\nCustom logos:"); - listAvailableLogos(); + if (value) + { + if (ffStrEqualsIgnCase(value, "autocompletion")) + ffLogoBuiltinListAutocompletion(); + else if (ffStrEqualsIgnCase(value, "builtin")) + ffLogoBuiltinList(); + else if (ffStrEqualsIgnCase(value, "custom")) + listAvailableLogos(); + else + { + fprintf(stderr, "Error: unsupported logo type: %s\n", value); + exit(415); + } + } + else + { + puts("Builtin logos:"); + ffLogoBuiltinList(); + puts("\nCustom logos:"); + listAvailableLogos(); + } } - else if(ffStrEqualsIgnCase(subkey, "logos-autocompletion")) - ffLogoBuiltinListAutocompletion(); else { fprintf(stderr, "Error: unsupported list option: %s\n", key); From 998193b0144f10cfc7077d84ed6752ebb41f8c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 16 Nov 2023 16:41:08 +0800 Subject: [PATCH 019/118] Fastfetch: support `-c none`; remove `--load-user-config` --- CHANGELOG.md | 10 +++++++--- completions/fish | 2 +- src/common/commandoption.h | 2 +- src/data/help.txt | 5 ++--- src/fastfetch.c | 28 ++++++++++++++++++---------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12abd719c..ec35493d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # 2.3.0 -Changes: +Config related changes: * The deprecated flag `--gen-config conf` is removed * Flag `--gen-config` now does the same thing as `--migrate-config`, which can be used as config migration and default config file generation. Flag `--migrate-config` is removed * Fastfetch now searchs for config files in the order of `fastfetch --list-config-paths`, and won't load other config if one is found. -* Flag `--load-user-config` now works in command line flags, but not in config file. +* The undocumented flag `--load-user-config` is removed. As an alternative, `--config none` can be used to disable loading config files. +* `--config` (previously named `--load-config`) is now supported for command line arguments only. If specified, other config files won't be loaded, which works like other programs. +* Config files will always be loaded before other command line flags being parsed. That is to say, command line flags will always override options defined in config files. + +We are deprecating flags based config files (will be removed in v3.0.0). We suggest you migrate to json based config files. Features: * Support Oils and elvish shell version detection (Shell) @@ -19,7 +23,7 @@ Bugfixes: * Fix terminal detection on NixOS (Terminal) # 2.2.2 -g + Changes: * `--percent-type` now defaults to 9 (colored percentage numbers) * `fastfetch` now prints LocalIp module by default diff --git a/completions/fish b/completions/fish index 1edf0a38c..d3177fa40 100755 --- a/completions/fish +++ b/completions/fish @@ -30,7 +30,7 @@ for line in (string match -- ' -*' $whole_text) set res $res -x -a "true\tBool false\tBool" case '' set -l presets (fastfetch --list-presets autocompletion)"\tPreset" - set res $res -r -a "$presets" + set res $res -r -a "none\tDisable $presets" case '' set res $res -F -r case '' diff --git a/src/common/commandoption.h b/src/common/commandoption.h index 276477b91..1736a4f12 100644 --- a/src/common/commandoption.h +++ b/src/common/commandoption.h @@ -14,7 +14,7 @@ typedef struct FFdata { FFstrbuf structure; FFlist customValues; // List of FFCustomValue - bool loadUserConfig; + bool configLoaded; } FFdata; bool ffParseModuleOptions(const char* key, const char* value); diff --git a/src/data/help.txt b/src/data/help.txt index c0069ca1d..5c6c45cd3 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -17,10 +17,9 @@ Informative options: --print-structure: Print the default structure Config options: - -c, --config : Load a config file or preset (+) + -c, --config : Specify the config file or preset to be loaded. If `none`, disable futher config loading (+) --gen-config : Generate a config file (or print it if is `-`), with options specified in the command line (if any) --gen-config-force : Generate a config file. Overwrite the existing one - --load-user-config : Set if user config should be loaded. Default is true if env-var `NO_CONFIG` is not set General options: --thread : Use separate threads to send HTTP requests @@ -184,4 +183,4 @@ Module specific options: Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci" If a value starts with a ?, it is optional. "true" will be used if not set. A (+) at the end indicates that more help can be printed with --help