Skip to content

Commit

Permalink
Merge pull request #36 better cpu info and colorful output
Browse files Browse the repository at this point in the history
better cpu info and colorful output
  • Loading branch information
git-user-cpp authored Feb 11, 2024
2 parents 4a94ebf + 6342694 commit b1dfbdb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 56 deletions.
35 changes: 10 additions & 25 deletions src/cpu/cpu_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,44 @@

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "cpu_info.h"

void print_cpu_info(void)
{
FILE *cpu_file;

printf(" ____________\n\
printf("\033[036m ____________\n\
|\n\
| CPU Info:\n\
|____________\n\
|\n");
|\033[0m\n");

cpu_file = fopen("/proc/cpuinfo", "r");
if (cpu_file) {
char line[128];
uint8_t lines = 0;

while (fgets(line, sizeof(line), cpu_file) && lines < 19) {
printf("| %s", line);
++lines;
}

fclose(cpu_file);

printf("|____________\n\n");
} else {
printf("Error opening /proc/cpuinfo\n");
}
system("lscpu");
printf("\033[036m|____________\033[0m\n\n");
}

void print_full_cpu_info(void)
{
FILE *cpu_file;

printf(" ____________\n\
printf("\033[036m ____________\n\
|\n\
| Full CPU Info:\n\
|____________\n\
|\n");
|\033[0m\n");

cpu_file = fopen("/proc/cpuinfo", "r");
if (cpu_file) {
char line[128];

while (fgets(line, sizeof(line), cpu_file)) {
printf("| %s", line);
printf("\033[036m|\033[0m %s", line);
}

fclose(cpu_file);

printf("|____________\n\n");
printf("\033[036m|____________\033[0m\n\n");
} else {
printf("Error opening /proc/cpuinfo\n");
printf("\033[031mError opening /proc/cpuinfo\033[0m\n");
}
}

8 changes: 4 additions & 4 deletions src/hlp/hlp_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,26 @@ void print_hlp_info(void)
print_banner();
printf("\033[36mSpynix is a commandline tool for gathering info about \
hardware.\033[0m\n\n\
\t\tInfo:\n\
\t\t\033[033mInfo:\033[0m\n\
\t\t\t-h or --help \t\t- show this menu\n\
\t\t\t-v or --version \t- show version\n\
\t\t\t-b or --banner \t\t- show ASCII banner\n\
\t\t\t-l or --logo \t\t- show ASCII logo\n\n");
printf("\t\tOptions:\n\
printf("\t\t\033[033mOptions:\033[0m\n\
\t\t\t-a or --all \t- show summary info about system, cpu, ram and rom\n\
\t\t\t-sys \t\t- show system info\n\
\t\t\t-cpu \t\t- show short Central Processing Unit info\n\
\t\t\t-ram \t\t- show Random Access Memory info\n\
\t\t\t-rom \t\t- show Read Only Memory info\n\
\t\t\t-net \t\t- show network info\n\n\
\t\tAdvanced:\n\
\t\t\033[033mAdvanced:\033[0m\n\
\t\t-cpu -f or -cpu --full \t- show full Central Processing Unit info\n");
}

void print_ver_info(void)
{
print_banner();
printf("spynix v4.1.3\n\nFor more info visit: \
printf("spynix v4.2.0\n\nFor more info visit: \
\033[36mhttps://github.com/git-user-cpp/spynix\033[0m\n");
}

3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ int main(int argc, char **argv)
} else if (strcmp(argv[1], "-net") == 0) {
char host_name[30];

printf("Enter a hostname or IP address: ");
printf("\033[036m ____________\n|\n\
|\033[0m\033[033m Enter a hostname or IP address:\033[0m ");
fgets(host_name, sizeof(host_name), stdin);
host_name[strcspn(host_name, "\n")] = '\0';

Expand Down
15 changes: 9 additions & 6 deletions src/net/net_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ void print_net_info(const char *hostname)
uint8_t i;

if (host == NULL) {
perror("gethostbyname");
perror("\033[036m|\033[0m \033[031mgethostbyname\033[0m");
printf("\033[036m|____________\033[0m\n\n");
exit(1);
} else {
printf("Host Name: %s\n", host->h_name);
printf("IP Address: ");
printf("\033[036m|\033[0m Host Name: %s\n", host->h_name);
printf("\033[036m|\033[0m IP Address: ");

for (i = 0; host->h_addr_list[i] != NULL; ++i) {
printf("%s ", inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
Expand All @@ -50,11 +51,13 @@ void print_net_info(const char *hostname)

for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET) {
printf("Interface: %s\n", ifa->ifa_name);
printf("Address: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr));
printf("Netmask: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr));
printf("\033[036m|\033[0m Interface: %s\n", ifa->ifa_name);
printf("\033[036m|\033[0m Address: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr));
printf("\033[036m|\033[0m Netmask: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr));
}
}

printf("\033[036m|____________\033[0m\n\n");

freeifaddrs(ifaddr);
}
12 changes: 6 additions & 6 deletions src/ram/ram_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ void print_ram_info(void)
struct sysinfo sys_info;
sysinfo(&sys_info);

printf(" ____________\n\
printf("\033[036m ____________\n\
|\n\
| RAM Info\n\
|____________\n\
|\n");
printf("| Uptime: %ld Hours\n", sys_info.uptime / 60 / 60);
printf("| Total RAM: %ld MiB\n",
|\033[0m\n");
printf("\033[036m|\033[0m Uptime: %ld Hours\n", sys_info.uptime / 60 / 60);
printf("\033[036m|\033[0m Total RAM: %ld MiB\n",
sys_info.totalram * sys_info.mem_unit / 1024 / 1024);
printf("| Free RAM: %ld MiB\n",
printf("\033[036m|\033[0m Free RAM: %ld MiB\n",
sys_info.freeram * sys_info.mem_unit / 1024 / 1024);
printf("|____________\n\n");
printf("\033[036m|____________\033[0m\n\n");
}
12 changes: 6 additions & 6 deletions src/rom/rom_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ void print_rom_info(void)
{
struct statvfs fs_info;

printf(" ____________\n\
printf("\033[036m ____________\n\
|\n\
| ROM Info:\n\
|____________\n\
|\n");
|\033[0m\n");

if (statvfs("/", &fs_info) == 0) {
printf("| Total Disk Space: %ld MiB\n",
printf("\033[036m|\033[0m Total Disk Space: %ld MiB\n",
fs_info.f_blocks * fs_info.f_bsize / 1024 / 1024);
printf("| Free Disk Space: %ld MiB\n",
printf("\033[036m|\033[0m Free Disk Space: %ld MiB\n",
fs_info.f_bfree * fs_info.f_bsize / 1024 / 1024);
printf("| Used Disk Space: %ld MiB\n",
printf("\033[036m|\033[0m Used Disk Space: %ld MiB\n",
(fs_info.f_blocks - fs_info.f_bfree) *
fs_info.f_bsize / 1024 / 1024);
printf("|____________\n\n");
printf("\033[036m|____________\033[0m\n\n");
}
}
16 changes: 8 additions & 8 deletions src/sys/sys_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ void print_sys_info(void)
struct utsname sys_info;
uname(&sys_info);

printf(" ____________\n\
printf("\033[036m ____________\n\
|\n\
| System Info\n\
|____________\n\
|\n");
printf("| System Name: %s\n", sys_info.sysname);
printf("| Host Name: %s\n", sys_info.nodename);
printf("| Kernel Release: %s\n", sys_info.release);
printf("| System Version: %s\n", sys_info.version);
printf("| Machine Type: %s\n", sys_info.machine);
printf("|____________\n\n");
|\033[0m\n");
printf("\033[036m|\033[0m System Name: %s\n", sys_info.sysname);
printf("\033[036m|\033[0m Host Name: %s\n", sys_info.nodename);
printf("\033[036m|\033[0m Kernel Release: %s\n", sys_info.release);
printf("\033[036m|\033[0m System Version: %s\n", sys_info.version);
printf("\033[036m|\033[0m Machine Type: %s\n", sys_info.machine);
printf("\033[036m|____________\033[0m\n\n");
}

0 comments on commit b1dfbdb

Please sign in to comment.