From 9cdba8979a6b060918414398aa9a668ab4cf1734 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 19 Jul 2015 03:26:30 -0700 Subject: [PATCH] no tmux checking code seems necessary. see #145. --- lib/program.js | 155 +++++++------------------------------------------ 1 file changed, 22 insertions(+), 133 deletions(-) diff --git a/lib/program.js b/lib/program.js index c9b956b..47df371 100644 --- a/lib/program.js +++ b/lib/program.js @@ -14,8 +14,6 @@ var EventEmitter = require('events').EventEmitter , util = require('util') , fs = require('fs'); -// cp = { __proto__: cp, execFileSync: null }; - var Tput = require('./tput') , colors = require('./colors') , slice = Array.prototype.slice; @@ -94,6 +92,16 @@ function Program(options) { this.isTMUX = this.term('screen') && !!process.env.TMUX; + this.tmuxVersion = (function() { + if (!process.env.TMUX) return 2; + try { + version = cp.execFileSync('tmux', ['-V'], { encoding: 'utf8' }); + return +version.trim().split(/\s+/).pop() || 2; + } catch (e) { + return 2; + } + })(); + this._buf = ''; this._flush = this.flush.bind(this); @@ -110,8 +118,6 @@ function Program(options) { Program.global = this; } - this.tmux.check(); - if (options.tput !== false) { this.setupTput(); } @@ -3079,85 +3085,6 @@ Program.prototype.normalBuffer = function() { return this.resetMode('?1049'); }; -Program.prototype.tmux = { - used: !!process.env.TMUX, - - check: function() { - var self = this; - if (!this.used) return; - if (cp.execFileSync) return; - self._tmuxLoading = 2; - cp.execFile('tmux', ['-V'], function(err, stdout, stderr) { - self._tmuxLoading--; - if (err || (stderr && stderr.trim())) return; - self._version = +(stdout || '1').trim().split(/\s+/).pop() || 1; - }); - cp.execFile('tmux', ['list-panes'], function(err, stdout, stderr) { - self._tmuxLoading--; - if (err || (stderr && stderr.trim())) return; - self._panes = (stdout || '1').trim().split('\n').length || 1; - }); - }, - - wait: function(callback) { - var self = this; - if (!this.used) return callback(); - if (cp.execFileSync) return callback(); - var timer = setInterval(function() { - if (!self._tmuxLoading) { - clearInterval(timer); - return callback(); - } - }, 100); - }, - - get version() { - var version = -1; - if (!this.used) return version; - - if (this._version != null) { - return this._version; - } - - try { - version = cp.execFileSync('tmux', ['-V'], { encoding: 'utf8' }); - version = +(version || '1').trim().split(/\s+/).pop() || 1; - } catch (e) { - ; - } - - if (this._version == null) { - this._version = version; - } - - return version; - }, - - get panes() { - return 1; // doesn't seem to matter - - var panes = -1; - if (!this.used) return panes; - - if (this._panes != null) { - return this._panes; - } - - try { - panes = cp.execFileSync('tmux', ['list-panes'], { encoding: 'utf8' }); - panes = (panes || '1').trim().split('\n').length || 1; - } catch (e) { - ; - } - - if (this._panes == null) { - this._panes = panes; - } - - return panes; - } -}; - Program.prototype.enableMouse = function() { if (process.env.BLESSED_FORCE_MODES) { var modes = process.env.BLESSED_FORCE_MODES.split(','); @@ -3247,29 +3174,11 @@ Program.prototype.enableMouse = function() { if (this.term('xterm') || this.term('screen') || (this.tput && this.tput.strings.key_mouse)) { - return this.tmux.wait(function() { - // console.error({ - // method: 'enable', - // sync: !!cp.execFileSync, - // version: this.tmux.version, - // panes: this.tmux.panes - // }); - if (this.tmux.used && this.tmux.version >= 2 && this.tmux.panes > 1) { - // NOTE: tmux>=2.0 does not support allMotion. - return this.setMouse({ - vt200Mouse: true, - utfMouse: true, - cellMotion: true, - allMotion: true - }, true); - } - - return this.setMouse({ - vt200Mouse: true, - utfMouse: true, - allMotion: true - }, true); - }.bind(this)); + return this.setMouse({ + vt200Mouse: true, + utfMouse: true, + allMotion: true + }, true); } }; @@ -3349,34 +3258,14 @@ Program.prototype.setMouse = function(opt, enable) { // Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking. // any event mouse if (opt.allMotion != null) { - if (opt.allMotion) { - this.tmux.wait(function() { - // console.error({ - // method: 'set', - // on: true, - // sync: !!cp.execFileSync, - // version: this.tmux.version, - // panes: this.tmux.panes - // }); - if (this.tmux.used && this.tmux.version >= 2 && this.tmux.panes === 1) { - this._twrite('\x1b[?1003h'); - } else { - this.setMode('?1003'); - } - }.bind(this)); + // 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 (opt.allMotion) this._twrite('\x1b[?1003h'); + else this._twrite('\x1b[?1003l'); } else { - // console.error({ - // method: 'set', - // on: false, - // sync: !!cp.execFileSync, - // version: this.tmux.version, - // panes: this.tmux.panes - // }); - if (this.tmux.used && this.tmux.version >= 2 && this.tmux.panes === 1) { - this._twrite('\x1b[?1003l'); - } else { - this.resetMode('?1003'); - } + if (opt.allMotion) this.setMode('?1003'); + else this.resetMode('?1003'); } }