more fixes for VTE. see #89.

This commit is contained in:
Christopher Jeffrey 2015-01-31 18:36:43 -08:00
parent f055496161
commit 3cdcc7a64b
3 changed files with 48 additions and 6 deletions

View File

@ -117,6 +117,10 @@ function emitKey(stream, s) {
}
}
if (~s.indexOf('\x1b[M')) {
return;
}
key.sequence = s;
if (s === '\r') {

View File

@ -68,6 +68,9 @@ function Program(options) {
|| process.env.TERM
|| (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
this.isXFCE = /xfce/i.test(process.env.COLORTERM);
this.isVTE = !!(process.env.VTE_VERSION || this.isXFCE);
this._buf = '';
this._flush = this.flush.bind(this);
@ -357,13 +360,13 @@ 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.prototype._bindMouse = function(s, buf) {
var self = this
, key
, parts;
@ -384,6 +387,24 @@ Program.prototype._bindMouse = function(s) {
}
}
if (this.isVTE && (parts = /^\x1b\[M([\u0000-\uffff]{3})/.exec(s))) {
var b = parts[1].charCodeAt(0)
, x = parts[1].charCodeAt(1)
, y = parts[1].charCodeAt(2)
, mod;
if (x >= 65533) x = buf[4];
if (y >= 65533) y = buf[5];
// if libvte goes over 255, it sends this.
// if (x > 0x00 && x < 0x20) x += 223;
// if (y > 0x00 && y < 0x20) y += 223;
s = '\x1b[M' + parts[1][0]
+ String.fromCharCode(x)
+ String.fromCharCode(y);
}
// XTerm / X10
if (parts = /^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(s)) {
var b = parts[1].charCodeAt(0)
@ -508,7 +529,7 @@ Program.prototype._bindMouse = function(s) {
// SGR
if (parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s)) {
var down = parts[2] === 'm'
var down = parts[2] === 'M'
, parts = parts[1].split(';')
, b = +parts[0]
, x = +parts[1]
@ -2644,13 +2665,25 @@ Program.prototype.normalBuffer = function() {
};
Program.prototype.enableMouse = function() {
if (this.term('rxvt-unicode') || process.env.VTE_VERSION) {
if (this.term('rxvt-unicode')) {
return this.setMouse({
urxvtMouse: true,
allMotion: true
}, true);
}
// libvte is broken
// NOTE: The old version of vte xfce-term uses
// doesn't support the urxvt or sgr mouse protocols.
// However, it seems to have supported SGR events before URXVT events. We'll
// stick to that and hope people are using the latest VTE.
if (this.isVTE) {
return this.setMouse({
sgrMouse: true,
allMotion: true
}, true);
}
if (this.term('linux')) {
return this.setMouse({
vt200Mouse: true

View File

@ -36,6 +36,11 @@ program.on('keypress', function(ch, data) {
console.log(data);
});
program.on('mousebuf', function(buf) {
program.cup(20, 0);
console.log(buf);
});
// program.getCursor(function(err, data) {
// console.log(data);
// });