Percent: add option --percent-width

This commit is contained in:
李通洲
2025-07-30 15:06:16 +08:00
parent ce554dbdd0
commit aa0bbd5aee
5 changed files with 23 additions and 1 deletions
+6
View File
@@ -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
}
}
},
+1 -1
View File
@@ -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)
+9
View File
@@ -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",
+6
View File
@@ -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;
+1
View File
@@ -67,6 +67,7 @@ typedef struct FFOptionsDisplay
FFstrbuf percentColorYellow;
FFstrbuf percentColorRed;
FFSpaceBeforeUnitType percentSpaceBeforeUnit;
uint8_t percentWidth;
bool noBuffer;
FFModuleKeyType keyType;
uint16_t keyWidth;