mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Processes: add new module
This commit is contained in:
@@ -98,6 +98,7 @@ set(SRCS
|
||||
src/modules/host.c
|
||||
src/modules/kernel.c
|
||||
src/modules/uptime.c
|
||||
src/modules/processes.c
|
||||
src/modules/packages.c
|
||||
src/modules/shell.c
|
||||
src/modules/resolution.c
|
||||
|
||||
@@ -145,6 +145,8 @@ __fastfetch_completion()
|
||||
"--kernel-key"
|
||||
"--uptime-format"
|
||||
"--uptime-key"
|
||||
"--processes-format"
|
||||
"--processes-key"
|
||||
"--packages-format"
|
||||
"--packages-key"
|
||||
"--shell-format"
|
||||
|
||||
@@ -6,6 +6,8 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg)
|
||||
ffStrbufAppendF(buffer, "%i", *(int*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_UINT)
|
||||
ffStrbufAppendF(buffer, "%u", *(uint32_t*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_UINT16)
|
||||
ffStrbufAppendF(buffer, "%hu", *(uint16_t*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_UINT8)
|
||||
ffStrbufAppendF(buffer, "%hhu", *(uint8_t*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_STRING)
|
||||
@@ -74,6 +76,7 @@ static inline bool formatArgSet(const FFformatarg* arg)
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_STRING && *(const char*)arg->value != '\0') ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_UINT8 && *(uint8_t*)arg->value > 0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_UINT16 && *(uint16_t*)arg->value > 0) ||
|
||||
(arg->type == FF_FORMAT_ARG_TYPE_UINT && *(uint32_t*)arg->value > 0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,6 +129,8 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInitA(&instance->config.kernelKey, 1);
|
||||
ffStrbufInitA(&instance->config.uptimeFormat, 1);
|
||||
ffStrbufInitA(&instance->config.uptimeKey, 1);
|
||||
ffStrbufInitA(&instance->config.processesFormat, 1);
|
||||
ffStrbufInitA(&instance->config.processesKey, 1);
|
||||
ffStrbufInitA(&instance->config.packagesFormat, 1);
|
||||
ffStrbufInitA(&instance->config.packagesKey, 1);
|
||||
ffStrbufInitA(&instance->config.shellFormat, 1);
|
||||
|
||||
@@ -71,6 +71,7 @@ static inline void printHelp()
|
||||
" --host-format <format>\n"
|
||||
" --kernel-format <format>\n"
|
||||
" --uptime-format <format>\n"
|
||||
" --processes-format <format>\n"
|
||||
" --packages-format <format>\n"
|
||||
" --shell-format <format>\n"
|
||||
" --resolution-format <format>\n"
|
||||
@@ -96,6 +97,7 @@ static inline void printHelp()
|
||||
" --host-key <key>\n"
|
||||
" --kernel-key <key>\n"
|
||||
" --uptime-key <key>\n"
|
||||
" --processes-key <key>\n"
|
||||
" --packages-key <key>\n"
|
||||
" --shell-key <key>\n"
|
||||
" --resolution-key <key>: takes the resolution index as argument\n"
|
||||
@@ -286,6 +288,12 @@ static inline void printCommandHelp(const char* command)
|
||||
"Seconds"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "processes-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("processes", "{}", 1,
|
||||
"Count"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "packages-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (xps), {7}, (flatpak), {8} (snap)", 8,
|
||||
@@ -501,6 +509,7 @@ static inline void printAvailableModules()
|
||||
"Memory\n"
|
||||
"OS\n"
|
||||
"Packages\n"
|
||||
"Processes\n"
|
||||
"Resolution\n"
|
||||
"Separator\n"
|
||||
"Shell\n"
|
||||
@@ -848,6 +857,10 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.uptimeFormat);
|
||||
else if(strcasecmp(key, "--uptime-key") == 0)
|
||||
optionParseString(key, value, &instance->config.uptimeKey);
|
||||
else if(strcasecmp(key, "--processes-format") == 0)
|
||||
optionParseString(key, value, &instance->config.processesFormat);
|
||||
else if(strcasecmp(key, "--processes-key") == 0)
|
||||
optionParseString(key, value, &instance->config.processesKey);
|
||||
else if(strcasecmp(key, "--packages-format") == 0)
|
||||
optionParseString(key, value, &instance->config.packagesFormat);
|
||||
else if(strcasecmp(key, "--packages-key") == 0)
|
||||
@@ -1043,6 +1056,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintKernel(instance);
|
||||
else if(strcasecmp(line, "uptime") == 0)
|
||||
ffPrintUptime(instance);
|
||||
else if(strcasecmp(line, "processes") == 0)
|
||||
ffPrintProcesses(instance);
|
||||
else if(strcasecmp(line, "packages") == 0)
|
||||
ffPrintPackages(instance);
|
||||
else if(strcasecmp(line, "shell") == 0)
|
||||
|
||||
@@ -55,6 +55,8 @@ typedef struct FFconfig
|
||||
FFstrbuf kernelKey;
|
||||
FFstrbuf uptimeFormat;
|
||||
FFstrbuf uptimeKey;
|
||||
FFstrbuf processesFormat;
|
||||
FFstrbuf processesKey;
|
||||
FFstrbuf packagesFormat;
|
||||
FFstrbuf packagesKey;
|
||||
FFstrbuf shellFormat;
|
||||
@@ -202,6 +204,7 @@ typedef enum FFformatargtype
|
||||
{
|
||||
FF_FORMAT_ARG_TYPE_NULL = 0,
|
||||
FF_FORMAT_ARG_TYPE_UINT,
|
||||
FF_FORMAT_ARG_TYPE_UINT16,
|
||||
FF_FORMAT_ARG_TYPE_UINT8,
|
||||
FF_FORMAT_ARG_TYPE_INT,
|
||||
FF_FORMAT_ARG_TYPE_STRING,
|
||||
@@ -368,6 +371,7 @@ void ffPrintOS(FFinstance* instance);
|
||||
void ffPrintHost(FFinstance* instance);
|
||||
void ffPrintKernel(FFinstance* instance);
|
||||
void ffPrintUptime(FFinstance* instance);
|
||||
void ffPrintProcesses(FFinstance* instance);
|
||||
void ffPrintPackages(FFinstance* instance);
|
||||
void ffPrintShell(FFinstance* instance);
|
||||
void ffPrintResolution(FFinstance* instance);
|
||||
|
||||
@@ -26,6 +26,7 @@ int main(int argc, char** argv)
|
||||
ffPrintHost(&instance);
|
||||
ffPrintKernel(&instance);
|
||||
ffPrintUptime(&instance);
|
||||
ffPrintProcesses(&instance);
|
||||
ffPrintPackages(&instance);
|
||||
ffPrintShell(&instance);
|
||||
ffPrintResolution(&instance);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_PROCESSES_MODULE_NAME "Processes"
|
||||
#define FF_PROCESSES_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance)
|
||||
{
|
||||
if(instance->config.processesFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey);
|
||||
|
||||
printf("%hu\n", instance->state.sysinfo.procs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey, &instance->config.processesFormat, NULL, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT16, &instance->state.sysinfo.procs}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
void ffPrintUptime(FFinstance* instance)
|
||||
{
|
||||
uint32_t days = instance->state.sysinfo.uptime / 86400;
|
||||
uint32_t hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
|
||||
uint32_t hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
|
||||
uint32_t minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
|
||||
uint32_t seconds = instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user