keys. no mouse focus events.

This commit is contained in:
Christopher Jeffrey 2013-07-12 05:11:15 -05:00
parent 87a5188de9
commit 97c582164b
2 changed files with 35 additions and 17 deletions

View File

@ -136,6 +136,11 @@ Program.prototype.listen = function() {
return;
}
if (key.name === 'undefined') {
// Not sure what this is, but we should probably ignore it.
return;
}
var name = (key.ctrl ? 'C-' : '')
+ (key.meta ? 'M-' : '')
+ (key.shift && key.name ? 'S-' : '')
@ -181,6 +186,28 @@ Program.prototype.listen = function() {
});
};
Program.prototype.key = function(key, listener) {
if (typeof key === 'string') key = key.split(/\s*,\s*/);
key.forEach(function(key) {
return this.on('key ' + key, listener);
}, this);
};
Program.prototype.onceKey = function(key, listener) {
if (typeof key === 'string') key = key.split(/\s*,\s*/);
key.forEach(function(key) {
return this.once('key ' + key, listener);
}, this);
};
Program.prototype.unkey =
Program.prototype.removeKey = function(key, listener) {
if (typeof key === 'string') key = key.split(/\s*,\s*/);
key.forEach(function(key) {
return this.removeListener('key ' + key, listener);
}, this);
};
// XTerm mouse events
// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
// To better understand these
@ -2109,8 +2136,8 @@ Program.prototype.enableMouse = function() {
if (this.term('xterm') || this.term('screen')) {
return this.setMouse({
allMotion: true,
utfMouse: true,
sendFocus: true
utfMouse: true
// sendFocus: true
}, true);
}

View File

@ -826,26 +826,17 @@ Screen.prototype.fillRegion = function(attr, ch, xi, xl, yi, yl) {
}
};
Screen.prototype.key = function(key, listener) {
if (typeof key === 'string') key = [key];
key.forEach(function(key) {
return this.on('key ' + key, listener);
}, this);
Screen.prototype.key = function() {
return this.program.key.apply(this, arguments);
};
Screen.prototype.onceKey = function(key, listener) {
if (typeof key === 'string') key = [key];
key.forEach(function(key) {
return this.once('key ' + key, listener);
}, this);
Screen.prototype.onceKey = function() {
return this.program.onceKey.apply(this, arguments);
};
Screen.prototype.unkey =
Screen.prototype.removeKey = function(key, listener) {
if (typeof key === 'string') key = [key];
key.forEach(function(key) {
return this.removeListener('key ' + key, listener);
}, this);
Screen.prototype.removeKey = function() {
return this.program.unkey.apply(this, arguments);
};
Screen.prototype.spawn = function(file, args, options) {