mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
Processes: add support for Windows
This commit is contained in:
+10
-23
@@ -1,47 +1,34 @@
|
||||
#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
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
void ffPrintProcesses(FFinstance* instance)
|
||||
{
|
||||
#if __APPLE__
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
size_t length;
|
||||
FFstrbuf error;
|
||||
ffStrbufInit(&error);
|
||||
uint32_t numProcesses = ffDetectProcesses(instance, &error);
|
||||
|
||||
if(sysctl(request, sizeof(request) / sizeof(*request), NULL, &length, NULL, 0) != 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "sysctl() failed");
|
||||
return;
|
||||
}
|
||||
uint16_t numProcesses = (uint16_t)(length / sizeof(struct kinfo_proc));
|
||||
#elif FF_HAVE_SYSINFO_H
|
||||
uint16_t numProcesses = (uint16_t) instance->state.sysinfo.procs;
|
||||
#else
|
||||
uint16_t numProcesses = 0;
|
||||
#endif
|
||||
|
||||
if(numProcesses == 0)
|
||||
if(error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "Could not get number of processes");
|
||||
ffPrintError(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, "%*s", error.length, error.chars);
|
||||
ffStrbufDestroy(&error);
|
||||
return;
|
||||
}
|
||||
ffStrbufDestroy(&error);
|
||||
|
||||
if(instance->config.processes.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes.key);
|
||||
|
||||
printf("%hu\n", numProcesses);
|
||||
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_UINT16, &numProcesses}
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &numProcesses}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user