From e9b3bdac34b1e34f650696ff6c72060955125eac Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 1 Feb 2015 08:47:24 -0800 Subject: [PATCH] allow VTE mouse access to cells up to 287. see #89. --- lib/program.js | 21 +++++++++++++++++++++ test/program-mouse.js | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/program.js b/lib/program.js index cd7db03..0e2bfd3 100644 --- a/lib/program.js +++ b/lib/program.js @@ -401,6 +401,27 @@ Program.prototype._bindMouse = function(s, buf) { } } + // XTerm / X10 for buggy VTE + // VTE can only send unsigned chars and no unicode for coords. This limits + // them to 0xff. However, normally the x10 protocol does not allow a byte + // under 0x20, but since VTE can have the bytes overflow, we can consider + // bytes below 0x20 to be up to 0xff + 0x20. This gives a limit of 287. Since + // characters ranging from 223 to 248 confuse javascript's utf parser, we + // need to parse the raw binary. + if (this.isVTE && buf[0] === 0x1b && buf[1] === 0x5b && buf[2] === 0x4d) { + var b = buf[3] + , x = buf[4] + , y = buf[5]; + + if (x < 0x20) x += 255; + if (y < 0x20) y += 255; + + s = '\x1b[M' + + String.fromCharCode(b) + + String.fromCharCode(x) + + String.fromCharCode(y); + } + // XTerm / X10 if (parts = /^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(s)) { var b = parts[1].charCodeAt(0) diff --git a/test/program-mouse.js b/test/program-mouse.js index 747e5fb..3280eec 100644 --- a/test/program-mouse.js +++ b/test/program-mouse.js @@ -36,9 +36,10 @@ program.on('keypress', function(ch, data) { console.log(data); }); -program.on('mousebuf', function(buf) { +program.on('mouse-debug', function(data) { program.cup(20, 0); - console.log(buf); + data = Array.prototype.slice.call(data); + console.log(data); }); // program.getCursor(function(err, data) {