Title: add option --title-color-user, --title-color-at and --title-color-host

This commit is contained in:
李通洲
2023-07-20 11:21:12 +08:00
parent 00a5f1bf3f
commit e9ec7d3597
6 changed files with 89 additions and 4 deletions
+1
View File
@@ -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)
+17
View File
@@ -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"
},
+15
View File
@@ -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.
+3
View File
@@ -107,6 +107,9 @@ Library options: Set the path of a library to load
Module specific options:
--title-fqdn <?value>: Set if the title should use fully qualified domain name. Default is false
--title-color-user <color>: Set color of the user name (left part). Default is empty (use color of `--color-title`).
--title-color-at <color>: Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`)
--title-color-host <color>: Set color of the host name (right part). Default is empty (use color of `--color-title`)
--separator-string <str>: Set the string printed by the separator module
--os-file <path>: Set the path to the file containing OS information
--disk-folders <folders>: A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows)
+3
View File
@@ -10,4 +10,7 @@ typedef struct FFTitleOptions
FFModuleArgs moduleArgs;
bool fqdn;
FFstrbuf colorUser;
FFstrbuf colorAt;
FFstrbuf colorHost;
} FFTitleOptions;
+50 -4
View File
@@ -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);
}
}