From 4a6209e0e370f3c902060701b50430a6c546721d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 22 Jul 2024 10:51:27 +0800 Subject: [PATCH] JsonConfig: rename `display.binaryPrefix` to `display.size.binaryPrefix` --- CHANGELOG.md | 3 ++ completions/fastfetch.bash | 4 +- doc/json_schema.json | 36 ++++++++--------- presets/examples/3.jsonc | 4 +- presets/examples/4.jsonc | 4 +- src/data/help.json | 26 ++++++------- src/options/display.c | 79 +++++++++++++++++++++++--------------- 7 files changed, 89 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b28912632..0099ee179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Changes: * Now: `{ "display": { "freq": { "ndigits": 2 } } }` * This option now affects GPU frequency too * By default, frequencies are displayed in *GHz*. Set `display.freq.ndigits` to `-1` to display them in *MHz* +* JSON option `display.binaryPrefix` has been moved to `display.size.binaryPrefix` + * Previously: `{ "display": { "binaryPrefix": "IEC" } }` + * Now: `{ "display": { "size": { "binaryPrefix": "IEC" } } }` Features: * Print physical diagonal length if supported (Display) diff --git a/completions/fastfetch.bash b/completions/fastfetch.bash index 8cfdc9a84..76e43859a 100644 --- a/completions/fastfetch.bash +++ b/completions/fastfetch.bash @@ -83,12 +83,12 @@ __fastfetch_complete_logo_type() __fastfetch_complete_binary_prefix() { - local __ff_binary_prefixes=( + local __ff_size_binary_prefixes=( "iec" "si" "jedec" ) - COMPREPLY=($(compgen -W "${__ff_binary_prefixes[*]}" -- "$CURRENT_WORD")) + COMPREPLY=($(compgen -W "${__ff_size_binary_prefixes[*]}" -- "$CURRENT_WORD")) } __fastfetch_complete_gl() diff --git a/doc/json_schema.json b/doc/json_schema.json index ec7bc3ead..ca8d45690 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -424,29 +424,29 @@ "minimum": 0, "default": 0 }, - "binaryPrefix": { - "type": "string", - "description": "Set the binary prefix to used when printing bytes", - "oneOf": [ - { - "const": "iec", - "description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)" - }, - { - "const": "si", - "description": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ..." - }, - { - "const": "jedec", - "description": "1024 Bytes = 1 kB, 1024 K = 1 MB, ..." - } - ] - }, "size": { "type": "object", "additionalProperties": false, "description": "Set how a size value should be displayed", "properties": { + "binaryPrefix": { + "type": "string", + "description": "Set the binary prefix to used when formatting sizes", + "oneOf": [ + { + "const": "iec", + "description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)" + }, + { + "const": "si", + "description": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ..." + }, + { + "const": "jedec", + "description": "1024 Bytes = 1 kB, 1024 K = 1 MB, ..." + } + ] + }, "maxPrefix": { "type": "string", "description": "Set the largest binary prefix to use when formatting sizes", diff --git a/presets/examples/3.jsonc b/presets/examples/3.jsonc index 670a942a8..f3cb7d431 100644 --- a/presets/examples/3.jsonc +++ b/presets/examples/3.jsonc @@ -6,7 +6,9 @@ "type": "small" }, "display": { - "binaryPrefix": "si" + "size": { + "binaryPrefix": "si" + } }, "modules": [ "vulkan", diff --git a/presets/examples/4.jsonc b/presets/examples/4.jsonc index fafeb892a..963164416 100644 --- a/presets/examples/4.jsonc +++ b/presets/examples/4.jsonc @@ -9,7 +9,9 @@ } }, "display": { - "binaryPrefix": "si", + "size": { + "binaryPrefix": "si" + }, "color": "blue", "separator": "  " }, diff --git a/src/data/help.json b/src/data/help.json index 7fc18e82e..d69c80d05 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -549,19 +549,6 @@ "default": false } }, - { - "long": "binary-prefix", - "desc": "Set the binary prefix to used", - "arg": { - "type": "enum", - "enum": { - "IEC": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ...", - "SI": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ...", - "JEDEC": "1024 Bytes = 1 kB, 1024 kB = 1 MB, ..." - }, - "default": "IEC" - } - }, { "long": "percent-type", "desc": "Set the percentage output type", @@ -669,6 +656,19 @@ "type": "num" } }, + { + "long": "size-binary-prefix", + "desc": "Set the binary prefix to used when formatting sizes", + "arg": { + "type": "enum", + "enum": { + "IEC": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ...", + "SI": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ...", + "JEDEC": "1024 Bytes = 1 kB, 1024 kB = 1 MB, ..." + }, + "default": "IEC" + } + }, { "long": "size-max-prefix", "desc": "Set the largest binary prefix to use when formatting sizes", diff --git a/src/options/display.c b/src/options/display.c index eb79a90db..2ed899cad 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -61,17 +61,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va else if (ffStrEqualsIgnCase(key, "brightColor")) options->brightColor = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "binaryPrefix")) - { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "iec", FF_BINARY_PREFIX_TYPE_IEC }, - { "si", FF_BINARY_PREFIX_TYPE_SI }, - { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, - {}, - }); - if (error) return error; - options->binaryPrefixType = (FFBinaryPrefixType) value; - } + return "`display.binaryPrefix` has been renamed to `display.size.binaryPrefix`. Sorry for another break change."; else if (ffStrEqualsIgnCase(key, "size")) { if (!yyjson_is_obj(val)) @@ -97,6 +87,20 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va options->sizeMaxPrefix = (uint8_t) value; } + yyjson_val* binaryPrefix = yyjson_obj_get(val, "binaryPrefix"); + if (binaryPrefix) + { + int value; + const char* error = ffJsonConfigParseEnum(binaryPrefix, &value, (FFKeyValuePair[]) { + { "iec", FF_BINARY_PREFIX_TYPE_IEC }, + { "si", FF_BINARY_PREFIX_TYPE_SI }, + { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, + {}, + }); + if (error) return error; + options->binaryPrefixType = (FFBinaryPrefixType) value; + } + yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); if (ndigits) options->sizeNdigits = (uint8_t) yyjson_get_uint(ndigits); } @@ -288,29 +292,40 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key options->brightColor = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--binary-prefix")) { - options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "iec", FF_BINARY_PREFIX_TYPE_IEC }, - { "si", FF_BINARY_PREFIX_TYPE_SI }, - { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, - {} - }); + fprintf(stderr, "--binary-prefix has been renamed to --size-binary-prefix\n"); + exit(477); } - else if(ffStrEqualsIgnCase(key, "--size-ndigits")) - options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(key, "--size-max-prefix")) + else if(ffStrStartsWithIgnCase(key, "--size-")) { - options->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 }, - {} - }); + const char* subkey = key + strlen("--size-"); + if (ffStrEqualsIgnCase(subkey, "binary-prefix")) + { + options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "iec", FF_BINARY_PREFIX_TYPE_IEC }, + { "si", FF_BINARY_PREFIX_TYPE_SI }, + { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, + {} + }); + } + else if (ffStrEqualsIgnCase(subkey, "ndigits")) + options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value); + else if (ffStrEqualsIgnCase(subkey, "max-prefix")) + { + options->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 + return false; } else if(ffStrStartsWithIgnCase(key, "--temp-")) {