diff --git a/doc/json_schema.json b/doc/json_schema.json index 4baa74a2d..07061c18f 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -343,6 +343,8 @@ "sizeNdigits": { "type": "integer", "title": "Set the number of digits to keep after the decimal point when formatting sizes", + "minimum": 0, + "maximum": 9, "default": 2 }, "sizeMaxPrefix": { @@ -388,9 +390,16 @@ "type": "number", "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", "minimum": 0, - "maximum": 9, + "maximum": 255, "default": 1 }, + "percentNdigits": { + "type": "number", + "title": "Set the number of digits to keep after the decimal point when formatting percentage numbers", + "minimum": 0, + "maximum": 9, + "default": 0 + }, "noBuffer": { "type": "boolean", "title": "Whether to disable the stdout application buffer", diff --git a/src/common/bar.c b/src/common/bar.c index 549c3ba50..e250188d7 100644 --- a/src/common/bar.c +++ b/src/common/bar.c @@ -93,7 +93,7 @@ void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } } - ffStrbufAppendF(buffer, "%u%%", (unsigned) (percent + 0.5)); + ffStrbufAppendF(buffer, "%.*f%%", instance.config.percentNdigits, percent); if (colored && !instance.config.pipe) { diff --git a/src/common/init.c b/src/common/init.c index 2f277ddfb..dfe8b4d19 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -74,6 +74,7 @@ static void defaultConfig(void) instance.config.barWidth = 10; instance.config.barBorder = true; instance.config.percentType = 1; + instance.config.percentNdigits = 0; ffInitBatteryOptions(&instance.config.battery); ffInitBiosOptions(&instance.config.bios); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 1cfbb9606..71bc3cf8f 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -325,7 +325,9 @@ const char* ffParseDisplayJsonConfig(void) config->temperatureUnit = (FFTemperatureUnit) value; } else if (ffStrEqualsIgnCase(key, "percentType")) - config->percentType = (uint32_t) yyjson_get_uint(val); + config->percentType = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "percentNdigits")) + config->percentNdigits = (uint8_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "bar")) { if (yyjson_is_obj(val)) diff --git a/src/fastfetch.c b/src/fastfetch.c index 73b4bc251..9786c070a 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1053,7 +1053,9 @@ static void parseOption(FFdata* data, const char* key, const char* value) }); } else if(ffStrEqualsIgnCase(key, "--percent-type")) - instance.config.percentType = ffOptionParseUInt32(key, value); + instance.config.percentType = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--percent-ndigits")) + instance.config.percentNdigits = (uint8_t) ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(key, "--no-buffer")) instance.config.noBuffer = ffOptionParseBoolean(value); else if(ffStrStartsWithIgnCase(key, "--bar")) diff --git a/src/fastfetch.h b/src/fastfetch.h index 6dfa675fa..a5f990912 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -61,7 +61,8 @@ typedef struct FFconfig FFstrbuf barCharTotal; uint8_t barWidth; bool barBorder; - uint32_t percentType; + uint8_t percentType; + uint8_t percentNdigits; bool pipe; //disables logo and all escape sequences bool multithreading; bool stat;