Skip to content

Commit 4a6209e

Browse files
committed
JsonConfig: rename display.binaryPrefix to display.size.binaryPrefix
1 parent 93bdaf1 commit 4a6209e

File tree

7 files changed

+89
-67
lines changed

7 files changed

+89
-67
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Changes:
66
* Now: `{ "display": { "freq": { "ndigits": 2 } } }`
77
* This option now affects GPU frequency too
88
* By default, frequencies are displayed in *GHz*. Set `display.freq.ndigits` to `-1` to display them in *MHz*
9+
* JSON option `display.binaryPrefix` has been moved to `display.size.binaryPrefix`
10+
* Previously: `{ "display": { "binaryPrefix": "IEC" } }`
11+
* Now: `{ "display": { "size": { "binaryPrefix": "IEC" } } }`
912

1013
Features:
1114
* Print physical diagonal length if supported (Display)

completions/fastfetch.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ __fastfetch_complete_logo_type()
8383

8484
__fastfetch_complete_binary_prefix()
8585
{
86-
local __ff_binary_prefixes=(
86+
local __ff_size_binary_prefixes=(
8787
"iec"
8888
"si"
8989
"jedec"
9090
)
91-
COMPREPLY=($(compgen -W "${__ff_binary_prefixes[*]}" -- "$CURRENT_WORD"))
91+
COMPREPLY=($(compgen -W "${__ff_size_binary_prefixes[*]}" -- "$CURRENT_WORD"))
9292
}
9393

9494
__fastfetch_complete_gl()

doc/json_schema.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,29 @@
424424
"minimum": 0,
425425
"default": 0
426426
},
427-
"binaryPrefix": {
428-
"type": "string",
429-
"description": "Set the binary prefix to used when printing bytes",
430-
"oneOf": [
431-
{
432-
"const": "iec",
433-
"description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)"
434-
},
435-
{
436-
"const": "si",
437-
"description": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ..."
438-
},
439-
{
440-
"const": "jedec",
441-
"description": "1024 Bytes = 1 kB, 1024 K = 1 MB, ..."
442-
}
443-
]
444-
},
445427
"size": {
446428
"type": "object",
447429
"additionalProperties": false,
448430
"description": "Set how a size value should be displayed",
449431
"properties": {
432+
"binaryPrefix": {
433+
"type": "string",
434+
"description": "Set the binary prefix to used when formatting sizes",
435+
"oneOf": [
436+
{
437+
"const": "iec",
438+
"description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)"
439+
},
440+
{
441+
"const": "si",
442+
"description": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ..."
443+
},
444+
{
445+
"const": "jedec",
446+
"description": "1024 Bytes = 1 kB, 1024 K = 1 MB, ..."
447+
}
448+
]
449+
},
450450
"maxPrefix": {
451451
"type": "string",
452452
"description": "Set the largest binary prefix to use when formatting sizes",

presets/examples/3.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"type": "small"
77
},
88
"display": {
9-
"binaryPrefix": "si"
9+
"size": {
10+
"binaryPrefix": "si"
11+
}
1012
},
1113
"modules": [
1214
"vulkan",

presets/examples/4.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
}
1010
},
1111
"display": {
12-
"binaryPrefix": "si",
12+
"size": {
13+
"binaryPrefix": "si"
14+
},
1315
"color": "blue",
1416
"separator": ""
1517
},

src/data/help.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,19 +549,6 @@
549549
"default": false
550550
}
551551
},
552-
{
553-
"long": "binary-prefix",
554-
"desc": "Set the binary prefix to used",
555-
"arg": {
556-
"type": "enum",
557-
"enum": {
558-
"IEC": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ...",
559-
"SI": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ...",
560-
"JEDEC": "1024 Bytes = 1 kB, 1024 kB = 1 MB, ..."
561-
},
562-
"default": "IEC"
563-
}
564-
},
565552
{
566553
"long": "percent-type",
567554
"desc": "Set the percentage output type",
@@ -669,6 +656,19 @@
669656
"type": "num"
670657
}
671658
},
659+
{
660+
"long": "size-binary-prefix",
661+
"desc": "Set the binary prefix to used when formatting sizes",
662+
"arg": {
663+
"type": "enum",
664+
"enum": {
665+
"IEC": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ...",
666+
"SI": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ...",
667+
"JEDEC": "1024 Bytes = 1 kB, 1024 kB = 1 MB, ..."
668+
},
669+
"default": "IEC"
670+
}
671+
},
672672
{
673673
"long": "size-max-prefix",
674674
"desc": "Set the largest binary prefix to use when formatting sizes",

src/options/display.c

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
6161
else if (ffStrEqualsIgnCase(key, "brightColor"))
6262
options->brightColor = yyjson_get_bool(val);
6363
else if (ffStrEqualsIgnCase(key, "binaryPrefix"))
64-
{
65-
int value;
66-
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
67-
{ "iec", FF_BINARY_PREFIX_TYPE_IEC },
68-
{ "si", FF_BINARY_PREFIX_TYPE_SI },
69-
{ "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
70-
{},
71-
});
72-
if (error) return error;
73-
options->binaryPrefixType = (FFBinaryPrefixType) value;
74-
}
64+
return "`display.binaryPrefix` has been renamed to `display.size.binaryPrefix`. Sorry for another break change.";
7565
else if (ffStrEqualsIgnCase(key, "size"))
7666
{
7767
if (!yyjson_is_obj(val))
@@ -97,6 +87,20 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va
9787
options->sizeMaxPrefix = (uint8_t) value;
9888
}
9989

90+
yyjson_val* binaryPrefix = yyjson_obj_get(val, "binaryPrefix");
91+
if (binaryPrefix)
92+
{
93+
int value;
94+
const char* error = ffJsonConfigParseEnum(binaryPrefix, &value, (FFKeyValuePair[]) {
95+
{ "iec", FF_BINARY_PREFIX_TYPE_IEC },
96+
{ "si", FF_BINARY_PREFIX_TYPE_SI },
97+
{ "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
98+
{},
99+
});
100+
if (error) return error;
101+
options->binaryPrefixType = (FFBinaryPrefixType) value;
102+
}
103+
100104
yyjson_val* ndigits = yyjson_obj_get(val, "ndigits");
101105
if (ndigits) options->sizeNdigits = (uint8_t) yyjson_get_uint(ndigits);
102106
}
@@ -288,29 +292,40 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key
288292
options->brightColor = ffOptionParseBoolean(value);
289293
else if(ffStrEqualsIgnCase(key, "--binary-prefix"))
290294
{
291-
options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
292-
{ "iec", FF_BINARY_PREFIX_TYPE_IEC },
293-
{ "si", FF_BINARY_PREFIX_TYPE_SI },
294-
{ "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
295-
{}
296-
});
295+
fprintf(stderr, "--binary-prefix has been renamed to --size-binary-prefix\n");
296+
exit(477);
297297
}
298-
else if(ffStrEqualsIgnCase(key, "--size-ndigits"))
299-
options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value);
300-
else if(ffStrEqualsIgnCase(key, "--size-max-prefix"))
298+
else if(ffStrStartsWithIgnCase(key, "--size-"))
301299
{
302-
options->sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
303-
{ "B", 0 },
304-
{ "kB", 1 },
305-
{ "MB", 2 },
306-
{ "GB", 3 },
307-
{ "TB", 4 },
308-
{ "PB", 5 },
309-
{ "EB", 6 },
310-
{ "ZB", 7 },
311-
{ "YB", 8 },
312-
{}
313-
});
300+
const char* subkey = key + strlen("--size-");
301+
if (ffStrEqualsIgnCase(subkey, "binary-prefix"))
302+
{
303+
options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
304+
{ "iec", FF_BINARY_PREFIX_TYPE_IEC },
305+
{ "si", FF_BINARY_PREFIX_TYPE_SI },
306+
{ "jedec", FF_BINARY_PREFIX_TYPE_JEDEC },
307+
{}
308+
});
309+
}
310+
else if (ffStrEqualsIgnCase(subkey, "ndigits"))
311+
options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value);
312+
else if (ffStrEqualsIgnCase(subkey, "max-prefix"))
313+
{
314+
options->sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
315+
{ "B", 0 },
316+
{ "kB", 1 },
317+
{ "MB", 2 },
318+
{ "GB", 3 },
319+
{ "TB", 4 },
320+
{ "PB", 5 },
321+
{ "EB", 6 },
322+
{ "ZB", 7 },
323+
{ "YB", 8 },
324+
{}
325+
});
326+
}
327+
else
328+
return false;
314329
}
315330
else if(ffStrStartsWithIgnCase(key, "--temp-"))
316331
{

0 commit comments

Comments
 (0)