diff --git a/lib/program.js b/lib/program.js index 47df371..6c26821 100644 --- a/lib/program.js +++ b/lib/program.js @@ -90,13 +90,12 @@ function Program(options) { this.isRxvt = /rxvt/i.test(process.env.COLORTERM); this.isXterm = false; - this.isTMUX = this.term('screen') && !!process.env.TMUX; - + this.tmux = !!process.env.TMUX; this.tmuxVersion = (function() { - if (!process.env.TMUX) return 2; + if (!self.tmux) return 2; try { version = cp.execFileSync('tmux', ['-V'], { encoding: 'utf8' }); - return +version.trim().split(/\s+/).pop() || 2; + return +/([\d.]+)/.exec(version)[1]; } catch (e) { return 2; } @@ -1496,9 +1495,9 @@ Program.prototype._write = function(text) { // Example: `DCS tmux; ESC Pt ST` // Real: `DCS tmux; ESC Pt ESC \` Program.prototype._twrite = function(data) { - if (process.env.TMUX) data = '\x1bPtmux;\x1b' + data + '\x1b\\'; + if (this.tmux) data = '\x1bPtmux;\x1b' + data + '\x1b\\'; // Should work but tmux doesn't implement ST correctly: - // if (process.env.TMUX) data = '\x1bPtmux;\x1b' + data + '\x07'; + // if (this.tmux) data = '\x1bPtmux;\x1b' + data + '\x07'; return this._write(data); }; @@ -2025,7 +2024,7 @@ Program.prototype.setTitle = function(title) { // if (this.term('screen')) { // // Tmux pane - // // if (process.env.TMUX) { + // // if (this.tmux) { // // return this._write('\x1b]2;' + title + '\x1b\\'); // // } // return this._write('\x1bk' + title + '\x1b\\'); @@ -3137,9 +3136,15 @@ Program.prototype.enableMouse = function() { return this.setMouse(options, true); } + // NOTE: + // Cell Motion isn't normally need for anything below here, but we'll + // activate it for tmux (whether using it or not) in case our all-motion + // passthrough does not work. It can't hurt. + if (this.term('rxvt-unicode')) { return this.setMouse({ urxvtMouse: true, + cellMotion: true, allMotion: true }, true); } @@ -3149,6 +3154,7 @@ Program.prototype.enableMouse = function() { return this.setMouse({ vt200Mouse: true, x10Mouse: true, + cellMotion: true, allMotion: true }, true); } @@ -3160,6 +3166,7 @@ Program.prototype.enableMouse = function() { return this.setMouse({ // NOTE: Could also use urxvtMouse here. sgrMouse: true, + cellMotion: true, allMotion: true }, true); } @@ -3177,6 +3184,7 @@ Program.prototype.enableMouse = function() { return this.setMouse({ vt200Mouse: true, utfMouse: true, + cellMotion: true, allMotion: true }, true); } @@ -3260,7 +3268,7 @@ Program.prototype.setMouse = function(opt, enable) { if (opt.allMotion != null) { // NOTE: Latest versions of tmux seem to only support cellMotion (not // allMotion). We pass all motion through to the terminal. - if (process.env.TMUX && this.tmuxVersion >= 2) { + if (this.tmux && this.tmuxVersion >= 2) { if (opt.allMotion) this._twrite('\x1b[?1003h'); else this._twrite('\x1b[?1003l'); } else {