mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
+24
-12
@@ -4,40 +4,52 @@
|
||||
#include "detection/memory/memory.h"
|
||||
|
||||
#define FF_MEMORY_MODULE_NAME "Memory"
|
||||
#define FF_SWAP_MODULE_NAME "Swap"
|
||||
|
||||
#define FF_MEMORY_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintMemory(FFinstance* instance)
|
||||
static void printMemory(FFinstance* instance, const char* name, const FFModuleArgs* moduleArgs, const FFMemoryStorage* storage)
|
||||
{
|
||||
const FFMemoryResult* memory = ffDetectMemory();
|
||||
|
||||
if(memory->bytesUsed == 0 && memory->bytesTotal == 0)
|
||||
if(storage->bytesUsed == 0 && storage->bytesTotal == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "Failed to detect memory");
|
||||
ffPrintError(instance, name, 0, moduleArgs, "Failed to detect memory");
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf usedPretty;
|
||||
ffStrbufInit(&usedPretty);
|
||||
ffParseSize(memory->bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
||||
ffParseSize(storage->bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
||||
|
||||
FFstrbuf totalPretty;
|
||||
ffStrbufInit(&totalPretty);
|
||||
ffParseSize(memory->bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
ffParseSize(storage->bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
|
||||
if(instance->config.memory.outputFormat.length == 0)
|
||||
if(moduleArgs->outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
|
||||
printf("%s / %s (%u%%)\n", usedPretty.chars, totalPretty.chars, memory->percentage);
|
||||
ffPrintLogoAndKey(instance, name, 0, &moduleArgs->key);
|
||||
printf("%s / %s (%u%%)\n", usedPretty.chars, totalPretty.chars, storage->percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
ffPrintFormat(instance, name, 0, moduleArgs, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &memory->percentage},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &storage->percentage},
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&usedPretty);
|
||||
ffStrbufDestroy(&totalPretty);
|
||||
}
|
||||
|
||||
void ffPrintMemory(FFinstance* instance)
|
||||
{
|
||||
const FFMemoryResult* memory = ffDetectMemory();
|
||||
printMemory(instance, FF_MEMORY_MODULE_NAME, &instance->config.memory, &memory->ram);
|
||||
}
|
||||
|
||||
void ffPrintSwap(FFinstance* instance)
|
||||
{
|
||||
const FFMemoryResult* memory = ffDetectMemory();
|
||||
printMemory(instance, FF_SWAP_MODULE_NAME, &instance->config.swap, &memory->swap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user