Percentage: add --bar-border-{left|right}; remove --bar-border

This commit is contained in:
李通洲
2024-06-06 16:36:57 +08:00
parent 3f4c03b172
commit 10f5fa1e7d
6 changed files with 54 additions and 30 deletions
+4
View File
@@ -1,5 +1,9 @@
# 2.15.0
Changes:
* `--bar-border <?bool>` has been changed to `--bar-border-left <string>` and `--bar-border-right <string>`, which are used for customizing the style of bar border.
* `--bar-border-left '' --bar-border-right ''` can be used to disable the border
Features:
* Add ability to skip installing license with INSTALL_LICENSE option (CMake)
* Make it possible to shorten the theme and icons output (Theme / Icons)
+9 -4
View File
@@ -499,10 +499,15 @@
"description": "Set the character to use in total part",
"default": "-"
},
"border": {
"type": "boolean",
"description": "Whether to show a border around the bar",
"default": true
"borderLeft": {
"type": "string",
"description": "Set the string to use at left border",
"default": "[ "
},
"borderRight": {
"type": "string",
"description": "Set the string to use at right border",
"default": " ]"
},
"width": {
"type": "integer",
+6 -8
View File
@@ -24,12 +24,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con
uint32_t blocksPercent = (uint32_t) (percent / 100.0 * options->barWidth + 0.5);
assert(blocksPercent <= options->barWidth);
if(options->barBorder)
if(options->barBorderLeft.length)
{
if(!options->pipe)
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m[ ");
else
ffStrbufAppendS(buffer, "[ ");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
ffStrbufAppend(buffer, &options->barBorderLeft);
}
if (percent != percent)
@@ -91,12 +90,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con
}
}
if(options->barBorder)
if(options->barBorderRight.length)
{
if(!options->pipe)
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m ]");\
else
ffStrbufAppendS(buffer, " ]");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
ffStrbufAppend(buffer, &options->barBorderRight);
}
if(!options->pipe)
+16 -9
View File
@@ -616,6 +616,22 @@
"default": "-"
}
},
{
"long": "bar-border-left",
"desc": "Set the string to use at left border of percentage bars",
"arg": {
"type": "string",
"default": "[ "
}
},
{
"long": "bar-border-right",
"desc": "Set the string to use at right border of percentage bars",
"arg": {
"type": "string",
"default": " ]"
}
},
{
"long": "bar-width",
"desc": "Set the width of percentage bars, in number of characters",
@@ -624,15 +640,6 @@
"default": 10
}
},
{
"long": "bar-border",
"desc": "Whether to show a border around percentage bars",
"arg": {
"type": "bool",
"optional": true,
"default": true
}
},
{
"long": "no-buffer",
"desc": "Set if the stdout application buffer should be disabled",
+17 -8
View File
@@ -180,9 +180,13 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
if (charTotal)
ffStrbufSetS(&options->barCharTotal, charTotal);
yyjson_val* border = yyjson_obj_get(val, "border");
if (border)
options->barBorder = yyjson_get_bool(border);
yyjson_val* borderLeft = yyjson_obj_get(val, "border-left");
if (borderLeft)
ffStrbufSetS(&options->barBorderLeft, yyjson_get_str(borderLeft));
yyjson_val* borderRight = yyjson_obj_get(val, "border-right");
if (borderRight)
ffStrbufSetS(&options->barBorderRight, yyjson_get_str(borderRight));
yyjson_val* width = yyjson_obj_get(val, "width");
if (width)
@@ -346,8 +350,10 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
ffOptionParseString(key, value, &options->barCharTotal);
else if(ffStrEqualsIgnCase(subkey, "width"))
options->barWidth = (uint8_t) ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(subkey, "border"))
options->barBorder = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(subkey, "border-left"))
ffOptionParseString(key, value, &options->barBorderLeft);
else if(ffStrEqualsIgnCase(subkey, "border-right"))
ffOptionParseString(key, value, &options->barBorderRight);
else
return false;
}
@@ -392,8 +398,9 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
ffStrbufInitStatic(&options->barCharElapsed, "");
ffStrbufInitStatic(&options->barCharTotal, "-");
ffStrbufInitStatic(&options->barBorderLeft, "[ ");
ffStrbufInitStatic(&options->barBorderRight, " ]");
options->barWidth = 10;
options->barBorder = true;
options->percentType = 9;
options->percentNdigits = 0;
ffStrbufInitStatic(&options->percentColorGreen, FF_COLOR_FG_GREEN);
@@ -561,8 +568,10 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
yyjson_mut_obj_add_strbuf(doc, bar, "charElapsed", &options->barCharElapsed);
if (!ffStrbufEqual(&options->barCharTotal, &defaultOptions.barCharTotal))
yyjson_mut_obj_add_strbuf(doc, bar, "charTotal", &options->barCharTotal);
if (options->barBorder != defaultOptions.barBorder)
yyjson_mut_obj_add_bool(doc, bar, "border", options->barBorder);
if (!ffStrbufEqual(&options->barBorderLeft, &defaultOptions.barBorderLeft))
yyjson_mut_obj_add_strbuf(doc, bar, "borderLeft", &options->barBorderLeft);
if (!ffStrbufEqual(&options->barBorderRight, &defaultOptions.barBorderRight))
yyjson_mut_obj_add_strbuf(doc, bar, "borderRight", &options->barBorderRight);
if (options->barWidth != defaultOptions.barWidth)
yyjson_mut_obj_add_uint(doc, bar, "width", options->barWidth);
+2 -1
View File
@@ -43,8 +43,9 @@ typedef struct FFOptionsDisplay
FFstrbuf tempColorRed;
FFstrbuf barCharElapsed;
FFstrbuf barCharTotal;
FFstrbuf barBorderLeft;
FFstrbuf barBorderRight;
uint8_t barWidth;
bool barBorder;
uint8_t percentType;
uint8_t percentNdigits;
FFstrbuf percentColorGreen;