Skip to content

Commit aa0bbd5

Browse files
committed
Percent: add option --percent-width
1 parent ce554db commit aa0bbd5

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

doc/json_schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,12 @@
10641064
},
10651065
"spaceBeforeUnit": {
10661066
"$ref": "#/$defs/spaceBeforeUnit"
1067+
},
1068+
"width": {
1069+
"type": "integer",
1070+
"description": "Set the width of the percentage number, in number of characters",
1071+
"minimum": 0,
1072+
"default": 0
10671073
}
10681074
}
10691075
},

src/common/percent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConf
186186
ffStrbufAppendF(buffer, "\e[%sm", colorGreen);
187187
}
188188
}
189-
ffStrbufAppendF(buffer, "%.*f%s%%", options->percentNdigits, percent,
189+
ffStrbufAppendF(buffer, "%*.*f%s%%", options->percentWidth, options->percentNdigits, percent,
190190
options->percentSpaceBeforeUnit == FF_SPACE_BEFORE_UNIT_ALWAYS ? " " : "");
191191

192192
if (colored && !options->pipe)

src/data/help.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,15 @@
658658
}
659659
}
660660
},
661+
{
662+
"long": "percent-width",
663+
"desc": "Specify the width of the percentage number, in number of characters",
664+
"remark": "This option affects only percentage numbers, not bars",
665+
"arg": {
666+
"type": "num",
667+
"default": 0
668+
}
669+
},
661670
{
662671
"long": "bar-char-elapsed",
663672
"desc": "Set the character to use in the elapsed part of percentage bars",

src/options/display.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
257257
if (error) return error;
258258
options->percentSpaceBeforeUnit = (FFSpaceBeforeUnitType) value;
259259
}
260+
261+
yyjson_val* width = yyjson_obj_get(val, "width");
262+
if (width) options->percentWidth = (uint8_t) yyjson_get_uint(width);
260263
}
261264
else if (ffStrEqualsIgnCase(key, "bar"))
262265
{
@@ -598,6 +601,8 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
598601
{},
599602
});
600603
}
604+
else if(ffStrEqualsIgnCase(subkey, "width"))
605+
options->percentWidth = (uint8_t) ffOptionParseUInt32(key, value);
601606
else
602607
return false;
603608
}
@@ -695,6 +700,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options)
695700
ffStrbufInitStatic(&options->percentColorYellow, instance.state.terminalLightTheme ? FF_COLOR_FG_YELLOW : FF_COLOR_FG_LIGHT_YELLOW);
696701
ffStrbufInitStatic(&options->percentColorRed, instance.state.terminalLightTheme ? FF_COLOR_FG_RED : FF_COLOR_FG_LIGHT_RED);
697702
options->percentSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT;
703+
options->percentWidth = 0;
698704

699705
options->freqNdigits = 2;
700706
options->freqSpaceBeforeUnit = FF_SPACE_BEFORE_UNIT_DEFAULT;

src/options/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct FFOptionsDisplay
6767
FFstrbuf percentColorYellow;
6868
FFstrbuf percentColorRed;
6969
FFSpaceBeforeUnitType percentSpaceBeforeUnit;
70+
uint8_t percentWidth;
7071
bool noBuffer;
7172
FFModuleKeyType keyType;
7273
uint16_t keyWidth;

0 commit comments

Comments
 (0)