diff --git a/CHANGELOG.md b/CHANGELOG.md index 76d94c2fd..99c95c7e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Features: * Add option `--localip-default-route-only` (LocalIP) * Add option `--weather-location` (Weather) * Support iTerm non-ascii font detection (Terminal, macOS) +* Add option `--title-color-user`, `--title-color-at` and `--title-color-host` (Title) Bugfixes: * Fix possible hanging (TerminalFont, #493) diff --git a/doc/json_schema.json b/doc/json_schema.json index 46a8cac71..f97dbdcf3 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -988,6 +988,23 @@ "title": "Set if the title should use fully qualified domain name", "default": false }, + "color": { + "title": "Set colors of the different part of title", + "properties": { + "user": { + "title": "Set color of the user name (left part)", + "$ref": "#/$defs/colors" + }, + "at": { + "title": "Set color of the @ symbol (middle part)", + "$ref": "#/$defs/colors" + }, + "host": { + "title": "Set color of the host name (right part)", + "$ref": "#/$defs/colors" + } + } + }, "key": { "$ref": "#/$defs/key" }, diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 3b62ac180..e7ea439e0 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -182,6 +182,21 @@ # 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. diff --git a/src/data/help.txt b/src/data/help.txt index f7985f03e..0870ec5d4 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -107,6 +107,9 @@ Library options: Set the path of a library to load Module specific options: --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`) --separator-string : Set the string printed by the separator module --os-file : Set the path to the file containing OS information --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) diff --git a/src/modules/title/option.h b/src/modules/title/option.h index ac3902e09..b44aef8ed 100644 --- a/src/modules/title/option.h +++ b/src/modules/title/option.h @@ -10,4 +10,7 @@ typedef struct FFTitleOptions FFModuleArgs moduleArgs; bool fqdn; + FFstrbuf colorUser; + FFstrbuf colorAt; + FFstrbuf colorHost; } FFTitleOptions; diff --git a/src/modules/title/title.c b/src/modules/title/title.c index b5ffa9349..3c29acb11 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -6,12 +6,12 @@ #define FF_TITLE_NUM_FORMAT_ARGS 2 -static inline void printTitlePart(const FFstrbuf* content) +static inline void printTitlePart(const FFstrbuf* content, const FFstrbuf* color) { if(!instance.config.pipe) { fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); - ffPrintColor(&instance.config.colorTitle); + ffPrintColor(color->length > 0 ? color : &instance.config.colorTitle); } ffStrbufWriteTo(content, stdout); @@ -29,9 +29,14 @@ void ffPrintTitle(FFTitleOptions* options) if (options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_TITLE_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); - printTitlePart(&instance.state.platform.userName); + + printTitlePart(&instance.state.platform.userName, &options->colorUser); + + if (!instance.config.pipe && options->colorAt.length > 0) + ffPrintColor(&options->colorAt); putchar('@'); - printTitlePart(host); + + printTitlePart(host, &options->colorHost); putchar('\n'); } else @@ -49,6 +54,9 @@ void ffInitTitleOptions(FFTitleOptions* options) options->moduleName = FF_TITLE_MODULE_NAME; ffOptionInitModuleArg(&options->moduleArgs); options->fqdn = false; + ffStrbufInit(&options->colorUser); + ffStrbufInit(&options->colorAt); + ffStrbufInit(&options->colorHost); } bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const char* value) @@ -64,12 +72,33 @@ bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const return true; } + if (ffStrEqualsIgnCase(subKey, "color-user")) + { + ffOptionParseColor(value, &options->colorUser); + return true; + } + + if (ffStrEqualsIgnCase(subKey, "color-at")) + { + ffOptionParseColor(value, &options->colorAt); + return true; + } + + if (ffStrEqualsIgnCase(subKey, "color-host")) + { + ffOptionParseColor(value, &options->colorHost); + return true; + } + return false; } void ffDestroyTitleOptions(FFTitleOptions* options) { ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->colorUser); + ffStrbufDestroy(&options->colorAt); + ffStrbufDestroy(&options->colorHost); } void ffParseTitleJsonObject(yyjson_val* module) @@ -96,6 +125,23 @@ void ffParseTitleJsonObject(yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "color")) + { + if (!yyjson_is_obj(val)) + continue; + + yyjson_val* color = yyjson_obj_get(val, "user"); + if (color) + ffOptionParseColor(yyjson_get_str(color), &options.colorUser); + color = yyjson_obj_get(val, "at"); + if (color) + ffOptionParseColor(yyjson_get_str(color), &options.colorAt); + color = yyjson_obj_get(val, "host"); + if (color) + ffOptionParseColor(yyjson_get_str(color), &options.colorHost); + continue; + } + ffPrintErrorString(FF_TITLE_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key); } }