From 03cdfbb39c777c2523981eddfe9a208e5e58daac Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 13 Feb 2015 19:14:27 -0800 Subject: [PATCH] add mouse protocols. window title restore. fix response. --- lib/program.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/program.js b/lib/program.js index 7c917b6..4f6b31c 100644 --- a/lib/program.js +++ b/lib/program.js @@ -260,6 +260,17 @@ Program.prototype.listen = function() { throw new Error('Not a terminal.'); } + // unshiftEvent(process, 'exit', function() { + // if (self._originalTitle) { + // self.setTitle(self._originalTitle); + // } + // }); + // this.setTitleModeFeature(3); + // this.manipulateWindow(21, function(err, data) { + // if (err) return; + // self._originalTitle = data.text; + // }); + // Input this.input.on('keypress', function(ch, key) { key = key || { ch: ch }; @@ -401,6 +412,11 @@ Program.prototype._bindMouse = function(s, buf) { } } + // if (this.8bit) { + // s = s.replace(/\233/g, '\x1b['); + // buf = new Buffer(s, 'utf8'); + // } + // 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 @@ -699,6 +715,24 @@ Program.prototype._bindMouse = function(s, buf) { return; } + // pterm mouse + // if (parts = /^\x1b\[([\x00\u0020-\uffff]{3})/.exec(s)) { + // ; + // } + + // jsbterm mouse + // if (parts = /^\x1b\[0~zw([\x00\u0020-\uffff]{3})/.exec(s)) { + // ; + // } + + // net + // if (parts = /^\x1b}([\x00\u0020-\uffff]{3})/.exec(s)) { + // ; + // } + + // TODO: + // sysmouse + if (parts = /^\x1b\[(O|I)/.exec(s)) { key.action = parts[1] === 'I' ? 'focus' @@ -1233,7 +1267,7 @@ Program.prototype._bindResponse = function(s) { // Ps = 2 1 -> Report xterm window's title. Result is OSC l // label ST if (parts = /^\x1b\](l|L)([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s)) { - out.type = 'window-manipulation'; + out.event = 'window-manipulation'; out.code = ''; if (parts[1] === 'L') { @@ -1367,6 +1401,8 @@ Program.prototype._bindResponse = function(s) { }; Program.prototype.response = function(name, text, callback) { + var self = this; + if (arguments.length === 2) { callback = text; text = name; @@ -1395,6 +1431,7 @@ Program.prototype.response = function(name, text, callback) { var timeout = setTimeout(function() { self.removeListener(name, onresponse); + return callback(new Error('Timeout.')); }, 2000); return this._write(text); @@ -2883,6 +2920,15 @@ Program.prototype.enableMouse = function() { case 'X10MOUSE': options.x10Mouse = v; break; + case 'DECMOUSE': + options.decMouse = v; + break; + case 'PTERMMOUSE': + options.ptermMouse = v; + break; + case 'JSBTERMMOUSE': + options.jsbtermMouse = v; + break; case 'VT200HILITE': options.vt200Hilite = v; break; @@ -3054,6 +3100,29 @@ Program.prototype.setMouse = function(opt, enable) { else this.resetMode('?1015'); } + // dec mouse + if (opt.decMouse != null) { + if (opt.decMouse) this._write('\x1b[1;2\'z\x1b[1;3\'{'); + else this._write('\x1b[\'z'); + } + + // pterm mouse + if (opt.ptermMouse != null) { + if (opt.ptermMouse) this._write('\x1b[>1h\x1b[>6h\x1b[>7h\x1b[>1h\x1b[>9l'); + else this._write('\x1b[>1l\x1b[>6l\x1b[>7l\x1b[>1l\x1b[>9h'); + } + + // jsbterm mouse + if (opt.jsbtermMouse != null) { + // + = advanced mode + if (opt.jsbtermMouse) this._write('\x1b[0~ZwLMRK+1Q\x1b\\'); + else this._write('\x1b[0~ZwQ\x1b\\'); + } + + // TODO: + // sysmouse + // net + // gpm mouse if (opt.gpmMouse != null) { if (opt.gpmMouse) this.enableGpm();