Permalink
Browse files

expose .current to the outside

  • Loading branch information...
1 parent cdd38fd commit c152053fd1ff2249f8260664022f373ea272557c @substack committed Oct 18, 2013
Showing with 10 additions and 9 deletions.
  1. +10 −9 index.js
View
19 index.js
@@ -70,10 +70,11 @@ Bash.prototype.createStream = function () {
var input = through(function write (buf) {
if (typeof buf !== 'string') buf = buf.toString('utf8');
+ if (self.current) self.current.write(buf);
for (var i = 0; i < buf.length; i++) {
var c = buf.charCodeAt(i);
- if (current) {}
+ if (self.current) {}
else if (mode === 'escape' && c === 0x5b) {
mode = '[';
continue;
@@ -175,9 +176,9 @@ Bash.prototype.createStream = function () {
}
if (c === 3) {
- if (current) {
+ if (self.current) {
line = '';
- current.emit('SIGINT');
+ self.current.emit('SIGINT');
output.queue('^C');
}
else {
@@ -191,7 +192,7 @@ Bash.prototype.createStream = function () {
return write(buf.slice(i + 1));
}
else if (c === 4) {
- if (current) current.end();
+ if (self.current) self.current.end();
else this.queue(null);
self._cursorX = 0;
return write(buf.slice(i + 1));
@@ -266,7 +267,7 @@ Bash.prototype.createStream = function () {
var output = resumer();
output.queue(self.getPrompt());
- var current = null;
+ self.current = null;
self.once('exit', end);
var queue = [];
@@ -281,7 +282,7 @@ Bash.prototype.createStream = function () {
}
return;
}
- if (current) return queue.push(line);
+ if (self.current) return queue.push(line);
var p = self.eval(line);
p.on('SIGALRM', exit('SIGALRM', 142, 'Alarm clock'));
@@ -306,15 +307,15 @@ Bash.prototype.createStream = function () {
};
}
- current = p;
+ self.current = p;
p.pause();
p.pipe(through(null, function () { p.emit('exit', 0) }));
var exitCode = null;
p.on('exit', function (code) {
if (exitCode !== null) return;
exitCode = code;
- current = null;
+ self.current = null;
nextTick(function () {
if (!closed) output.queue(self.getPrompt());
if (queue.length) {
@@ -332,7 +333,7 @@ Bash.prototype.createStream = function () {
function end () {
closed = true;
- if (!current) {
+ if (!self.current) {
output.queue(null);
self.emit('exit', 0);
}

0 comments on commit c152053

Please sign in to comment.