From daabd44a9e97400157a636843969bac26d70b8bb Mon Sep 17 00:00:00 2001 From: LukeHuckman Date: Thu, 24 Jun 2021 03:24:43 +0800 Subject: [PATCH 1/5] RAM usage now uses correct units (MiB instead of MB), tweaked uptime to only show hours when relevant (>=1 hour). --- uwufetch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 6f30c62..ff8d6af 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -314,7 +314,7 @@ void print_info() // print ram to uptime and colors if (show_ram) - printf("\033[18C%s%sWAM %s%i MB/%i MB\n", + printf("\033[18C%s%sWAM %s%i MiB/%i MiB\n", NORMAL, BOLD, NORMAL, (ram_used), ram_total); if (show_resolution) if (screen_width != 0 || screen_height != 0) @@ -338,7 +338,10 @@ void print_info() #else uptime = sys.uptime; #endif - if (uptime / 3600 < 24) + if (uptime < 3600) + printf("\033[18C%s%sUWUPTIME %s%lim\n", + NORMAL, BOLD, NORMAL, uptime / 60 % 60); + else if (uptime / 3600 < 24) printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", NORMAL, BOLD, NORMAL, uptime / 3600, uptime / 60 % 60); else From b767645854aad36f1cd1764204e3553d1f330e77 Mon Sep 17 00:00:00 2001 From: LukeHuckman Date: Thu, 24 Jun 2021 03:46:22 +0800 Subject: [PATCH 2/5] Replaced ifs with a switch statement for printing uptime --- uwufetch.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index ff8d6af..ec852d2 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -338,15 +338,19 @@ void print_info() #else uptime = sys.uptime; #endif - if (uptime < 3600) - printf("\033[18C%s%sUWUPTIME %s%lim\n", + switch (uptime) { + case 0 ... 3599: + printf("\033[18C%s%sUWUPTIME %s%lim\n", NORMAL, BOLD, NORMAL, uptime / 60 % 60); - else if (uptime / 3600 < 24) - printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", + break; + case 3600 ... 86399: + printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", NORMAL, BOLD, NORMAL, uptime / 3600, uptime / 60 % 60); - else - printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n", + break; + default: + printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n", NORMAL, BOLD, NORMAL, uptime / 86400, uptime / 3600 % 24, uptime / 60 % 60); + } } if (show_colors) printf("\033[18C%s%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\n", From 9eb6df1eb44970479e9aa004272b92e77f1ebffc Mon Sep 17 00:00:00 2001 From: Darkpelz <45264354+LukeHuckman@users.noreply.github.com> Date: Thu, 24 Jun 2021 03:58:51 +0800 Subject: [PATCH 3/5] Update uwufetch.c --- uwufetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index ec852d2..5350433 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -462,10 +462,10 @@ void get_info() // free command prints like this: "Mem:" total used free shared buff/cache available if (sscanf(line, "Mem: %d %d", &ram_total, &ram_used)) { - // convert to megabytes + // convert to mebibytes if (ram_total > 0 && ram_used > 0) { - // data is in bytes + // data is in kibibytes ram_total /= 1024; ram_used /= 1024; break; From 8d53fe306e34baa09ef8d72be475842fc4f1e400 Mon Sep 17 00:00:00 2001 From: LukeHuckman Date: Thu, 24 Jun 2021 04:03:48 +0800 Subject: [PATCH 4/5] free already has an -m option to get value in mebibytes. Using that instead of calculating it in the code. --- uwufetch.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 5350433..f4ebbc7 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -456,21 +456,11 @@ void get_info() #ifndef __CYGWIN__ FILE *meminfo; - meminfo = popen("LANG=EN_us free 2> /dev/null", "r"); + meminfo = popen("LANG=EN_us free -m 2> /dev/null", "r"); while (fgets(line, sizeof(line), meminfo)) { // free command prints like this: "Mem:" total used free shared buff/cache available - if (sscanf(line, "Mem: %d %d", &ram_total, &ram_used)) - { - // convert to mebibytes - if (ram_total > 0 && ram_used > 0) - { - // data is in kibibytes - ram_total /= 1024; - ram_used /= 1024; - break; - } - } + sscanf(line, "Mem: %d %d", &ram_total, &ram_used); } fclose(meminfo); #else From fd1b9e6cfc22823d980b434f9908d20f2565972a Mon Sep 17 00:00:00 2001 From: LukeHuckman Date: Thu, 24 Jun 2021 04:17:28 +0800 Subject: [PATCH 5/5] Code cleanup --- uwufetch.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index f4ebbc7..0395be0 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -338,7 +338,8 @@ void print_info() #else uptime = sys.uptime; #endif - switch (uptime) { + switch (uptime) + { case 0 ... 3599: printf("\033[18C%s%sUWUPTIME %s%lim\n", NORMAL, BOLD, NORMAL, uptime / 60 % 60); @@ -458,10 +459,8 @@ void get_info() meminfo = popen("LANG=EN_us free -m 2> /dev/null", "r"); while (fgets(line, sizeof(line), meminfo)) - { // free command prints like this: "Mem:" total used free shared buff/cache available sscanf(line, "Mem: %d %d", &ram_total, &ram_used); - } fclose(meminfo); #else //wmic OS get FreePhysicalMemory