diff --git a/doc/json_schema.json b/doc/json_schema.json index ffc056d75..25c3f47ad 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1064,6 +1064,12 @@ }, "spaceBeforeUnit": { "$ref": "#/$defs/spaceBeforeUnit" + }, + "width": { + "type": "integer", + "description": "Set the width of the percentage number, in number of characters", + "minimum": 0, + "default": 0 } } }, diff --git a/src/common/percent.c b/src/common/percent.c index 8e4a0c24d..746556183 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -186,7 +186,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConf ffStrbufAppendF(buffer, "\e[%sm", colorGreen); } } - ffStrbufAppendF(buffer, "%.*f%s%%", options->percentNdigits, percent, + ffStrbufAppendF(buffer, "%*.*f%s%%", options->percentWidth, options->percentNdigits, percent, options->percentSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_ALWAYS ? " " : ""); if (colored && !options->pipe) diff --git a/src/data/help.json b/src/data/help.json index 552affcca..59f16be66 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -658,6 +658,15 @@ } } }, + { + "long": "percent-width", + "desc": "Specify the width of the percentage number, in number of characters", + "remark": "This option affects only percentage numbers, not bars", + "arg": { + "type": "num", + "default": 0 + } + }, { "long": "bar-char-elapsed", "desc": "Set the character to use in the elapsed part of percentage bars", diff --git a/src/options/display.c b/src/options/display.c index 5eb1e33e5..eae73b1c9 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -257,6 +257,9 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va if (error) return error; options->percentSpaceBeforeUnit = (FFSpaceBeforeUnitType) value; } + + yyjson_val* width = yyjson_obj_get(val, "width"); + if (width) options->percentWidth = (uint8_t) yyjson_get_uint(width); } else if (ffStrEqualsIgnCase(key, "bar")) { @@ -598,6 +601,8 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key {}, }); } + else if(ffStrEqualsIgnCase(subkey, "width")) + options->percentWidth = (uint8_t) ffOptionParseUInt32(key, value); else return false; } @@ -695,6 +700,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) ffStrbufInitStatic(&options->percentColorYellow, instance.state.terminalLightTheme ? FF_COLOR_FG_YELLOW : FF_COLOR_FG_LIGHT_YELLOW); ffStrbufInitStatic(&options->percentColorRed, instance.state.terminalLightTheme ? FF_COLOR_FG_RED : FF_COLOR_FG_LIGHT_RED); options->percentSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT; + options->percentWidth = 0; options->freqNdigits = 2; options->freqSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT; diff --git a/src/options/display.h b/src/options/display.h index cc516e877..6a50b848c 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -67,6 +67,7 @@ typedef struct FFOptionsDisplay FFstrbuf percentColorYellow; FFstrbuf percentColorRed; FFSpaceBeforeUnitType percentSpaceBeforeUnit; + uint8_t percentWidth; bool noBuffer; FFModuleKeyType keyType; uint16_t keyWidth;