Skip to content

Commit b1dfbdb

Browse files
authored
Merge pull request #36 better cpu info and colorful output
better cpu info and colorful output
2 parents 4a94ebf + 6342694 commit b1dfbdb

File tree

7 files changed

+45
-56
lines changed

7 files changed

+45
-56
lines changed

src/cpu/cpu_info.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,44 @@
1616

1717
#include <stdio.h>
1818
#include <stdint.h>
19+
#include <stdlib.h>
1920
#include "cpu_info.h"
2021

2122
void print_cpu_info(void)
2223
{
23-
FILE *cpu_file;
24-
25-
printf(" ____________\n\
24+
printf("\033[036m ____________\n\
2625
|\n\
2726
| CPU Info:\n\
2827
|____________\n\
29-
|\n");
28+
|\033[0m\n");
3029

31-
cpu_file = fopen("/proc/cpuinfo", "r");
32-
if (cpu_file) {
33-
char line[128];
34-
uint8_t lines = 0;
35-
36-
while (fgets(line, sizeof(line), cpu_file) && lines < 19) {
37-
printf("| %s", line);
38-
++lines;
39-
}
40-
41-
fclose(cpu_file);
42-
43-
printf("|____________\n\n");
44-
} else {
45-
printf("Error opening /proc/cpuinfo\n");
46-
}
30+
system("lscpu");
31+
printf("\033[036m|____________\033[0m\n\n");
4732
}
4833

4934
void print_full_cpu_info(void)
5035
{
5136
FILE *cpu_file;
5237

53-
printf(" ____________\n\
38+
printf("\033[036m ____________\n\
5439
|\n\
5540
| Full CPU Info:\n\
5641
|____________\n\
57-
|\n");
42+
|\033[0m\n");
5843

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

6348
while (fgets(line, sizeof(line), cpu_file)) {
64-
printf("| %s", line);
49+
printf("\033[036m|\033[0m %s", line);
6550
}
6651

6752
fclose(cpu_file);
6853

69-
printf("|____________\n\n");
54+
printf("\033[036m|____________\033[0m\n\n");
7055
} else {
71-
printf("Error opening /proc/cpuinfo\n");
56+
printf("\033[031mError opening /proc/cpuinfo\033[0m\n");
7257
}
7358
}
7459

src/hlp/hlp_info.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,26 @@ void print_hlp_info(void)
8282
print_banner();
8383
printf("\033[36mSpynix is a commandline tool for gathering info about \
8484
hardware.\033[0m\n\n\
85-
\t\tInfo:\n\
85+
\t\t\033[033mInfo:\033[0m\n\
8686
\t\t\t-h or --help \t\t- show this menu\n\
8787
\t\t\t-v or --version \t- show version\n\
8888
\t\t\t-b or --banner \t\t- show ASCII banner\n\
8989
\t\t\t-l or --logo \t\t- show ASCII logo\n\n");
90-
printf("\t\tOptions:\n\
90+
printf("\t\t\033[033mOptions:\033[0m\n\
9191
\t\t\t-a or --all \t- show summary info about system, cpu, ram and rom\n\
9292
\t\t\t-sys \t\t- show system info\n\
9393
\t\t\t-cpu \t\t- show short Central Processing Unit info\n\
9494
\t\t\t-ram \t\t- show Random Access Memory info\n\
9595
\t\t\t-rom \t\t- show Read Only Memory info\n\
9696
\t\t\t-net \t\t- show network info\n\n\
97-
\t\tAdvanced:\n\
97+
\t\t\033[033mAdvanced:\033[0m\n\
9898
\t\t-cpu -f or -cpu --full \t- show full Central Processing Unit info\n");
9999
}
100100

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

src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ int main(int argc, char **argv)
4949
} else if (strcmp(argv[1], "-net") == 0) {
5050
char host_name[30];
5151

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

src/net/net_info.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ void print_net_info(const char *hostname)
3030
uint8_t i;
3131

3232
if (host == NULL) {
33-
perror("gethostbyname");
33+
perror("\033[036m|\033[0m \033[031mgethostbyname\033[0m");
34+
printf("\033[036m|____________\033[0m\n\n");
3435
exit(1);
3536
} else {
36-
printf("Host Name: %s\n", host->h_name);
37-
printf("IP Address: ");
37+
printf("\033[036m|\033[0m Host Name: %s\n", host->h_name);
38+
printf("\033[036m|\033[0m IP Address: ");
3839

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

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

60+
printf("\033[036m|____________\033[0m\n\n");
61+
5962
freeifaddrs(ifaddr);
6063
}

src/ram/ram_info.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ void print_ram_info(void)
2323
struct sysinfo sys_info;
2424
sysinfo(&sys_info);
2525

26-
printf(" ____________\n\
26+
printf("\033[036m ____________\n\
2727
|\n\
2828
| RAM Info\n\
2929
|____________\n\
30-
|\n");
31-
printf("| Uptime: %ld Hours\n", sys_info.uptime / 60 / 60);
32-
printf("| Total RAM: %ld MiB\n",
30+
|\033[0m\n");
31+
printf("\033[036m|\033[0m Uptime: %ld Hours\n", sys_info.uptime / 60 / 60);
32+
printf("\033[036m|\033[0m Total RAM: %ld MiB\n",
3333
sys_info.totalram * sys_info.mem_unit / 1024 / 1024);
34-
printf("| Free RAM: %ld MiB\n",
34+
printf("\033[036m|\033[0m Free RAM: %ld MiB\n",
3535
sys_info.freeram * sys_info.mem_unit / 1024 / 1024);
36-
printf("|____________\n\n");
36+
printf("\033[036m|____________\033[0m\n\n");
3737
}

src/rom/rom_info.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ void print_rom_info(void)
2222
{
2323
struct statvfs fs_info;
2424

25-
printf(" ____________\n\
25+
printf("\033[036m ____________\n\
2626
|\n\
2727
| ROM Info:\n\
2828
|____________\n\
29-
|\n");
29+
|\033[0m\n");
3030

3131
if (statvfs("/", &fs_info) == 0) {
32-
printf("| Total Disk Space: %ld MiB\n",
32+
printf("\033[036m|\033[0m Total Disk Space: %ld MiB\n",
3333
fs_info.f_blocks * fs_info.f_bsize / 1024 / 1024);
34-
printf("| Free Disk Space: %ld MiB\n",
34+
printf("\033[036m|\033[0m Free Disk Space: %ld MiB\n",
3535
fs_info.f_bfree * fs_info.f_bsize / 1024 / 1024);
36-
printf("| Used Disk Space: %ld MiB\n",
36+
printf("\033[036m|\033[0m Used Disk Space: %ld MiB\n",
3737
(fs_info.f_blocks - fs_info.f_bfree) *
3838
fs_info.f_bsize / 1024 / 1024);
39-
printf("|____________\n\n");
39+
printf("\033[036m|____________\033[0m\n\n");
4040
}
4141
}

src/sys/sys_info.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ void print_sys_info(void)
2323
struct utsname sys_info;
2424
uname(&sys_info);
2525

26-
printf(" ____________\n\
26+
printf("\033[036m ____________\n\
2727
|\n\
2828
| System Info\n\
2929
|____________\n\
30-
|\n");
31-
printf("| System Name: %s\n", sys_info.sysname);
32-
printf("| Host Name: %s\n", sys_info.nodename);
33-
printf("| Kernel Release: %s\n", sys_info.release);
34-
printf("| System Version: %s\n", sys_info.version);
35-
printf("| Machine Type: %s\n", sys_info.machine);
36-
printf("|____________\n\n");
30+
|\033[0m\n");
31+
printf("\033[036m|\033[0m System Name: %s\n", sys_info.sysname);
32+
printf("\033[036m|\033[0m Host Name: %s\n", sys_info.nodename);
33+
printf("\033[036m|\033[0m Kernel Release: %s\n", sys_info.release);
34+
printf("\033[036m|\033[0m System Version: %s\n", sys_info.version);
35+
printf("\033[036m|\033[0m Machine Type: %s\n", sys_info.machine);
36+
printf("\033[036m|____________\033[0m\n\n");
3737
}

0 commit comments

Comments
 (0)