diff --git a/doc/json_schema.json b/doc/json_schema.json index 5e580d434..b4c82c33e 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1027,6 +1027,20 @@ "description": "If both borderLeftElapsed and borderRightElapsed are set, the border will be used as parts of bar content", "default": "" }, + "colorElapsed": { + "description": "Color to use in the elapsed part of percentage bars", + "$ref": "#/$defs/colors" + }, + "colorTotal": { + "description": "Color to use in the total part of percentage bars", + "$ref": "#/$defs/colors", + "default": "light_white" + }, + "colorBorder": { + "description": "Color to use in the borders of percentage bars", + "$ref": "#/$defs/colors", + "default": "light_white" + }, "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 947925174..1d164db47 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -68,7 +68,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf if(!borderAsValue && options->barBorderLeft.length) { if(!options->pipe) - ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); + ffStrbufAppendF(buffer, "\e[%sm", options->barColorBorder.chars); ffStrbufAppend(buffer, &options->barBorderLeft); } @@ -78,11 +78,13 @@ 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, borderAsValue && i == 0 ? &options->barBorderLeft : borderAsValue && i == options->barWidth - 1 ? &options->barBorderRight : &options->barCharTotal); + } } else { @@ -91,7 +93,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf const char* colorRed = options->percentColorRed.chars; FFPercentageTypeFlags percentType = config.type == 0 ? options->percentType : config.type; - bool monochrome = !!(percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT); + bool monochrome = !!(percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT) || options->barColorElapsed.length; for (uint32_t i = 0; i < blocksPercent; ++i) { @@ -100,7 +102,9 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf if (monochrome) { const char* color = NULL; - if (green <= yellow) + if (options->barColorElapsed.length) + color = options->barColorElapsed.chars; + else if (green <= yellow) { if (percent < green) color = colorGreen; else if (percent < yellow) color = colorYellow; @@ -136,20 +140,22 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf if (blocksPercent < options->barWidth) { if(!options->pipe) - ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); + ffStrbufAppendF(buffer, "\e[%sm", options->barColorTotal.chars); for (uint32_t i = blocksPercent; i < options->barWidth; ++i) + { ffStrbufAppend(buffer, borderAsValue && i == 0 ? &options->barBorderLeft : borderAsValue && i == options->barWidth - 1 ? &options->barBorderRight : &options->barCharTotal); + } } } if(!borderAsValue && options->barBorderRight.length) { if(!options->pipe) - ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); + ffStrbufAppendF(buffer, "\e[%sm", options->barColorBorder.chars); ffStrbufAppend(buffer, &options->barBorderRight); } diff --git a/src/data/help.json b/src/data/help.json index c36ab4a96..7a5ba4ec1 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -715,6 +715,31 @@ "default": "" } }, + { + "long": "bar-color-elapsed", + "desc": "Set the color to use in the elapsed part of percentage bars", + "remark": "By default, auto selected by percent-color-{green,yellow,red}", + "arg": { + "type": "color", + "default": "" + } + }, + { + "long": "bar-color-total", + "desc": "Set the color to use in the total part of percentage bars", + "arg": { + "type": "color", + "default": "light_white" + } + }, + { + "long": "bar-color-border", + "desc": "Set the color to use in the borders of percentage bars", + "arg": { + "type": "color", + "default": "light_white" + } + }, { "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 767ec825e..99adbf61c 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -289,6 +289,15 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va if (borderRightElapsed) ffStrbufSetS(&options->barBorderRightElapsed, yyjson_get_str(borderRightElapsed)); + yyjson_val* colorElapsed = yyjson_obj_get(val, "colorElapsed"); + if (colorElapsed) ffOptionParseColor(yyjson_get_str(colorElapsed), &options->barColorElapsed); + + yyjson_val* colorTotal = yyjson_obj_get(val, "colorTotal"); + if (colorTotal) ffOptionParseColor(yyjson_get_str(colorTotal), &options->barColorTotal); + + yyjson_val* colorBorder = yyjson_obj_get(val, "colorBorder"); + if (colorBorder) ffOptionParseColor(yyjson_get_str(colorBorder), &options->barColorBorder); + yyjson_val* width = yyjson_obj_get(val, "width"); if (width) options->barWidth = (uint8_t) yyjson_get_uint(width); @@ -635,6 +644,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key ffOptionParseString(key, value, &options->barBorderLeftElapsed); else if(ffStrEqualsIgnCase(subkey, "border-right-elapsed")) ffOptionParseString(key, value, &options->barBorderRightElapsed); + else if(ffStrEqualsIgnCase(subkey, "color-elapsed")) + ffOptionParseColor(value, &options->barColorElapsed); + else if(ffStrEqualsIgnCase(subkey, "color-total")) + ffOptionParseColor(value, &options->barColorTotal); + else if(ffStrEqualsIgnCase(subkey, "color-border")) + ffOptionParseColor(value, &options->barColorBorder); else return false; } @@ -705,7 +720,11 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) ffStrbufInitStatic(&options->barBorderRight, " ]"); ffStrbufInit(&options->barBorderLeftElapsed); ffStrbufInit(&options->barBorderRightElapsed); + ffStrbufInit(&options->barColorElapsed); + ffStrbufInitStatic(&options->barColorTotal, instance.state.terminalLightTheme ? FF_COLOR_FG_WHITE : FF_COLOR_FG_LIGHT_WHITE); + ffStrbufInitStatic(&options->barColorBorder, instance.state.terminalLightTheme ? FF_COLOR_FG_WHITE : FF_COLOR_FG_LIGHT_WHITE); options->barWidth = 10; + options->durationAbbreviation = false; options->durationSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT; options->percentType = 9; diff --git a/src/options/display.h b/src/options/display.h index 90d4da316..c1255f468 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -62,6 +62,9 @@ typedef struct FFOptionsDisplay FFstrbuf barBorderRight; FFstrbuf barBorderLeftElapsed; FFstrbuf barBorderRightElapsed; + FFstrbuf barColorElapsed; + FFstrbuf barColorTotal; + FFstrbuf barColorBorder; uint8_t barWidth; FFPercentageTypeFlags percentType; uint8_t percentNdigits;