Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line flags for which windows to show #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/gtop
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#!/usr/bin/env node

require('../lib/gtop').init()
if (process.argv[2] === '--help') {
console.log(`
gtop [-cpu|-mem|-net|-disk|-proc]

With no flags supplied gtop runs all on default
Adding flags will show only the windows for the flags supplied

-cpu: Show the cpu usage window
-mem: Show the memory usage window
-net: Show the network history window
-disk: Show the disk usage window
-proc: Show the running processes window
`);
} else {
let flags = process.argv.slice(2);
require('../lib/gtop').init(flags)
}
29 changes: 28 additions & 1 deletion lib/gtop.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,41 @@ screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});

function init() {
function init(flags) {
flags.length === 0 ? showAll() : showSelected(flags);
}

function showAll() {
new monitor.Cpu(cpuLine); //no Windows support
new monitor.Mem(memLine, memDonut, swapDonut);
new monitor.Net(netSpark);
new monitor.Disk(diskDonut);
new monitor.Proc(procTable); // no Windows support
}

function showSelected(flags) {
flags.forEach((flag) => {
switch(flag) {
case '-cpu':
new monitor.Cpu(cpuLine);
break;
case '-mem':
new monitor.Mem(memLine, memDonut, swapDonut);
break;
case '-net':
new monitor.Net(netSpark);
break;
case '-disk':
new monitor.Disk(diskDonut);
break;
case '-proc':
new monitor.Proc(procTable);
break;
default:
break;
}
});
}

process.on('uncaughtException', function(err) {
// avoid exiting due to unsupported system resources in Windows
Expand Down