2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-08-26 16:02:04 +02:00
|
|
|
#include "common/parsing.h"
|
2022-10-18 22:55:28 +08:00
|
|
|
#include "common/bar.h"
|
2022-09-05 10:57:09 +02:00
|
|
|
#include "detection/memory/memory.h"
|
2022-06-18 14:25:31 +02:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_MEMORY_MODULE_NAME "Memory"
|
2022-08-26 16:02:04 +02:00
|
|
|
#define FF_MEMORY_NUM_FORMAT_ARGS 3
|
2021-04-15 18:59:26 +02:00
|
|
|
|
2023-05-11 20:39:54 +08:00
|
|
|
void ffPrintMemory(FFinstance* instance)
|
2022-10-18 23:46:42 +08:00
|
|
|
{
|
2023-05-11 20:39:54 +08:00
|
|
|
FFMemoryResult storage;
|
|
|
|
|
const char* error = ffDetectMemory(&storage);
|
2022-10-18 23:46:42 +08:00
|
|
|
|
2023-05-11 20:39:54 +08:00
|
|
|
if(error)
|
2021-04-15 18:59:26 +02:00
|
|
|
{
|
2023-05-11 20:39:54 +08:00
|
|
|
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "%s", error);
|
2021-04-15 18:59:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 15:29:54 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate();
|
2023-05-11 20:39:54 +08:00
|
|
|
ffParseSize(storage.bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
2022-08-26 16:02:04 +02:00
|
|
|
|
2023-04-15 15:29:54 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate();
|
2023-05-11 20:39:54 +08:00
|
|
|
ffParseSize(storage.bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
2022-08-26 16:02:04 +02:00
|
|
|
|
2023-05-11 20:39:54 +08:00
|
|
|
uint8_t percentage = storage.bytesTotal == 0
|
|
|
|
|
? 0
|
|
|
|
|
: (uint8_t) (((long double) storage.bytesUsed / (long double) storage.bytesTotal) * 100.0);
|
2022-10-18 23:46:42 +08:00
|
|
|
|
2023-05-11 20:39:54 +08:00
|
|
|
if(instance->config.memory.outputFormat.length == 0)
|
2021-03-19 20:57:07 +01:00
|
|
|
{
|
2023-05-11 20:39:54 +08:00
|
|
|
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
|
|
|
|
|
if (storage.bytesTotal == 0)
|
2022-09-21 15:21:51 +08:00
|
|
|
puts("Disabled");
|
|
|
|
|
else
|
2022-10-18 22:55:28 +08:00
|
|
|
{
|
2023-04-15 15:29:54 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
2022-10-18 22:55:28 +08:00
|
|
|
|
|
|
|
|
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
|
|
|
|
{
|
|
|
|
|
ffAppendPercentBar(instance, &str, percentage, 0, 5, 8);
|
|
|
|
|
ffStrbufAppendC(&str, ' ');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 22:41:11 +08:00
|
|
|
if(!(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
|
|
|
|
|
ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars);
|
2022-10-18 22:55:28 +08:00
|
|
|
|
|
|
|
|
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
2023-01-31 19:42:02 +08:00
|
|
|
ffAppendPercentNum(instance, &str, (uint8_t) percentage, 50, 80, str.length > 0);
|
2022-10-18 22:55:28 +08:00
|
|
|
|
2023-01-12 22:41:11 +08:00
|
|
|
ffStrbufTrimRight(&str, ' ');
|
2022-10-18 22:55:28 +08:00
|
|
|
ffStrbufPutTo(&str, stdout);
|
|
|
|
|
}
|
2021-03-19 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-05-11 20:39:54 +08:00
|
|
|
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2022-08-26 16:02:04 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
2022-10-18 23:46:42 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT8, &percentage},
|
2021-04-15 18:59:26 +02:00
|
|
|
});
|
2021-03-19 20:57:07 +01:00
|
|
|
}
|
2022-09-08 14:51:31 +02:00
|
|
|
}
|