diff --git a/doc/json_schema.json b/doc/json_schema.json index 01f05602d..6391b2b79 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -302,9 +302,10 @@ "default": 2 }, "sizeMaxPrefix": { - "type": "integer", - "title": "Set the largest binary prefix to use when formatting sizes. 0 is B; 1 is KB; 2 is MB; etc.", - "default": 255 + "type": "string", + "title": "Set the largest binary prefix to use when formatting sizes", + "enum": ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], + "default": "YB" }, "percentType": { "type": "number", diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 4b6d09546..3fa6fe37f 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -389,7 +389,23 @@ const char* ffParseDisplayJsonConfig(void) else if (ffStrEqualsIgnCase(key, "sizeNdigits")) config->sizeNdigits = (uint8_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "sizeMaxPrefix")) - config->sizeMaxPrefix = (uint8_t) yyjson_get_uint(val); + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "B", 0 }, + { "kB", 1 }, + { "MB", 2 }, + { "GB", 3 }, + { "TB", 4 }, + { "PB", 5 }, + { "EB", 6 }, + { "ZB", 7 }, + { "YB", 8 }, + {} + }); + if (error) return error; + config->sizeMaxPrefix = (uint8_t) value; + } else if (ffStrEqualsIgnCase(key, "percentType")) config->percentType = (uint32_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "noBuffer")) diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 2128c51a2..e9a481727 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -159,10 +159,10 @@ #--size-ndigits 2 # Size max prefix option: -# Sets the largest binary prefix to use when formatting sizes. 0 is B; 1 is KB; 2 is MB; etc. -# Must be an possitive integer. -# Default is 255 (unlimited). -#--size-max-prefix 255 +# Sets the largest binary prefix to use when formatting sizes. +# Must be one of B, kB, MB, GB, TB, PB, EB, ZB, YB +# Default is YB. +#--size-max-prefix YB # Disable output buffer option: # Sets if the stdout application buffer should be disabled. diff --git a/src/data/help.txt b/src/data/help.txt index fdc21004a..78af50b05 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -66,7 +66,7 @@ Display options: --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 1 --no-buffer : Set if the stdout application buffer should be disabled. Default is false --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes - --size-max-prefix : Set the largest binary prefix to use when formatting sizes. 0 is B; 1 is KB; 2 is MB; etc. + --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB General module options: ---format : Set the format string to use for each specific module. diff --git a/src/fastfetch.c b/src/fastfetch.c index 94453774b..c83718fa9 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -918,7 +918,20 @@ static void parseOption(FFdata* data, const char* key, const char* value) else if(ffStrEqualsIgnCase(key, "--size-ndigits")) instance.config.sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(key, "--size-max-prefix")) - instance.config.sizeMaxPrefix = (uint8_t) ffOptionParseUInt32(key, value); + { + instance.config.sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "B", 0 }, + { "kB", 1 }, + { "MB", 2 }, + { "GB", 3 }, + { "TB", 4 }, + { "PB", 5 }, + { "EB", 6 }, + { "ZB", 7 }, + { "YB", 8 }, + {} + }); + } else if(ffStrEqualsIgnCase(key, "--percent-type")) instance.config.percentType = ffOptionParseUInt32(key, value); else if(ffStrEqualsIgnCase(key, "--no-buffer"))