From 952989c1e88297522d7361bfaa97f197aed1c899 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 23 Aug 2022 13:53:12 +0200 Subject: [PATCH] Show huge ram values in GiB #218 --- presets/verbose | 2 +- src/fastfetch.c | 12 ++++++++---- src/modules/disk.c | 2 +- src/modules/memory.c | 40 +++++++++++++++++++++++++++++++--------- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/presets/verbose b/presets/verbose index f859551c5..4ac51c653 100644 --- a/presets/verbose +++ b/presets/verbose @@ -20,7 +20,7 @@ --cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" --gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}; Temperature: {}" ---memory-format "Used: {}; Total: {}; Percentage: {}" +--memory-format "Percentage: {}; Used KiB: {}, Total KiB: {}, Used MiB: {}, Total MiB: {}, Used GiB: {}, Total GiB: {}" --disk-format "Used: {}; Total: {}; Files: {}; Percentage: {}" --battery-format "Manufactor: {}; Model: {}; Technology: {}; Capacaty: {}; Status: {}" --player-format "Name: {}" diff --git a/src/fastfetch.c b/src/fastfetch.c index a7a3634ed..88858a1f3 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -284,10 +284,14 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "memory-format") == 0) { - constructAndPrintCommandHelpFormat("memory", "{}MiB / {}MiB ({}%)", 3, - "Used memory", - "Total memory", - "Used memory percentage" + constructAndPrintCommandHelpFormat("memory", "{6}GiB / {7}GiB ({1}%)", 7, + "Percentage", + "Used KiB", + "Total KiB", + "Used MiB", + "Total MiB", + "Used GiB", + "Total GiB" ); } else if(strcasecmp(command, "disk-format") == 0) diff --git a/src/modules/disk.c b/src/modules/disk.c index 923293cb1..1794b63e3 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -43,7 +43,7 @@ static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs else printf("%.1f", used); - fputs(" GB / ", stdout); + fputs(" GiB / ", stdout); if(total >= 100.0) printf("%.0f", total); diff --git a/src/modules/memory.c b/src/modules/memory.c index cb0f09cbd..a3c063f63 100644 --- a/src/modules/memory.c +++ b/src/modules/memory.c @@ -4,7 +4,17 @@ #include #define FF_MEMORY_MODULE_NAME "Memory" -#define FF_MEMORY_NUM_FORMAT_ARGS 3 +#define FF_MEMORY_NUM_FORMAT_ARGS 7 + +static void printValue(uint32_t kib, double mib, double gib) +{ + if(gib >= 1.0) + printf("%.2f GiB", gib); + else if(mib >= 1.0) + printf("%.2f MiB", mib); + else + printf("%u KiB", kib); +} // Impl inspired by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544 void ffPrintMemory(FFinstance* instance) @@ -39,11 +49,16 @@ void ffPrintMemory(FFinstance* instance) fclose(meminfo); - uint32_t used_mem = (total + shared - memfree - buffers - cached - reclaimable) / 1024; - uint32_t total_mem = total / 1024; - uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100); + uint32_t used = total + shared - memfree - buffers - cached - reclaimable; + uint8_t percentage = (uint8_t) ((used / (double) total) * 100); - if(used_mem == 0 && total_mem == 0 && percentage == 0) + double usedMiB = used / 1024.0; + double totalMiB = total / 1024.0; + + double usedGiB = usedMiB / 1024.0; + double totalGiB = totalMiB / 1024.0; + + if(used == 0 && total == 0) { ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "/proc/meminfo could't be parsed"); return; @@ -52,14 +67,21 @@ void ffPrintMemory(FFinstance* instance) if(instance->config.memory.outputFormat.length == 0) { ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key); - printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage); + printValue(used, usedMiB, usedGiB); + fputs(" / ", stdout); + printValue(total, totalMiB, totalGiB); + printf(" (%u%%)\n", percentage); } else { ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &used_mem}, - {FF_FORMAT_ARG_TYPE_UINT, &total_mem}, - {FF_FORMAT_ARG_TYPE_UINT8, &percentage} + {FF_FORMAT_ARG_TYPE_UINT8, &percentage}, + {FF_FORMAT_ARG_TYPE_UINT, &total}, + {FF_FORMAT_ARG_TYPE_UINT, &used}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &usedMiB}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &totalMiB}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &usedGiB}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &totalGiB} }); } }