refactor mouse events. put `buf` on event object.

This commit is contained in:
Christopher Jeffrey 2015-02-07 15:37:01 -08:00
parent 64d65c444a
commit e8fe076681
2 changed files with 22 additions and 36 deletions

View File

@ -445,12 +445,11 @@ Program.prototype._bindMouse = function(s, buf) {
, y = parts[1].charCodeAt(2) , y = parts[1].charCodeAt(2)
, mod; , mod;
this.emit('mouse-debug', s, buf);
key.name = 'mouse'; key.name = 'mouse';
key.type = 'X10'; key.type = 'X10';
key.raw = [b, x, y, parts[0]]; key.raw = [b, x, y, parts[0]];
key.buf = buf;
key.x = x - 32; key.x = x - 32;
key.y = y - 32; key.y = y - 32;
@ -508,16 +507,16 @@ Program.prototype._bindMouse = function(s, buf) {
// URxvt // URxvt
if (parts = /^\x1b\[(\d+;\d+;\d+)M/.exec(s)) { if (parts = /^\x1b\[(\d+;\d+;\d+)M/.exec(s)) {
var parts = parts[1].split(';') var params = parts[1].split(';')
, b = +parts[0] , b = +params[0]
, x = +parts[1] , x = +params[1]
, y = +parts[2]; , y = +params[2];
this.emit('mouse-debug', s, buf);
key.name = 'mouse'; key.name = 'mouse';
key.type = 'urxvt'; key.type = 'urxvt';
key.raw = [b, x, y, parts[0]];
key.buf = buf;
key.x = x; key.x = x;
key.y = y; key.y = y;
@ -577,16 +576,16 @@ Program.prototype._bindMouse = function(s, buf) {
// SGR // SGR
if (parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s)) { if (parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s)) {
var down = parts[2] === 'M' var down = parts[2] === 'M'
, parts = parts[1].split(';') , params = parts[1].split(';')
, b = +parts[0] , b = +params[0]
, x = +parts[1] , x = +params[1]
, y = +parts[2]; , y = +params[2];
this.emit('mouse-debug', s, buf);
key.name = 'mouse'; key.name = 'mouse';
key.type = 'sgr'; key.type = 'sgr';
key.raw = [b, x, y, parts[0]];
key.buf = buf;
key.x = x; key.x = x;
key.y = y; key.y = y;
@ -637,18 +636,17 @@ Program.prototype._bindMouse = function(s, buf) {
// The xterm mouse documentation says there is a // The xterm mouse documentation says there is a
// `<` prefix, the DECRQLP says there is no prefix. // `<` prefix, the DECRQLP says there is no prefix.
if (parts = /^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(s)) { if (parts = /^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(s)) {
var parts = parts[1].split(';') var params = parts[1].split(';')
, b = +parts[0] , b = +params[0]
, x = +parts[1] , x = +params[1]
, y = +parts[2] , y = +params[2]
, page = +parts[3]; , page = +params[3];
this.emit('mouse-debug', s, buf);
key.name = 'mouse'; key.name = 'mouse';
key.type = 'dec'; key.type = 'dec';
key.button = b; key.raw = [b, x, y, parts[0]];
key.buf = buf;
key.x = x; key.x = x;
key.y = y; key.y = y;
@ -676,11 +674,11 @@ Program.prototype._bindMouse = function(s, buf) {
, x = +parts[2] , x = +parts[2]
, y = +parts[3]; , y = +parts[3];
this.emit('mouse-debug', s, buf);
key.name = 'mouse'; key.name = 'mouse';
key.type = 'vt300'; key.type = 'vt300';
key.raw = [b, x, y, parts[0]];
key.buf = buf;
key.x = x; key.x = x;
key.y = y; key.y = y;

View File

@ -39,18 +39,6 @@ program.on('keypress', function(ch, data) {
program.write(util.inspect(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.getCursor(function(err, data) {
// program.write(util.inspect(data)); // program.write(util.inspect(data));
// }); // });