Global: add option --size-ndigits and --size-max-prefix

This commit is contained in:
李通洲
2023-07-10 15:25:45 +08:00
parent d5f0ccae88
commit 856d732e13
9 changed files with 45 additions and 10 deletions
+1
View File
@@ -21,6 +21,7 @@ Features:
* Add `--wmi-timeout` option (Windows)
* Add `--logo-type small` to search for small logos
* Support detecting brightness of external displays with DDC/CI (guard behind `--allow-slow-operations`) (Brightness)
* Add option `--size-ndigits` and `--size-max-prefix` (#494)
# 1.12.2
+10
View File
@@ -296,6 +296,16 @@
"jedec"
]
},
"sizeNdigits": {
"type": "integer",
"title": "Set the number of digits to keep after the decimal point when formatting sizes",
"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
},
"percentType": {
"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",
+2
View File
@@ -60,6 +60,8 @@ static void defaultConfig(void)
instance.config.escapeBedrock = true;
instance.config.binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC;
instance.config.sizeNdigits = 2;
instance.config.sizeMaxPrefix = UINT8_MAX;
instance.config.multithreading = true;
instance.config.stat = false;
instance.config.noBuffer = false;
+4
View File
@@ -386,6 +386,10 @@ const char* ffParseDisplayJsonConfig(void)
if (error) return error;
config->binaryPrefixType = (FFBinaryPrefixType) value;
}
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);
else if (ffStrEqualsIgnCase(key, "percentType"))
config->percentType = (uint32_t) yyjson_get_uint(val);
else if (ffStrEqualsIgnCase(key, "noBuffer"))
+8 -10
View File
@@ -60,12 +60,12 @@ void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty)
ffStrbufAppendF(pretty, ".%u", version->patch);
}
static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, uint8_t prefixesLength, const char** prefixes)
static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, const char** prefixes)
{
long double size = (long double) bytes;
double size = (double) bytes;
uint8_t counter = 0;
while(size >= base && counter < prefixesLength - 1)
while(size >= base && counter < instance.config.sizeMaxPrefix && prefixes[counter + 1])
{
size /= base;
counter++;
@@ -73,22 +73,20 @@ static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, uint8_t p
if(counter == 0)
ffStrbufAppendF(result, "%"PRIu64" %s", bytes, prefixes[0]);
else if(counter < 3 || (counter == 3 && size < 100.0))
ffStrbufAppendF(result, "%.2Lf %s", size, prefixes[counter]);
else
ffStrbufAppendF(result, "%.0Lf %s", size, prefixes[counter]);
ffStrbufAppendF(result, "%.*f %s", instance.config.sizeNdigits, size, prefixes[counter]);
}
void ffParseSize(uint64_t bytes, FFBinaryPrefixType binaryPrefix, FFstrbuf* result)
{
if(binaryPrefix == FF_BINARY_PREFIX_TYPE_IEC)
parseSize(result, bytes, 1024, 5, (const char*[]) {"B", "KiB", "MiB", "GiB", "TiB"});
parseSize(result, bytes, 1024, (const char*[]) {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", NULL});
else if(binaryPrefix == FF_BINARY_PREFIX_TYPE_SI)
parseSize(result, bytes, 1000, 5, (const char*[]) {"B", "kB", "MB", "GB", "TB"});
parseSize(result, bytes, 1000, (const char*[]) {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", NULL});
else if(binaryPrefix == FF_BINARY_PREFIX_TYPE_JEDEC)
parseSize(result, bytes, 1024, 5, (const char*[]) {"B", "KB", "MB", "GB", "TB"});
parseSize(result, bytes, 1024, (const char*[]) {"B", "KB", "MB", "GB", "TB", NULL});
else
parseSize(result, bytes, 1024, 1, (const char*[]) {"B"});
parseSize(result, bytes, 1024, (const char*[]) {"B", NULL});
}
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4)
+12
View File
@@ -152,6 +152,18 @@
# Default is IEC.
#--binary-prefix IEC
# Size number of digits option:
# Sets the number of digits to keep after the decimal point when formatting sizes.
# Must be an possitive integer.
# Default is 2.
#--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
# Disable output buffer option:
# Sets if the stdout application buffer should be disabled.
# Must be true or false.
+2
View File
@@ -65,6 +65,8 @@ Display options:
--binary-prefix <value>: Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC
--percent-type <value>: 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 <?value>: Set if the stdout application buffer should be disabled. Default is false
--size-ndigits <value>: Set the number of digits to keep after the decimal point when formatting sizes
--size-max-prefix <value>: Set the largest binary prefix to use when formatting sizes. 0 is B; 1 is KB; 2 is MB; etc.
General module options:
--<module>-format <format>: Set the format string to use for each specific module.
+4
View File
@@ -915,6 +915,10 @@ 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);
else if(ffStrEqualsIgnCase(key, "--percent-type"))
instance.config.percentType = ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(key, "--no-buffer"))
+2
View File
@@ -44,6 +44,8 @@ typedef struct FFconfig
bool hideCursor;
bool escapeBedrock;
FFBinaryPrefixType binaryPrefixType;
uint8_t sizeNdigits;
uint8_t sizeMaxPrefix;
bool pipe; //disables logo and all escape sequences
bool multithreading;
bool stat;