diff --git a/doc/json_schema.json b/doc/json_schema.json index 3805a71fe..5e580d434 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1017,6 +1017,16 @@ "description": "Set the string to use at right border", "default": " ]" }, + "borderLeftElapsed": { + "type": "string", + "description": "If both borderLeftElapsed and borderRightElapsed are set, the border will be used as parts of bar content", + "default": "" + }, + "borderRightElapsed": { + "type": "string", + "description": "If both borderLeftElapsed and borderRightElapsed are set, the border will be used as parts of bar content", + "default": "" + }, "width": { "type": "integer", "description": "Set the width of the bar, in number of characters", diff --git a/src/common/percent.c b/src/common/percent.c index 746556183..947925174 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -60,10 +60,12 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf const FFOptionsDisplay* options = &instance.config.display; + const bool borderAsValue = options->barBorderLeftElapsed.length && options->barBorderRightElapsed.length; + uint32_t blocksPercent = (uint32_t) (percent / 100.0 * options->barWidth + 0.5); assert(blocksPercent <= options->barWidth); - if(options->barBorderLeft.length) + if(!borderAsValue && options->barBorderLeft.length) { if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); @@ -76,7 +78,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_BLACK "m"); for (uint32_t i = 0; i < options->barWidth; ++i) - ffStrbufAppend(buffer, &options->barCharElapsed); + ffStrbufAppend(buffer, borderAsValue && i == 0 + ? &options->barBorderLeft + : borderAsValue && i == options->barWidth - 1 + ? &options->barBorderRight + : &options->barCharTotal); } else { @@ -120,7 +126,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf ffStrbufAppendF(buffer, "\e[%sm", (green <= yellow ? colorGreen : colorRed)); } } - ffStrbufAppend(buffer, &options->barCharElapsed); + ffStrbufAppend(buffer, borderAsValue && i == 0 + ? &options->barBorderLeftElapsed + : borderAsValue && i == options->barWidth - 1 + ? &options->barBorderRightElapsed + : &options->barCharElapsed); } if (blocksPercent < options->barWidth) @@ -128,11 +138,15 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); for (uint32_t i = blocksPercent; i < options->barWidth; ++i) - ffStrbufAppend(buffer, &options->barCharTotal); + ffStrbufAppend(buffer, borderAsValue && i == 0 + ? &options->barBorderLeft + : borderAsValue && i == options->barWidth - 1 + ? &options->barBorderRight + : &options->barCharTotal); } } - if(options->barBorderRight.length) + if(!borderAsValue && options->barBorderRight.length) { if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); diff --git a/src/data/help.json b/src/data/help.json index 59f16be66..c36ab4a96 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -699,6 +699,22 @@ "default": " ]" } }, + { + "long": "bar-border-left-elapsed", + "desc": "If both bar-border-left-elapsed and bar-border-right-elapsed are set, the border will be used as parts of bar content", + "arg": { + "type": "string", + "default": "" + } + }, + { + "long": "bar-border-right-elapsed", + "desc": "If both bar-border-left-elapsed and bar-border-right-elapsed are set, the border will be used as parts of bar content", + "arg": { + "type": "string", + "default": "" + } + }, { "long": "bar-width", "desc": "Set the width of percentage bars in characters", diff --git a/src/options/display.c b/src/options/display.c index eae73b1c9..767ec825e 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -281,6 +281,14 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va if (borderRight) ffStrbufSetS(&options->barBorderRight, yyjson_get_str(borderRight)); + yyjson_val* borderLeftElapsed = yyjson_obj_get(val, "borderLeftElapsed"); + if (borderLeftElapsed) + ffStrbufSetS(&options->barBorderLeftElapsed, yyjson_get_str(borderLeftElapsed)); + + yyjson_val* borderRightElapsed = yyjson_obj_get(val, "borderRightElapsed"); + if (borderRightElapsed) + ffStrbufSetS(&options->barBorderRightElapsed, yyjson_get_str(borderRightElapsed)); + yyjson_val* width = yyjson_obj_get(val, "width"); if (width) options->barWidth = (uint8_t) yyjson_get_uint(width); @@ -623,6 +631,10 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key ffOptionParseString(key, value, &options->barBorderLeft); else if(ffStrEqualsIgnCase(subkey, "border-right")) ffOptionParseString(key, value, &options->barBorderRight); + else if(ffStrEqualsIgnCase(subkey, "border-left-elapsed")) + ffOptionParseString(key, value, &options->barBorderLeftElapsed); + else if(ffStrEqualsIgnCase(subkey, "border-right-elapsed")) + ffOptionParseString(key, value, &options->barBorderRightElapsed); else return false; } @@ -691,6 +703,8 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) ffStrbufInitStatic(&options->barCharTotal, "-"); ffStrbufInitStatic(&options->barBorderLeft, "[ "); ffStrbufInitStatic(&options->barBorderRight, " ]"); + ffStrbufInit(&options->barBorderLeftElapsed); + ffStrbufInit(&options->barBorderRightElapsed); options->barWidth = 10; options->durationAbbreviation = false; options->durationSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT; diff --git a/src/options/display.h b/src/options/display.h index 6a50b848c..90d4da316 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -60,6 +60,8 @@ typedef struct FFOptionsDisplay FFstrbuf barCharTotal; FFstrbuf barBorderLeft; FFstrbuf barBorderRight; + FFstrbuf barBorderLeftElapsed; + FFstrbuf barBorderRightElapsed; uint8_t barWidth; FFPercentageTypeFlags percentType; uint8_t percentNdigits;