mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Percent: add option --percent-width
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -67,6 +67,7 @@ typedef struct FFOptionsDisplay
|
||||
FFstrbuf percentColorYellow;
|
||||
FFstrbuf percentColorRed;
|
||||
FFSpaceBeforeUnitType percentSpaceBeforeUnit;
|
||||
uint8_t percentWidth;
|
||||
bool noBuffer;
|
||||
FFModuleKeyType keyType;
|
||||
uint16_t keyWidth;
|
||||
|
||||
Reference in New Issue
Block a user