-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
165 lines (138 loc) · 4.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env node
import os from 'os';
import chalk from 'chalk';
import si from 'systeminformation';
import figlet from 'figlet';
import inquirer from 'inquirer';
const log = console.log;
const green = chalk.green;
const grey = chalk.grey;
const blueBright = chalk.blueBright;
const greenBright = chalk.greenBright;
const brown = chalk.hex('#A44A3F');
const azure = chalk.hex('#7776BC');
const lightBrown = chalk.hex('#D1B490');
const lightAzure = chalk.hex('#30C5FF');
const lightGreen = chalk.hex('#157145');
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
let initialChoice: string;
function printName() {
const msg = `Hello ${os.userInfo().username}\n`;
figlet(msg, { font: 'Colossal' }, (err, data) => {
log(greenBright(data));
});
}
async function askChoice() {
log(grey(`\nMade with ❤️ by ${greenBright('beef_e')}`));
const question = await inquirer.prompt({
type: 'list',
name: 'choice',
message: 'What do you want to do?',
choices: [
{
name: 'Get system informations',
value: 'system',
},
{
name: 'Go to System monitoring',
value: 'monitoring',
},
],
});
initialChoice = question.choice;
}
async function getSysInfo() {
console.clear();
log(blueBright('\n\nSystem Informations\n'));
await si.system().then((data) => {
log(brown(`Manufacturer: ${data.manufacturer}`));
log(lightBrown(`Model: ${data.model}`));
if (data.virtual) {
log(lightBrown(`You are running on a virtual machine`));
log(brown(data.virtualHost));
}
log('\n');
});
await si.baseboard().then((data) => {
log(brown(`Motherboard manufacturer: ${data.manufacturer}`));
log(lightBrown(`Model: ${data.model}`));
log(brown(`Version: ${data.version}`));
log('\n');
});
await si.cpu().then((data) => {
log(greenBright(`CPU Brand: ${data.brand}`));
log(lightGreen(`Governor: ${data.governor}`));
log(greenBright(`Cores: ${data.cores}`));
log(lightGreen(`Physical Cores: ${data.physicalCores}`));
log(lightGreen(`Socket type: ${data.socket}`));
if (data.virtualization) {
log(greenBright(`Virtualization is supported on your system`));
}
log('\n');
});
await si.osInfo().then((data) => {
log(lightAzure(`OS: ${data.distro}`));
log(azure(`Kernel Version: ${data.kernel}`));
log(lightAzure(`${data.logofile}`));
log('\n');
});
await si.battery().then((data) => {
if (data.hasBattery) {
log(greenBright(`Battery Status`));
if (data.isCharging) {
log(green(`Battery is currently charging`));
} else {
log(green(`You have ${data.timeRemaining} minutes of use left\t(${data.percent}%))`));
}
log(
greenBright(
`The battery max Capacity is now ${data.maxCapacity} ${data.capacityUnit} out of a original ${data.designedCapacity} ${data.capacityUnit}`
)
);
log(green(`Current voltage: ${data.voltage} V`));
log(greenBright(`Manufacturer: ${data.manufacturer}`));
log(green(`Model: ${data.model}`));
log(greenBright(`The battery is a ${data.type} type of battery`));
} else {
log(greenBright(`\nYou don't have a battery`));
}
});
}
async function monitorSys() {
console.clear();
log(lightBrown(`Your system uptime is ${Math.floor(os.uptime() / 60)} mins\n`));
await wait(3000);
while (true) {
await si.cpuTemperature().then(async (data) => {
log(blueBright(`Stats of your system CPU\n`));
log(azure(`CPU Architecture: ${os.arch()}`));
log(blueBright(`CPU Model: ${os.cpus()[0].model}\n`));
os.cpus().forEach((cpu, index) => {
log(azure(`\nCPU n. ${index + 1}`));
log(lightGreen(`Speed: ${cpu.speed} MHz`));
if (data.cores[index]) {
log(greenBright(`Temperature: ${data.cores[index]}°C`));
}
});
log(blueBright(`RAM Stats\n`));
log(azure(`Total: ${Math.floor(os.totalmem() / 1024 / 1024)} MB`));
log(
azure(`Currently in use: ${Math.floor((os.totalmem() - os.freemem()) / 1024 / 1024)} MB`)
);
log(grey(`\nPress CTRL + C to exit`));
await wait(4000);
});
}
}
//! Inizio Programma
printName();
await wait(350);
await askChoice().then(() => {
if (initialChoice === 'system') {
// System informations
getSysInfo();
} else if (initialChoice === 'monitoring') {
// System monitoring
monitorSys();
}
});