Skip to content

Commit 10f5fa1

Browse files
committed
Percentage: add --bar-border-{left|right}; remove --bar-border
1 parent 3f4c03b commit 10f5fa1

File tree

6 files changed

+54
-30
lines changed

6 files changed

+54
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 2.15.0
22

3+
Changes:
4+
* `--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.
5+
* `--bar-border-left '' --bar-border-right ''` can be used to disable the border
6+
37
Features:
48
* Add ability to skip installing license with INSTALL_LICENSE option (CMake)
59
* Make it possible to shorten the theme and icons output (Theme / Icons)

doc/json_schema.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,15 @@
499499
"description": "Set the character to use in total part",
500500
"default": "-"
501501
},
502-
"border": {
503-
"type": "boolean",
504-
"description": "Whether to show a border around the bar",
505-
"default": true
502+
"borderLeft": {
503+
"type": "string",
504+
"description": "Set the string to use at left border",
505+
"default": "[ "
506+
},
507+
"borderRight": {
508+
"type": "string",
509+
"description": "Set the string to use at right border",
510+
"default": " ]"
506511
},
507512
"width": {
508513
"type": "integer",

src/common/percent.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con
2424
uint32_t blocksPercent = (uint32_t) (percent / 100.0 * options->barWidth + 0.5);
2525
assert(blocksPercent <= options->barWidth);
2626

27-
if(options->barBorder)
27+
if(options->barBorderLeft.length)
2828
{
2929
if(!options->pipe)
30-
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m[ ");
31-
else
32-
ffStrbufAppendS(buffer, "[ ");
30+
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
31+
ffStrbufAppend(buffer, &options->barBorderLeft);
3332
}
3433

3534
if (percent != percent)
@@ -91,12 +90,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con
9190
}
9291
}
9392

94-
if(options->barBorder)
93+
if(options->barBorderRight.length)
9594
{
9695
if(!options->pipe)
97-
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m ]");\
98-
else
99-
ffStrbufAppendS(buffer, " ]");
96+
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
97+
ffStrbufAppend(buffer, &options->barBorderRight);
10098
}
10199

102100
if(!options->pipe)

src/data/help.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,20 +617,27 @@
617617
}
618618
},
619619
{
620-
"long": "bar-width",
621-
"desc": "Set the width of percentage bars, in number of characters",
620+
"long": "bar-border-left",
621+
"desc": "Set the string to use at left border of percentage bars",
622622
"arg": {
623-
"type": "num",
624-
"default": 10
623+
"type": "string",
624+
"default": "[ "
625625
}
626626
},
627627
{
628-
"long": "bar-border",
629-
"desc": "Whether to show a border around percentage bars",
628+
"long": "bar-border-right",
629+
"desc": "Set the string to use at right border of percentage bars",
630630
"arg": {
631-
"type": "bool",
632-
"optional": true,
633-
"default": true
631+
"type": "string",
632+
"default": " ]"
633+
}
634+
},
635+
{
636+
"long": "bar-width",
637+
"desc": "Set the width of percentage bars, in number of characters",
638+
"arg": {
639+
"type": "num",
640+
"default": 10
634641
}
635642
},
636643
{

src/options/display.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
180180
if (charTotal)
181181
ffStrbufSetS(&options->barCharTotal, charTotal);
182182

183-
yyjson_val* border = yyjson_obj_get(val, "border");
184-
if (border)
185-
options->barBorder = yyjson_get_bool(border);
183+
yyjson_val* borderLeft = yyjson_obj_get(val, "border-left");
184+
if (borderLeft)
185+
ffStrbufSetS(&options->barBorderLeft, yyjson_get_str(borderLeft));
186+
187+
yyjson_val* borderRight = yyjson_obj_get(val, "border-right");
188+
if (borderRight)
189+
ffStrbufSetS(&options->barBorderRight, yyjson_get_str(borderRight));
186190

187191
yyjson_val* width = yyjson_obj_get(val, "width");
188192
if (width)
@@ -346,8 +350,10 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
346350
ffOptionParseString(key, value, &options->barCharTotal);
347351
else if(ffStrEqualsIgnCase(subkey, "width"))
348352
options->barWidth = (uint8_t) ffOptionParseUInt32(key, value);
349-
else if(ffStrEqualsIgnCase(subkey, "border"))
350-
options->barBorder = ffOptionParseBoolean(value);
353+
else if(ffStrEqualsIgnCase(subkey, "border-left"))
354+
ffOptionParseString(key, value, &options->barBorderLeft);
355+
else if(ffStrEqualsIgnCase(subkey, "border-right"))
356+
ffOptionParseString(key, value, &options->barBorderRight);
351357
else
352358
return false;
353359
}
@@ -392,8 +398,9 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
392398

393399
ffStrbufInitStatic(&options->barCharElapsed, "■");
394400
ffStrbufInitStatic(&options->barCharTotal, "-");
401+
ffStrbufInitStatic(&options->barBorderLeft, "[ ");
402+
ffStrbufInitStatic(&options->barBorderRight, " ]");
395403
options->barWidth = 10;
396-
options->barBorder = true;
397404
options->percentType = 9;
398405
options->percentNdigits = 0;
399406
ffStrbufInitStatic(&options->percentColorGreen, FF_COLOR_FG_GREEN);
@@ -561,8 +568,10 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
561568
yyjson_mut_obj_add_strbuf(doc, bar, "charElapsed", &options->barCharElapsed);
562569
if (!ffStrbufEqual(&options->barCharTotal, &defaultOptions.barCharTotal))
563570
yyjson_mut_obj_add_strbuf(doc, bar, "charTotal", &options->barCharTotal);
564-
if (options->barBorder != defaultOptions.barBorder)
565-
yyjson_mut_obj_add_bool(doc, bar, "border", options->barBorder);
571+
if (!ffStrbufEqual(&options->barBorderLeft, &defaultOptions.barBorderLeft))
572+
yyjson_mut_obj_add_strbuf(doc, bar, "borderLeft", &options->barBorderLeft);
573+
if (!ffStrbufEqual(&options->barBorderRight, &defaultOptions.barBorderRight))
574+
yyjson_mut_obj_add_strbuf(doc, bar, "borderRight", &options->barBorderRight);
566575
if (options->barWidth != defaultOptions.barWidth)
567576
yyjson_mut_obj_add_uint(doc, bar, "width", options->barWidth);
568577

src/options/display.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ typedef struct FFOptionsDisplay
4343
FFstrbuf tempColorRed;
4444
FFstrbuf barCharElapsed;
4545
FFstrbuf barCharTotal;
46+
FFstrbuf barBorderLeft;
47+
FFstrbuf barBorderRight;
4648
uint8_t barWidth;
47-
bool barBorder;
4849
uint8_t percentType;
4950
uint8_t percentNdigits;
5051
FFstrbuf percentColorGreen;

0 commit comments

Comments
 (0)