From e8fe076681cd2465f88ed532083ed9ed11da3da1 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 7 Feb 2015 15:37:01 -0800 Subject: [PATCH] refactor mouse events. put `buf` on event object. --- lib/program.js | 46 +++++++++++++++++++++---------------------- test/program-mouse.js | 12 ----------- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/lib/program.js b/lib/program.js index 99d4434..c9aa931 100644 --- a/lib/program.js +++ b/lib/program.js @@ -445,12 +445,11 @@ Program.prototype._bindMouse = function(s, buf) { , y = parts[1].charCodeAt(2) , mod; - this.emit('mouse-debug', s, buf); - key.name = 'mouse'; key.type = 'X10'; key.raw = [b, x, y, parts[0]]; + key.buf = buf; key.x = x - 32; key.y = y - 32; @@ -508,16 +507,16 @@ Program.prototype._bindMouse = function(s, buf) { // URxvt if (parts = /^\x1b\[(\d+;\d+;\d+)M/.exec(s)) { - var parts = parts[1].split(';') - , b = +parts[0] - , x = +parts[1] - , y = +parts[2]; - - this.emit('mouse-debug', s, buf); + var params = parts[1].split(';') + , b = +params[0] + , x = +params[1] + , y = +params[2]; key.name = 'mouse'; key.type = 'urxvt'; + key.raw = [b, x, y, parts[0]]; + key.buf = buf; key.x = x; key.y = y; @@ -577,16 +576,16 @@ Program.prototype._bindMouse = function(s, buf) { // SGR if (parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s)) { var down = parts[2] === 'M' - , parts = parts[1].split(';') - , b = +parts[0] - , x = +parts[1] - , y = +parts[2]; - - this.emit('mouse-debug', s, buf); + , params = parts[1].split(';') + , b = +params[0] + , x = +params[1] + , y = +params[2]; key.name = 'mouse'; key.type = 'sgr'; + key.raw = [b, x, y, parts[0]]; + key.buf = buf; key.x = x; key.y = y; @@ -637,18 +636,17 @@ Program.prototype._bindMouse = function(s, buf) { // The xterm mouse documentation says there is a // `<` prefix, the DECRQLP says there is no prefix. if (parts = /^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(s)) { - var parts = parts[1].split(';') - , b = +parts[0] - , x = +parts[1] - , y = +parts[2] - , page = +parts[3]; - - this.emit('mouse-debug', s, buf); + var params = parts[1].split(';') + , b = +params[0] + , x = +params[1] + , y = +params[2] + , page = +params[3]; key.name = 'mouse'; key.type = 'dec'; - key.button = b; + key.raw = [b, x, y, parts[0]]; + key.buf = buf; key.x = x; key.y = y; @@ -676,11 +674,11 @@ Program.prototype._bindMouse = function(s, buf) { , x = +parts[2] , y = +parts[3]; - this.emit('mouse-debug', s, buf); - key.name = 'mouse'; key.type = 'vt300'; + key.raw = [b, x, y, parts[0]]; + key.buf = buf; key.x = x; key.y = y; diff --git a/test/program-mouse.js b/test/program-mouse.js index f73c1a6..03e4df1 100755 --- a/test/program-mouse.js +++ b/test/program-mouse.js @@ -39,18 +39,6 @@ program.on('keypress', function(ch, data) { program.write(util.inspect(data)); }); -program.on('mouse-debug', function(s, buf) { - if (s) { - program.cup(10, 0); - program.write(util.inspect(s)); - } - if (buf) { - program.cup(11, 0); - buf = Array.prototype.slice.call(buf); - program.write(util.inspect(buf)); - } -}); - // program.getCursor(function(err, data) { // program.write(util.inspect(data)); // });