Skip to content

Commit

Permalink
REF: dashboard option improved
Browse files Browse the repository at this point in the history
  • Loading branch information
royriojas committed Feb 3, 2017
1 parent dee0c4c commit 3d53cca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shell-executor",
"version": "3.0.0",
"version": "3.0.8",
"description": "A small nodejs module to execute shell commands in parallel",
"main": "index.js",
"scripts": {
Expand Down
42 changes: 36 additions & 6 deletions source/src/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,33 @@ const getPositionByIndex = (index) => {
export const setProcessLogToGrid = (cmd, grid, index) => {
const { row, col } = getPositionByIndex(index);

const log = grid.set(row, col, 6, 4, contrib.log, {
fg: 'green',
selectedFg: 'green',
label: cmd.substr(0, 40),
const box = grid.set(row, col, 6, 4, blessed.box, {
label: cmd.substr(0, 40),
padding: { top: 0, left: 0, right: 0, bottom: 0 },
border: {
type: 'line',
},
style: {
border: {
fg: 'yellow',
},
},
});

const log = blessed.log({
parent: box,
tags: true,
width: '100%-5',
scrollable: true,
input: true,
alwaysScroll: true,
scrollbar: {
ch: ' ',
inverse: true,
},
keys: true,
vi: true,
mouse: true,
});

const addListener = (stream) => {
Expand All @@ -41,9 +64,10 @@ export const setProcessLogToGrid = (cmd, grid, index) => {
);
};

let cp;
return {
start: () => {
const cp = spawn(cmd, { stdio: 'pipe' });
start() {
cp = spawn(cmd, { stdio: 'pipe' });

addListener(cp.stdout);
addListener(cp.stderr);
Expand All @@ -52,5 +76,11 @@ export const setProcessLogToGrid = (cmd, grid, index) => {
log.log(`process exit with code ${ exitCode }`);
});
},
stop() {
if (cp && !cp.exitCode) {
cp.removeAllListeners('close');
cp.kill('SIGINT');
}
},
};
};
6 changes: 4 additions & 2 deletions source/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ module.exports = {

const { grid, screen } = getGridAndScreen();

cmds.forEach((cmd, index) => {
cmds.reduce((seq, cmd, index) => {
const command = setProcessLogToGrid(cmd, grid, index);
command.start();
});
seq.push(command);
return seq;
}, []);

screen.render();
},
Expand Down

0 comments on commit 3d53cca

Please sign in to comment.