lint lib/program.js
This commit is contained in:
parent
6d9cf6b7aa
commit
add386f796
231
lib/program.js
231
lib/program.js
|
@ -8,15 +8,15 @@
|
|||
* Modules
|
||||
*/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
, StringDecoder = require('string_decoder').StringDecoder
|
||||
, cp = require('child_process')
|
||||
, util = require('util')
|
||||
, fs = require('fs');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var StringDecoder = require('string_decoder').StringDecoder;
|
||||
var cp = require('child_process');
|
||||
var util = require('util');
|
||||
var fs = require('fs');;
|
||||
|
||||
var Tput = require('./tput')
|
||||
, colors = require('./colors')
|
||||
, slice = Array.prototype.slice;
|
||||
var Tput = require('./tput');
|
||||
var colors = require('./colors');
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
var nextTick = global.setImmediate || process.nextTick.bind(process);
|
||||
|
||||
|
@ -66,17 +66,13 @@ function Program(options) {
|
|||
this.scrollTop = 0;
|
||||
this.scrollBottom = this.rows - 1;
|
||||
|
||||
this._terminal = options.terminal
|
||||
|| options.term
|
||||
|| process.env.TERM
|
||||
|| (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
|
||||
this._terminal = options.terminal || options.term || process.env.TERM || (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
|
||||
|
||||
this._terminal = this._terminal.toLowerCase();
|
||||
|
||||
// OSX
|
||||
this.isOSXTerm = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
||||
this.isiTerm2 = process.env.TERM_PROGRAM === 'iTerm.app'
|
||||
|| !!process.env.ITERM_SESSION_ID;
|
||||
this.isiTerm2 = process.env.TERM_PROGRAM === 'iTerm.app' || !!process.env.ITERM_SESSION_ID;
|
||||
|
||||
// VTE
|
||||
// NOTE: lxterminal does not provide an env variable to check for.
|
||||
|
@ -85,10 +81,7 @@ function Program(options) {
|
|||
this.isXFCE = /xfce/i.test(process.env.COLORTERM);
|
||||
this.isTerminator = !!process.env.TERMINATOR_UUID;
|
||||
this.isLXDE = false;
|
||||
this.isVTE = !!process.env.VTE_VERSION
|
||||
|| this.isXFCE
|
||||
|| this.isTerminator
|
||||
|| this.isLXDE;
|
||||
this.isVTE = !!process.env.VTE_VERSION || this.isXFCE || this.isTerminator || this.isLXDE;
|
||||
|
||||
// xterm and rxvt - not accurate
|
||||
this.isRxvt = /rxvt/i.test(process.env.COLORTERM);
|
||||
|
@ -398,10 +391,7 @@ Program.prototype._listenInput = function() {
|
|||
self.input.emit('keypress', ch, merge({}, key, { name: 'enter' }));
|
||||
}
|
||||
|
||||
var name = (key.ctrl ? 'C-' : '')
|
||||
+ (key.meta ? 'M-' : '')
|
||||
+ (key.shift && key.name ? 'S-' : '')
|
||||
+ (key.name || ch);
|
||||
var name = (key.ctrl ? 'C-' : '') + (key.meta ? 'M-' : '') + (key.shift && key.name ? 'S-' : '') + (key.name || ch);
|
||||
|
||||
key.full = name;
|
||||
|
||||
|
@ -557,8 +547,7 @@ Program.prototype.bindMouse = function() {
|
|||
if (this._boundMouse) return;
|
||||
this._boundMouse = true;
|
||||
|
||||
var decoder = new StringDecoder('utf8')
|
||||
, self = this;
|
||||
var decoder = new StringDecoder('utf8'), self = this;
|
||||
|
||||
this.on('data', function(data) {
|
||||
var text = decoder.write(data);
|
||||
|
@ -568,17 +557,7 @@ Program.prototype.bindMouse = function() {
|
|||
};
|
||||
|
||||
Program.prototype._bindMouse = function(s, buf) {
|
||||
var self = this
|
||||
, key
|
||||
, parts
|
||||
, b
|
||||
, x
|
||||
, y
|
||||
, mod
|
||||
, params
|
||||
, down
|
||||
, page
|
||||
, button;
|
||||
var self = this, key, parts, b, x, y, mod, params, down, page, button;
|
||||
|
||||
key = {
|
||||
name: undefined,
|
||||
|
@ -2565,106 +2544,64 @@ Program.prototype._attr = function(param, val) {
|
|||
if (val === false) return '';
|
||||
return '\x1b[m';
|
||||
case 'bold':
|
||||
return val === false
|
||||
? '\x1b[22m'
|
||||
: '\x1b[1m';
|
||||
return val === false ? '\x1b[22m' : '\x1b[1m';
|
||||
case 'ul':
|
||||
case 'underline':
|
||||
case 'underlined':
|
||||
return val === false
|
||||
? '\x1b[24m'
|
||||
: '\x1b[4m';
|
||||
return val === false ? '\x1b[24m' : '\x1b[4m';
|
||||
case 'blink':
|
||||
return val === false
|
||||
? '\x1b[25m'
|
||||
: '\x1b[5m';
|
||||
return val === false ? '\x1b[25m' : '\x1b[5m';
|
||||
case 'inverse':
|
||||
return val === false
|
||||
? '\x1b[27m'
|
||||
: '\x1b[7m';
|
||||
return val === false ? '\x1b[27m' : '\x1b[7m';
|
||||
case 'invisible':
|
||||
return val === false
|
||||
? '\x1b[28m'
|
||||
: '\x1b[8m';
|
||||
return val === false ? '\x1b[28m' : '\x1b[8m';
|
||||
|
||||
// 8-color foreground
|
||||
case 'black fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[30m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[30m';
|
||||
case 'red fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[31m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[31m';
|
||||
case 'green fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[32m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[32m';
|
||||
case 'yellow fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[33m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[33m';
|
||||
case 'blue fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[34m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[34m';
|
||||
case 'magenta fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[35m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[35m';
|
||||
case 'cyan fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[36m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[36m';
|
||||
case 'white fg':
|
||||
case 'light grey fg':
|
||||
case 'light gray fg':
|
||||
case 'bright grey fg':
|
||||
case 'bright gray fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[37m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[37m';
|
||||
case 'default fg':
|
||||
if (val === false) return '';
|
||||
return '\x1b[39m';
|
||||
|
||||
// 8-color background
|
||||
case 'black bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[40m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[40m';
|
||||
case 'red bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[41m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[41m';
|
||||
case 'green bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[42m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[42m';
|
||||
case 'yellow bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[43m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[43m';
|
||||
case 'blue bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[44m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[44m';
|
||||
case 'magenta bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[45m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[45m';
|
||||
case 'cyan bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[46m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[46m';
|
||||
case 'white bg':
|
||||
case 'light grey bg':
|
||||
case 'light gray bg':
|
||||
case 'bright grey bg':
|
||||
case 'bright gray bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[47m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[47m';
|
||||
case 'default bg':
|
||||
if (val === false) return '';
|
||||
return '\x1b[49m';
|
||||
|
@ -2674,95 +2611,61 @@ Program.prototype._attr = function(param, val) {
|
|||
case 'bright black fg':
|
||||
case 'grey fg':
|
||||
case 'gray fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[90m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[90m';
|
||||
case 'light red fg':
|
||||
case 'bright red fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[91m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[91m';
|
||||
case 'light green fg':
|
||||
case 'bright green fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[92m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[92m';
|
||||
case 'light yellow fg':
|
||||
case 'bright yellow fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[93m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[93m';
|
||||
case 'light blue fg':
|
||||
case 'bright blue fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[94m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[94m';
|
||||
case 'light magenta fg':
|
||||
case 'bright magenta fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[95m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[95m';
|
||||
case 'light cyan fg':
|
||||
case 'bright cyan fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[96m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[96m';
|
||||
case 'light white fg':
|
||||
case 'bright white fg':
|
||||
return val === false
|
||||
? '\x1b[39m'
|
||||
: '\x1b[97m';
|
||||
return val === false ? '\x1b[39m' : '\x1b[97m';
|
||||
|
||||
// 16-color background
|
||||
case 'light black bg':
|
||||
case 'bright black bg':
|
||||
case 'grey bg':
|
||||
case 'gray bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[100m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[100m';
|
||||
case 'light red bg':
|
||||
case 'bright red bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[101m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[101m';
|
||||
case 'light green bg':
|
||||
case 'bright green bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[102m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[102m';
|
||||
case 'light yellow bg':
|
||||
case 'bright yellow bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[103m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[103m';
|
||||
case 'light blue bg':
|
||||
case 'bright blue bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[104m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[104m';
|
||||
case 'light magenta bg':
|
||||
case 'bright magenta bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[105m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[105m';
|
||||
case 'light cyan bg':
|
||||
case 'bright cyan bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[106m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[106m';
|
||||
case 'light white bg':
|
||||
case 'bright white bg':
|
||||
return val === false
|
||||
? '\x1b[49m'
|
||||
: '\x1b[107m';
|
||||
return val === false ? '\x1b[49m' : '\x1b[107m';
|
||||
|
||||
// non-16-color rxvt default fg and bg
|
||||
case 'default fg bg':
|
||||
if (val === false) return '';
|
||||
return this.term('rxvt')
|
||||
? '\x1b[100m'
|
||||
: '\x1b[39;49m';
|
||||
return this.term('rxvt') ? '\x1b[100m' : '\x1b[39;49m';
|
||||
|
||||
default:
|
||||
// 256-color fg and bg
|
||||
|
@ -3430,12 +3333,12 @@ Program.prototype.disableMouse = function() {
|
|||
|
||||
// Set Mouse
|
||||
Program.prototype.setMouse = function(opt, enable) {
|
||||
if (opt.normalMouse != null) {
|
||||
if (opt.normalMouse !== null) {
|
||||
opt.vt200Mouse = opt.normalMouse;
|
||||
opt.allMotion = opt.normalMouse;
|
||||
}
|
||||
|
||||
if (opt.hiliteTracking != null) {
|
||||
if (opt.hiliteTracking !== null) {
|
||||
opt.vt200Hilite = opt.hiliteTracking;
|
||||
}
|
||||
|
||||
|
@ -3458,7 +3361,7 @@ Program.prototype.setMouse = function(opt, enable) {
|
|||
// tion Mouse Tracking.
|
||||
// Ps = 9 -> Don't send Mouse X & Y on button press.
|
||||
// x10 mouse
|
||||
if (opt.x10Mouse != null) {
|
||||
if (opt.x10Mouse !== null) {
|
||||
if (opt.x10Mouse) this.setMode('?9');
|
||||
else this.resetMode('?9');
|
||||
}
|
||||
|
@ -3468,14 +3371,14 @@ Program.prototype.setMouse = function(opt, enable) {
|
|||
// Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
|
||||
// release. See the section Mouse Tracking.
|
||||
// vt200 mouse
|
||||
if (opt.vt200Mouse != null) {
|
||||
if (opt.vt200Mouse !== null) {
|
||||
if (opt.vt200Mouse) this.setMode('?1000');
|
||||
else this.resetMode('?1000');
|
||||
}
|
||||
|
||||
// Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
|
||||
// Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
|
||||
if (opt.vt200Hilite != null) {
|
||||
if (opt.vt200Hilite !== null) {
|
||||
if (opt.vt200Hilite) this.setMode('?1001');
|
||||
else this.resetMode('?1001');
|
||||
}
|
||||
|
@ -3483,7 +3386,7 @@ Program.prototype.setMouse = function(opt, enable) {
|
|||
// Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
|
||||
// Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
|
||||
// button event mouse
|
||||
if (opt.cellMotion != null) {
|
||||
if (opt.cellMotion !== null) {
|
||||
if (opt.cellMotion) this.setMode('?1002');
|
||||
else this.resetMode('?1002');
|
||||
}
|
||||
|
@ -3491,7 +3394,7 @@ Program.prototype.setMouse = function(opt, enable) {
|
|||
// Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
|
||||
// Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
|
||||
// any event mouse
|
||||
if (opt.allMotion != null) {
|
||||
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 (this.tmux && this.tmuxVersion >= 2) {
|
||||
|
@ -3505,51 +3408,51 @@ Program.prototype.setMouse = function(opt, enable) {
|
|||
|
||||
// Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
|
||||
// Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
|
||||
if (opt.sendFocus != null) {
|
||||
if (opt.sendFocus !== null) {
|
||||
if (opt.sendFocus) this.setMode('?1004');
|
||||
else this.resetMode('?1004');
|
||||
}
|
||||
|
||||
// Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
|
||||
// Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
|
||||
if (opt.utfMouse != null) {
|
||||
if (opt.utfMouse !== null) {
|
||||
if (opt.utfMouse) this.setMode('?1005');
|
||||
else this.resetMode('?1005');
|
||||
}
|
||||
|
||||
// sgr mouse
|
||||
if (opt.sgrMouse != null) {
|
||||
if (opt.sgrMouse !== null) {
|
||||
if (opt.sgrMouse) this.setMode('?1006');
|
||||
else this.resetMode('?1006');
|
||||
}
|
||||
|
||||
// urxvt mouse
|
||||
if (opt.urxvtMouse != null) {
|
||||
if (opt.urxvtMouse !== null) {
|
||||
if (opt.urxvtMouse) this.setMode('?1015');
|
||||
else this.resetMode('?1015');
|
||||
}
|
||||
|
||||
// dec mouse
|
||||
if (opt.decMouse != null) {
|
||||
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 !== 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) {
|
||||
if (opt.jsbtermMouse !== null) {
|
||||
// + = advanced mode
|
||||
if (opt.jsbtermMouse) this._write('\x1b[0~ZwLMRK+1Q\x1b\\');
|
||||
else this._write('\x1b[0~ZwQ\x1b\\');
|
||||
}
|
||||
|
||||
// gpm mouse
|
||||
if (opt.gpmMouse != null) {
|
||||
if (opt.gpmMouse !== null) {
|
||||
if (opt.gpmMouse) this.enableGpm();
|
||||
else this.disableGpm();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue