From e6be90614a82ae7430d8f1e1375b708890fc09e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 15 Aug 2023 17:10:09 +0800 Subject: [PATCH] fastfetch: support `--key-width` --- CHANGELOG.md | 5 ++++- doc/json_schema.json | 5 +++++ src/common/init.c | 1 + src/common/jsonconfig.c | 2 ++ src/common/printing.c | 3 +++ src/fastfetch.c | 2 ++ src/fastfetch.h | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1098eb19..83883afcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,10 @@ Changes: * Previously: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\: *`. Note the backslashs are unescaped twice (once by shell and once by fastfetch). * Now: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\\: *` -# 2.0.0 (beta) +Features: +* Add `--key-width` for aligning the left edge of values + +# 2.0.0-beta Fastfetch v2 introduces a new configuration file format: JSON config. Please refer to for details. diff --git a/doc/json_schema.json b/doc/json_schema.json index 279aac96c..f311c92cb 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -221,6 +221,11 @@ "title": "Use multiple threads to detect values", "default": true }, + "thread": { + "type": "boolean", + "title": "Alias of multithreading", + "default": true + }, "stat": { "type": "boolean", "title": "Show time usage (in ms) for individual modules", diff --git a/src/common/init.c b/src/common/init.c index a74be3e33..f102ef66a 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -68,6 +68,7 @@ static void defaultConfig(void) instance.config.multithreading = true; instance.config.stat = false; instance.config.noBuffer = false; + instance.config.keyWidth = 0; ffInitTitleOptions(&instance.config.title); ffInitOSOptions(&instance.config.os); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 7b623d7c5..601d8b480 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -433,6 +433,8 @@ const char* ffParseDisplayJsonConfig(void) config->percentType = (uint32_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "noBuffer")) config->noBuffer = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "keyWidth")) + config->keyWidth = (uint32_t) yyjson_get_uint(val); else return "Unknown display property"; } diff --git a/src/common/printing.c b/src/common/printing.c index 35ab27aa0..f62f50fa6 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -46,6 +46,9 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb if(!instance.config.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + + if (instance.config.keyWidth > 0) + printf("\e[%uG", (unsigned) (instance.config.keyWidth + instance.state.logoWidth)); } void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments) diff --git a/src/fastfetch.c b/src/fastfetch.c index 00d3d43ff..58fd773e6 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -997,6 +997,8 @@ static void parseOption(FFdata* data, const char* key, const char* value) optionCheckString(key, value, &instance.config.colorTitle); ffOptionParseColor(value, &instance.config.colorTitle); } + else if(ffStrEqualsIgnCase(key, "--key-width")) + instance.config.keyWidth = ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(key, "--bright-color")) instance.config.brightColor = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--color")) diff --git a/src/fastfetch.h b/src/fastfetch.h index d8d4ccde7..3af517c7b 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -60,6 +60,7 @@ typedef struct FFconfig bool stat; bool noBuffer; int32_t processingTimeout; + uint32_t keyWidth; // Module options that cannot be put in module option structure #if defined(__linux__) || defined(__FreeBSD__)