Disk: allows array input for disk folder and filesystem options

This commit is contained in:
李通洲
2025-09-18 14:51:00 +08:00
parent 2c22c3b0c0
commit f0e9caaf04
4 changed files with 85 additions and 16 deletions
+49 -6
View File
@@ -2307,17 +2307,60 @@
"const": "disk"
},
"folders": {
"type": "string",
"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"
"description": "A list of folder paths for the disk output\nDefault: auto detection using mount-points\nThis option overrides other `show*` options",
"oneOf": [
{
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to get disk usage from",
"default": "/"
},
{
"type": "array",
"description": "An array of folder paths to get disk usage from",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
]
},
"hideFolders": {
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output",
"description": "A list of folder paths to hide from the disk output",
"oneOf": [
{
"type": "string",
"description": "A colon (semicolon on Windows) separated list of folder paths to hide from the disk output"
},
{
"type": "array",
"description": "An array of folder paths to hide from the disk output",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
],
"default": "/efi:/boot:/boot/efi:/boot/firmware"
},
"hideFS": {
"type": "string",
"description": "A colon separated file systems to hide from the disk output"
"description": "A list of file systems to hide from the disk output",
"oneOf": [
{
"type": "string",
"description": "A colon separated list of file systems to hide from the disk output"
},
{
"type": "array",
"description": "An array of file systems to hide from the disk output",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
]
},
"showRegular": {
"type": "boolean",
+1 -7
View File
@@ -2,18 +2,12 @@
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
{
#ifdef _WIN32
const char separator = ';';
#else
const char separator = ':';
#endif
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
uint32_t startIndex = 0;
while(startIndex < folders->length)
{
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, FF_DISK_FOLDER_SEPARATOR);
uint32_t folderLength = colonIndex - startIndex;
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)
+6
View File
@@ -3,6 +3,12 @@
#include "fastfetch.h"
#include "modules/disk/option.h"
#ifdef _WIN32
#define FF_DISK_FOLDER_SEPARATOR ';'
#else
#define FF_DISK_FOLDER_SEPARATOR ':'
#endif
typedef struct FFDisk
{
FFstrbuf mountFrom;
+29 -3
View File
@@ -223,6 +223,32 @@ bool ffPrintDisk(FFDiskOptions* options)
return true;
}
static bool setSeparatedList(FFstrbuf* strbuf, yyjson_val* val, char separator)
{
if (yyjson_is_str(val))
{
ffStrbufSetJsonVal(strbuf, val);
return true;
}
if (yyjson_is_arr(val))
{
ffStrbufClear(strbuf);
yyjson_val *elem;
size_t eidx, emax;
yyjson_arr_foreach(val, eidx, emax, elem)
{
if (yyjson_is_str(elem))
{
if (strbuf->length > 0)
ffStrbufAppendC(strbuf, separator);
ffStrbufAppendJsonVal(strbuf, elem);
}
}
return true;
}
return false;
}
void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
{
yyjson_val *key, *val;
@@ -234,19 +260,19 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
if (unsafe_yyjson_equals_str(key, "folders"))
{
ffStrbufSetJsonVal(&options->folders, val);
setSeparatedList(&options->folders, val, FF_DISK_FOLDER_SEPARATOR);
continue;
}
if (unsafe_yyjson_equals_str(key, "hideFolders"))
{
ffStrbufSetJsonVal(&options->hideFolders, val);
setSeparatedList(&options->hideFolders, val, FF_DISK_FOLDER_SEPARATOR);
continue;
}
if (unsafe_yyjson_equals_str(key, "hideFS"))
{
ffStrbufSetJsonVal(&options->hideFS, val);
setSeparatedList(&options->hideFS, val, ':');
continue;
}