From ef3989d18d641572bb13bd7435b6b39712bf5e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 19 Sep 2025 14:51:31 +0800 Subject: [PATCH] CommandOption: refactors code with `ffStrbufSeparatedContainIgnCaseS` --- src/common/commandoption.c | 33 +++++++++++++-------------------- src/fastfetch.c | 5 +++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index a419a7867..626a1c06f 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -71,42 +71,35 @@ bool ffParseModuleOptions(const char* key, const char* value) void ffPrepareCommandOption(FFdata* data) { - //If we don't have a custom structure, use the default one - if(data->structure.length == 0) - ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string - - if(ffStrbufContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME)) + if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME, ':')) ffPrepareCPUUsage(); - if(ffStrbufContainIgnCaseS(&data->structure, FF_DISKIO_MODULE_NAME)) + if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_DISKIO_MODULE_NAME, ':')) { __attribute__((__cleanup__(ffDestroyDiskIOOptions))) FFDiskIOOptions options; ffInitDiskIOOptions(&options); ffPrepareDiskIO(&options); } - if(ffStrbufContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME)) + if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME, ':')) { __attribute__((__cleanup__(ffDestroyNetIOOptions))) FFNetIOOptions options; ffInitNetIOOptions(&options); ffPrepareNetIO(&options); } - if(instance.config.general.multithreading) + if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME, ':')) { - if(ffStrbufContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME)) - { - __attribute__((__cleanup__(ffDestroyPublicIpOptions))) FFPublicIPOptions options; - ffInitPublicIpOptions(&options); - ffPreparePublicIp(&options); - } + __attribute__((__cleanup__(ffDestroyPublicIpOptions))) FFPublicIPOptions options; + ffInitPublicIpOptions(&options); + ffPreparePublicIp(&options); + } - if(ffStrbufContainIgnCaseS(&data->structure, FF_WEATHER_MODULE_NAME)) - { - __attribute__((__cleanup__(ffDestroyWeatherOptions))) FFWeatherOptions options; - ffInitWeatherOptions(&options); - ffPrepareWeather(&options); - } + if(ffStrbufSeparatedContainIgnCaseS(&data->structure, FF_WEATHER_MODULE_NAME, ':')) + { + __attribute__((__cleanup__(ffDestroyWeatherOptions))) FFWeatherOptions options; + ffInitWeatherOptions(&options); + ffPrepareWeather(&options); } } diff --git a/src/fastfetch.c b/src/fastfetch.c index 961af21f9..d92760d0d 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -749,7 +749,12 @@ static void run(FFdata* data) if (useJsonConfig) ffPrintJsonConfig(true /* prepare */, instance.state.resultDoc); else + { + //If we don't have a custom structure, use the default one + if(data->structure.length == 0) + ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); // Cannot use `ffStrbufSetStatic` here because we will modify the string ffPrepareCommandOption(data); + } ffStart();