Skip to content

Commit f0e9caa

Browse files
committed
Disk: allows array input for disk folder and filesystem options
1 parent 2c22c3b commit f0e9caa

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

doc/json_schema.json

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,17 +2307,60 @@
23072307
"const": "disk"
23082308
},
23092309
"folders": {
2310-
"type": "string",
2311-
"description": "A colon (semicolon on Windows) separated list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options"
2310+
"description": "A list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options",
2311+
"oneOf": [
2312+
{
2313+
"type": "string",
2314+
"description": "A colon (semicolon on Windows) separated list of folder paths to get disk usage from",
2315+
"default": "/"
2316+
},
2317+
{
2318+
"type": "array",
2319+
"description": "An array of folder paths to get disk usage from",
2320+
"items": {
2321+
"type": "string"
2322+
},
2323+
"minItems": 1,
2324+
"uniqueItems": true
2325+
}
2326+
]
23122327
},
23132328
"hideFolders": {
2314-
"type": "string",
2315-
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output",
2329+
"description": "A list of folder paths to hide from the disk output",
2330+
"oneOf": [
2331+
{
2332+
"type": "string",
2333+
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output"
2334+
},
2335+
{
2336+
"type": "array",
2337+
"description": "An array of folder paths to hide from the disk output",
2338+
"items": {
2339+
"type": "string"
2340+
},
2341+
"minItems": 1,
2342+
"uniqueItems": true
2343+
}
2344+
],
23162345
"default": "/efi:/boot:/boot/efi:/boot/firmware"
23172346
},
23182347
"hideFS": {
2319-
"type": "string",
2320-
"description": "A colon separated file systems to hide from the disk output"
2348+
"description": "A list of file systems to hide from the disk output",
2349+
"oneOf": [
2350+
{
2351+
"type": "string",
2352+
"description": "A colon separated list of file systems to hide from the disk output"
2353+
},
2354+
{
2355+
"type": "array",
2356+
"description": "An array of file systems to hide from the disk output",
2357+
"items": {
2358+
"type": "string"
2359+
},
2360+
"minItems": 1,
2361+
"uniqueItems": true
2362+
}
2363+
]
23212364
},
23222365
"showRegular": {
23232366
"type": "boolean",

src/detection/disk/disk.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
44
{
5-
#ifdef _WIN32
6-
const char separator = ';';
7-
#else
8-
const char separator = ':';
9-
#endif
10-
115
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
126

137
uint32_t startIndex = 0;
148
while(startIndex < folders->length)
159
{
16-
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
10+
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, FF_DISK_FOLDER_SEPARATOR);
1711

1812
uint32_t folderLength = colonIndex - startIndex;
1913
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)

src/detection/disk/disk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include "fastfetch.h"
44
#include "modules/disk/option.h"
55

6+
#ifdef _WIN32
7+
#define FF_DISK_FOLDER_SEPARATOR ';'
8+
#else
9+
#define FF_DISK_FOLDER_SEPARATOR ':'
10+
#endif
11+
612
typedef struct FFDisk
713
{
814
FFstrbuf mountFrom;

src/modules/disk/disk.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ bool ffPrintDisk(FFDiskOptions* options)
223223
return true;
224224
}
225225

226+
static bool setSeparatedList(FFstrbuf* strbuf, yyjson_val* val, char separator)
227+
{
228+
if (yyjson_is_str(val))
229+
{
230+
ffStrbufSetJsonVal(strbuf, val);
231+
return true;
232+
}
233+
if (yyjson_is_arr(val))
234+
{
235+
ffStrbufClear(strbuf);
236+
yyjson_val *elem;
237+
size_t eidx, emax;
238+
yyjson_arr_foreach(val, eidx, emax, elem)
239+
{
240+
if (yyjson_is_str(elem))
241+
{
242+
if (strbuf->length > 0)
243+
ffStrbufAppendC(strbuf, separator);
244+
ffStrbufAppendJsonVal(strbuf, elem);
245+
}
246+
}
247+
return true;
248+
}
249+
return false;
250+
}
251+
226252
void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
227253
{
228254
yyjson_val *key, *val;
@@ -234,19 +260,19 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
234260

235261
if (unsafe_yyjson_equals_str(key, "folders"))
236262
{
237-
ffStrbufSetJsonVal(&options->folders, val);
263+
setSeparatedList(&options->folders, val, FF_DISK_FOLDER_SEPARATOR);
238264
continue;
239265
}
240266

241267
if (unsafe_yyjson_equals_str(key, "hideFolders"))
242268
{
243-
ffStrbufSetJsonVal(&options->hideFolders, val);
269+
setSeparatedList(&options->hideFolders, val, FF_DISK_FOLDER_SEPARATOR);
244270
continue;
245271
}
246272

247273
if (unsafe_yyjson_equals_str(key, "hideFS"))
248274
{
249-
ffStrbufSetJsonVal(&options->hideFS, val);
275+
setSeparatedList(&options->hideFS, val, ':');
250276
continue;
251277
}
252278

0 commit comments

Comments
 (0)