Skip to content

Commit 4adebff

Browse files
committed
lint & upgrade
1 parent 4f9e3f4 commit 4adebff

File tree

10 files changed

+96
-449
lines changed

10 files changed

+96
-449
lines changed

lib/gtop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var procTable = grid.set(8, 6, 4, 6, contrib.table, {
6969
procTable.focus()
7070

7171
screen.render();
72-
screen.on('resize', function(a) {
72+
screen.on('resize', function (a) {
7373
cpuLine.emit('attach');
7474
memLine.emit('attach');
7575
memDonut.emit('attach');
@@ -79,7 +79,7 @@ screen.on('resize', function(a) {
7979
procTable.emit('attach');
8080
});
8181

82-
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
82+
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
8383
return process.exit(0);
8484
});
8585

@@ -92,7 +92,7 @@ function init() {
9292
}
9393

9494

95-
process.on('uncaughtException', function(err) {
95+
process.on('uncaughtException', function (err) {
9696
// avoid exiting due to unsupported system resources in Windows
9797
});
9898

lib/monitor/cpu.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ function Cpu(line) {
1010
return {
1111
title: 'CPU' + (i + 1),
1212
style: {
13-
line: colors[i % colors.length]
13+
line: colors[i % colors.length],
1414
},
15-
x: Array(61).fill().map((_, i) => 60 - i),
16-
y: Array(61).fill(0)
17-
}
18-
})
15+
x: Array(61)
16+
.fill()
17+
.map((_, i) => 60 - i),
18+
y: Array(61).fill(0),
19+
};
20+
});
1921
this.updateData(data);
2022
this.interval = setInterval(() => {
2123
si.currentLoad(data => {
2224
this.updateData(data);
23-
})
25+
});
2426
}, 1000);
2527
});
2628
}
@@ -31,16 +33,15 @@ Cpu.prototype.updateData = function(data) {
3133
while (loadString.length < 6) {
3234
loadString = ' ' + loadString;
3335
}
34-
loadString = loadString + '\%';
36+
loadString = loadString + '%';
3537

3638
this.cpuData[i].title = 'CPU' + (i + 1) + loadString;
3739
this.cpuData[i].y.shift();
3840
this.cpuData[i].y.push(cpu.load);
39-
})
41+
});
4042

4143
this.line.setData(this.cpuData);
4244
this.line.screen.render();
43-
}
44-
45+
};
4546

4647
module.exports = Cpu;

lib/monitor/disk.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@ function Disk(donut) {
88

99
si.fsSize(data => {
1010
this.updateData(data);
11-
})
11+
});
1212

1313
this.interval = setInterval(() => {
1414
si.fsSize(data => {
1515
this.updateData(data);
16-
})
16+
});
1717
}, 10000);
1818
}
1919

2020
Disk.prototype.updateData = function(data) {
21-
2221
var disk = data[0];
2322

24-
var label = utils.humanFileSize(disk.used, true) +
23+
var label =
24+
utils.humanFileSize(disk.used, true) +
2525
' of ' +
2626
utils.humanFileSize(disk.size, true);
2727

28-
this.donut.setData([{
29-
percent: disk.use / 100,
30-
label: label,
31-
'color': colors[5]
32-
}, ]);
28+
this.donut.setData([
29+
{
30+
percent: disk.use / 100,
31+
label: label,
32+
color: colors[5],
33+
},
34+
]);
3335
this.donut.screen.render();
3436
};
3537

lib/monitor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
Mem: require('./mem'),
44
Net: require('./net'),
55
Disk: require('./disk'),
6-
Proc: require('./proc')
7-
}
6+
Proc: require('./proc'),
7+
};

lib/monitor/mem.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,39 @@ function Mem(line, memDonut, swapDonut) {
88
this.memDonut = memDonut;
99
this.swapDonut = swapDonut;
1010

11-
1211
si.mem(data => {
13-
this.memData = [{
12+
this.memData = [
13+
{
1414
title: 'Memory',
1515
style: {
16-
line: colors[0]
16+
line: colors[0],
1717
},
18-
x: Array(61).fill().map((_, i) => 60 - i),
19-
y: Array(61).fill(0)
18+
x: Array(61)
19+
.fill()
20+
.map((_, i) => 60 - i),
21+
y: Array(61).fill(0),
2022
},
2123
{
2224
title: 'Swap',
2325
style: {
24-
line: colors[1]
26+
line: colors[1],
2527
},
26-
x: Array(61).fill().map((_, i) => 60 - i),
27-
y: Array(61).fill(0)
28-
}
28+
x: Array(61)
29+
.fill()
30+
.map((_, i) => 60 - i),
31+
y: Array(61).fill(0),
32+
},
2933
];
3034
this.updateData(data);
3135
this.interval = setInterval(() => {
3236
si.mem(data => {
3337
this.updateData(data);
34-
})
38+
});
3539
}, 1000);
3640
});
3741
}
3842

3943
Mem.prototype.updateData = function(data) {
40-
4144
var memPer = (100 * (1 - data.available / data.total)).toFixed();
4245
var swapPer = (100 * (1 - data.swapfree / data.swaptotal)).toFixed();
4346

@@ -60,16 +63,20 @@ Mem.prototype.updateData = function(data) {
6063
utils.humanFileSize(data.swaptotal);
6164

6265
this.line.setData(this.memData);
63-
this.memDonut.setData([{
64-
percent: memPer / 100,
65-
label: memTitle,
66-
'color': colors[0]
67-
}, ]);
68-
this.swapDonut.setData([{
69-
percent: swapPer / 100,
70-
label: swapTitle,
71-
'color': colors[1]
72-
}, ]);
66+
this.memDonut.setData([
67+
{
68+
percent: memPer / 100,
69+
label: memTitle,
70+
color: colors[0],
71+
},
72+
]);
73+
this.swapDonut.setData([
74+
{
75+
percent: swapPer / 100,
76+
label: swapTitle,
77+
color: colors[1],
78+
},
79+
]);
7380
this.line.screen.render();
7481
};
7582

lib/monitor/net.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ function Net(sparkline) {
1313
si.networkStats(iface, data => {
1414
that.updateData(data[0]);
1515
});
16-
}
16+
};
1717
updater();
1818
this.interval = setInterval(updater, 1000);
19-
})
19+
});
2020
}
2121

2222
Net.prototype.updateData = function(data) {
23-
2423
var rx_sec = Math.max(0, data['rx_sec']);
2524
var tx_sec = Math.max(0, data['tx_sec']);
2625

@@ -30,12 +29,14 @@ Net.prototype.updateData = function(data) {
3029
this.netData[1].shift();
3130
this.netData[1].push(tx_sec);
3231

33-
rx_label = 'Receiving: ' +
32+
rx_label =
33+
'Receiving: ' +
3434
utils.humanFileSize(rx_sec) +
3535
'/s \nTotal received: ' +
3636
utils.humanFileSize(data['rx_bytes']);
3737

38-
tx_label = 'Transferring: ' +
38+
tx_label =
39+
'Transferring: ' +
3940
utils.humanFileSize(tx_sec) +
4041
'/s \nTotal transferred: ' +
4142
utils.humanFileSize(data['tx_bytes']);

lib/monitor/proc.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var colors = utils.colors;
66
var pars = {
77
p: 'pid',
88
c: 'pcpu',
9-
m: 'pmem'
10-
}
9+
m: 'pmem',
10+
};
1111

1212
function Proc(table) {
1313
this.table = table;
@@ -21,14 +21,12 @@ function Proc(table) {
2121
var updater = function() {
2222
si.processes(data => {
2323
that.updateData(data);
24-
})
25-
}
24+
});
25+
};
2626
updater();
2727
this.interval = setInterval(updater, 3000);
2828
this.table.screen.key(['m', 'c', 'p'], function(ch, key) {
29-
3029
if (pars[ch] == that.pSort) {
31-
3230
that.reverse = !that.reverse;
3331
} else {
3432
that.pSort = pars[ch] || that.pSort;
@@ -37,7 +35,6 @@ function Proc(table) {
3735
that.reIndex = true;
3836
updater();
3937
});
40-
4138
}
4239

4340
Proc.prototype.updateData = function(data) {
@@ -52,24 +49,24 @@ Proc.prototype.updateData = function(data) {
5249
p.pid,
5350
p.command, //.slice(0,10),
5451
' ' + p.pcpu.toFixed(1),
55-
p.pmem.toFixed(1)
56-
]
57-
58-
})
52+
p.pmem.toFixed(1),
53+
];
54+
});
5955

6056
var headers = ['PID', 'Command', '%CPU', '%MEM'];
6157

62-
headers[{
63-
pid: 0,
64-
pcpu: 2,
65-
pmem: 3
66-
}[this.pSort]] += this.reverse ? '▲' : '▼';
67-
58+
headers[
59+
{
60+
pid: 0,
61+
pcpu: 2,
62+
pmem: 3,
63+
}[this.pSort]
64+
] += this.reverse ? '▲' : '▼';
6865

6966
this.table.setData({
7067
headers: headers,
71-
data: this.reverse ? data.reverse() : data
72-
})
68+
data: this.reverse ? data.reverse() : data,
69+
});
7370

7471
if (this.reIndex) {
7572
this.table.rows.select(0);

lib/utils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
var utils = {}
2-
1+
var utils = {};
32

43
utils.humanFileSize = function(bytes, isDecimal) {
5-
isDecimal = (typeof isDecimal !== 'undefined') ? isDecimal : false;
4+
isDecimal = typeof isDecimal !== "undefined" ? isDecimal : false;
65
if (bytes == 0) {
76
return "0.00 B";
87
}
98
var base = isDecimal ? 1000 : 1024;
109
var e = Math.floor(Math.log(bytes) / Math.log(base));
11-
return (bytes / Math.pow(base, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + (isDecimal || e == 0 ? '' : 'i') + 'B';
12-
}
10+
return (
11+
(bytes / Math.pow(base, e)).toFixed(2) +
12+
" " +
13+
" KMGTP".charAt(e) +
14+
(isDecimal || e == 0 ? "" : "i") +
15+
"B"
16+
);
17+
};
1318

14-
utils.colors = ['magenta', 'cyan', 'blue', 'yellow', 'green', 'red'];
19+
utils.colors = ["magenta", "cyan", "blue", "yellow", "green", "red"];
1520

1621
module.exports = utils;

0 commit comments

Comments
 (0)