add workarounds for libvte mouse events. see #89.

This commit is contained in:
Christopher Jeffrey 2015-01-31 01:43:16 -08:00
parent d136c46ecc
commit bb61e5c144
3 changed files with 38 additions and 6 deletions

View File

@ -117,6 +117,12 @@ function emitKey(stream, s) {
}
}
// libvte sometimes sends mouse events in chunks.
// deal with this in a better way later.
if (process.env.VTE_VERSION) {
if (~s.indexOf('\x1b[M')) return;
}
key.sequence = s;
if (s === '\r') {

View File

@ -355,13 +355,19 @@ Program.prototype.bindMouse = function() {
, self = this;
this.on('data', function(data) {
data = decoder.write(data);
if (!data) return;
self._bindMouse(data);
var text = decoder.write(data);
if (!text) return;
self._bindMouse(text, data);
});
};
Program.prototype._bindMouse = function(s) {
Program.saneMouse = /^\x1b\[M([\x00\u0020-\uffff]{3})/;
Program.vteMouse = /^\x1b\[M([\u0000-\uffff]{3})/;
Program.x10Mouse = !process.env.VTE_VERSION
? Program.saneMouse
: Program.vteMouse;
Program.prototype._bindMouse = function(s, buf) {
var self = this
, key
, parts;
@ -383,12 +389,24 @@ Program.prototype._bindMouse = function(s) {
}
// XTerm / X10
if (parts = /^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(s)) {
if (parts = Program.x10Mouse.exec(s)) {
var b = parts[1].charCodeAt(0)
, x = parts[1].charCodeAt(1)
, y = parts[1].charCodeAt(2)
, mod;
if (process.env.VTE_VERSION) {
if (x > 65000) {
x = buf[4];
}
// if libvte goes over 255, it sends this.
// it can't go beyond 262 with this:
if (x > 0x00 && x < 0x20) {
x += 223;
}
}
key.name = 'mouse';
key.type = 'X10';

View File

@ -22,6 +22,14 @@ program.on('mouse', function(data) {
console.log(data);
});
program.input.on('data', function(data) {
program.cup(10, 0);
program.write(JSON.stringify(data + ''));
program.nel();
program.cr();
program.write(JSON.stringify(Array.prototype.slice.call(data)));
});
program.key(['q', 'escape', 'C-c'], function() {
program.showCursor();
program.disableMouse();
@ -32,6 +40,6 @@ program.key(['q', 'escape', 'C-c'], function() {
program.on('keypress', function(ch, data) {
if (data.name === 'mouse') return;
program.clear();
program.cup(0, 0);
program.cup(20, 0);
console.log(data);
});