JsonConfig: restructure some keys

This commit is contained in:
李通洲
2023-10-29 00:17:24 +08:00
parent 25849dc4bb
commit 627d5fc659
3 changed files with 103 additions and 67 deletions
+1
View File
@@ -4,6 +4,7 @@ This release introduces a new option `--migrate-config`, which migrates old flag
Changes:
* `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration.
* Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }`
* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version)
* Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version)
+37 -25
View File
@@ -359,18 +359,24 @@
}
]
},
"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": {
"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"
"size": {
"type": "object",
"title": "Set how a size value should be displayed",
"properties": {
"maxPrefix": {
"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"
},
"ndigits": {
"type": "integer",
"title": "Set the number of digits to keep after the decimal point when formatting sizes",
"minimum": 0,
"maximum": 9,
"default": 2
}
}
},
"temperatureUnit": {
"type": "string",
@@ -405,19 +411,25 @@
}
}
},
"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",
"minimum": 0,
"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
"percent": {
"type": "object",
"title": "Set how a percentage value should be displayed",
"properties": {
"type": {
"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": 255,
"default": 1
},
"ndigits": {
"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",
+65 -42
View File
@@ -65,25 +65,33 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
if (error) return error;
options->binaryPrefixType = (FFBinaryPrefixType) value;
}
else if (ffStrEqualsIgnCase(key, "sizeNdigits"))
options->sizeNdigits = (uint8_t) yyjson_get_uint(val);
else if (ffStrEqualsIgnCase(key, "sizeMaxPrefix"))
else if (ffStrEqualsIgnCase(key, "size"))
{
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;
options->sizeMaxPrefix = (uint8_t) value;
if (!yyjson_is_obj(val))
return "display.size must be an object";
yyjson_val* maxPrefix = yyjson_obj_get(val, "maxPrefix");
if (maxPrefix)
{
int value;
const char* error = ffJsonConfigParseEnum(maxPrefix, &value, (FFKeyValuePair[]) {
{ "B", 0 },
{ "kB", 1 },
{ "MB", 2 },
{ "GB", 3 },
{ "TB", 4 },
{ "PB", 5 },
{ "EB", 6 },
{ "ZB", 7 },
{ "YB", 8 },
{}
});
if (error) return error;
options->sizeMaxPrefix = (uint8_t) value;
}
yyjson_val* ndigits = yyjson_obj_get(val, "ndigits");
if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits);
}
else if (ffStrEqualsIgnCase(key, "temperatureUnit"))
{
@@ -100,10 +108,17 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
if (error) return error;
options->temperatureUnit = (FFTemperatureUnit) value;
}
else if (ffStrEqualsIgnCase(key, "percentType"))
options->percentType = (uint8_t) yyjson_get_uint(val);
else if (ffStrEqualsIgnCase(key, "percentNdigits"))
options->percentNdigits = (uint8_t) yyjson_get_uint(val);
else if (ffStrEqualsIgnCase(key, "percent"))
{
if (!yyjson_is_obj(val))
return "display.percent must be an object";
yyjson_val* type = yyjson_obj_get(val, "type");
if (type) options->percentType = (uint8_t) yyjson_get_uint(type);
yyjson_val* ndigits = yyjson_obj_get(val, "ndigits");
if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits);
}
else if (ffStrEqualsIgnCase(key, "bar"))
{
if (yyjson_is_obj(val))
@@ -357,22 +372,26 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
}
}
if (options->sizeNdigits != defaultOptions.sizeNdigits)
yyjson_mut_obj_add_uint(doc, obj, "sizeNdigits", options->sizeNdigits);
if (options->sizeMaxPrefix != defaultOptions.sizeMaxPrefix && options->sizeMaxPrefix <= 8)
{
yyjson_mut_obj_add_str(doc, obj, "sizeMaxPrefix", ((const char* []) {
"B",
"kB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB",
})[options->sizeMaxPrefix]);
yyjson_mut_val* size = yyjson_mut_obj(doc);
if (options->sizeNdigits != defaultOptions.sizeNdigits)
yyjson_mut_obj_add_uint(doc, size, "ndigits", options->sizeNdigits);
if (options->sizeMaxPrefix != defaultOptions.sizeMaxPrefix && options->sizeMaxPrefix <= 8)
{
yyjson_mut_obj_add_str(doc, size, "maxPrefix", ((const char* []) {
"B",
"kB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB",
})[options->sizeMaxPrefix]);
}
if (yyjson_mut_obj_size(size) > 0)
yyjson_mut_obj_add_val(doc, obj, "size", size);
}
if (options->temperatureUnit != defaultOptions.temperatureUnit)
@@ -391,11 +410,15 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do
}
}
if (options->percentType != defaultOptions.percentType)
yyjson_mut_obj_add_uint(doc, obj, "percentType", options->percentType);
if (options->percentNdigits != defaultOptions.percentNdigits)
yyjson_mut_obj_add_uint(doc, obj, "percentNdigits", options->percentNdigits);
{
yyjson_mut_val* percent = yyjson_mut_obj(doc);
if (options->percentType != defaultOptions.percentType)
yyjson_mut_obj_add_uint(doc, percent, "type", options->percentType);
if (options->percentNdigits != defaultOptions.percentNdigits)
yyjson_mut_obj_add_uint(doc, percent, "ndigits", options->percentNdigits);
if (yyjson_mut_obj_size(percent) > 0)
yyjson_mut_obj_add_val(doc, obj, "percent", percent);
}
{
yyjson_mut_val* bar = yyjson_mut_obj(doc);