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)
, 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;

View File

@ -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));
// });