mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Colors: add and default to --colors-symbol background
This commit is contained in:
parent
4f3649e96e
commit
2a9f9d5a34
@ -1180,13 +1180,14 @@
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"block",
|
||||
"background",
|
||||
"circle",
|
||||
"diamond",
|
||||
"triangle",
|
||||
"square",
|
||||
"star"
|
||||
],
|
||||
"default": "block"
|
||||
"default": "background"
|
||||
},
|
||||
"paddingLeft": {
|
||||
"description": "Set the number of white spaces to print before the symbol",
|
||||
|
@ -1538,13 +1538,14 @@
|
||||
"type": "enum",
|
||||
"enum": {
|
||||
"block": "\u2588\u2588\u2588",
|
||||
"background": "(whitespaces with background)",
|
||||
"circle": "\u25cf",
|
||||
"diamond": "\u25c6",
|
||||
"triangle": "\u25b2",
|
||||
"square": "\u25a0",
|
||||
"star": "\u2605"
|
||||
},
|
||||
"default": "block"
|
||||
"default": "background"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -20,15 +20,24 @@ void ffPrintColors(FFColorsOptions* options)
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(128);
|
||||
|
||||
if (options->symbol == FF_COLORS_SYMBOL_BLOCK)
|
||||
if (options->symbol == FF_COLORS_SYMBOL_BLOCK || options->symbol == FF_COLORS_SYMBOL_BACKGROUND)
|
||||
{
|
||||
// 3%d: Set the foreground color
|
||||
for(uint8_t i = options->block.range[0]; i <= min(options->block.range[1], 7); i++)
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[3%dm", i);
|
||||
for (uint8_t j = 0; j < options->block.width; j++)
|
||||
ffStrbufAppendS(&result, "█");
|
||||
if (options->symbol == FF_COLORS_SYMBOL_BLOCK)
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[3%dm", i);
|
||||
for (uint8_t j = 0; j < options->block.width; j++)
|
||||
ffStrbufAppendS(&result, "█");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[4%dm", i);
|
||||
ffStrbufAppendNC(&result, options->block.width, ' ');
|
||||
}
|
||||
}
|
||||
if (result.length > 0)
|
||||
{
|
||||
@ -44,14 +53,22 @@ void ffPrintColors(FFColorsOptions* options)
|
||||
ffStrbufClear(&result);
|
||||
}
|
||||
|
||||
// 1: Set everything to bolt. This causes normal colors on some systems to be bright.
|
||||
// 9%d: Set the foreground to the bright color
|
||||
for(uint8_t i = max(options->block.range[0], 8); i <= options->block.range[1]; i++)
|
||||
{
|
||||
if(!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[9%dm", i - 8);
|
||||
for (uint8_t j = 0; j < options->block.width; j++)
|
||||
ffStrbufAppendS(&result, "█");
|
||||
if (options->symbol == FF_COLORS_SYMBOL_BLOCK)
|
||||
{
|
||||
if(!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[9%dm", i - 8);
|
||||
for (uint8_t j = 0; j < options->block.width; j++)
|
||||
ffStrbufAppendS(&result, "█");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
ffStrbufAppendF(&result, "\e[10%dm", i - 8);
|
||||
ffStrbufAppendNC(&result, options->block.width, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -109,6 +126,7 @@ bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, cons
|
||||
{
|
||||
options->symbol = (FFColorsSymbol) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
|
||||
{ "block", FF_COLORS_SYMBOL_BLOCK },
|
||||
{ "background", FF_COLORS_SYMBOL_BACKGROUND },
|
||||
{ "circle", FF_COLORS_SYMBOL_CIRCLE },
|
||||
{ "diamond", FF_COLORS_SYMBOL_DIAMOND },
|
||||
{ "triangle", FF_COLORS_SYMBOL_TRIANGLE },
|
||||
@ -164,6 +182,7 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "block", FF_COLORS_SYMBOL_BLOCK },
|
||||
{ "background", FF_COLORS_SYMBOL_BACKGROUND },
|
||||
{ "circle", FF_COLORS_SYMBOL_CIRCLE },
|
||||
{ "diamond", FF_COLORS_SYMBOL_DIAMOND },
|
||||
{ "triangle", FF_COLORS_SYMBOL_TRIANGLE },
|
||||
@ -278,7 +297,7 @@ void ffInitColorsOptions(FFColorsOptions* options)
|
||||
);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
ffStrbufSetStatic(&options->moduleArgs.key, " ");
|
||||
options->symbol = FF_COLORS_SYMBOL_BLOCK;
|
||||
options->symbol = FF_COLORS_SYMBOL_BACKGROUND;
|
||||
options->paddingLeft = 0;
|
||||
options->block = (FFBlockConfig) {
|
||||
.width = 3,
|
||||
|
@ -7,6 +7,7 @@
|
||||
typedef enum FFColorsSymbol
|
||||
{
|
||||
FF_COLORS_SYMBOL_BLOCK,
|
||||
FF_COLORS_SYMBOL_BACKGROUND,
|
||||
FF_COLORS_SYMBOL_CIRCLE,
|
||||
FF_COLORS_SYMBOL_DIAMOND,
|
||||
FF_COLORS_SYMBOL_SQUARE,
|
||||
|
Loading…
x
Reference in New Issue
Block a user