allow multiple programs to use the same streams correctly. see #157.

This commit is contained in:
Christopher Jeffrey 2015-07-22 05:43:50 -07:00
parent 5e31eb1370
commit e35811ae97
1 changed files with 36 additions and 24 deletions

View File

@ -363,30 +363,38 @@ Program.prototype._listenInput = function() {
key.full = name;
Program.list.forEach(function(self) {
self.emit('keypress', ch, key);
self.emit('key ' + name, ch, key);
});
});
this.input.on('data', function(data) {
Program.list.forEach(function(self) {
self.emit('data', data);
});
});
keys.emitKeypressEvents(this.input);
this.on('newListener', function fn(type) {
if (type === 'keypress' || type === 'mouse') {
Program.list.forEach(function(self) {
self.removeListener('newListener', fn);
if (self.input.setRawMode && !self.input.isRaw) {
self.input.setRawMode(true);
self.input.resume();
}
});
}
});
this.on('newListener', function fn(type) {
if (type === 'mouse') {
Program.list.forEach(function(self) {
self.removeListener('newListener', fn);
self.bindMouse();
});
}
});
};
@ -402,12 +410,15 @@ Program.prototype._listenOutput = function() {
// Output
function resize() {
Program.list.forEach(function(self) {
self.cols = self.output.columns;
self.rows = self.output.rows;
self.emit('resize');
});
}
this.output.on('resize', function() {
Program.list.forEach(function(self) {
if (!self.options.resizeTimeout) {
return resize();
}
@ -420,6 +431,7 @@ Program.prototype._listenOutput = function() {
: 300;
self._resizeTimer = setTimeout(resize, time);
});
});
};
Program.prototype.destroy = function() {