diff --git a/lib/program.js b/lib/program.js index d239597..6e4a230 100644 --- a/lib/program.js +++ b/lib/program.js @@ -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); } diff --git a/lib/widget.js b/lib/widget.js index acb92a6..e10c42d 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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) {