mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Processes: add JSON config
This commit is contained in:
+1
-1
@@ -291,7 +291,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/opengl/opengl.c
|
||||
src/modules/os/os.c
|
||||
src/modules/packages/packages.c
|
||||
src/modules/processes.c
|
||||
src/modules/processes/processes.c
|
||||
src/modules/player/player.c
|
||||
src/modules/poweradapter/poweradapter.c
|
||||
src/modules/publicip/publicip.c
|
||||
|
||||
+2
-16
@@ -28,13 +28,6 @@ static void initState(FFstate* state)
|
||||
ffPlatformInit(&state->platform);
|
||||
}
|
||||
|
||||
static void initModuleArg(FFModuleArgs* args)
|
||||
{
|
||||
ffStrbufInit(&args->key);
|
||||
ffStrbufInit(&args->outputFormat);
|
||||
ffStrbufInit(&args->errorFormat);
|
||||
}
|
||||
|
||||
static void defaultConfig(FFinstance* instance)
|
||||
{
|
||||
ffInitLogoOptions(&instance->config.logo);
|
||||
@@ -67,7 +60,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffInitCustomOptions(&instance->config.custom);
|
||||
ffInitKernelOptions(&instance->config.kernel);
|
||||
ffInitUptimeOptions(&instance->config.uptime);
|
||||
initModuleArg(&instance->config.processes);
|
||||
ffInitProcessesOptions(&instance->config.processes);
|
||||
ffInitPackagesOptions(&instance->config.packages);
|
||||
ffInitShellOptions(&instance->config.shell);
|
||||
ffInitDisplayOptions(&instance->config.display);
|
||||
@@ -252,13 +245,6 @@ void ffFinish(FFinstance* instance)
|
||||
resetConsole();
|
||||
}
|
||||
|
||||
static void destroyModuleArg(FFModuleArgs* args)
|
||||
{
|
||||
ffStrbufDestroy(&args->key);
|
||||
ffStrbufDestroy(&args->outputFormat);
|
||||
ffStrbufDestroy(&args->errorFormat);
|
||||
}
|
||||
|
||||
static void destroyConfig(FFinstance* instance)
|
||||
{
|
||||
ffDestroyLogoOptions(&instance->config.logo);
|
||||
@@ -278,7 +264,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
ffDestroyCustomOptions(&instance->config.custom);
|
||||
ffDestroyKernelOptions(&instance->config.kernel);
|
||||
ffDestroyUptimeOptions(&instance->config.uptime);
|
||||
destroyModuleArg(&instance->config.processes);
|
||||
ffDestroyProcessesOptions(&instance->config.processes);
|
||||
ffDestroyPackagesOptions(&instance->config.packages);
|
||||
ffDestroyShellOptions(&instance->config.shell);
|
||||
ffDestroyDisplayOptions(&instance->config.display);
|
||||
|
||||
+3
-37
@@ -746,40 +746,6 @@ static void optionParseEnum(const char* argumentKey, const char* requestedKey, v
|
||||
exit(478);
|
||||
}
|
||||
|
||||
static bool optionParseModuleArgs(const char* argumentKey, const char* value, const char* moduleName, struct FFModuleArgs* result)
|
||||
{
|
||||
const char* pkey = argumentKey;
|
||||
if(!(pkey[0] == '-' && pkey[1] == '-'))
|
||||
return false;
|
||||
|
||||
pkey += 2;
|
||||
uint32_t moduleNameLen = (uint32_t)strlen(moduleName);
|
||||
if(strncasecmp(pkey, moduleName, moduleNameLen) != 0)
|
||||
return false;
|
||||
|
||||
pkey += moduleNameLen;
|
||||
if(pkey[0] != '-')
|
||||
return false;
|
||||
|
||||
pkey += 1;
|
||||
if(strcasecmp(pkey, "key") == 0)
|
||||
{
|
||||
optionParseString(argumentKey, value, &result->key);
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(pkey, "format") == 0)
|
||||
{
|
||||
optionParseString(argumentKey, value, &result->outputFormat);
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(pkey, "error") == 0)
|
||||
{
|
||||
optionParseString(argumentKey, value, &result->errorFormat);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
|
||||
{
|
||||
///////////////////////
|
||||
@@ -983,7 +949,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(ffParseCustomCommandOptions(&instance->config.custom, key, value)) {}
|
||||
else if(ffParseKernelCommandOptions(&instance->config.kernel, key, value)) {}
|
||||
else if(ffParseUptimeCommandOptions(&instance->config.uptime, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "processes", &instance->config.processes)) {}
|
||||
else if(ffParseProcessesCommandOptions(&instance->config.processes, key, value)) {}
|
||||
else if(ffParsePackagesCommandOptions(&instance->config.packages, key, value)) {}
|
||||
else if(ffParseShellCommandOptions(&instance->config.shell, key, value)) {}
|
||||
else if(ffParseDisplayCommandOptions(&instance->config.display, key, value)) {}
|
||||
@@ -1162,8 +1128,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintChassis(instance, &instance->config.chassis);
|
||||
else if(strcasecmp(line, FF_KERNEL_MODULE_NAME) == 0)
|
||||
ffPrintKernel(instance, &instance->config.kernel);
|
||||
else if(strcasecmp(line, "processes") == 0)
|
||||
ffPrintProcesses(instance);
|
||||
else if(strcasecmp(line, FF_PROCESSES_MODULE_NAME) == 0)
|
||||
ffPrintProcesses(instance, &instance->config.processes);
|
||||
else if(strcasecmp(line, FF_UPTIME_MODULE_NAME) == 0)
|
||||
ffPrintUptime(instance, &instance->config.uptime);
|
||||
else if(strcasecmp(line, FF_PACKAGES_MODULE_NAME) == 0)
|
||||
|
||||
+1
-9
@@ -57,7 +57,7 @@ typedef struct FFconfig
|
||||
FFCommandOptions command;
|
||||
FFKernelOptions kernel;
|
||||
FFUptimeOptions uptime;
|
||||
FFModuleArgs processes;
|
||||
FFProcessesOptions processes;
|
||||
FFPackagesOptions packages;
|
||||
FFShellOptions shell;
|
||||
FFDisplayOptions display;
|
||||
@@ -168,12 +168,4 @@ void ffLogoBuiltinPrint(FFinstance* instance);
|
||||
void ffLogoBuiltinList();
|
||||
void ffLogoBuiltinListAutocompletion();
|
||||
|
||||
//////////////////////
|
||||
// Module functions //
|
||||
//////////////////////
|
||||
|
||||
//Printing
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ int main(int argc, char** argv)
|
||||
//ffPrintBoard(&instance, &instance.config.board);
|
||||
//ffPrintChassis(&instance, &instance.config.chassis);
|
||||
ffPrintKernel(&instance, &instance.config.kernel);
|
||||
//ffPrintProcesses(&instance);
|
||||
//ffPrintProcesses(&instance, &instance.config.processes);
|
||||
ffPrintUptime(&instance, &instance.config.uptime);
|
||||
ffPrintPackages(&instance, &instance.config.packages);
|
||||
ffPrintShell(&instance, &instance.config.shell);
|
||||
|
||||
@@ -116,6 +116,7 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
tryModule(instance, type, module, FF_PACKAGES_MODULE_NAME, ffParsePackagesJsonObject) ||
|
||||
tryModule(instance, type, module, FF_PLAYER_MODULE_NAME, ffParsePlayerJsonObject) ||
|
||||
tryModule(instance, type, module, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterJsonObject) ||
|
||||
tryModule(instance, type, module, FF_PROCESSES_MODULE_NAME, ffParseProcessesJsonObject) ||
|
||||
tryModule(instance, type, module, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "modules/packages/packages.h"
|
||||
#include "modules/player/player.h"
|
||||
#include "modules/poweradapter/poweradapter.h"
|
||||
#include "modules/processes/processes.h"
|
||||
#include "modules/publicip/publicip.h"
|
||||
#include "modules/separator/separator.h"
|
||||
#include "modules/shell/shell.h"
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "modules/packages/option.h"
|
||||
#include "modules/player/option.h"
|
||||
#include "modules/poweradapter/option.h"
|
||||
#include "modules/processes/option.h"
|
||||
#include "modules/publicip/option.h"
|
||||
#include "modules/separator/option.h"
|
||||
#include "modules/shell/option.h"
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/processes/processes.h"
|
||||
|
||||
#define FF_PROCESSES_MODULE_NAME "Processes"
|
||||
#define FF_PROCESSES_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance)
|
||||
{
|
||||
uint32_t numProcesses = 0;
|
||||
const char* error = ffDetectProcesses(&numProcesses);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.processes.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes.key);
|
||||
|
||||
printf("%u\n", numProcesses);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &numProcesses}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFProcessesOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFProcessesOptions;
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/processes/processes.h"
|
||||
#include "modules/processes/processes.h"
|
||||
|
||||
#define FF_PROCESSES_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance, FFProcessesOptions* options)
|
||||
{
|
||||
uint32_t numProcesses = 0;
|
||||
const char* error = ffDetectProcesses(&numProcesses);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
printf("%u\n", numProcesses);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_PROCESSES_MODULE_NAME, 0, &options->moduleArgs, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &numProcesses}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitProcessesOptions(FFProcessesOptions* options)
|
||||
{
|
||||
options->moduleName = FF_PROCESSES_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_PROCESSES_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyProcessesOptions(FFProcessesOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseProcessesJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFProcessesOptions __attribute__((__cleanup__(ffDestroyProcessesOptions))) options;
|
||||
ffInitProcessesOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintProcesses(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_PROCESSES_MODULE_NAME "Processes"
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance, FFProcessesOptions* options);
|
||||
void ffInitProcessesOptions(FFProcessesOptions* options);
|
||||
bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key, const char* value);
|
||||
void ffDestroyProcessesOptions(FFProcessesOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseProcessesJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user