From 6f970c36e360a177a2f97f9eb434d250fdd5c61a Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Wed, 23 Aug 2023 17:07:36 -0400 Subject: [PATCH 01/17] Fix typo in config parsing for --color-title --- src/fastfetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index b06570ea1..73b4bc251 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1002,7 +1002,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) optionCheckString(key, value, &instance.config.colorKeys); ffOptionParseColor(value, &instance.config.colorKeys); } - else if(ffStrEqualsIgnCase(key, "-title")) + else if(ffStrEqualsIgnCase(subkey, "-title")) { optionCheckString(key, value, &instance.config.colorTitle); ffOptionParseColor(value, &instance.config.colorTitle); From 721816408891ba7c3f5c623ac0cb9af2e25c5f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 23 Aug 2023 11:04:03 +0800 Subject: [PATCH 02/17] Doc: add more badges in README --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a6257ecce..4f1a1ebc3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # Fastfetch -[![CI](https://github.com/fastfetch-cli/fastfetch/actions/workflows/ci.yml/badge.svg)](https://github.com/fastfetch-cli/fastfetch/actions/workflows/ci.yml) +![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/fastfetch-cli/fastfetch/ci.yml) +![GitHub license](https://img.shields.io/github/license/fastfetch-cli/fastfetch) +![GitHub contributors](https://img.shields.io/github/contributors/fastfetch-cli/fastfetch) +![GitHub top language](https://img.shields.io/github/languages/top/fastfetch-cli/fastfetch?logo=c&label=) +![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/fastfetch-cli/fastfetch) +![homebrew downloads](https://img.shields.io/homebrew/installs/dm/fastfetch?logo=homebrew) +![GitHub all releases](https://img.shields.io/github/downloads/fastfetch-cli/fastfetch/total?logo=github) +![GitHub release (with filter)](https://img.shields.io/github/v/release/fastfetch-cli/fastfetch?logo=github) +[![latest packaged version(s)](https://repology.org/badge/latest-versions/fastfetch.svg)](https://repology.org/project/fastfetch/versions) +[![Packaging status](https://repology.org/badge/tiny-repos/fastfetch.svg)](https://repology.org/project/fastfetch/versions) Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying them in a pretty way. It is written mainly in C, with performance and customizability in mind. Currently, Linux, Android, FreeBSD, MacOS and Windows 7+ are supported. From 326d83f25bfb6139ce266f8e4dc7d8dded2ce76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 09:12:24 +0800 Subject: [PATCH 03/17] Global: fix percent formatting for `--*-format` fix #535 --- src/modules/battery/battery.c | 9 +++++---- src/modules/brightness/brightness.c | 7 ++++--- src/modules/cpuusage/cpuusage.c | 4 +++- src/modules/disk/disk.c | 10 +++++++--- src/modules/memory/memory.c | 4 +++- src/modules/swap/swap.c | 4 +++- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 4ad292943..4f239650a 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -10,17 +10,16 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8_t index) { - if(instance.config.battery.moduleArgs.outputFormat.length == 0) + if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); bool showStatus = !(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) && result->status.length > 0 && ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0; - FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if(result->capacity >= 0) { if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) @@ -62,11 +61,13 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8 } else { + FF_STRBUF_AUTO_DESTROY capacityStr = ffStrbufCreate(); + ffAppendPercentNum(&capacityStr, result->capacity, 51, 21, false); ffPrintFormat(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &result->capacity}, + {FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->status}, {FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature}, }); diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 24d31c5df..560353749 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -43,10 +43,9 @@ void ffPrintBrightness(FFBrightnessOptions* options) }); } - FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if(options->moduleArgs.outputFormat.length == 0) { + FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY); if (instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) @@ -66,8 +65,10 @@ void ffPrintBrightness(FFBrightnessOptions* options) } else { + FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate(); + ffAppendPercentNum(&valueStr, item->value, 10, 10, false); ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_FLOAT, &item->value}, + {FF_FORMAT_ARG_TYPE_STRBUF, &valueStr}, {FF_FORMAT_ARG_TYPE_STRBUF, &item->name}, }); } diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 27a53d776..23b29e791 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -36,8 +36,10 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) } else { + FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); + ffAppendPercentNum(&percentageStr, percentage, 50, 80, false); ffPrintFormat(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_CPUUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_DOUBLE, &percentage} + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr} }); } } diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 199779f97..a6d8b98c6 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -92,17 +92,21 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) } else { - uint8_t filesPercentage = disk->filesTotal > 0 ? (uint8_t) (((double) disk->filesUsed / (double) disk->filesTotal) * 100.0) : 0; + FF_STRBUF_AUTO_DESTROY bytesPercentageStr = ffStrbufCreate(); + ffAppendPercentNum(&bytesPercentageStr, bytesPercentage, 50, 80, false); + FF_STRBUF_AUTO_DESTROY filesPercentageStr = ffStrbufCreate(); + double filesPercentage = disk->filesTotal > 0 ? ((double) disk->filesUsed / (double) disk->filesTotal) * 100.0 : 0; + ffAppendPercentNum(&filesPercentageStr, filesPercentage, 50, 80, false); bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_BIT); bool isHidden = !!(disk->type & FF_DISK_TYPE_HIDDEN_BIT); ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageStr}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal}, - {FF_FORMAT_ARG_TYPE_UINT8, &filesPercentage}, + {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageStr}, {FF_FORMAT_ARG_TYPE_BOOL, &isExternal}, {FF_FORMAT_ARG_TYPE_BOOL, &isHidden}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem}, diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index e19f61f59..410fb97f2 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -56,10 +56,12 @@ void ffPrintMemory(FFMemoryOptions* options) } else { + FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); + ffAppendPercentNum(&percentageStr, percentage, 50, 80, false); ffPrintFormat(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_UINT8, &percentage}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, }); } } diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index be23eefec..d4b08031d 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -63,10 +63,12 @@ void ffPrintSwap(FFSwapOptions* options) } else { + FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); + ffAppendPercentNum(&percentageStr, percentage, 50, 80, false); ffPrintFormat(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_SWAP_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_UINT8, &percentage}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, }); } } From b1ac31f590131a546e260d2dca0152ed455d4f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 09:35:17 +0800 Subject: [PATCH 04/17] Global: add option `--percent-ndigits` --- doc/json_schema.json | 11 ++++++++++- src/common/bar.c | 2 +- src/common/init.c | 1 + src/common/jsonconfig.c | 4 +++- src/fastfetch.c | 4 +++- src/fastfetch.h | 3 ++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index 4baa74a2d..07061c18f 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -343,6 +343,8 @@ "sizeNdigits": { "type": "integer", "title": "Set the number of digits to keep after the decimal point when formatting sizes", + "minimum": 0, + "maximum": 9, "default": 2 }, "sizeMaxPrefix": { @@ -388,9 +390,16 @@ "type": "number", "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", "minimum": 0, - "maximum": 9, + "maximum": 255, "default": 1 }, + "percentNdigits": { + "type": "number", + "title": "Set the number of digits to keep after the decimal point when formatting percentage numbers", + "minimum": 0, + "maximum": 9, + "default": 0 + }, "noBuffer": { "type": "boolean", "title": "Whether to disable the stdout application buffer", diff --git a/src/common/bar.c b/src/common/bar.c index 549c3ba50..e250188d7 100644 --- a/src/common/bar.c +++ b/src/common/bar.c @@ -93,7 +93,7 @@ void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } } - ffStrbufAppendF(buffer, "%u%%", (unsigned) (percent + 0.5)); + ffStrbufAppendF(buffer, "%.*f%%", instance.config.percentNdigits, percent); if (colored && !instance.config.pipe) { diff --git a/src/common/init.c b/src/common/init.c index 2f277ddfb..dfe8b4d19 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -74,6 +74,7 @@ static void defaultConfig(void) instance.config.barWidth = 10; instance.config.barBorder = true; instance.config.percentType = 1; + instance.config.percentNdigits = 0; ffInitBatteryOptions(&instance.config.battery); ffInitBiosOptions(&instance.config.bios); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 1cfbb9606..71bc3cf8f 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -325,7 +325,9 @@ const char* ffParseDisplayJsonConfig(void) config->temperatureUnit = (FFTemperatureUnit) value; } else if (ffStrEqualsIgnCase(key, "percentType")) - config->percentType = (uint32_t) yyjson_get_uint(val); + config->percentType = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "percentNdigits")) + config->percentNdigits = (uint8_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "bar")) { if (yyjson_is_obj(val)) diff --git a/src/fastfetch.c b/src/fastfetch.c index 73b4bc251..9786c070a 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1053,7 +1053,9 @@ static void parseOption(FFdata* data, const char* key, const char* value) }); } else if(ffStrEqualsIgnCase(key, "--percent-type")) - instance.config.percentType = ffOptionParseUInt32(key, value); + instance.config.percentType = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--percent-ndigits")) + instance.config.percentNdigits = (uint8_t) ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(key, "--no-buffer")) instance.config.noBuffer = ffOptionParseBoolean(value); else if(ffStrStartsWithIgnCase(key, "--bar")) diff --git a/src/fastfetch.h b/src/fastfetch.h index 6dfa675fa..a5f990912 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -61,7 +61,8 @@ typedef struct FFconfig FFstrbuf barCharTotal; uint8_t barWidth; bool barBorder; - uint32_t percentType; + uint8_t percentType; + uint8_t percentNdigits; bool pipe; //disables logo and all escape sequences bool multithreading; bool stat; From bc6ed4f4a27616ce3f4a126e7d22a76748ef3e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 09:55:00 +0800 Subject: [PATCH 05/17] OpenGL: use `FFOpenGLOptions` in detection code --- src/detection/opengl/opengl.h | 2 +- src/detection/opengl/opengl_apple.c | 2 +- src/detection/opengl/opengl_linux.c | 8 ++++---- src/detection/opengl/opengl_windows.c | 2 +- src/modules/opengl/opengl.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/detection/opengl/opengl.h b/src/detection/opengl/opengl.h index b4426856b..fbd9e897d 100644 --- a/src/detection/opengl/opengl.h +++ b/src/detection/opengl/opengl.h @@ -13,6 +13,6 @@ typedef struct FFOpenGLResult FFstrbuf slv; } FFOpenGLResult; -const char* ffDetectOpenGL(FFOpenGLResult* result); +const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result); #endif diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c index b6f4fe257..e7f3ad0e9 100644 --- a/src/detection/opengl/opengl_apple.c +++ b/src/detection/opengl/opengl_apple.c @@ -35,7 +35,7 @@ static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatOb return error; } -const char* ffDetectOpenGL(FFOpenGLResult* result) +const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLResult* result) { CGLPixelFormatObj pixelFormat; CGLPixelFormatAttribute attrs[] = { diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index 43378be63..8da49361b 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -314,11 +314,11 @@ static const char* osMesaPrint(FFOpenGLResult* result) #endif //FF_HAVE_OSMESA -const char* ffDetectOpenGL(FFOpenGLResult* result) +const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) { #if FF_HAVE_GL - if(instance.config.openGL.library == FF_OPENGL_LIBRARY_GLX) + if(options->library == FF_OPENGL_LIBRARY_GLX) { #ifdef FF_HAVE_GLX return glxPrint(result); @@ -327,7 +327,7 @@ const char* ffDetectOpenGL(FFOpenGLResult* result) #endif } - if(instance.config.openGL.library == FF_OPENGL_LIBRARY_EGL) + if(options->library == FF_OPENGL_LIBRARY_EGL) { #ifdef FF_HAVE_EGL return eglPrint(result); @@ -336,7 +336,7 @@ const char* ffDetectOpenGL(FFOpenGLResult* result) #endif } - if(instance.config.openGL.library == FF_OPENGL_LIBRARY_OSMESA) + if(options->library == FF_OPENGL_LIBRARY_OSMESA) { #ifdef FF_HAVE_OSMESA return osMesaPrint(result); diff --git a/src/detection/opengl/opengl_windows.c b/src/detection/opengl/opengl_windows.c index 11d608db5..d1b2eb67f 100644 --- a/src/detection/opengl/opengl_windows.c +++ b/src/detection/opengl/opengl_windows.c @@ -82,7 +82,7 @@ LRESULT CALLBACK wglHandleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM } } -const char* ffDetectOpenGL(FFOpenGLResult* result) +const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLResult* result) { MSG msg = {0}; WNDCLASSW wc = { diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index 81e960de9..d94849cf5 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -14,7 +14,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options) ffStrbufInit(&result.vendor); ffStrbufInit(&result.slv); - const char* error = ffDetectOpenGL(&result); + const char* error = ffDetectOpenGL(options, &result); if(error) { ffPrintError(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, "%s", error); From f1b047c32b33a991afaa879139e2b889868fe810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 09:55:40 +0800 Subject: [PATCH 06/17] Display: use `FFDisplayOptions` --- src/modules/display/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 210d6861e..31371de42 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -12,7 +12,7 @@ void ffPrintDisplay(FFDisplayOptions* options) if(dsResult->displays.length == 0) { - ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &instance.config.display.moduleArgs, "Couldn't detect display"); + ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, "Couldn't detect display"); return; } From ce47a82fb5ec7d8ccefc3dd7aa3eaf9de1ed1cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 10:46:38 +0800 Subject: [PATCH 07/17] Doc: update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbe7e8026..7faca3eb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 2.0.3 + +Bugfixes: +* Fix typo in config parsing for --color-title (#534) +* Fix percent formatting for `--*-format` (#535) + +Features: +* Add option `--percent-ndigits` + # 2.0.2 Bugfixes: From 28c01599d571f52b7eb5b78cb2bf0ad5d3428efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 10:49:59 +0800 Subject: [PATCH 08/17] Platform: add `$EXE_PATH/../share` to `dataDir` Support loading presets when fastfetch is installed in a special path. eg. `/opt/homebrew/bin/` --- .../terminalshell/terminalshell_linux.c | 2 +- src/util/platform/FFPlatform_unix.c | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index fb2f7d755..58e29f1f8 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -48,7 +48,7 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex if(length > 0) exe->length = (uint32_t)length; - #else + #elif defined(__FreeBSD__) size_t size = exe->allocated; if(!sysctl( diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index a6e5d1b13..2fa403ca6 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -5,8 +5,15 @@ #include #include +#include #include +#ifdef __APPLE__ + #include +#elif defined(__FreeBSD__) + #include +#endif + static void platformPathAddEnv(FFlist* dirs, const char* env) { const char* envValue = getenv(env); @@ -82,7 +89,31 @@ static void getDataDirs(FFPlatform* platform) platformPathAddEnv(&platform->dataDirs, "XDG_DATA_HOME"); ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/"); - #if defined(__APPLE__) + // Add ${currentExePath}/../share + FF_STRBUF_AUTO_DESTROY exePath = ffStrbufCreateA(PATH_MAX); + #ifdef __linux__ + ssize_t exePathLen = readlink("/proc/self/exe", exePath.chars, exePath.allocated); + #elif defined(__APPLE__) + int exePathLen = proc_pidpath((int) getpid(), exePath.chars, exePath.allocated); + #elif defined(__FreeBSD__) + size_t exePathLen = exePath.allocated; + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, + exePath.chars, &exePathLen, + NULL, 0 + )) + exePathLen = 0; + #endif + if (exePathLen > 0) + { + exePath.length = (uint32_t) exePathLen; + ffStrbufSubstrBeforeLastC(&exePath, '/'); + ffStrbufSubstrBeforeLastC(&exePath, '/'); + ffStrbufAppendS(&exePath, "/share"); + ffPlatformPathAddAbsolute(&platform->dataDirs, exePath.chars); + } + + #ifdef __APPLE__ ffPlatformPathAddHome(&platform->dataDirs, platform, "Library/Application Support/"); #endif From 5e9166847d19557fb315a561686e0f0e3a832946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 13:47:20 +0800 Subject: [PATCH 09/17] Platform (Windows): add exePath --- src/util/platform/FFPlatform.c | 1 + src/util/platform/FFPlatform.h | 1 + src/util/platform/FFPlatform_windows.c | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/src/util/platform/FFPlatform.c b/src/util/platform/FFPlatform.c index 27b470b3b..ad0a179da 100644 --- a/src/util/platform/FFPlatform.c +++ b/src/util/platform/FFPlatform.c @@ -8,6 +8,7 @@ void ffPlatformInit(FFPlatform* platform) ffStrbufInit(&platform->cacheDir); ffListInit(&platform->configDirs, sizeof(FFstrbuf)); ffListInit(&platform->dataDirs, sizeof(FFstrbuf)); + ffStrbufInit(&platform->exePath); ffStrbufInit(&platform->userName); ffStrbufInit(&platform->hostName); diff --git a/src/util/platform/FFPlatform.h b/src/util/platform/FFPlatform.h index caebc7c6f..fa646f9de 100644 --- a/src/util/platform/FFPlatform.h +++ b/src/util/platform/FFPlatform.h @@ -11,6 +11,7 @@ typedef struct FFPlatform { FFstrbuf cacheDir; // Trailing slash included FFlist configDirs; // List of FFstrbuf, trailing slash included FFlist dataDirs; // List of FFstrbuf, trailing slash included + FFstrbuf exePath; // The real path of current exe FFstrbuf userName; FFstrbuf hostName; diff --git a/src/util/platform/FFPlatform_windows.c b/src/util/platform/FFPlatform_windows.c index 13fc97246..0009dd10e 100644 --- a/src/util/platform/FFPlatform_windows.c +++ b/src/util/platform/FFPlatform_windows.c @@ -6,6 +6,18 @@ #include #include +static void getExePath(FFPlatform* platform) +{ + wchar_t exePathW[MAX_PATH]; + DWORD exePathWLen = GetModuleFileNameW(NULL, exePathW, MAX_PATH); + if (exePathWLen == 0 && exePathWLen >= MAX_PATH) return; + + ffStrbufSetNWS(&platform->exePath, exePathWLen, exePathW); + if (ffStrbufStartsWithS(&platform->exePath, "\\\\?\\")) + ffStrbufSubstrAfter(&platform->exePath, 3); + ffStrbufReplaceAllC(&platform->exePath, '\\', '/'); +} + static void getHomeDir(FFPlatform* platform) { PWSTR pPath; @@ -213,6 +225,7 @@ static void getSystemArchitecture(FFPlatform* platform) void ffPlatformInitImpl(FFPlatform* platform) { + getExePath(platform); getHomeDir(platform); getCacheDir(platform); getConfigDirs(platform); From b2ead8735bd97e187188a3a91105df7fd6366b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:20:48 +0800 Subject: [PATCH 10/17] Platform (Unix): add `exePath` --- src/util/platform/FFPlatform_unix.c | 48 +++++++++++++++++------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index 2fa403ca6..3f7aada12 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -14,6 +14,27 @@ #include #endif +static void getExePath(FFPlatform* platform) +{ + FFstrbuf* const exePath = &platform->exePath; + ffStrbufEnsureFree(exePath, PATH_MAX); + #ifdef __linux__ + ssize_t exePathLen = readlink("/proc/self/exe", exePath->chars, exePath->allocated); + #elif defined(__APPLE__) + int exePathLen = proc_pidpath((int) getpid(), exePath->chars, exePath->allocated); + #elif defined(__FreeBSD__) + size_t exePathLen = exePath->allocated; + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, + exePath->chars, &exePathLen, + NULL, 0 + )) + exePathLen = 0; + #endif + if (exePathLen > 0) + exePath->length = (uint32_t) exePathLen; +} + static void platformPathAddEnv(FFlist* dirs, const char* env) { const char* envValue = getenv(env); @@ -90,27 +111,13 @@ static void getDataDirs(FFPlatform* platform) ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/"); // Add ${currentExePath}/../share - FF_STRBUF_AUTO_DESTROY exePath = ffStrbufCreateA(PATH_MAX); - #ifdef __linux__ - ssize_t exePathLen = readlink("/proc/self/exe", exePath.chars, exePath.allocated); - #elif defined(__APPLE__) - int exePathLen = proc_pidpath((int) getpid(), exePath.chars, exePath.allocated); - #elif defined(__FreeBSD__) - size_t exePathLen = exePath.allocated; - if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, - exePath.chars, &exePathLen, - NULL, 0 - )) - exePathLen = 0; - #endif - if (exePathLen > 0) + if (platform->exePath.length > 0) { - exePath.length = (uint32_t) exePathLen; - ffStrbufSubstrBeforeLastC(&exePath, '/'); - ffStrbufSubstrBeforeLastC(&exePath, '/'); - ffStrbufAppendS(&exePath, "/share"); - ffPlatformPathAddAbsolute(&platform->dataDirs, exePath.chars); + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&platform->exePath); + ffStrbufSubstrBeforeLastC(&path, '/'); + ffStrbufSubstrBeforeLastC(&path, '/'); + ffStrbufAppendS(&path, "/share"); + ffPlatformPathAddAbsolute(&platform->dataDirs, path.chars); } #ifdef __APPLE__ @@ -183,6 +190,7 @@ void ffPlatformInitImpl(FFPlatform* platform) if(uname(&uts) != 0) memset(&uts, 0, sizeof(uts)); + getExePath(platform); getHomeDir(platform, pwd); getCacheDir(platform); getConfigDirs(platform); From 2e82f8294f908b59d5e10ded5736283a644cc537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:21:08 +0800 Subject: [PATCH 11/17] Doc: document `--precent-ndigits` --- src/data/help.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/help.txt b/src/data/help.txt index b008edf83..f8fff7be1 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -70,6 +70,7 @@ Display options: --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 1 + --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 From 1c49ae53241ac8b600f1d3a6cdf92d9432d8ced4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:29:35 +0800 Subject: [PATCH 12/17] Fastfetch: try `$exePath/presets` with `--load-config` --- src/fastfetch.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/fastfetch.c b/src/fastfetch.c index 9786c070a..118146d16 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -779,6 +779,19 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val return; } + { + //Try exe path + ffStrbufSet(&absolutePath, &instance.state.platform.exePath); + ffStrbufSubstrBeforeLastC(&absolutePath, '/'); + ffStrbufAppendS(&absolutePath, "/presets/"); + ffStrbufAppendS(&absolutePath, value); + + bool success = isJsonConfig ? parseJsoncFile(absolutePath.chars) : parseConfigFile(data, absolutePath.chars); + + if(success) + return; + } + //File not found fprintf(stderr, "Error: couldn't find config: %s\n", value); From 1f7c6ab70c74be3a44670555e3314316921c6dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:36:32 +0800 Subject: [PATCH 13/17] Fastfetch: add `--config` --- CHANGELOG.md | 2 ++ src/data/help.txt | 1 + src/fastfetch.c | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7faca3eb8..c5d22ace9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,11 @@ Bugfixes: * Fix typo in config parsing for --color-title (#534) * Fix percent formatting for `--*-format` (#535) +* Fix loading presets for homebrew (macOS) Features: * Add option `--percent-ndigits` +* Add command flag `--config` as an alias of `--load-config` # 2.0.2 diff --git a/src/data/help.txt b/src/data/help.txt index f8fff7be1..48a076e88 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -19,6 +19,7 @@ Informative options: General options: --load-config : Load a config file or preset (+) + --config : Alias of --load-config (+) --multithreading : Use multiple threads to detect values --stat : Show time usage (in ms) for individual modules --allow-slow-operations : Allow operations that are usually very slow for more detailed output diff --git a/src/fastfetch.c b/src/fastfetch.c index 118146d16..fd13f7862 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -58,11 +58,11 @@ static inline void printCommandHelp(const char* command) { if(command == NULL) puts(FASTFETCH_DATATEXT_HELP); - else if(ffStrEqualsIgnCase(command, "c") || ffStrEqualsIgnCase(command, "color")) + else if(ffStrEqualsIgnCase(command, "color")) puts(FASTFETCH_DATATEXT_HELP_COLOR); else if(ffStrEqualsIgnCase(command, "format")) puts(FASTFETCH_DATATEXT_HELP_FORMAT); - else if(ffStrEqualsIgnCase(command, "load-config") || ffStrEqualsIgnCase(command, "loadconfig") || ffStrEqualsIgnCase(command, "config")) + else if(ffStrEqualsIgnCase(command, "load-config") || ffStrEqualsIgnCase(command, "config")) puts(FASTFETCH_DATATEXT_HELP_CONFIG); else if(ffStrEqualsIgnCase(command, "os-format")) { @@ -945,7 +945,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) //General options// /////////////////// - else if(ffStrEqualsIgnCase(key, "--load-config")) + else if(ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config")) optionParseConfigFile(data, key, value); else if(ffStrEqualsIgnCase(key, "--gen-config")) generateConfigFile(false, value); From 047dca3849f07d49c6c506eca8b04b85a9d2df19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:42:47 +0800 Subject: [PATCH 14/17] CI: include presets (Windows) --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcc466ccf..5ae6f99f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,7 +222,7 @@ jobs: run: ctest - name: create zip archive - run: zip fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe + run: zip fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 @@ -280,7 +280,7 @@ jobs: run: ctest - name: create zip archive - run: zip fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe + run: zip fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d22ace9..2a50d9ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Bugfixes: Features: * Add option `--percent-ndigits` * Add command flag `--config` as an alias of `--load-config` +* Windows packages now include presets (Windows) # 2.0.2 From 1d9f462071604d5177d211954b4875b858846ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 14:43:19 +0800 Subject: [PATCH 15/17] Release: 2.0.3 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eae60577d..829bdb7d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.0.2 + VERSION 2.0.3 LANGUAGES C DESCRIPTION "Fast system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" From 81f0e4d583b52eb96774b54ee76ae740fb3674d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 15:13:25 +0800 Subject: [PATCH 16/17] cI: really bundle presets --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ae6f99f9..87fc30e8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,7 +222,7 @@ jobs: run: ctest - name: create zip archive - run: zip fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe presets + run: zip -r9 fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 @@ -280,7 +280,7 @@ jobs: run: ctest - name: create zip archive - run: zip fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe presets + run: zip -r9 fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 From d78e5285274fd869bfc184e31f56674adf45aa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Aug 2023 15:46:54 +0800 Subject: [PATCH 17/17] CI: generate 7z archive --- .github/workflows/ci.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87fc30e8f..715ebbcdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -187,7 +187,7 @@ jobs: with: msystem: CLANG64 update: true - install: git zip mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd + install: git mingw-w64-clang-x86_64-7zip mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd - name: print msys version run: uname -a @@ -222,13 +222,16 @@ jobs: run: ctest - name: create zip archive - run: zip -r9 fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe presets + run: 7z a -tzip -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win64.zip *.dll fastfetch.exe flashfetch.exe presets + + - name: create 7z archive + run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win64.7z *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 with: name: fastfetch-win64 - path: ./fastfetch-*-Win64.zip + path: ./fastfetch-*-Win64.* win32: name: Win32 @@ -248,7 +251,7 @@ jobs: with: msystem: CLANG32 update: true - install: git zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-opencl-icd + install: git mingw-w64-clang-i686-7zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-opencl-icd - name: print msys version run: uname -a @@ -280,13 +283,16 @@ jobs: run: ctest - name: create zip archive - run: zip -r9 fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe presets + run: 7z a -tzip -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win32.zip *.dll fastfetch.exe flashfetch.exe presets + + - name: create 7z archive + run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win32.7z *.dll fastfetch.exe flashfetch.exe presets - name: upload artifacts uses: actions/upload-artifact@v3 with: name: fastfetch-win32 - path: ./fastfetch-*-Win32.zip + path: ./fastfetch-*-Win32.* release: if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'fastfetch-cli/fastfetch'