Skip to content

Commit 1c87d72

Browse files
committed
many fixes
1 parent c6e4e73 commit 1c87d72

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
node_modules/
3+
tests/

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ module.exports.run = function run(commands, opt = {title: 'my commander'}) {
1717

1818
// Quit on Escape, q, or Control-C.
1919
screen.key(['q', 'C-c'], function (ch, key) {
20-
return process.exit(0);
20+
Promise.all(_.map(coms, (com) => com.shutdown()))
21+
.catch((err) => {
22+
console.error(err);
23+
process.exit(1);
24+
})
25+
.then(() => process.exit(0));
2126
});
2227

2328
// Focus our element.

lib/command.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const _ = require('lodash');
4+
const kill = require('tree-kill');
45
const cp = require('child_process');
56
const blessed = require('blessed');
67

@@ -79,6 +80,13 @@ class Command {
7980
});
8081
}
8182

83+
shutdown() {
84+
if (this.isRunning()) {
85+
return new Promise((res, rej) => kill(this.cpHandler.pid, null, (err) => err ? rej(err) : res()));
86+
}
87+
return Promise.resolve()
88+
}
89+
8290
isFailed() {
8391
return this.execError !== null;
8492
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-shell-commandor",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "javascript terminal multiplexer and command runner",
55
"main": "index.js",
66
"scripts": {
@@ -10,7 +10,9 @@
1010
"license": "MIT",
1111
"repository": "git://github.com/tomfun/node-shell-commandor.git",
1212
"dependencies": {
13-
"lodash": "^4.16.6"
13+
"blessed": "^0.1.81",
14+
"lodash": "^4.16.6",
15+
"tree-kill": "^1.1.0"
1416
},
1517
"devDependencies": {
1618
"mocha": "^3.1.2",

0 commit comments

Comments
 (0)