diff --git a/src/detection/icons/icons.h b/src/detection/icons/icons.h index 3e2096e09..f921270c6 100644 --- a/src/detection/icons/icons.h +++ b/src/detection/icons/icons.h @@ -2,4 +2,11 @@ #include "fastfetch.h" -const char* ffDetectIcons(FFstrbuf* result); +typedef struct FFIconsResult +{ + FFstrbuf icons1; + FFstrbuf icons2; +} FFIconsResult; + + +const char* ffDetectIcons(FFIconsResult* result); diff --git a/src/detection/icons/icons_linux.c b/src/detection/icons/icons_linux.c index 357cfadb6..d83b7ab7f 100644 --- a/src/detection/icons/icons_linux.c +++ b/src/detection/icons/icons_linux.c @@ -3,7 +3,7 @@ #include "detection/gtk_qt/gtk_qt.h" #include "detection/displayserver/displayserver.h" -const char* ffDetectIcons(FFstrbuf* result) +const char* ffDetectIcons(FFIconsResult* result) { const FFDisplayServerResult* wmde = ffConnectDisplayServer(); @@ -18,18 +18,13 @@ const char* ffDetectIcons(FFstrbuf* result) if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) return "No icons could be found"; - FF_STRBUF_AUTO_DESTROY gtkPretty = ffStrbufCreate(); - ffParseGTK(>kPretty, gtk2, gtk3, gtk4); + ffParseGTK(&result->icons2, gtk2, gtk3, gtk4); if(plasma->length > 0) { - ffStrbufAppend(result, plasma); - ffStrbufAppendS(result, " [QT]"); - - if(gtkPretty.length > 0) - ffStrbufAppendS(result, ", "); + ffStrbufAppend(&result->icons1, plasma); + ffStrbufAppendS(&result->icons1, " [QT]"); } - ffStrbufAppend(result, >kPretty); return NULL; } diff --git a/src/detection/icons/icons_nosupport.c b/src/detection/icons/icons_nosupport.c index f0a0ebe8c..da6ef936e 100644 --- a/src/detection/icons/icons_nosupport.c +++ b/src/detection/icons/icons_nosupport.c @@ -1,6 +1,6 @@ #include "icons.h" -const char* ffDetectIcons(FF_MAYBE_UNUSED FFstrbuf* result) +const char* ffDetectIcons(FF_MAYBE_UNUSED FFIconsResult* result) { return "Not supported on this platform"; } diff --git a/src/detection/icons/icons_windows.c b/src/detection/icons/icons_windows.c index 894e34465..dc5d36cf0 100644 --- a/src/detection/icons/icons_windows.c +++ b/src/detection/icons/icons_windows.c @@ -1,7 +1,7 @@ #include "icons.h" #include "util/windows/registry.h" -const char* ffDetectIcons(FFstrbuf* result) +const char* ffDetectIcons(FFIconsResult* result) { FF_HKEY_AUTO_DESTROY hKey = NULL; if(!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel", &hKey, NULL) && @@ -17,18 +17,20 @@ const char* ffDetectIcons(FFstrbuf* result) ffRegReadUint(hKey, L"{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", &ControlPanel, NULL); if (!ThisPC) - ffStrbufAppendS(result, "This PC, "); + ffStrbufAppendS(&result->icons1, "This PC, "); if (!UsersFiles) - ffStrbufAppendS(result, "User's Files, "); - if (!RemoteNetwork) - ffStrbufAppendS(result, "Remote Network, "); - if (!RecycleBin) - ffStrbufAppendS(result, "Recycle Bin, "); - if (!ControlPanel) - ffStrbufAppendS(result, "Control Panel"); + ffStrbufAppendS(&result->icons1, "User's Files"); + ffStrbufTrimRight(&result->icons1, ' '); + ffStrbufTrimRight(&result->icons1, ','); - ffStrbufTrimRight(result, ' '); - ffStrbufTrimRight(result, ','); + if (!RemoteNetwork) + ffStrbufAppendS(&result->icons2, "Remote Network, "); + if (!RecycleBin) + ffStrbufAppendS(&result->icons2, "Recycle Bin, "); + if (!ControlPanel) + ffStrbufAppendS(&result->icons2, "Control Panel"); + ffStrbufTrimRight(&result->icons2, ' '); + ffStrbufTrimRight(&result->icons2, ','); return NULL; } diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 722ddee1a..379a5d6a9 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -4,12 +4,15 @@ #include "modules/icons/icons.h" #include "util/stringUtils.h" -#define FF_ICONS_NUM_FORMAT_ARGS 1 +#define FF_ICONS_NUM_FORMAT_ARGS 2 void ffPrintIcons(FFIconsOptions* options) { - FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate(); - const char* error = ffDetectIcons(&icons); + FFIconsResult result = { + .icons1 = ffStrbufCreate(), + .icons2 = ffStrbufCreate(), + }; + const char* error = ffDetectIcons(&result); if(error) { @@ -20,12 +23,21 @@ void ffPrintIcons(FFIconsOptions* options) if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_ICONS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - ffStrbufPutTo(&icons, stdout); + if (result.icons1.length) + ffStrbufWriteTo(&result.icons1, stdout); + if (result.icons2.length) + { + if (result.icons1.length) + fputs(", ", stdout); + ffStrbufWriteTo(&result.icons2, stdout); + } + putchar('\n'); } else { FF_PRINT_FORMAT_CHECKED(FF_ICONS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_ICONS_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &icons, "combined"} + {FF_FORMAT_ARG_TYPE_STRBUF, &result.icons1, "icons1"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.icons2, "icons2"}, })); } } @@ -67,22 +79,28 @@ void ffGenerateIconsJsonConfig(FFIconsOptions* options, yyjson_mut_doc* doc, yyj void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { - FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate(); - const char* error = ffDetectIcons(&icons); + FFIconsResult result = { + .icons1 = ffStrbufCreate(), + .icons2 = ffStrbufCreate() + }; + const char* error = ffDetectIcons(&result); - if (error) + if(error) { yyjson_mut_obj_add_str(doc, module, "error", error); return; } - yyjson_mut_obj_add_strbuf(doc, module, "result", &icons); + yyjson_mut_val* icons = yyjson_mut_obj_add_obj(doc, module, "result"); + yyjson_mut_obj_add_strbuf(doc, icons, "icons1", &result.icons1); + yyjson_mut_obj_add_strbuf(doc, icons, "icons2", &result.icons2); } void ffPrintIconsHelpFormat(void) { - FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_ICONS_MODULE_NAME, "{1}", FF_ICONS_NUM_FORMAT_ARGS, ((const char* []) { - "Combined icons - combined" + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_ICONS_MODULE_NAME, "{1}, {2}", FF_ICONS_NUM_FORMAT_ARGS, ((const char* []) { + "Icons part 1 - icons1", + "Icons part 2 - icons2", })); }