Merge pull request #105 from LukeHuckman/main

Corrected wrong units and tweaked uptime display
This commit is contained in:
TheDarkBug 2021-06-24 13:39:29 +02:00 committed by GitHub
commit 9e32e5011c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -314,7 +314,7 @@ void print_info()
// print ram to uptime and colors // print ram to uptime and colors
if (show_ram) 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); NORMAL, BOLD, NORMAL, (ram_used), ram_total);
if (show_resolution) if (show_resolution)
if (screen_width != 0 || screen_height != 0) if (screen_width != 0 || screen_height != 0)
@ -338,13 +338,21 @@ void print_info()
#else #else
uptime = sys.uptime; uptime = sys.uptime;
#endif #endif
if (uptime / 3600 < 24) switch (uptime)
{
case 0 ... 3599:
printf("\033[18C%s%sUWUPTIME %s%lim\n",
NORMAL, BOLD, NORMAL, uptime / 60 % 60);
break;
case 3600 ... 86399:
printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n",
NORMAL, BOLD, NORMAL, uptime / 3600, uptime / 60 % 60); NORMAL, BOLD, NORMAL, uptime / 3600, uptime / 60 % 60);
else break;
default:
printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n", printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n",
NORMAL, BOLD, NORMAL, uptime / 86400, uptime / 3600 % 24, uptime / 60 % 60); NORMAL, BOLD, NORMAL, uptime / 86400, uptime / 3600 % 24, uptime / 60 % 60);
} }
}
if (show_colors) 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", 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",
BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL); BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL);
@ -449,22 +457,10 @@ void get_info()
#ifndef __CYGWIN__ #ifndef __CYGWIN__
FILE *meminfo; 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)) while (fgets(line, sizeof(line), meminfo))
{
// free command prints like this: "Mem:" total used free shared buff/cache available // free command prints like this: "Mem:" total used free shared buff/cache available
if (sscanf(line, "Mem: %d %d", &ram_total, &ram_used)) sscanf(line, "Mem: %d %d", &ram_total, &ram_used);
{
// convert to megabytes
if (ram_total > 0 && ram_used > 0)
{
// data is in bytes
ram_total /= 1024;
ram_used /= 1024;
break;
}
}
}
fclose(meminfo); fclose(meminfo);
#else #else
//wmic OS get FreePhysicalMemory //wmic OS get FreePhysicalMemory