diff --git a/doc/json_schema.json b/doc/json_schema.json index 7086ef497..3de8047d9 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1948,12 +1948,19 @@ "const": "separator" }, "string": { - "description": "Set the string to be printed", + "description": "Set the string to be printed by the separator line", "type": "string", "default": "-" }, "outputColor": { + "description": "Set the color of the separator line", "$ref": "#/$defs/outputColor" + }, + "length": { + "description": "Set the length of the separator line, or 0 to auto-detect", + "type": "integer", + "minimum": 0, + "default": 0 } } }, diff --git a/src/data/help.json b/src/data/help.json index bd919b01d..5b1a8b848 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -947,7 +947,7 @@ }, { "long": "separator-string", - "desc": "Set the string printed by the separator module", + "desc": "Set the string to be printed by the separator line", "arg": { "type": "str", "default": "-" @@ -955,12 +955,21 @@ }, { "long": "separator-output-color", - "desc": "Set the color of the separator module", + "desc": "Set the color of the separator line", "arg": { "type": "color", "default": "default" } }, + { + "long": "separator-length", + "desc": "Set the length of the separator line", + "remark": "Set to 0 to automatically calculate it with the title length", + "arg": { + "type": "num", + "default": "0" + } + }, { "long": "disk-folders", "desc": "A colon (semicolon on Windows) separated list of folder paths to be detected", diff --git a/src/modules/separator/option.h b/src/modules/separator/option.h index 6f4d49953..5f435e7f0 100644 --- a/src/modules/separator/option.h +++ b/src/modules/separator/option.h @@ -10,4 +10,5 @@ typedef struct FFSeparatorOptions FFstrbuf string; FFstrbuf outputColor; + uint32_t length; } FFSeparatorOptions; diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index f1b9ecc35..90a4e2096 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -34,6 +34,23 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate void ffPrintSeparator(FFSeparatorOptions* options) { + ffLogoPrintLine(); + + if (options->length > 0) + { + if(__builtin_expect(options->string.length == 1, 1)) + ffPrintCharTimes(options->string.chars[0], options->length); + else + { + for (uint32_t i = 0; i < options->length; i++) + { + fputs(options->string.chars, stdout); + } + } + putchar('\n'); + return; + } + setlocale(LC_CTYPE, ""); mbstate_t state = {}; bool fqdn = instance.config.modules.title.fqdn; @@ -45,7 +62,6 @@ void ffPrintSeparator(FFSeparatorOptions* options) uint32_t titleLength = 1 // @ + getWcsWidth(&platform->userName, wstr, &state) // user name + (fqdn ? platform->hostName.length : ffStrbufFirstIndexC(&platform->hostName, '.')); // host name - ffLogoPrintLine(); if(options->outputColor.length && !instance.config.display.pipe) ffPrintColor(&options->outputColor); @@ -112,6 +128,12 @@ bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key return true; } + if (ffStrEqualsIgnCase(subKey, "length")) + { + options->length = ffOptionParseUInt32(key, value); + return true; + } + return false; } @@ -137,6 +159,12 @@ void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) continue; } + if (ffStrEndsWithIgnCase(key, "length")) + { + options->length = (uint32_t) yyjson_get_uint(val); + continue; + } + ffPrintError(FF_SEPARATOR_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", key); } } @@ -164,6 +192,8 @@ void ffInitSeparatorOptions(FFSeparatorOptions* options) ffGenerateSeparatorJsonConfig ); ffStrbufInitStatic(&options->string, "-"); + ffStrbufInit(&options->outputColor); + options->length = 0; } void ffDestroySeparatorOptions(FFSeparatorOptions* options)