JsonConfig: rename display.binaryPrefix to display.size.binaryPrefix

This commit is contained in:
李通洲
2024-07-22 10:51:27 +08:00
parent 93bdaf10c4
commit 4a6209e0e3
7 changed files with 89 additions and 67 deletions
+3
View File
@@ -6,6 +6,9 @@ Changes:
* Now: `{ "display": { "freq": { "ndigits": 2 } } }` * Now: `{ "display": { "freq": { "ndigits": 2 } } }`
* This option now affects GPU frequency too * 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* * 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: Features:
* Print physical diagonal length if supported (Display) * Print physical diagonal length if supported (Display)
+2 -2
View File
@@ -83,12 +83,12 @@ __fastfetch_complete_logo_type()
__fastfetch_complete_binary_prefix() __fastfetch_complete_binary_prefix()
{ {
local __ff_binary_prefixes=( local __ff_size_binary_prefixes=(
"iec" "iec"
"si" "si"
"jedec" "jedec"
) )
COMPREPLY=($(compgen -W "${__ff_binary_prefixes[*]}" -- "$CURRENT_WORD")) COMPREPLY=($(compgen -W "${__ff_size_binary_prefixes[*]}" -- "$CURRENT_WORD"))
} }
__fastfetch_complete_gl() __fastfetch_complete_gl()
+18 -18
View File
@@ -424,29 +424,29 @@
"minimum": 0, "minimum": 0,
"default": 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": { "size": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"description": "Set how a size value should be displayed", "description": "Set how a size value should be displayed",
"properties": { "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": { "maxPrefix": {
"type": "string", "type": "string",
"description": "Set the largest binary prefix to use when formatting sizes", "description": "Set the largest binary prefix to use when formatting sizes",
+3 -1
View File
@@ -6,7 +6,9 @@
"type": "small" "type": "small"
}, },
"display": { "display": {
"binaryPrefix": "si" "size": {
"binaryPrefix": "si"
}
}, },
"modules": [ "modules": [
"vulkan", "vulkan",
+3 -1
View File
@@ -9,7 +9,9 @@
} }
}, },
"display": { "display": {
"binaryPrefix": "si", "size": {
"binaryPrefix": "si"
},
"color": "blue", "color": "blue",
"separator": "  " "separator": "  "
}, },
+13 -13
View File
@@ -549,19 +549,6 @@
"default": false "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", "long": "percent-type",
"desc": "Set the percentage output type", "desc": "Set the percentage output type",
@@ -669,6 +656,19 @@
"type": "num" "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", "long": "size-max-prefix",
"desc": "Set the largest binary prefix to use when formatting sizes", "desc": "Set the largest binary prefix to use when formatting sizes",
+47 -32
View File
@@ -61,17 +61,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
else if (ffStrEqualsIgnCase(key, "brightColor")) else if (ffStrEqualsIgnCase(key, "brightColor"))
options->brightColor = yyjson_get_bool(val); options->brightColor = yyjson_get_bool(val);
else if (ffStrEqualsIgnCase(key, "binaryPrefix")) else if (ffStrEqualsIgnCase(key, "binaryPrefix"))
{ return "`display.binaryPrefix` has been renamed to `display.size.binaryPrefix`. Sorry for another break change.";
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;
}
else if (ffStrEqualsIgnCase(key, "size")) else if (ffStrEqualsIgnCase(key, "size"))
{ {
if (!yyjson_is_obj(val)) if (!yyjson_is_obj(val))
@@ -97,6 +87,20 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
options->sizeMaxPrefix = (uint8_t) value; 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"); yyjson_val* ndigits = yyjson_obj_get(val, "ndigits");
if (ndigits) options->sizeNdigits = (uint8_t) yyjson_get_uint(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); options->brightColor = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "--binary-prefix")) else if(ffStrEqualsIgnCase(key, "--binary-prefix"))
{ {
options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { fprintf(stderr, "--binary-prefix has been renamed to --size-binary-prefix\n");
{ "iec", FF_BINARY_PREFIX_TYPE_IEC }, exit(477);
{ "si", FF_BINARY_PREFIX_TYPE_SI },
{ "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
{}
});
} }
else if(ffStrEqualsIgnCase(key, "--size-ndigits")) else if(ffStrStartsWithIgnCase(key, "--size-"))
options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(key, "--size-max-prefix"))
{ {
options->sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { const char* subkey = key + strlen("--size-");
{ "B", 0 }, if (ffStrEqualsIgnCase(subkey, "binary-prefix"))
{ "kB", 1 }, {
{ "MB", 2 }, options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
{ "GB", 3 }, { "iec", FF_BINARY_PREFIX_TYPE_IEC },
{ "TB", 4 }, { "si", FF_BINARY_PREFIX_TYPE_SI },
{ "PB", 5 }, { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
{ "EB", 6 }, {}
{ "ZB", 7 }, });
{ "YB", 8 }, }
{} 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-")) else if(ffStrStartsWithIgnCase(key, "--temp-"))
{ {