-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (34 loc) · 1.04 KB
/
index.js
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
#!/usr/bin/env node
const si = require('systeminformation');
const EOL = require('os').EOL; // Get End of Line for current OS
function log(message, count=1) {
[...Array(count).keys()].forEach(x => process.stdout.write(message));
}
function getBatteryInfo() {
return si.battery((info) => info);
}
(async function displayBatteryInfo() {
const {
percent,
ischarging,
timeremaining
} = await getBatteryInfo();
log(EOL);
log(`🔋 Charge Remaining: ${percent}%`);
log(EOL, 2);
/*
If battery is 100% charged and charger is connected, then
this will still show charging "NO" since the laptop is now
running on AC power and not battery power.
*/
log(`🔌 Charging: ${ischarging ? "YES ⚡" : "NO ❌"}`);
log(EOL, 2);
const hours = Math.floor(timeremaining / 60);
const minutes = timeremaining - (hours * 60);
log("⏲️ Time remaining: ");
log((timeremaining != -1)
? `${hours}h ${minutes}m`
: `Not available`
);
log(EOL, 2);
})();