lazily set raw mode.
This commit is contained in:
parent
1428b7137b
commit
9020f645af
|
@ -44,16 +44,14 @@ Program.prototype.term = function(is) {
|
|||
};
|
||||
|
||||
Program.prototype.listen = function() {
|
||||
if (!this.input.isTTY || !this.output.isTTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
var readline = require('readline')
|
||||
, self = this;
|
||||
|
||||
if (!this.input.isRaw) {
|
||||
this.input.setRawMode(true);
|
||||
if (!this.input.isTTY || !this.output.isTTY) {
|
||||
throw new Error('Not a terminal.');
|
||||
}
|
||||
|
||||
// Input
|
||||
this.input.on('keypress', function(ch, key) {
|
||||
key = key || 0;
|
||||
if (key.ctrl && key.name === 'c') {
|
||||
|
@ -74,13 +72,14 @@ Program.prototype.listen = function() {
|
|||
|
||||
readline.emitKeypressEvents(this.input);
|
||||
|
||||
this.input.resume();
|
||||
this.on('newListener', function fn(type) {
|
||||
if (type === 'keypress' || type === 'mouse') {
|
||||
self.removeListener('newListener', fn);
|
||||
if (!self.input.isRaw) {
|
||||
self.input.setRawMode(true);
|
||||
self.input.resume();
|
||||
}
|
||||
}
|
||||
|
||||
this.output.on('resize', function() {
|
||||
self.cols = self.output.columns;
|
||||
self.rows = self.output.rows;
|
||||
self.emit('resize');
|
||||
});
|
||||
|
||||
this.on('newListener', function fn(type) {
|
||||
|
@ -92,6 +91,13 @@ Program.prototype.listen = function() {
|
|||
|
||||
// self.bindMouse();
|
||||
// self.bindResponse();
|
||||
|
||||
// Output
|
||||
this.output.on('resize', function() {
|
||||
self.cols = self.output.columns;
|
||||
self.rows = self.output.rows;
|
||||
self.emit('resize');
|
||||
});
|
||||
};
|
||||
|
||||
// XTerm mouse events
|
||||
|
|
Loading…
Reference in New Issue