Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

passing test for detach with &

  • Loading branch information...
commit 5cb3a67537e17d57f3c14fe5b264f50dba996f8e 1 parent e6349d3
@substack authored
Showing with 24 additions and 5 deletions.
  1. +23 −4 index.js
  2. +1 −1  test/detach.js
View
27 index.js
@@ -37,6 +37,7 @@ function Bash (opts) {
this.history = [];
this.historyIndex = 0;
this._historyLast = null;
+ this._jobs = [];
}
Bash.prototype._read = function (rfile) {
@@ -257,9 +258,19 @@ Bash.prototype.createStream = function () {
function inputEnd () {
if (line.length) this.queue(line);
- nextTick(function () {
- input.queue(null);
- });
+ if (self._jobs.length > 0) {
+ var pending = self._jobs.length;
+ self._jobs.forEach(function (j) {
+ j.on('data', function (buf) {
+ output.queue(buf);
+ });
+ j.on('end', function () {
+console.log('JOB END');
+ if (--pending === 0) input.queue(null);
+ });
+ });
+ }
+ else input.queue(null);
}
var closed = false;
@@ -398,11 +409,19 @@ Bash.prototype.eval = function (line) {
var cmd = shiftCommand();
var redirected = false;
- while (commands[0] && /^[|<>]$/.test(commands[0].op)) {
+ while (commands[0] && /^[&|<>]$/.test(commands[0].op)) {
var op = commands.shift().op;
if (op === '|') {
cmd = cmd.pipe(shiftCommand());
}
+ else if (op === '&') {
+ self._jobs.push(cmd);
+ cmd.on('end', function () {
+ var ix = self._jobs.indexOf(cmd);
+ self._jobs.splice(ix, 1);
+ });
+ cmd = shiftCommand();
+ }
else if (op === '>') {
var c = commands.shift();
var file = typeof c === 'object' && c.env
View
2  test/detach.js
@@ -10,7 +10,7 @@ test('detach', function (t) {
var s = sh.createStream();
s.pipe(concat(function (src) {
- t.equal(src + '', '$ beep boop!');
+ t.equal(src + '', '$ beep $ boop!');
}));
s.write('first & second\n');
s.end();
Please sign in to comment.
Something went wrong with that request. Please try again.