2013-01-27 16:06:58 +00:00
|
|
|
/**
|
2013-07-24 19:40:05 +00:00
|
|
|
* program.js - basic curses-like functionality for blessed.
|
2015-02-01 15:22:39 +00:00
|
|
|
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
|
2013-07-24 19:40:05 +00:00
|
|
|
* https://github.com/chjj/blessed
|
2013-01-27 16:06:58 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
/**
|
|
|
|
* Modules
|
|
|
|
*/
|
|
|
|
|
2013-02-22 21:51:13 +00:00
|
|
|
var EventEmitter = require('events').EventEmitter
|
2013-08-13 16:30:44 +00:00
|
|
|
, StringDecoder = require('string_decoder').StringDecoder
|
2015-07-19 10:20:25 +00:00
|
|
|
, cp = require('child_process')
|
2013-07-31 05:14:13 +00:00
|
|
|
, util = require('util')
|
2013-08-29 23:00:13 +00:00
|
|
|
, fs = require('fs');
|
|
|
|
|
|
|
|
var Tput = require('./tput')
|
2013-07-18 19:52:56 +00:00
|
|
|
, colors = require('./colors')
|
|
|
|
, slice = Array.prototype.slice;
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2015-01-31 20:26:19 +00:00
|
|
|
var nextTick = global.setImmediate || process.nextTick.bind(process);
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
/**
|
|
|
|
* Program
|
|
|
|
*/
|
|
|
|
|
2013-02-24 18:04:22 +00:00
|
|
|
function Program(options) {
|
2013-07-18 22:56:05 +00:00
|
|
|
var self = this;
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
if (!(this instanceof Program)) {
|
2013-02-24 18:04:22 +00:00
|
|
|
return new Program(options);
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
EventEmitter.call(this);
|
|
|
|
|
2013-02-24 18:04:22 +00:00
|
|
|
if (!options || options.__proto__ !== Object.prototype) {
|
|
|
|
options = {
|
|
|
|
input: arguments[0],
|
|
|
|
output: arguments[1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.options = options;
|
|
|
|
this.input = options.input || process.stdin;
|
|
|
|
this.output = options.output || process.stdout;
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2013-07-31 05:14:13 +00:00
|
|
|
options.log = options.log || options.dump;
|
|
|
|
if (options.log) {
|
2013-08-29 23:00:13 +00:00
|
|
|
this._logger = fs.createWriteStream(options.log);
|
2013-07-31 05:14:13 +00:00
|
|
|
if (options.dump) this.setupDump();
|
2013-07-14 17:08:03 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 05:36:36 +00:00
|
|
|
this.zero = options.zero !== false;
|
2013-08-01 08:13:20 +00:00
|
|
|
this.useBuffer = options.buffer;
|
2013-07-12 05:00:11 +00:00
|
|
|
|
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
2013-07-12 05:08:36 +00:00
|
|
|
this.savedX = 0;
|
|
|
|
this.savedY = 0;
|
2013-01-27 10:30:52 +00:00
|
|
|
|
|
|
|
this.cols = this.output.columns || 1;
|
|
|
|
this.rows = this.output.rows || 1;
|
|
|
|
|
2013-07-12 05:00:11 +00:00
|
|
|
this.scrollTop = 0;
|
|
|
|
this.scrollBottom = this.rows - 1;
|
|
|
|
|
2013-07-14 14:32:50 +00:00
|
|
|
this.terminal = options.term
|
|
|
|
|| options.terminal
|
|
|
|
|| process.env.TERM
|
2013-08-29 23:00:13 +00:00
|
|
|
|| (process.platform === 'win32' ? 'windows-ansi' : 'xterm');
|
2013-02-24 18:04:22 +00:00
|
|
|
|
2015-02-01 06:29:43 +00:00
|
|
|
// OSX
|
|
|
|
this.isOSXTerm = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
|
|
this.isiTerm2 = process.env.TERM_PROGRAM === 'iTerm.app'
|
|
|
|
|| !!process.env.ITERM_SESSION_ID;
|
|
|
|
|
|
|
|
// VTE
|
2015-02-01 06:22:15 +00:00
|
|
|
// NOTE: lxterminal does not provide an env variable to check for.
|
|
|
|
// NOTE: gnome-terminal and sakura use a later version of VTE
|
|
|
|
// which provides VTE_VERSION as well as supports SGR events.
|
2015-02-01 02:36:43 +00:00
|
|
|
this.isXFCE = /xfce/i.test(process.env.COLORTERM);
|
2015-02-01 06:22:15 +00:00
|
|
|
this.isTerminator = !!process.env.TERMINATOR_UUID;
|
|
|
|
this.isLXDE = false;
|
|
|
|
this.isVTE = !!process.env.VTE_VERSION
|
|
|
|
|| this.isXFCE
|
|
|
|
|| this.isTerminator
|
|
|
|
|| this.isLXDE;
|
2015-02-01 02:36:43 +00:00
|
|
|
|
2015-03-20 06:49:26 +00:00
|
|
|
// xterm and rxvt - not accurate
|
|
|
|
this.isRxvt = /rxvt/i.test(process.env.COLORTERM);
|
|
|
|
this.isXterm = false;
|
|
|
|
|
2015-06-24 01:02:05 +00:00
|
|
|
this.isTMUX = this.term('screen') && !!process.env.TMUX;
|
|
|
|
|
2015-07-19 10:26:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2013-07-31 22:09:41 +00:00
|
|
|
this._buf = '';
|
2013-08-01 06:52:28 +00:00
|
|
|
this._flush = this.flush.bind(this);
|
|
|
|
|
|
|
|
unshiftEvent(process, 'exit', function() {
|
|
|
|
// Ensure the buffer is flushed (it should
|
|
|
|
// always be at this point, but who knows).
|
|
|
|
self.flush();
|
|
|
|
// Ensure _exiting is set (could technically
|
|
|
|
// use process._exiting).
|
|
|
|
self._exiting = true;
|
|
|
|
});
|
2013-07-31 22:09:41 +00:00
|
|
|
|
2013-07-12 05:08:36 +00:00
|
|
|
if (!Program.global) {
|
|
|
|
Program.global = this;
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:13:20 +00:00
|
|
|
if (options.tput !== false) {
|
2013-02-26 01:10:19 +00:00
|
|
|
this.setupTput();
|
2013-02-24 18:04:22 +00:00
|
|
|
}
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
this.listen();
|
|
|
|
}
|
|
|
|
|
|
|
|
Program.prototype.__proto__ = EventEmitter.prototype;
|
|
|
|
|
2013-07-31 05:14:13 +00:00
|
|
|
Program.prototype.log = function() {
|
|
|
|
return this._log('LOG', util.format.apply(util, arguments));
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.debug = function() {
|
|
|
|
if (!this.options.debug) return;
|
|
|
|
return this._log('DEBUG', util.format.apply(util, arguments));
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype._log = function(pre, msg) {
|
|
|
|
if (!this._logger) return;
|
|
|
|
return this._logger.write(pre + ': ' + msg + '\n-\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.setupDump = function() {
|
2013-07-14 17:08:03 +00:00
|
|
|
var self = this
|
2013-07-31 05:14:13 +00:00
|
|
|
, write = this.output.write
|
2013-08-13 16:30:44 +00:00
|
|
|
, decoder = new StringDecoder('utf8');
|
2013-07-14 17:08:03 +00:00
|
|
|
|
2013-07-30 00:06:22 +00:00
|
|
|
function stringify(data) {
|
2013-07-30 00:00:31 +00:00
|
|
|
return caret(data
|
|
|
|
.replace(/\r/g, '\\r')
|
|
|
|
.replace(/\n/g, '\\n')
|
|
|
|
.replace(/\t/g, '\\t'))
|
|
|
|
.replace(/[^ -~]/g, function(ch) {
|
|
|
|
if (ch.charCodeAt(0) > 0xff) return ch;
|
|
|
|
ch = ch.charCodeAt(0).toString(16);
|
|
|
|
if (ch.length > 2) {
|
|
|
|
if (ch.length < 4) ch = '0' + ch;
|
|
|
|
return '\\u' + ch;
|
|
|
|
}
|
|
|
|
if (ch.length < 2) ch = '0' + ch;
|
|
|
|
return '\\x' + ch;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function caret(data) {
|
|
|
|
return data.replace(/[\0\x80\x1b-\x1f\x7f\x01-\x1a]/g, function(ch) {
|
|
|
|
switch (ch) {
|
|
|
|
case '\0':
|
|
|
|
case '\200':
|
|
|
|
ch = '@';
|
|
|
|
break;
|
|
|
|
case '\x1b':
|
|
|
|
ch = '[';
|
|
|
|
break;
|
|
|
|
case '\x1c':
|
|
|
|
ch = '\\';
|
|
|
|
break;
|
|
|
|
case '\x1d':
|
|
|
|
ch = ']';
|
|
|
|
break;
|
|
|
|
case '\x1e':
|
|
|
|
ch = '^';
|
|
|
|
break;
|
|
|
|
case '\x1f':
|
|
|
|
ch = '_';
|
|
|
|
break;
|
|
|
|
case '\x7f':
|
|
|
|
ch = '?';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ch = ch.charCodeAt(0);
|
2013-07-30 00:06:22 +00:00
|
|
|
// From ('A' - 64) to ('Z' - 64).
|
2013-07-30 00:00:31 +00:00
|
|
|
if (ch >= 1 && ch <= 26) {
|
|
|
|
ch = String.fromCharCode(ch + 64);
|
|
|
|
} else {
|
|
|
|
return String.fromCharCode(ch);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return '^' + ch;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.input.on('data', function(data) {
|
2013-07-31 05:14:13 +00:00
|
|
|
self._log('IN', stringify(decoder.write(data)));
|
2013-07-30 00:00:31 +00:00
|
|
|
});
|
2013-07-31 05:14:13 +00:00
|
|
|
|
|
|
|
this.output.write = function(data) {
|
|
|
|
self._log('OUT', stringify(data));
|
|
|
|
return write.apply(this, arguments);
|
|
|
|
};
|
2013-07-14 17:08:03 +00:00
|
|
|
};
|
|
|
|
|
2013-02-27 18:22:31 +00:00
|
|
|
Program.prototype.setupTput = function() {
|
2013-08-01 08:13:20 +00:00
|
|
|
if (this._tputSetup) return;
|
|
|
|
this._tputSetup = true;
|
|
|
|
|
2013-02-26 01:10:19 +00:00
|
|
|
var self = this
|
2013-02-27 18:22:31 +00:00
|
|
|
, options = this.options
|
|
|
|
, write = this.write.bind(this);
|
2013-02-26 01:10:19 +00:00
|
|
|
|
|
|
|
var tput = this.tput = new Tput({
|
|
|
|
term: this.terminal,
|
2013-07-22 08:58:44 +00:00
|
|
|
padding: options.padding,
|
|
|
|
extended: options.extended,
|
|
|
|
printf: options.printf,
|
|
|
|
termcap: options.termcap
|
2013-02-26 01:10:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.put = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var args = slice.call(arguments)
|
2013-02-26 01:10:19 +00:00
|
|
|
, cap = args.shift();
|
|
|
|
|
|
|
|
if (tput[cap]) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write(tput[cap].apply(tput, args));
|
2013-02-26 01:10:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-27 18:22:31 +00:00
|
|
|
Object.keys(tput).forEach(function(key) {
|
2013-02-27 18:24:38 +00:00
|
|
|
if (self[key] == null) {
|
|
|
|
self[key] = tput[key];
|
|
|
|
}
|
2013-02-27 18:22:31 +00:00
|
|
|
|
2013-02-26 01:10:19 +00:00
|
|
|
if (typeof tput[key] !== 'function') {
|
|
|
|
self.put[key] = tput[key];
|
|
|
|
return;
|
|
|
|
}
|
2013-02-27 18:24:38 +00:00
|
|
|
|
2013-02-26 01:10:19 +00:00
|
|
|
if (options.padding) {
|
|
|
|
self.put[key] = function() {
|
|
|
|
return tput._print(tput[key].apply(tput, arguments), write);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
self.put[key] = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return self._write(tput[key].apply(tput, arguments));
|
2013-02-26 01:10:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-07-14 13:37:57 +00:00
|
|
|
Program.prototype.has = function(name) {
|
|
|
|
return this.tput
|
|
|
|
? this.tput.has(name)
|
|
|
|
: false;
|
|
|
|
};
|
|
|
|
|
2013-01-28 23:30:51 +00:00
|
|
|
Program.prototype.term = function(is) {
|
|
|
|
return this.terminal.indexOf(is) === 0;
|
|
|
|
};
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.listen = function() {
|
2015-01-16 19:56:00 +00:00
|
|
|
var keys = require('./keys')
|
2013-01-27 10:30:52 +00:00
|
|
|
, self = this;
|
|
|
|
|
2015-04-19 13:01:09 +00:00
|
|
|
if (!this.output.isTTY) {
|
|
|
|
// TODO: Add an ncurses-like warning.
|
2013-02-07 18:33:50 +00:00
|
|
|
}
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2015-02-14 03:14:27 +00:00
|
|
|
// 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;
|
|
|
|
// });
|
|
|
|
|
2013-02-07 18:33:50 +00:00
|
|
|
// Input
|
|
|
|
this.input.on('keypress', function(ch, key) {
|
2013-07-12 09:59:58 +00:00
|
|
|
key = key || { ch: ch };
|
|
|
|
|
2013-07-12 08:34:32 +00:00
|
|
|
if (key.name === 'undefined'
|
|
|
|
&& (key.code === '[M' || key.code === '[I' || key.code === '[O')) {
|
2015-01-16 19:56:00 +00:00
|
|
|
// A mouse sequence. The `keys` module doesn't understand these.
|
2013-06-20 11:43:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-12 09:59:58 +00:00
|
|
|
|
2013-07-12 10:11:15 +00:00
|
|
|
if (key.name === 'undefined') {
|
|
|
|
// Not sure what this is, but we should probably ignore it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-13 16:18:31 +00:00
|
|
|
if (key.name === 'enter' && key.sequence === '\n') {
|
|
|
|
key.name = 'linefeed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key.name === 'return' && key.sequence === '\r') {
|
2013-08-18 19:42:39 +00:00
|
|
|
self.input.emit('keypress', ch, merge({}, key, { name: 'enter' }));
|
2013-08-13 16:18:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 09:59:58 +00:00
|
|
|
var name = (key.ctrl ? 'C-' : '')
|
|
|
|
+ (key.meta ? 'M-' : '')
|
|
|
|
+ (key.shift && key.name ? 'S-' : '')
|
|
|
|
+ (key.name || ch);
|
|
|
|
|
|
|
|
key.full = name;
|
|
|
|
|
2013-02-07 18:33:50 +00:00
|
|
|
self.emit('keypress', ch, key);
|
2013-07-12 09:59:58 +00:00
|
|
|
self.emit('key ' + name, ch, key);
|
2013-02-07 18:33:50 +00:00
|
|
|
});
|
2013-01-27 17:00:02 +00:00
|
|
|
|
2013-02-07 18:33:50 +00:00
|
|
|
this.input.on('data', function(data) {
|
|
|
|
self.emit('data', data);
|
|
|
|
});
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2015-01-16 19:56:00 +00:00
|
|
|
keys.emitKeypressEvents(this.input);
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2013-02-07 18:33:50 +00:00
|
|
|
this.on('newListener', function fn(type) {
|
|
|
|
if (type === 'keypress' || type === 'mouse') {
|
|
|
|
self.removeListener('newListener', fn);
|
2015-06-09 12:13:11 +00:00
|
|
|
if (self.input.setRawMode && !self.input.isRaw) {
|
2013-02-07 18:33:50 +00:00
|
|
|
self.input.setRawMode(true);
|
|
|
|
self.input.resume();
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 10:30:52 +00:00
|
|
|
});
|
2013-01-27 14:54:30 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
this.on('newListener', function fn(type) {
|
|
|
|
if (type === 'mouse') {
|
|
|
|
self.removeListener('newListener', fn);
|
|
|
|
self.bindMouse();
|
|
|
|
}
|
|
|
|
});
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-02-07 18:33:50 +00:00
|
|
|
// Output
|
2015-03-20 06:49:26 +00:00
|
|
|
function resize() {
|
2013-02-07 18:33:50 +00:00
|
|
|
self.cols = self.output.columns;
|
|
|
|
self.rows = self.output.rows;
|
|
|
|
self.emit('resize');
|
2015-03-20 06:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.output.on('resize', function() {
|
|
|
|
if (!self.options.resizeTimeout) {
|
|
|
|
return resize();
|
|
|
|
}
|
|
|
|
if (self._resizeTimer) {
|
|
|
|
clearTimeout(self._resizeTimer);
|
|
|
|
delete self._resizeTimer;
|
|
|
|
}
|
|
|
|
var time = typeof self.options.resizeTimeout === 'number'
|
|
|
|
? self.options.resizeTimeout
|
|
|
|
: 300;
|
|
|
|
self._resizeTimer = setTimeout(resize, time);
|
2013-02-07 18:33:50 +00:00
|
|
|
});
|
2013-01-27 17:00:02 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 10:11:15 +00:00
|
|
|
Program.prototype.key = function(key, listener) {
|
|
|
|
if (typeof key === 'string') key = key.split(/\s*,\s*/);
|
|
|
|
key.forEach(function(key) {
|
|
|
|
return this.on('key ' + key, listener);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.onceKey = function(key, listener) {
|
|
|
|
if (typeof key === 'string') key = key.split(/\s*,\s*/);
|
|
|
|
key.forEach(function(key) {
|
|
|
|
return this.once('key ' + key, listener);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.unkey =
|
|
|
|
Program.prototype.removeKey = function(key, listener) {
|
|
|
|
if (typeof key === 'string') key = key.split(/\s*,\s*/);
|
|
|
|
key.forEach(function(key) {
|
|
|
|
return this.removeListener('key ' + key, listener);
|
|
|
|
}, this);
|
|
|
|
};
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
// XTerm mouse events
|
|
|
|
// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
|
|
|
// To better understand these
|
|
|
|
// the xterm code is very helpful:
|
|
|
|
// Relevant files:
|
|
|
|
// button.c, charproc.c, misc.c
|
|
|
|
// Relevant functions in xterm/button.c:
|
|
|
|
// BtnCode, EmitButtonCode, EditorButton, SendMousePosition
|
2013-01-29 23:57:47 +00:00
|
|
|
// send a mouse event:
|
|
|
|
// regular/utf8: ^[[M Cb Cx Cy
|
|
|
|
// urxvt: ^[[ Cb ; Cx ; Cy M
|
|
|
|
// sgr: ^[[ Cb ; Cx ; Cy M/m
|
|
|
|
// vt300: ^[[ 24(1/3/5)~ [ Cx , Cy ] \r
|
|
|
|
// locator: CSI P e ; P b ; P r ; P c ; P p & w
|
|
|
|
// motion example of a left click:
|
|
|
|
// ^[[M 3<^[[M@4<^[[M@5<^[[M@6<^[[M@7<^[[M#7<
|
|
|
|
// mouseup, mousedown, mousewheel
|
|
|
|
// left click: ^[[M 3<^[[M#3<
|
|
|
|
// mousewheel up: ^[[M`3>
|
2013-01-27 17:00:02 +00:00
|
|
|
Program.prototype.bindMouse = function() {
|
2013-08-13 16:30:44 +00:00
|
|
|
if (this._boundMouse) return;
|
|
|
|
this._boundMouse = true;
|
|
|
|
|
|
|
|
var decoder = new StringDecoder('utf8')
|
|
|
|
, self = this;
|
|
|
|
|
|
|
|
this.on('data', function(data) {
|
2015-02-01 02:36:43 +00:00
|
|
|
var text = decoder.write(data);
|
|
|
|
if (!text) return;
|
|
|
|
self._bindMouse(text, data);
|
2013-08-13 16:30:44 +00:00
|
|
|
});
|
2013-01-27 17:00:02 +00:00
|
|
|
};
|
|
|
|
|
2015-02-01 02:36:43 +00:00
|
|
|
Program.prototype._bindMouse = function(s, buf) {
|
2013-07-18 06:03:47 +00:00
|
|
|
var self = this
|
|
|
|
, key
|
2013-01-27 17:00:02 +00:00
|
|
|
, parts;
|
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
key = {
|
|
|
|
name: undefined,
|
|
|
|
ctrl: false,
|
|
|
|
meta: false,
|
|
|
|
shift: false
|
|
|
|
};
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
if (Buffer.isBuffer(s)) {
|
|
|
|
if (s[0] > 127 && s[1] === undefined) {
|
|
|
|
s[0] -= 128;
|
|
|
|
s = '\x1b' + s.toString('utf-8');
|
|
|
|
} else {
|
|
|
|
s = s.toString('utf-8');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 03:14:27 +00:00
|
|
|
// if (this.8bit) {
|
|
|
|
// s = s.replace(/\233/g, '\x1b[');
|
|
|
|
// buf = new Buffer(s, 'utf8');
|
|
|
|
// }
|
|
|
|
|
2015-02-01 16:47:24 +00:00
|
|
|
// 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
|
2015-02-01 17:21:07 +00:00
|
|
|
// need to parse the raw binary. We can detect whether the terminal is using
|
|
|
|
// a bugged VTE version by examining the coordinates and seeing whether they
|
|
|
|
// are a value they would never otherwise be with a properly implemented x10
|
|
|
|
// protocol. This method of detecting VTE is only 99% reliable because we
|
|
|
|
// can't check if the coords are 0x00 (255) since that is a valid x10 coord
|
|
|
|
// technically.
|
|
|
|
var bx = s.charCodeAt(4);
|
|
|
|
var by = s.charCodeAt(5);
|
|
|
|
if (buf[0] === 0x1b && buf[1] === 0x5b && buf[2] === 0x4d
|
|
|
|
&& (this.isVTE
|
|
|
|
|| bx >= 65533 || by >= 65533
|
|
|
|
|| (bx > 0x00 && bx < 0x20)
|
|
|
|
|| (by > 0x00 && by < 0x20)
|
|
|
|
|| (buf[4] > 223 && buf[4] < 248 && buf.length === 6)
|
|
|
|
|| (buf[5] > 223 && buf[5] < 248 && buf.length === 6))) {
|
2015-02-01 16:47:24 +00:00
|
|
|
var b = buf[3]
|
|
|
|
, x = buf[4]
|
|
|
|
, y = buf[5];
|
|
|
|
|
2015-02-01 17:21:07 +00:00
|
|
|
// unsigned char overflow.
|
|
|
|
if (x < 0x20) x += 0xff;
|
|
|
|
if (y < 0x20) y += 0xff;
|
2015-02-01 16:47:24 +00:00
|
|
|
|
2015-02-01 17:21:07 +00:00
|
|
|
// Convert the coordinates into a
|
|
|
|
// properly formatted x10 utf8 sequence.
|
2015-02-01 16:47:24 +00:00
|
|
|
s = '\x1b[M'
|
|
|
|
+ String.fromCharCode(b)
|
|
|
|
+ String.fromCharCode(x)
|
|
|
|
+ String.fromCharCode(y);
|
|
|
|
}
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
// XTerm / X10
|
2015-01-31 09:51:12 +00:00
|
|
|
if (parts = /^\x1b\[M([\x00\u0020-\uffff]{3})/.exec(s)) {
|
2013-01-27 17:00:02 +00:00
|
|
|
var b = parts[1].charCodeAt(0)
|
|
|
|
, x = parts[1].charCodeAt(1)
|
2013-01-28 23:30:51 +00:00
|
|
|
, y = parts[1].charCodeAt(2)
|
|
|
|
, mod;
|
2013-01-27 17:00:02 +00:00
|
|
|
|
|
|
|
key.name = 'mouse';
|
|
|
|
key.type = 'X10';
|
2013-01-28 23:30:51 +00:00
|
|
|
|
|
|
|
key.raw = [b, x, y, parts[0]];
|
2015-02-07 23:37:01 +00:00
|
|
|
key.buf = buf;
|
2013-01-27 17:00:02 +00:00
|
|
|
key.x = x - 32;
|
|
|
|
key.y = y - 32;
|
|
|
|
|
2013-07-14 12:35:00 +00:00
|
|
|
if (this.zero) key.x--, key.y--;
|
|
|
|
|
2015-03-14 23:14:39 +00:00
|
|
|
if (x === 0) key.x = 255;
|
|
|
|
if (y === 0) key.y = 255;
|
|
|
|
|
2014-04-21 04:31:01 +00:00
|
|
|
mod = b >> 2;
|
|
|
|
key.shift = !!(mod & 1);
|
|
|
|
key.meta = !!((mod >> 1) & 1);
|
|
|
|
key.ctrl = !!((mod >> 2) & 1);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
|
|
|
b -= 32;
|
|
|
|
|
2014-04-21 04:31:01 +00:00
|
|
|
if ((b >> 6) & 1) {
|
|
|
|
key.action = b & 1 ? 'wheeldown' : 'wheelup';
|
2013-01-28 23:30:51 +00:00
|
|
|
key.button = 'middle';
|
|
|
|
} else if (b === 3) {
|
2015-02-05 04:39:34 +00:00
|
|
|
// NOTE: x10 and urxvt have no way
|
|
|
|
// of telling which button mouseup used.
|
2013-01-28 23:30:51 +00:00
|
|
|
key.action = 'mouseup';
|
2015-02-25 02:19:16 +00:00
|
|
|
key.button = this._lastButton || 'unknown';
|
|
|
|
delete this._lastButton;
|
2013-01-28 23:30:51 +00:00
|
|
|
} else {
|
|
|
|
key.action = 'mousedown';
|
2015-02-05 04:39:34 +00:00
|
|
|
var button = b & 3;
|
2013-01-28 23:30:51 +00:00
|
|
|
key.button =
|
2015-02-05 04:39:34 +00:00
|
|
|
button === 0 ? 'left'
|
|
|
|
: button === 1 ? 'middle'
|
|
|
|
: button === 2 ? 'right'
|
2013-01-28 23:30:51 +00:00
|
|
|
: 'unknown';
|
2015-02-25 02:19:16 +00:00
|
|
|
this._lastButton = key.button;
|
2013-01-28 23:30:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 14:31:55 +00:00
|
|
|
// Probably a movement.
|
2015-02-05 04:39:34 +00:00
|
|
|
// The *newer* VTE gets mouse movements comepletely wrong.
|
|
|
|
// This presents a problem: older versions of VTE that get it right might
|
|
|
|
// be confused by the second conditional in the if statement.
|
|
|
|
// NOTE: Possibly just switch back to the if statement below.
|
|
|
|
// none, shift, ctrl, alt
|
|
|
|
// gnome: 32, 36, 48, 40
|
|
|
|
// xterm: 35, _, 51, _
|
|
|
|
// urxvt: 35, _, _, _
|
|
|
|
// if (key.action === 'mousedown' && key.button === 'unknown') {
|
|
|
|
if (b === 35 || b === 39 || b === 51 || b === 43
|
|
|
|
|| (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))) {
|
2013-06-16 14:31:55 +00:00
|
|
|
delete key.button;
|
|
|
|
key.action = 'mousemove';
|
|
|
|
}
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
self.emit('mouse', key);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// URxvt
|
2013-01-28 23:30:51 +00:00
|
|
|
if (parts = /^\x1b\[(\d+;\d+;\d+)M/.exec(s)) {
|
2015-02-07 23:37:01 +00:00
|
|
|
var params = parts[1].split(';')
|
|
|
|
, b = +params[0]
|
|
|
|
, x = +params[1]
|
|
|
|
, y = +params[2];
|
2015-02-05 04:39:34 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
key.name = 'mouse';
|
|
|
|
key.type = 'urxvt';
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-07 23:37:01 +00:00
|
|
|
key.raw = [b, x, y, parts[0]];
|
|
|
|
key.buf = buf;
|
2013-01-27 17:00:02 +00:00
|
|
|
key.x = x;
|
|
|
|
key.y = y;
|
|
|
|
|
2013-07-14 12:35:00 +00:00
|
|
|
if (this.zero) key.x--, key.y--;
|
|
|
|
|
2015-02-04 05:20:41 +00:00
|
|
|
mod = b >> 2;
|
|
|
|
key.shift = !!(mod & 1);
|
|
|
|
key.meta = !!((mod >> 1) & 1);
|
|
|
|
key.ctrl = !!((mod >> 2) & 1);
|
2013-01-29 23:57:47 +00:00
|
|
|
|
2015-02-08 00:04:14 +00:00
|
|
|
// XXX Bug in urxvt after wheelup/down on mousemove
|
|
|
|
// NOTE: This may be different than 128/129 depending
|
|
|
|
// on mod keys.
|
2015-02-05 04:39:34 +00:00
|
|
|
if (b === 128 || b === 129) {
|
|
|
|
b = 67;
|
|
|
|
}
|
|
|
|
|
|
|
|
b -= 32;
|
|
|
|
|
2015-02-04 05:20:41 +00:00
|
|
|
if ((b >> 6) & 1) {
|
|
|
|
key.action = b & 1 ? 'wheeldown' : 'wheelup';
|
2013-01-29 23:57:47 +00:00
|
|
|
key.button = 'middle';
|
2015-02-05 04:39:34 +00:00
|
|
|
} else if (b === 3) {
|
|
|
|
// NOTE: x10 and urxvt have no way
|
|
|
|
// of telling which button mouseup used.
|
|
|
|
key.action = 'mouseup';
|
2015-02-25 02:19:16 +00:00
|
|
|
key.button = this._lastButton || 'unknown';
|
|
|
|
delete this._lastButton;
|
2013-01-29 23:57:47 +00:00
|
|
|
} else {
|
|
|
|
key.action = 'mousedown';
|
2015-02-05 04:39:34 +00:00
|
|
|
var button = b & 3;
|
2013-01-29 23:57:47 +00:00
|
|
|
key.button =
|
2015-02-05 04:39:34 +00:00
|
|
|
button === 0 ? 'left'
|
|
|
|
: button === 1 ? 'middle'
|
|
|
|
: button === 2 ? 'right'
|
2013-01-29 23:57:47 +00:00
|
|
|
: 'unknown';
|
2015-03-14 23:14:39 +00:00
|
|
|
// NOTE: 0/32 = mousemove, 32/64 = mousemove with left down
|
|
|
|
// if ((b >> 1) === 32)
|
2015-02-25 02:19:16 +00:00
|
|
|
this._lastButton = key.button;
|
2013-01-29 23:57:47 +00:00
|
|
|
}
|
|
|
|
|
2013-07-14 12:16:33 +00:00
|
|
|
// Probably a movement.
|
2015-02-05 04:39:34 +00:00
|
|
|
// The *newer* VTE gets mouse movements comepletely wrong.
|
|
|
|
// This presents a problem: older versions of VTE that get it right might
|
|
|
|
// be confused by the second conditional in the if statement.
|
|
|
|
// NOTE: Possibly just switch back to the if statement below.
|
|
|
|
// none, shift, ctrl, alt
|
|
|
|
// urxvt: 35, _, _, _
|
|
|
|
// gnome: 32, 36, 48, 40
|
|
|
|
// if (key.action === 'mousedown' && key.button === 'unknown') {
|
|
|
|
if (b === 35 || b === 39 || b === 51 || b === 43
|
|
|
|
|| (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))) {
|
2013-07-14 12:16:33 +00:00
|
|
|
delete key.button;
|
|
|
|
key.action = 'mousemove';
|
|
|
|
}
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
self.emit('mouse', key);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SGR
|
2013-01-28 23:30:51 +00:00
|
|
|
if (parts = /^\x1b\[<(\d+;\d+;\d+)([mM])/.exec(s)) {
|
2015-02-01 02:36:43 +00:00
|
|
|
var down = parts[2] === 'M'
|
2015-02-07 23:37:01 +00:00
|
|
|
, params = parts[1].split(';')
|
|
|
|
, b = +params[0]
|
|
|
|
, x = +params[1]
|
|
|
|
, y = +params[2];
|
2015-02-05 04:39:34 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
key.name = 'mouse';
|
|
|
|
key.type = 'sgr';
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-07 23:37:01 +00:00
|
|
|
key.raw = [b, x, y, parts[0]];
|
|
|
|
key.buf = buf;
|
2013-01-27 17:00:02 +00:00
|
|
|
key.x = x;
|
|
|
|
key.y = y;
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-07-14 12:35:00 +00:00
|
|
|
if (this.zero) key.x--, key.y--;
|
|
|
|
|
2015-02-04 05:20:41 +00:00
|
|
|
mod = b >> 2;
|
|
|
|
key.shift = !!(mod & 1);
|
|
|
|
key.meta = !!((mod >> 1) & 1);
|
|
|
|
key.ctrl = !!((mod >> 2) & 1);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-04 05:20:41 +00:00
|
|
|
if ((b >> 6) & 1) {
|
|
|
|
key.action = b & 1 ? 'wheeldown' : 'wheelup';
|
|
|
|
key.button = 'middle';
|
|
|
|
} else {
|
|
|
|
key.action = down
|
|
|
|
? 'mousedown'
|
|
|
|
: 'mouseup';
|
2015-02-05 04:39:34 +00:00
|
|
|
var button = b & 3;
|
2015-02-04 05:20:41 +00:00
|
|
|
key.button =
|
2015-02-05 04:39:34 +00:00
|
|
|
button === 0 ? 'left'
|
|
|
|
: button === 1 ? 'middle'
|
|
|
|
: button === 2 ? 'right'
|
2015-02-04 05:20:41 +00:00
|
|
|
: 'unknown';
|
|
|
|
}
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-04 05:20:41 +00:00
|
|
|
// Probably a movement.
|
2015-02-05 04:39:34 +00:00
|
|
|
// The *newer* VTE gets mouse movements comepletely wrong.
|
|
|
|
// This presents a problem: older versions of VTE that get it right might
|
|
|
|
// be confused by the second conditional in the if statement.
|
|
|
|
// NOTE: Possibly just switch back to the if statement below.
|
|
|
|
// none, shift, ctrl, alt
|
|
|
|
// xterm: 35, _, 51, _
|
|
|
|
// gnome: 32, 36, 48, 40
|
|
|
|
// if (key.action === 'mousedown' && key.button === 'unknown') {
|
|
|
|
if (b === 35 || b === 39 || b === 51 || b === 43
|
|
|
|
|| (this.isVTE && (b === 32 || b === 36 || b === 48 || b === 40))) {
|
2015-02-04 05:20:41 +00:00
|
|
|
delete key.button;
|
|
|
|
key.action = 'mousemove';
|
|
|
|
}
|
2013-01-27 17:00:02 +00:00
|
|
|
|
|
|
|
self.emit('mouse', key);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEC
|
2013-07-18 06:03:47 +00:00
|
|
|
// The xterm mouse documentation says there is a
|
|
|
|
// `<` prefix, the DECRQLP says there is no prefix.
|
2013-01-28 23:30:51 +00:00
|
|
|
if (parts = /^\x1b\[<(\d+;\d+;\d+;\d+)&w/.exec(s)) {
|
2015-02-07 23:37:01 +00:00
|
|
|
var params = parts[1].split(';')
|
|
|
|
, b = +params[0]
|
|
|
|
, x = +params[1]
|
|
|
|
, y = +params[2]
|
|
|
|
, page = +params[3];
|
2015-02-05 04:39:34 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
key.name = 'mouse';
|
|
|
|
key.type = 'dec';
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-07 23:37:01 +00:00
|
|
|
key.raw = [b, x, y, parts[0]];
|
|
|
|
key.buf = buf;
|
2013-01-27 17:00:02 +00:00
|
|
|
key.x = x;
|
|
|
|
key.y = y;
|
|
|
|
|
2013-07-14 12:35:00 +00:00
|
|
|
if (this.zero) key.x--, key.y--;
|
|
|
|
|
2013-01-28 23:30:51 +00:00
|
|
|
key.action = b === 3
|
|
|
|
? 'mouseup'
|
|
|
|
: 'mousedown';
|
|
|
|
|
|
|
|
key.button =
|
|
|
|
b === 2 ? 'left'
|
|
|
|
: b === 4 ? 'middle'
|
|
|
|
: b === 6 ? 'right'
|
|
|
|
: 'unknown';
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
self.emit('mouse', key);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vt300
|
|
|
|
if (parts = /^\x1b\[24([0135])~\[(\d+),(\d+)\]\r/.exec(s)) {
|
|
|
|
var b = +parts[1]
|
|
|
|
, x = +parts[2]
|
|
|
|
, y = +parts[3];
|
|
|
|
|
|
|
|
key.name = 'mouse';
|
|
|
|
key.type = 'vt300';
|
2013-01-28 23:30:51 +00:00
|
|
|
|
2015-02-07 23:37:01 +00:00
|
|
|
key.raw = [b, x, y, parts[0]];
|
|
|
|
key.buf = buf;
|
2013-01-27 17:00:02 +00:00
|
|
|
key.x = x;
|
|
|
|
key.y = y;
|
|
|
|
|
2013-07-14 12:35:00 +00:00
|
|
|
if (this.zero) key.x--, key.y--;
|
|
|
|
|
2013-01-28 23:30:51 +00:00
|
|
|
key.action = 'mousedown';
|
|
|
|
key.button =
|
|
|
|
b === 1 ? 'left'
|
|
|
|
: b === 2 ? 'middle'
|
|
|
|
: b === 5 ? 'right'
|
|
|
|
: 'unknown';
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
self.emit('mouse', key);
|
2013-01-28 23:30:51 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parts = /^\x1b\[(O|I)/.exec(s)) {
|
|
|
|
key.action = parts[1] === 'I'
|
|
|
|
? 'focus'
|
|
|
|
: 'blur';
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
self.emit(key.action);
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2015-02-01 15:10:17 +00:00
|
|
|
// gpm support for linux vc
|
2015-01-28 02:43:48 +00:00
|
|
|
Program.prototype.enableGpm = function() {
|
2015-02-01 15:07:55 +00:00
|
|
|
var self = this;
|
|
|
|
var gpmclient = require('./gpmclient')
|
|
|
|
|
2015-02-18 06:12:49 +00:00
|
|
|
if (this.gpm) return;
|
|
|
|
|
2015-02-01 15:07:55 +00:00
|
|
|
this.gpm = gpmclient();
|
|
|
|
|
|
|
|
this.gpm.on('btndown', function(btn, modifier, x, y) {
|
|
|
|
x--, y--;
|
|
|
|
|
|
|
|
var key = {
|
|
|
|
name: 'mouse',
|
|
|
|
type: 'GPM',
|
|
|
|
action: 'mousedown',
|
|
|
|
button: self.gpm.ButtonName(btn),
|
2015-02-01 15:36:53 +00:00
|
|
|
raw: [btn, modifier, x, y],
|
2015-02-01 15:07:55 +00:00
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
shift: self.gpm.hasShiftKey(modifier),
|
|
|
|
meta: self.gpm.hasMetaKey(modifier),
|
|
|
|
ctrl: self.gpm.hasCtrlKey(modifier)
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.gpm.on('btnup', function(btn, modifier, x, y) {
|
|
|
|
x--, y--;
|
|
|
|
|
|
|
|
var key = {
|
|
|
|
name: 'mouse',
|
|
|
|
type: 'GPM',
|
|
|
|
action: 'mouseup',
|
|
|
|
button: self.gpm.ButtonName(btn),
|
2015-02-01 15:36:53 +00:00
|
|
|
raw: [btn, modifier, x, y],
|
2015-02-01 15:07:55 +00:00
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
shift: self.gpm.hasShiftKey(modifier),
|
|
|
|
meta: self.gpm.hasMetaKey(modifier),
|
|
|
|
ctrl: self.gpm.hasCtrlKey(modifier)
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.gpm.on('move', function(btn, modifier, x, y) {
|
|
|
|
x--, y--;
|
|
|
|
|
|
|
|
var key = {
|
|
|
|
name: 'mouse',
|
|
|
|
type: 'GPM',
|
|
|
|
action: 'mousemove',
|
|
|
|
button: self.gpm.ButtonName(btn),
|
2015-02-01 15:36:53 +00:00
|
|
|
raw: [btn, modifier, x, y],
|
2015-02-01 15:07:55 +00:00
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
shift: self.gpm.hasShiftKey(modifier),
|
|
|
|
meta: self.gpm.hasMetaKey(modifier),
|
|
|
|
ctrl: self.gpm.hasCtrlKey(modifier)
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.gpm.on('drag', function(btn, modifier, x, y) {
|
|
|
|
x--, y--;
|
|
|
|
|
|
|
|
var key = {
|
|
|
|
name: 'mouse',
|
|
|
|
type: 'GPM',
|
|
|
|
action: 'mousemove',
|
|
|
|
button: self.gpm.ButtonName(btn),
|
2015-02-01 15:36:53 +00:00
|
|
|
raw: [btn, modifier, x, y],
|
2015-02-01 15:07:55 +00:00
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
shift: self.gpm.hasShiftKey(modifier),
|
|
|
|
meta: self.gpm.hasMetaKey(modifier),
|
|
|
|
ctrl: self.gpm.hasCtrlKey(modifier)
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.gpm.on('mousewheel', function(btn, modifier, x, y, dx, dy) {
|
|
|
|
var key = {
|
|
|
|
name: 'mouse',
|
|
|
|
type: 'GPM',
|
2015-02-01 15:36:53 +00:00
|
|
|
action: dy > 0 ? 'wheelup' : 'wheeldown',
|
2015-02-01 15:07:55 +00:00
|
|
|
button: self.gpm.ButtonName(btn),
|
2015-02-01 15:36:53 +00:00
|
|
|
raw: [btn, modifier, x, y, dx, dy],
|
2015-02-01 15:07:55 +00:00
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
shift: self.gpm.hasShiftKey(modifier),
|
|
|
|
meta: self.gpm.hasMetaKey(modifier),
|
|
|
|
ctrl: self.gpm.hasCtrlKey(modifier)
|
|
|
|
};
|
|
|
|
|
|
|
|
self.emit('mouse', key);
|
|
|
|
});
|
2015-01-28 02:43:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.disableGpm = function() {
|
2015-02-01 15:07:55 +00:00
|
|
|
if (this.gpm) {
|
|
|
|
this.gpm.stop();
|
|
|
|
delete this.gpm;
|
|
|
|
}
|
2015-01-28 02:43:48 +00:00
|
|
|
};
|
|
|
|
|
2013-02-07 18:19:49 +00:00
|
|
|
// All possible responses from the terminal
|
2013-01-30 05:26:27 +00:00
|
|
|
Program.prototype.bindResponse = function() {
|
2013-08-13 16:30:44 +00:00
|
|
|
if (this._boundResponse) return;
|
|
|
|
this._boundResponse = true;
|
|
|
|
|
|
|
|
var decoder = new StringDecoder('utf8')
|
|
|
|
, self = this;
|
|
|
|
|
|
|
|
this.on('data', function(data) {
|
|
|
|
data = decoder.write(data);
|
|
|
|
if (!data) return;
|
|
|
|
self._bindResponse(data);
|
|
|
|
});
|
2013-01-30 05:26:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype._bindResponse = function(s) {
|
2013-07-18 06:03:47 +00:00
|
|
|
var self = this
|
|
|
|
, out = {}
|
2013-01-30 05:26:27 +00:00
|
|
|
, parts;
|
|
|
|
|
|
|
|
if (Buffer.isBuffer(s)) {
|
|
|
|
if (s[0] > 127 && s[1] === undefined) {
|
|
|
|
s[0] -= 128;
|
|
|
|
s = '\x1b' + s.toString('utf-8');
|
|
|
|
} else {
|
|
|
|
s = s.toString('utf-8');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-14 04:38:43 +00:00
|
|
|
// CSI P s c
|
|
|
|
// Send Device Attributes (Primary DA).
|
|
|
|
// CSI > P s c
|
|
|
|
// Send Device Attributes (Secondary DA).
|
|
|
|
if (parts = /^\x1b\[(\?|>)(\d*(?:;\d*)*)c/.exec(s)) {
|
2013-07-18 06:03:47 +00:00
|
|
|
parts = parts[2].split(';').map(function(ch) {
|
|
|
|
return +ch || 0;
|
|
|
|
});
|
2013-07-14 04:38:43 +00:00
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
out.event = 'device-attributes';
|
|
|
|
out.code = 'DA';
|
|
|
|
|
|
|
|
if (parts[1] === '?') {
|
2013-07-14 04:38:43 +00:00
|
|
|
out.type = 'primary-attribute';
|
|
|
|
// VT100-style params:
|
|
|
|
if (parts[0] === 1 && parts[2] === 2) {
|
|
|
|
out.term = 'vt100';
|
|
|
|
out.advancedVideo = true;
|
|
|
|
} else if (parts[0] === 1 && parts[2] === 0) {
|
|
|
|
out.term = 'vt101';
|
|
|
|
} else if (parts[0] === 6) {
|
|
|
|
out.term = 'vt102';
|
|
|
|
} else if (parts[0] === 60
|
|
|
|
&& parts[1] === 1 && parts[2] === 2
|
|
|
|
&& parts[3] === 6 && parts[4] === 8
|
|
|
|
&& parts[5] === 9 && parts[6] === 15) {
|
|
|
|
out.term = 'vt220';
|
|
|
|
} else {
|
|
|
|
// VT200-style params:
|
|
|
|
parts.forEach(function(attr) {
|
|
|
|
switch (attr) {
|
|
|
|
case 1:
|
2013-07-14 04:41:47 +00:00
|
|
|
out.cols132 = true;
|
2013-07-14 04:38:43 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
out.printer = true;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
out.selectiveErase = true;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
out.userDefinedKeys = true;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
out.nationalReplacementCharsets = true;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
out.technicalCharacters = true;
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
out.userWindows = true;
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
out.horizontalScrolling = true;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
out.ansiColor = true;
|
|
|
|
break;
|
|
|
|
case 29:
|
|
|
|
out.ansiTextLocator = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.type = 'secondary-attribute';
|
|
|
|
switch (parts[0]) {
|
|
|
|
case 0:
|
|
|
|
out.term = 'vt100';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
out.term = 'vt220';
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
out.term = 'vt240';
|
|
|
|
break;
|
|
|
|
case 18:
|
|
|
|
out.term = 'vt330';
|
|
|
|
break;
|
|
|
|
case 19:
|
|
|
|
out.term = 'vt340';
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
out.term = 'vt320';
|
|
|
|
break;
|
|
|
|
case 41:
|
|
|
|
out.term = 'vt420';
|
|
|
|
break;
|
|
|
|
case 61:
|
|
|
|
out.term = 'vt510';
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
out.term = 'vt520';
|
|
|
|
break;
|
|
|
|
case 65:
|
|
|
|
out.term = 'vt525';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out.firmwareVersion = parts[1];
|
|
|
|
out.romCartridgeRegistrationNumber = parts[2];
|
|
|
|
}
|
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
// LEGACY
|
|
|
|
out.deviceAttributes = out;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-07-14 04:38:43 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
// CSI Ps n Device Status Report (DSR).
|
|
|
|
// Ps = 5 -> Status Report. Result (``OK'') is
|
|
|
|
// CSI 0 n
|
|
|
|
// CSI ? Ps n
|
|
|
|
// Device Status Report (DSR, DEC-specific).
|
|
|
|
// Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
|
|
|
|
// or CSI ? 1 1 n (not ready).
|
|
|
|
// Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
|
|
|
|
// or CSI ? 2 1 n (locked).
|
|
|
|
// Ps = 2 6 -> Report Keyboard status as
|
|
|
|
// CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
|
|
|
|
// The last two parameters apply to VT400 & up, and denote key-
|
|
|
|
// board ready and LK01 respectively.
|
|
|
|
// Ps = 5 3 -> Report Locator status as
|
|
|
|
// CSI ? 5 3 n Locator available, if compiled-in, or
|
|
|
|
// CSI ? 5 0 n No Locator, if not.
|
|
|
|
if (parts = /^\x1b\[(\?)?(\d+)(?:;(\d+);(\d+);(\d+))?n/.exec(s)) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.event = 'device-status';
|
|
|
|
out.code = 'DSR';
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
if (!parts[1] && parts[2] === '0' && !parts[3]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'device-status';
|
|
|
|
out.status = 'OK';
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.deviceStatus = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] && (parts[2] === '10' || parts[2] === '11') && !parts[3]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'printer-status';
|
|
|
|
out.status = parts[2] === '10'
|
|
|
|
? 'ready'
|
|
|
|
: 'not ready';
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.printerStatus = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] && (parts[2] === '20' || parts[2] === '21') && !parts[3]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'udk-status';
|
|
|
|
out.status = parts[2] === '20'
|
|
|
|
? 'unlocked'
|
|
|
|
: 'locked';
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.UDKStatus = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1]
|
|
|
|
&& parts[2] === '27'
|
|
|
|
&& parts[3] === '1'
|
|
|
|
&& parts[4] === '0'
|
|
|
|
&& parts[5] === '0') {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'keyboard-status';
|
|
|
|
out.status = 'OK';
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.keyboardStatus = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] && (parts[2] === '53' || parts[2] === '50') && !parts[3]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'locator-status';
|
|
|
|
out.status = parts[2] === '53'
|
2013-01-30 05:26:27 +00:00
|
|
|
? 'available'
|
2013-07-18 06:03:47 +00:00
|
|
|
: 'unavailable';
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.locator = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'error';
|
|
|
|
out.text = 'Unhandled: ' + JSON.stringify(parts);
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.error = out.text;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-02-07 18:19:49 +00:00
|
|
|
}
|
2013-01-30 05:26:27 +00:00
|
|
|
|
2013-02-07 18:19:49 +00:00
|
|
|
// CSI Ps n Device Status Report (DSR).
|
2013-01-30 05:26:27 +00:00
|
|
|
// Ps = 6 -> Report Cursor Position (CPR) [row;column].
|
|
|
|
// Result is
|
|
|
|
// CSI r ; c R
|
2013-02-07 18:19:49 +00:00
|
|
|
// CSI ? Ps n
|
|
|
|
// Device Status Report (DSR, DEC-specific).
|
2013-01-30 05:26:27 +00:00
|
|
|
// Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
|
|
|
|
// ? r ; c R (assumes page is zero).
|
|
|
|
if (parts = /^\x1b\[(\?)?(\d+);(\d+)R/.exec(s)) {
|
2015-01-31 20:57:21 +00:00
|
|
|
out.event = 'device-status';
|
2013-07-18 06:03:47 +00:00
|
|
|
out.code = 'DSR';
|
|
|
|
out.type = 'cursor-status';
|
|
|
|
|
|
|
|
out.status = {
|
|
|
|
x: +parts[3],
|
|
|
|
y: +parts[2],
|
|
|
|
page: !parts[1] ? undefined : 0
|
|
|
|
};
|
|
|
|
|
|
|
|
out.x = out.status.x;
|
|
|
|
out.y = out.status.y;
|
|
|
|
out.page = out.status.page;
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.cursor = out.status;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CSI Ps ; Ps ; Ps t
|
|
|
|
// Window manipulation (from dtterm, as well as extensions).
|
|
|
|
// These controls may be disabled using the allowWindowOps
|
|
|
|
// resource. Valid values for the first (and any additional
|
|
|
|
// parameters) are:
|
|
|
|
// Ps = 1 1 -> Report xterm window state. If the xterm window
|
|
|
|
// is open (non-iconified), it returns CSI 1 t . If the xterm
|
|
|
|
// window is iconified, it returns CSI 2 t .
|
|
|
|
// Ps = 1 3 -> Report xterm window position. Result is CSI 3
|
|
|
|
// ; x ; y t
|
|
|
|
// Ps = 1 4 -> Report xterm window in pixels. Result is CSI
|
|
|
|
// 4 ; height ; width t
|
|
|
|
// Ps = 1 8 -> Report the size of the text area in characters.
|
|
|
|
// Result is CSI 8 ; height ; width t
|
|
|
|
// Ps = 1 9 -> Report the size of the screen in characters.
|
|
|
|
// Result is CSI 9 ; height ; width t
|
|
|
|
if (parts = /^\x1b\[(\d+)(?:;(\d+);(\d+))?t/.exec(s)) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.event = 'window-manipulation';
|
|
|
|
out.code = '';
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
if ((parts[1] === '1' || parts[1] === '2') && !parts[2]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'window-state';
|
|
|
|
out.state = parts[1] === '1'
|
|
|
|
? 'non-iconified'
|
|
|
|
: 'iconified'
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.windowState = out.state;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] === '3' && parts[2]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'window-position';
|
|
|
|
|
|
|
|
out.position = {
|
|
|
|
x: +parts[2],
|
|
|
|
y: +parts[3]
|
|
|
|
};
|
2013-07-18 19:52:56 +00:00
|
|
|
out.x = out.position.x;
|
|
|
|
out.y = out.position.y;
|
2013-07-18 06:03:47 +00:00
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.windowPosition = out.position;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] === '4' && parts[2]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'window-size-pixels';
|
|
|
|
out.size = {
|
|
|
|
height: +parts[2],
|
|
|
|
width: +parts[3]
|
|
|
|
};
|
2013-07-18 19:52:56 +00:00
|
|
|
out.height = out.size.height;
|
|
|
|
out.width = out.size.width;
|
2013-07-18 06:03:47 +00:00
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.windowSizePixels = out.size;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] === '8' && parts[2]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'textarea-size';
|
|
|
|
out.size = {
|
|
|
|
height: +parts[2],
|
|
|
|
width: +parts[3]
|
|
|
|
};
|
2013-07-18 19:52:56 +00:00
|
|
|
out.height = out.size.height;
|
|
|
|
out.width = out.size.width;
|
2013-07-18 06:03:47 +00:00
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.textAreaSizeCharacters = out.size;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] === '9' && parts[2]) {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'screen-size';
|
|
|
|
out.size = {
|
|
|
|
height: +parts[2],
|
|
|
|
width: +parts[3]
|
|
|
|
};
|
2013-07-18 19:52:56 +00:00
|
|
|
out.height = out.size.height;
|
|
|
|
out.width = out.size.width;
|
2013-07-18 06:03:47 +00:00
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.screenSizeCharacters = out.size;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'error';
|
|
|
|
out.text = 'Unhandled: ' + JSON.stringify(parts);
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.error = out.text;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CSI Ps ; Ps ; Ps t
|
|
|
|
// Window manipulation (from dtterm, as well as extensions).
|
|
|
|
// These controls may be disabled using the allowWindowOps
|
|
|
|
// resource. Valid values for the first (and any additional
|
|
|
|
// parameters) are:
|
|
|
|
// Ps = 2 0 -> Report xterm window's icon label. Result is
|
|
|
|
// OSC L label ST
|
|
|
|
// Ps = 2 1 -> Report xterm window's title. Result is OSC l
|
|
|
|
// label ST
|
2013-02-07 18:53:01 +00:00
|
|
|
if (parts = /^\x1b\](l|L)([^\x07\x1b]*)(?:\x07|\x1b\\)/.exec(s)) {
|
2015-02-14 03:14:27 +00:00
|
|
|
out.event = 'window-manipulation';
|
2013-07-18 06:03:47 +00:00
|
|
|
out.code = '';
|
|
|
|
|
2013-01-30 05:26:27 +00:00
|
|
|
if (parts[1] === 'L') {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'window-icon-label';
|
|
|
|
out.text = parts[2];
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.windowIconLabel = out.text;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parts[1] === 'l') {
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'window-title';
|
|
|
|
out.text = parts[2];
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.windowTitle = out.text;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
out.type = 'error';
|
|
|
|
out.text = 'Unhandled: ' + JSON.stringify(parts);
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.error = out.text;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSI Ps ' |
|
|
|
|
// Request Locator Position (DECRQLP).
|
|
|
|
// -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w
|
|
|
|
// Parameters are [event;button;row;column;page].
|
|
|
|
// Valid values for the event:
|
|
|
|
// Pe = 0 -> locator unavailable - no other parameters sent.
|
|
|
|
// Pe = 1 -> request - xterm received a DECRQLP.
|
|
|
|
// Pe = 2 -> left button down.
|
|
|
|
// Pe = 3 -> left button up.
|
|
|
|
// Pe = 4 -> middle button down.
|
|
|
|
// Pe = 5 -> middle button up.
|
|
|
|
// Pe = 6 -> right button down.
|
|
|
|
// Pe = 7 -> right button up.
|
|
|
|
// Pe = 8 -> M4 button down.
|
|
|
|
// Pe = 9 -> M4 button up.
|
|
|
|
// Pe = 1 0 -> locator outside filter rectangle.
|
|
|
|
// ``button'' parameter is a bitmask indicating which buttons are
|
|
|
|
// pressed:
|
|
|
|
// Pb = 0 <- no buttons down.
|
|
|
|
// Pb & 1 <- right button down.
|
|
|
|
// Pb & 2 <- middle button down.
|
|
|
|
// Pb & 4 <- left button down.
|
|
|
|
// Pb & 8 <- M4 button down.
|
|
|
|
// ``row'' and ``column'' parameters are the coordinates of the
|
|
|
|
// locator position in the xterm window, encoded as ASCII deci-
|
|
|
|
// mal.
|
|
|
|
// The ``page'' parameter is not used by xterm, and will be omit-
|
|
|
|
// ted.
|
|
|
|
// NOTE:
|
|
|
|
// This is already implemented in the _bindMouse
|
|
|
|
// method, but it might make more sense here.
|
|
|
|
// The xterm mouse documentation says there is a
|
|
|
|
// `<` prefix, the DECRQLP says there is no prefix.
|
|
|
|
if (parts = /^\x1b\[(\d+(?:;\d+){4})&w/.exec(s)) {
|
|
|
|
parts = parts[1].split(';').map(function(ch) {
|
|
|
|
return +ch;
|
2013-02-07 18:19:49 +00:00
|
|
|
});
|
2013-07-18 06:03:47 +00:00
|
|
|
|
|
|
|
out.event = 'locator-position';
|
|
|
|
out.code = 'DECRQLP';
|
|
|
|
|
|
|
|
switch (parts[0]) {
|
|
|
|
case 0:
|
|
|
|
out.status = 'locator-unavailable';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
out.status = 'request';
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
out.status = 'left-button-down';
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
out.status = 'left-button-up';
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
out.status = 'middle-button-down';
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
out.status = 'middle-button-up';
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
out.status = 'right-button-down';
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
out.status = 'right-button-up';
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
out.status = 'm4-button-down';
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
out.status = 'm4-button-up';
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
out.status = 'locator-outside';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.mask = parts[1];
|
|
|
|
out.row = parts[2];
|
|
|
|
out.col = parts[3];
|
|
|
|
out.page = parts[4];
|
|
|
|
|
|
|
|
// LEGACY
|
|
|
|
out.locatorPosition = out;
|
|
|
|
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
|
|
|
|
return;
|
2013-01-30 05:26:27 +00:00
|
|
|
}
|
2015-03-20 06:49:26 +00:00
|
|
|
|
|
|
|
// OSC Ps ; Pt BEL
|
|
|
|
// OSC Ps ; Pt ST
|
|
|
|
// Set Text Parameters
|
|
|
|
if (parts = /^\x1b\](\d+);([^\x07\x1b]+)(?:\x07|\x1b\\)/.exec(s)) {
|
|
|
|
out.event = 'text-params';
|
|
|
|
out.code = 'Set Text Parameters';
|
|
|
|
out.ps = +s[1];
|
|
|
|
out.pt = s[2];
|
|
|
|
this.emit('response', out);
|
|
|
|
this.emit('response ' + out.event, out);
|
|
|
|
}
|
2013-01-30 05:26:27 +00:00
|
|
|
};
|
|
|
|
|
2015-03-19 11:16:59 +00:00
|
|
|
Program.prototype.response = function(name, text, callback, noBypass) {
|
2015-02-14 03:14:27 +00:00
|
|
|
var self = this;
|
|
|
|
|
2013-07-18 06:03:47 +00:00
|
|
|
if (arguments.length === 2) {
|
|
|
|
callback = text;
|
|
|
|
text = name;
|
|
|
|
name = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callback) {
|
|
|
|
callback = function() {};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bindResponse();
|
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
name = name
|
|
|
|
? 'response ' + name
|
|
|
|
: 'response';
|
|
|
|
|
2015-02-07 08:15:25 +00:00
|
|
|
var onresponse;
|
|
|
|
|
|
|
|
this.once(name, onresponse = function(event) {
|
|
|
|
if (timeout) clearTimeout(timeout);
|
2013-07-18 06:03:47 +00:00
|
|
|
if (event.type === 'error') {
|
|
|
|
return callback(new Error(event.event + ': ' + event.text));
|
|
|
|
}
|
|
|
|
return callback(null, event);
|
|
|
|
});
|
|
|
|
|
2015-02-07 08:15:25 +00:00
|
|
|
var timeout = setTimeout(function() {
|
|
|
|
self.removeListener(name, onresponse);
|
2015-02-14 03:14:27 +00:00
|
|
|
return callback(new Error('Timeout.'));
|
2015-02-07 08:15:25 +00:00
|
|
|
}, 2000);
|
|
|
|
|
2015-03-19 11:16:59 +00:00
|
|
|
return noBypass
|
|
|
|
? this._write(text)
|
|
|
|
: this._twrite(text);
|
2013-07-18 06:03:47 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 22:09:41 +00:00
|
|
|
Program.prototype._buffer = function(text) {
|
2013-08-01 06:52:28 +00:00
|
|
|
if (this._exiting) {
|
|
|
|
this.flush();
|
2013-07-31 22:09:41 +00:00
|
|
|
this.output.write(text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._buf) {
|
|
|
|
this._buf += text;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._buf = text;
|
|
|
|
|
2015-01-31 20:26:19 +00:00
|
|
|
nextTick(this._flush);
|
2013-07-31 22:09:41 +00:00
|
|
|
};
|
|
|
|
|
2013-08-01 06:52:28 +00:00
|
|
|
Program.prototype.flush = function(text) {
|
2013-07-31 22:09:41 +00:00
|
|
|
if (!this._buf) return;
|
|
|
|
this.output.write(this._buf);
|
|
|
|
this._buf = '';
|
|
|
|
};
|
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
Program.prototype._write = function(text) {
|
|
|
|
if (this.ret) return text;
|
2013-08-01 08:13:20 +00:00
|
|
|
if (this.useBuffer) {
|
2013-07-31 22:09:41 +00:00
|
|
|
return this._buffer(text);
|
|
|
|
}
|
2013-07-24 19:17:52 +00:00
|
|
|
return this.output.write(text);
|
2013-07-24 18:23:35 +00:00
|
|
|
};
|
|
|
|
|
2015-03-14 23:14:39 +00:00
|
|
|
// 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\\';
|
|
|
|
// Should work but tmux doesn't implement ST correctly:
|
|
|
|
// if (process.env.TMUX) data = '\x1bPtmux;\x1b' + data + '\x07';
|
|
|
|
return this._write(data);
|
|
|
|
};
|
|
|
|
|
2013-07-24 18:23:35 +00:00
|
|
|
Program.prototype.echo =
|
|
|
|
Program.prototype.write = function(text, attr) {
|
2013-02-07 18:19:49 +00:00
|
|
|
return attr
|
2013-07-31 22:09:41 +00:00
|
|
|
? this._write(this.text(text, attr))
|
|
|
|
: this._write(text);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 05:00:11 +00:00
|
|
|
Program.prototype._ncoords = function() {
|
|
|
|
if (this.x < 0) this.x = 0;
|
|
|
|
else if (this.x >= this.cols) this.x = this.cols - 1;
|
|
|
|
if (this.y < 0) this.y = 0;
|
|
|
|
else if (this.y >= this.rows) this.y = this.rows - 1;
|
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.setx = function(x) {
|
2013-01-30 05:26:27 +00:00
|
|
|
return this.cursorCharAbsolute(x);
|
|
|
|
// return this.charPosAbsolute(x);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.sety = function(y) {
|
|
|
|
return this.linePosAbsolute(y);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.move = function(x, y) {
|
|
|
|
return this.cursorPos(y, x);
|
|
|
|
};
|
|
|
|
|
2013-07-12 06:04:57 +00:00
|
|
|
// TODO: Fix cud and cuu calls.
|
|
|
|
Program.prototype.omove = function(x, y) {
|
|
|
|
if (!this.zero) {
|
|
|
|
x = (x || 1) - 1;
|
|
|
|
y = (y || 1) - 1;
|
|
|
|
} else {
|
|
|
|
x = x || 0;
|
|
|
|
y = y || 0;
|
|
|
|
}
|
|
|
|
if (y === this.y && x === this.x) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (y === this.y) {
|
|
|
|
if (x > this.x) {
|
|
|
|
this.cuf(x - this.x);
|
|
|
|
} else if (x < this.x) {
|
|
|
|
this.cub(this.x - x);
|
|
|
|
}
|
|
|
|
} else if (x === this.x) {
|
|
|
|
if (y > this.y) {
|
|
|
|
this.cud(y - this.y);
|
|
|
|
} else if (y < this.y) {
|
|
|
|
this.cuu(this.y - y);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!this.zero) x++, y++;
|
|
|
|
this.cup(y, x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.rsetx = function(x) {
|
|
|
|
// return this.HPositionRelative(x);
|
|
|
|
if (!x) return;
|
|
|
|
return x > 0
|
|
|
|
? this.forward(x)
|
2013-06-14 20:58:54 +00:00
|
|
|
: this.back(-x);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.rsety = function(y) {
|
|
|
|
// return this.VPositionRelative(y);
|
|
|
|
if (!y) return;
|
|
|
|
return y > 0
|
|
|
|
? this.up(y)
|
2013-06-14 20:58:54 +00:00
|
|
|
: this.down(-y);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.rmove = function(x, y) {
|
2013-06-14 20:58:54 +00:00
|
|
|
this.rsetx(x);
|
|
|
|
this.rsety(y);
|
2013-01-27 16:01:30 +00:00
|
|
|
};
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2013-02-07 18:53:01 +00:00
|
|
|
Program.prototype.simpleInsert = function(ch, i, attr) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write(this.repeat(ch, i), attr);
|
2013-02-07 18:53:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.repeat = function(ch, i) {
|
|
|
|
if (!(i >= 0)) i = 0;
|
|
|
|
return Array(i + 1).join(ch);
|
|
|
|
};
|
|
|
|
|
2015-01-30 04:08:23 +00:00
|
|
|
Program.prototype.__defineGetter__('title', function() {
|
|
|
|
return this._title;
|
|
|
|
});
|
|
|
|
|
|
|
|
Program.prototype.__defineSetter__('title', function(title) {
|
|
|
|
this.setTitle(title);
|
|
|
|
return this._title;
|
|
|
|
});
|
|
|
|
|
2015-03-14 23:35:17 +00:00
|
|
|
// Specific to iTerm2, but I think it's really cool.
|
|
|
|
// Example:
|
|
|
|
// if (!screen.copyToClipboard(text)) {
|
|
|
|
// execClipboardProgram(text);
|
|
|
|
// }
|
|
|
|
Program.prototype.copyToClipboard = function(text) {
|
|
|
|
if (this.isiTerm2) {
|
|
|
|
this._twrite('\x1b]50;CopyToCliboard=' + text + '\x07');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Only XTerm and iTerm2. If you know of any others, post them.
|
|
|
|
Program.prototype.cursorShape = function(shape, blink) {
|
|
|
|
if (this.isiTerm2) {
|
|
|
|
switch (shape) {
|
|
|
|
case 'block':
|
|
|
|
if (!blink) {
|
|
|
|
this._twrite('\x1b]50;CursorShape=0;BlinkingCursorEnabled=0\x07');
|
|
|
|
} else {
|
|
|
|
this._twrite('\x1b]50;CursorShape=0;BlinkingCursorEnabled=1\x07');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'underline':
|
|
|
|
if (!blink) {
|
|
|
|
// this._twrite('\x1b]50;CursorShape=n;BlinkingCursorEnabled=0\x07');
|
|
|
|
} else {
|
|
|
|
// this._twrite('\x1b]50;CursorShape=n;BlinkingCursorEnabled=1\x07');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'line':
|
|
|
|
if (!blink) {
|
|
|
|
this._twrite('\x1b]50;CursorShape=1;BlinkingCursorEnabled=0\x07');
|
|
|
|
} else {
|
|
|
|
this._twrite('\x1b]50;CursorShape=1;BlinkingCursorEnabled=1\x07');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2015-03-20 06:49:26 +00:00
|
|
|
} else if (this.term('xterm') || this.term('screen')) {
|
2015-03-14 23:35:17 +00:00
|
|
|
switch (shape) {
|
|
|
|
case 'block':
|
|
|
|
if (!blink) {
|
|
|
|
this._twrite('\x1b[0 q');
|
|
|
|
} else {
|
|
|
|
this._twrite('\x1b[1 q');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'underline':
|
|
|
|
if (!blink) {
|
|
|
|
this._twrite('\x1b[2 q');
|
|
|
|
} else {
|
|
|
|
this._twrite('\x1b[3 q');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'line':
|
|
|
|
if (!blink) {
|
|
|
|
this._twrite('\x1b[4 q');
|
|
|
|
} else {
|
|
|
|
this._twrite('\x1b[5 q');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.cursorColor = function(color) {
|
2015-03-20 06:49:26 +00:00
|
|
|
if (this.term('xterm') || this.term('rxvt') || this.term('screen')) {
|
2015-03-14 23:35:17 +00:00
|
|
|
this._twrite('\x1b]12;' + color + '\x07');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-03-20 06:49:26 +00:00
|
|
|
Program.prototype.cursorReset =
|
2015-03-14 23:35:17 +00:00
|
|
|
Program.prototype.resetCursor = function() {
|
2015-03-20 06:49:26 +00:00
|
|
|
if (this.term('xterm') || this.term('rxvt') || this.term('screen')) {
|
2015-03-14 23:35:17 +00:00
|
|
|
// XXX
|
|
|
|
// return this.resetColors();
|
2015-03-20 06:49:26 +00:00
|
|
|
this._twrite('\x1b[0 q');
|
2015-03-14 23:35:17 +00:00
|
|
|
this._twrite('\x1b]112\x07');
|
2015-03-20 06:49:26 +00:00
|
|
|
// urxvt doesnt support OSC 112
|
|
|
|
this._twrite('\x1b]12;white\x07');
|
2015-03-14 23:35:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-03-20 06:49:26 +00:00
|
|
|
Program.prototype.getTextParams = function(param, callback) {
|
|
|
|
return this.response('text-params', '\x1b]' + param + ';?\x07', function(err, data) {
|
|
|
|
if (err) return callback(err);
|
|
|
|
return callback(null, data.pt);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.getCursorColor = function(callback) {
|
|
|
|
return this.getTextParams(12, callback);
|
|
|
|
};
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
/**
|
|
|
|
* Normal
|
|
|
|
*/
|
|
|
|
|
2013-07-12 04:00:03 +00:00
|
|
|
//Program.prototype.pad =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.nul = function() {
|
2013-07-14 13:37:57 +00:00
|
|
|
//if (this.has('pad')) return this.put.pad();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\200');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.bel =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.bell = function() {
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('bel')) return this.put.bel();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x07');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.vtab = function() {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.y++;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x0b');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 06:04:57 +00:00
|
|
|
Program.prototype.ff =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.form = function() {
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('ff')) return this.put.ff();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x0c');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.kbs =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.backspace = function() {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.x--;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('kbs')) return this.put.kbs();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x08');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.ht =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.tab = function() {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.x += 8;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('ht')) return this.put.ht();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\t');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.shiftOut = function() {
|
2013-07-14 13:37:57 +00:00
|
|
|
// if (this.has('S2')) return this.put.S2();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x0e');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.shiftIn = function() {
|
2013-07-14 13:37:57 +00:00
|
|
|
// if (this.has('S3')) return this.put.S3();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x0f');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-02-25 07:47:32 +00:00
|
|
|
Program.prototype.cr =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.return = function() {
|
2013-07-12 05:00:11 +00:00
|
|
|
this.x = 0;
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('cr')) return this.put.cr();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\r');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.nel =
|
|
|
|
Program.prototype.newline =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.feed = function() {
|
2013-07-22 04:53:10 +00:00
|
|
|
if (this.tput && this.tput.bools.eat_newline_glitch && this.x >= this.cols) {
|
2013-07-22 02:00:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-12 05:00:11 +00:00
|
|
|
this.x = 0;
|
2013-01-27 14:54:30 +00:00
|
|
|
this.y++;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('nel')) return this.put.nel();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\n');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Esc
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ESC D Index (IND is 0x84).
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.ind =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.index = function() {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.y++;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.ind();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1bD');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC M Reverse Index (RI is 0x8d).
|
2013-07-12 04:00:03 +00:00
|
|
|
Program.prototype.ri =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.reverse =
|
|
|
|
Program.prototype.reverseIndex = function() {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.y--;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.ri();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1bM');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC E Next Line (NEL is 0x85).
|
|
|
|
Program.prototype.nextLine = function() {
|
|
|
|
this.y++;
|
2013-07-12 05:00:11 +00:00
|
|
|
this.x = 0;
|
|
|
|
this._ncoords();
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('nel')) return this.put.nel();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1bE');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC c Full Reset (RIS).
|
|
|
|
Program.prototype.reset = function() {
|
2013-07-12 05:08:36 +00:00
|
|
|
this.x = this.y = 0;
|
2013-07-14 13:37:57 +00:00
|
|
|
if (this.has('rs1') || this.has('ris')) {
|
|
|
|
return this.has('rs1')
|
|
|
|
? this.put.rs1()
|
|
|
|
: this.put.ris();
|
|
|
|
}
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1bc');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC H Tab Set (HTS is 0x88).
|
|
|
|
Program.prototype.tabSet = function() {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.hts();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1bH');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 14:54:30 +00:00
|
|
|
// ESC 7 Save Cursor (DECSC).
|
2013-07-03 23:46:06 +00:00
|
|
|
Program.prototype.sc =
|
2013-07-22 04:53:10 +00:00
|
|
|
Program.prototype.saveCursor = function(key) {
|
|
|
|
if (key) return this.lsaveCursor(key);
|
2013-07-12 05:00:11 +00:00
|
|
|
this.savedX = this.x || 0;
|
|
|
|
this.savedY = this.y || 0;
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.sc();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b7');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC 8 Restore Cursor (DECRC).
|
2013-07-03 23:46:06 +00:00
|
|
|
Program.prototype.rc =
|
2013-07-22 04:53:10 +00:00
|
|
|
Program.prototype.restoreCursor = function(key, hide) {
|
|
|
|
if (key) return this.lrestoreCursor(key, hide);
|
2013-07-12 05:00:11 +00:00
|
|
|
this.x = this.savedX || 0;
|
|
|
|
this.y = this.savedY || 0;
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.rc();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b8');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
2013-07-22 04:53:10 +00:00
|
|
|
// Save Cursor Locally
|
|
|
|
Program.prototype.lsaveCursor = function(key) {
|
|
|
|
var key = key || 'local';
|
|
|
|
this._saved = this._saved || {};
|
|
|
|
this._saved[key] = this._saved[key] || {};
|
|
|
|
this._saved[key].x = this.x;
|
|
|
|
this._saved[key].y = this.y;
|
|
|
|
this._saved[key].hidden = this.cursorHidden;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Restore Cursor Locally
|
|
|
|
Program.prototype.lrestoreCursor = function(key, hide) {
|
|
|
|
var key = key || 'local', pos;
|
|
|
|
if (!this._saved || !this._saved[key]) return;
|
|
|
|
pos = this._saved[key];
|
2013-07-23 21:37:54 +00:00
|
|
|
//delete this._saved[key];
|
2013-07-22 04:53:10 +00:00
|
|
|
this.cup(pos.y, pos.x);
|
|
|
|
if (hide && pos.hidden !== this.cursorHidden) {
|
|
|
|
if (pos.hidden) {
|
|
|
|
this.hideCursor();
|
|
|
|
} else {
|
|
|
|
this.showCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-27 14:54:30 +00:00
|
|
|
// ESC # 3 DEC line height/width
|
|
|
|
Program.prototype.lineHeight = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b#');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ESC (,),*,+,-,. Designate G0-G2 Character Set.
|
|
|
|
Program.prototype.charset = function(val, level) {
|
|
|
|
level = level || 0;
|
|
|
|
|
2013-06-25 11:34:10 +00:00
|
|
|
// See also:
|
|
|
|
// acs_chars / acsc / ac
|
|
|
|
// enter_alt_charset_mode / smacs / as
|
|
|
|
// exit_alt_charset_mode / rmacs / ae
|
|
|
|
// enter_pc_charset_mode / smpch / S2
|
|
|
|
// exit_pc_charset_mode / rmpch / S3
|
|
|
|
|
2013-01-27 14:54:30 +00:00
|
|
|
switch (level) {
|
|
|
|
case 0:
|
|
|
|
level = '(';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
level = ')';
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
level = '*';
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
level = '+';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:10:33 +00:00
|
|
|
var name = typeof val === 'string'
|
|
|
|
? val.toLowerCase()
|
|
|
|
: val;
|
|
|
|
|
|
|
|
switch (name) {
|
|
|
|
case 'acs':
|
|
|
|
case 'scld': // DEC Special Character and Line Drawing Set.
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.smacs();
|
2013-01-27 14:54:30 +00:00
|
|
|
val = '0';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'uk': // UK
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'A';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'us': // United States (USASCII).
|
|
|
|
case 'usascii':
|
|
|
|
case 'ascii':
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.rmacs();
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'B';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'dutch': // Dutch
|
2013-01-27 14:54:30 +00:00
|
|
|
val = '4';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'finnish': // Finnish
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'C';
|
|
|
|
val = '5';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'french': // French
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'R';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'frenchcanadian': // FrenchCanadian
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'Q';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'german': // German
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'K';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'italian': // Italian
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'Y';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'norwegiandanish': // NorwegianDanish
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'E';
|
|
|
|
val = '6';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'spanish': // Spanish
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'Z';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'swedish': // Swedish
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'H';
|
|
|
|
val = '7';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'swiss': // Swiss
|
2013-01-27 14:54:30 +00:00
|
|
|
val = '=';
|
|
|
|
break;
|
2013-07-18 07:10:33 +00:00
|
|
|
case 'isolatin': // ISOLatin (actually /A)
|
2013-01-27 14:54:30 +00:00
|
|
|
val = '/A';
|
|
|
|
break;
|
|
|
|
default: // Default
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.rmacs();
|
2013-01-27 14:54:30 +00:00
|
|
|
val = 'B';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b(' + val);
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.enter_alt_charset_mode =
|
|
|
|
Program.prototype.as =
|
|
|
|
Program.prototype.smacs = function() {
|
2013-07-18 07:10:33 +00:00
|
|
|
return this.charset('acs');
|
2013-06-25 11:34:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.exit_alt_charset_mode =
|
|
|
|
Program.prototype.ae =
|
|
|
|
Program.prototype.rmacs = function() {
|
2013-07-18 07:10:33 +00:00
|
|
|
return this.charset('ascii');
|
2013-06-25 11:34:10 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 14:54:30 +00:00
|
|
|
// ESC N
|
|
|
|
// Single Shift Select of G2 Character Set
|
|
|
|
// ( SS2 is 0x8e). This affects next character only.
|
|
|
|
// ESC O
|
|
|
|
// Single Shift Select of G3 Character Set
|
|
|
|
// ( SS3 is 0x8f). This affects next character only.
|
|
|
|
// ESC n
|
|
|
|
// Invoke the G2 Character Set as GL (LS2).
|
|
|
|
// ESC o
|
|
|
|
// Invoke the G3 Character Set as GL (LS3).
|
|
|
|
// ESC |
|
|
|
|
// Invoke the G3 Character Set as GR (LS3R).
|
|
|
|
// ESC }
|
|
|
|
// Invoke the G2 Character Set as GR (LS2R).
|
|
|
|
// ESC ~
|
|
|
|
// Invoke the G1 Character Set as GR (LS1R).
|
|
|
|
Program.prototype.setG = function(val) {
|
2013-07-12 06:04:57 +00:00
|
|
|
// if (this.tput) return this.put.S2();
|
|
|
|
// if (this.tput) return this.put.S3();
|
2013-01-27 14:54:30 +00:00
|
|
|
switch (val) {
|
|
|
|
case 1:
|
|
|
|
val = '~'; // GR
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val = 'n'; // GL
|
|
|
|
val = '}'; // GR
|
|
|
|
val = 'N'; // Next Char Only
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
val = 'o'; // GL
|
|
|
|
val = '|'; // GR
|
|
|
|
val = 'O'; // Next Char Only
|
|
|
|
break;
|
|
|
|
}
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b' + val);
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OSC
|
|
|
|
*/
|
|
|
|
|
|
|
|
// OSC Ps ; Pt ST
|
|
|
|
// OSC Ps ; Pt BEL
|
|
|
|
// Set Text Parameters.
|
|
|
|
Program.prototype.setTitle = function(title) {
|
2015-01-28 04:39:00 +00:00
|
|
|
this._title = title;
|
|
|
|
|
2015-03-18 06:26:27 +00:00
|
|
|
// if (this.term('screen')) {
|
|
|
|
// // Tmux pane
|
|
|
|
// // if (process.env.TMUX) {
|
|
|
|
// // return this._write('\x1b]2;' + title + '\x1b\\');
|
|
|
|
// // }
|
|
|
|
// return this._write('\x1bk' + title + '\x1b\\');
|
|
|
|
// }
|
2015-01-28 04:39:00 +00:00
|
|
|
|
2015-03-14 23:14:39 +00:00
|
|
|
return this._twrite('\x1b]0;' + title + '\x07');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-03-06 10:27:42 +00:00
|
|
|
// OSC Ps ; Pt ST
|
|
|
|
// OSC Ps ; Pt BEL
|
|
|
|
// Reset colors
|
|
|
|
Program.prototype.resetColors = function(param) {
|
2013-07-18 07:10:33 +00:00
|
|
|
if (this.has('Cr')) {
|
2013-03-06 10:27:42 +00:00
|
|
|
return this.put.Cr(param);
|
|
|
|
}
|
2015-03-14 23:14:39 +00:00
|
|
|
return this._twrite('\x1b]112\x07');
|
|
|
|
//return this._twrite('\x1b]112;' + param + '\x07');
|
2013-03-06 10:27:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// OSC Ps ; Pt ST
|
|
|
|
// OSC Ps ; Pt BEL
|
|
|
|
// Change dynamic colors
|
|
|
|
Program.prototype.dynamicColors = function(param) {
|
2013-07-18 06:03:47 +00:00
|
|
|
if (this.has('Cs')) {
|
2013-03-06 10:27:42 +00:00
|
|
|
return this.put.Cs(param);
|
|
|
|
}
|
2015-03-14 23:14:39 +00:00
|
|
|
return this._twrite('\x1b]12;' + param + '\x07');
|
2013-03-06 10:27:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// OSC Ps ; Pt ST
|
|
|
|
// OSC Ps ; Pt BEL
|
|
|
|
// Sel data
|
|
|
|
Program.prototype.selData = function(a, b) {
|
2013-07-18 06:03:47 +00:00
|
|
|
if (this.has('Ms')) {
|
2013-03-06 10:27:42 +00:00
|
|
|
return this.put.Ms(a, b);
|
|
|
|
}
|
2015-03-14 23:14:39 +00:00
|
|
|
return this._twrite('\x1b]52;' + a + ';' + b + '\x07');
|
2013-03-06 10:27:42 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
/**
|
|
|
|
* CSI
|
|
|
|
*/
|
|
|
|
|
|
|
|
// CSI Ps A
|
|
|
|
// Cursor Up Ps Times (default = 1) (CUU).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cuu =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.up =
|
|
|
|
Program.prototype.cursorUp = function(param) {
|
|
|
|
this.y -= param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.cuu(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'A');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps B
|
|
|
|
// Cursor Down Ps Times (default = 1) (CUD).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cud =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.down =
|
|
|
|
Program.prototype.cursorDown = function(param) {
|
|
|
|
this.y += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.cud(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'B');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps C
|
|
|
|
// Cursor Forward Ps Times (default = 1) (CUF).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cuf =
|
|
|
|
Program.prototype.right =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.forward =
|
|
|
|
Program.prototype.cursorForward = function(param) {
|
|
|
|
this.x += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.cuf(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'C');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps D
|
|
|
|
// Cursor Backward Ps Times (default = 1) (CUB).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cub =
|
|
|
|
Program.prototype.left =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.back =
|
|
|
|
Program.prototype.cursorBackward = function(param) {
|
|
|
|
this.x -= param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.cub(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'D');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Ps H
|
|
|
|
// Cursor Position [row;column] (default = [1,1]) (CUP).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cup =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.pos =
|
|
|
|
Program.prototype.cursorPos = function(row, col) {
|
2013-07-12 05:00:11 +00:00
|
|
|
if (!this.zero) {
|
|
|
|
row = (row || 1) - 1;
|
|
|
|
col = (col || 1) - 1;
|
|
|
|
} else {
|
|
|
|
row = row || 0;
|
|
|
|
col = col || 0;
|
|
|
|
}
|
|
|
|
this.x = col;
|
|
|
|
this.y = row;
|
|
|
|
this._ncoords();
|
|
|
|
if (this.tput) return this.put.cup(row, col);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (row + 1) + ';' + (col + 1) + 'H');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps J Erase in Display (ED).
|
|
|
|
// Ps = 0 -> Erase Below (default).
|
|
|
|
// Ps = 1 -> Erase Above.
|
|
|
|
// Ps = 2 -> Erase All.
|
|
|
|
// Ps = 3 -> Erase Saved Lines (xterm).
|
|
|
|
// CSI ? Ps J
|
|
|
|
// Erase in Display (DECSED).
|
|
|
|
// Ps = 0 -> Selective Erase Below (default).
|
|
|
|
// Ps = 1 -> Selective Erase Above.
|
|
|
|
// Ps = 2 -> Selective Erase All.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.ed =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.eraseInDisplay = function(param) {
|
2013-02-25 07:14:38 +00:00
|
|
|
if (this.tput) {
|
|
|
|
switch (param) {
|
|
|
|
case 'above':
|
|
|
|
param = 1;
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
param = 2;
|
|
|
|
break;
|
|
|
|
case 'saved':
|
|
|
|
param = 3;
|
|
|
|
break;
|
|
|
|
case 'below':
|
|
|
|
default:
|
2013-02-25 07:47:32 +00:00
|
|
|
param = 0;
|
2013-02-25 07:14:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-06 10:27:42 +00:00
|
|
|
// extended tput.E3 = ^[[3;J
|
2013-02-25 07:47:32 +00:00
|
|
|
return this.put.ed(param);
|
2013-02-25 07:14:38 +00:00
|
|
|
}
|
2013-01-27 10:30:52 +00:00
|
|
|
switch (param) {
|
|
|
|
case 'above':
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\X1b[1J');
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'all':
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[2J');
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'saved':
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[3J');
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'below':
|
|
|
|
default:
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[J');
|
2013-01-27 10:30:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.clear = function() {
|
2013-07-26 05:19:57 +00:00
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
2013-02-27 18:24:38 +00:00
|
|
|
if (this.tput) return this.put.clear();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[H\x1b[J');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps K Erase in Line (EL).
|
|
|
|
// Ps = 0 -> Erase to Right (default).
|
|
|
|
// Ps = 1 -> Erase to Left.
|
|
|
|
// Ps = 2 -> Erase All.
|
|
|
|
// CSI ? Ps K
|
|
|
|
// Erase in Line (DECSEL).
|
|
|
|
// Ps = 0 -> Selective Erase to Right (default).
|
|
|
|
// Ps = 1 -> Selective Erase to Left.
|
|
|
|
// Ps = 2 -> Selective Erase All.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.el =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.eraseInLine = function(param) {
|
2013-02-25 07:14:38 +00:00
|
|
|
if (this.tput) {
|
2013-06-25 11:34:10 +00:00
|
|
|
//if (this.tput.back_color_erase) ...
|
2013-02-25 07:14:38 +00:00
|
|
|
switch (param) {
|
|
|
|
case 'left':
|
|
|
|
param = 1;
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
param = 2;
|
|
|
|
break;
|
|
|
|
case 'right':
|
|
|
|
default:
|
2013-02-25 07:47:32 +00:00
|
|
|
param = 0;
|
2013-02-25 07:14:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-25 07:47:32 +00:00
|
|
|
return this.put.el(param);
|
2013-02-25 07:14:38 +00:00
|
|
|
}
|
2013-01-27 10:30:52 +00:00
|
|
|
switch (param) {
|
|
|
|
case 'left':
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[1K');
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'all':
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[2K');
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'right':
|
|
|
|
default:
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[K');
|
2013-01-27 10:30:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm m Character Attributes (SGR).
|
|
|
|
// Ps = 0 -> Normal (default).
|
|
|
|
// Ps = 1 -> Bold.
|
|
|
|
// Ps = 4 -> Underlined.
|
|
|
|
// Ps = 5 -> Blink (appears as Bold).
|
|
|
|
// Ps = 7 -> Inverse.
|
|
|
|
// Ps = 8 -> Invisible, i.e., hidden (VT300).
|
|
|
|
// Ps = 2 2 -> Normal (neither bold nor faint).
|
|
|
|
// Ps = 2 4 -> Not underlined.
|
|
|
|
// Ps = 2 5 -> Steady (not blinking).
|
|
|
|
// Ps = 2 7 -> Positive (not inverse).
|
|
|
|
// Ps = 2 8 -> Visible, i.e., not hidden (VT300).
|
|
|
|
// Ps = 3 0 -> Set foreground color to Black.
|
|
|
|
// Ps = 3 1 -> Set foreground color to Red.
|
|
|
|
// Ps = 3 2 -> Set foreground color to Green.
|
|
|
|
// Ps = 3 3 -> Set foreground color to Yellow.
|
|
|
|
// Ps = 3 4 -> Set foreground color to Blue.
|
|
|
|
// Ps = 3 5 -> Set foreground color to Magenta.
|
|
|
|
// Ps = 3 6 -> Set foreground color to Cyan.
|
|
|
|
// Ps = 3 7 -> Set foreground color to White.
|
|
|
|
// Ps = 3 9 -> Set foreground color to default (original).
|
|
|
|
// Ps = 4 0 -> Set background color to Black.
|
|
|
|
// Ps = 4 1 -> Set background color to Red.
|
|
|
|
// Ps = 4 2 -> Set background color to Green.
|
|
|
|
// Ps = 4 3 -> Set background color to Yellow.
|
|
|
|
// Ps = 4 4 -> Set background color to Blue.
|
|
|
|
// Ps = 4 5 -> Set background color to Magenta.
|
|
|
|
// Ps = 4 6 -> Set background color to Cyan.
|
|
|
|
// Ps = 4 7 -> Set background color to White.
|
|
|
|
// Ps = 4 9 -> Set background color to default (original).
|
|
|
|
|
|
|
|
// If 16-color support is compiled, the following apply. Assume
|
|
|
|
// that xterm's resources are set so that the ISO color codes are
|
|
|
|
// the first 8 of a set of 16. Then the aixterm colors are the
|
|
|
|
// bright versions of the ISO colors:
|
|
|
|
// Ps = 9 0 -> Set foreground color to Black.
|
|
|
|
// Ps = 9 1 -> Set foreground color to Red.
|
|
|
|
// Ps = 9 2 -> Set foreground color to Green.
|
|
|
|
// Ps = 9 3 -> Set foreground color to Yellow.
|
|
|
|
// Ps = 9 4 -> Set foreground color to Blue.
|
|
|
|
// Ps = 9 5 -> Set foreground color to Magenta.
|
|
|
|
// Ps = 9 6 -> Set foreground color to Cyan.
|
|
|
|
// Ps = 9 7 -> Set foreground color to White.
|
|
|
|
// Ps = 1 0 0 -> Set background color to Black.
|
|
|
|
// Ps = 1 0 1 -> Set background color to Red.
|
|
|
|
// Ps = 1 0 2 -> Set background color to Green.
|
|
|
|
// Ps = 1 0 3 -> Set background color to Yellow.
|
|
|
|
// Ps = 1 0 4 -> Set background color to Blue.
|
|
|
|
// Ps = 1 0 5 -> Set background color to Magenta.
|
|
|
|
// Ps = 1 0 6 -> Set background color to Cyan.
|
|
|
|
// Ps = 1 0 7 -> Set background color to White.
|
|
|
|
|
|
|
|
// If xterm is compiled with the 16-color support disabled, it
|
|
|
|
// supports the following, from rxvt:
|
|
|
|
// Ps = 1 0 0 -> Set foreground and background color to
|
|
|
|
// default.
|
|
|
|
|
|
|
|
// If 88- or 256-color support is compiled, the following apply.
|
|
|
|
// Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
|
|
|
|
// Ps.
|
|
|
|
// Ps = 4 8 ; 5 ; Ps -> Set background color to the second
|
|
|
|
// Ps.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.sgr =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.attr =
|
|
|
|
Program.prototype.charAttributes = function(param, val) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write(this._attr(param, val));
|
2013-02-07 18:19:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.text = function(text, attr) {
|
|
|
|
return this._attr(attr, true) + text + this._attr(attr, false);
|
|
|
|
};
|
|
|
|
|
2013-07-16 20:57:12 +00:00
|
|
|
// NOTE: sun-color may not allow multiple params for SGR.
|
2013-02-07 18:19:49 +00:00
|
|
|
Program.prototype._attr = function(param, val) {
|
|
|
|
var self = this
|
2013-07-28 15:52:13 +00:00
|
|
|
, param
|
|
|
|
, parts
|
2013-07-16 00:35:36 +00:00
|
|
|
, color
|
|
|
|
, m;
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-07-28 15:52:13 +00:00
|
|
|
if (Array.isArray(param)) {
|
|
|
|
parts = param;
|
|
|
|
param = parts[0] || 'normal';
|
|
|
|
} else {
|
|
|
|
param = param || 'normal';
|
|
|
|
parts = param.split(/\s*[,;]\s*/);
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:19:49 +00:00
|
|
|
if (parts.length > 1) {
|
2013-07-28 15:52:13 +00:00
|
|
|
var used = {}
|
|
|
|
, out = [];
|
|
|
|
|
|
|
|
parts.forEach(function(part) {
|
|
|
|
part = self._attr(part, val).slice(2, -1);
|
|
|
|
if (part === '') return;
|
|
|
|
if (used[part]) return;
|
|
|
|
used[part] = true;
|
|
|
|
out.push(part);
|
2013-02-07 18:19:49 +00:00
|
|
|
});
|
2013-07-28 15:52:13 +00:00
|
|
|
|
|
|
|
return '\x1b[' + out.join(';') + 'm';
|
2013-02-07 18:19:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 17:14:06 +00:00
|
|
|
if (param.indexOf('no ') === 0) {
|
|
|
|
param = param.substring(3);
|
|
|
|
val = false;
|
|
|
|
} else if (param.indexOf('!') === 0) {
|
|
|
|
param = param.substring(1);
|
|
|
|
val = false;
|
|
|
|
}
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
switch (param) {
|
2013-02-07 18:19:49 +00:00
|
|
|
// attributes
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'normal':
|
2013-06-14 01:21:41 +00:00
|
|
|
case 'default':
|
2013-07-28 15:52:13 +00:00
|
|
|
if (val === false) return '';
|
2013-02-07 18:19:49 +00:00
|
|
|
return '\x1b[m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'bold':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[22m'
|
|
|
|
: '\x1b[1m';
|
2013-06-14 01:21:41 +00:00
|
|
|
case 'ul':
|
|
|
|
case 'underline':
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'underlined':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[24m'
|
|
|
|
: '\x1b[4m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'blink':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[25m'
|
|
|
|
: '\x1b[5m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'inverse':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[27m'
|
|
|
|
: '\x1b[7m';
|
2013-01-27 10:30:52 +00:00
|
|
|
break;
|
|
|
|
case 'invisible':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[28m'
|
|
|
|
: '\x1b[8m';
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2013-02-07 18:19:49 +00:00
|
|
|
// 8-color foreground
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'black fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[30m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'red fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[31m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'green fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[32m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'yellow fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[33m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'blue fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[34m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'magenta fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[35m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'cyan fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[36m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'white fg':
|
2015-05-01 08:29:37 +00:00
|
|
|
case 'light grey fg':
|
|
|
|
case 'light gray fg':
|
|
|
|
case 'bright grey fg':
|
|
|
|
case 'bright gray fg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[37m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'default fg':
|
2013-07-28 15:52:13 +00:00
|
|
|
if (val === false) return '';
|
2013-02-07 18:19:49 +00:00
|
|
|
return '\x1b[39m';
|
2013-01-27 10:30:52 +00:00
|
|
|
|
2013-02-07 18:19:49 +00:00
|
|
|
// 8-color background
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'black bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[40m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'red bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[41m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'green bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[42m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'yellow bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[43m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'blue bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[44m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'magenta bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[45m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'cyan bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[46m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'white bg':
|
2015-05-01 08:29:37 +00:00
|
|
|
case 'light grey bg':
|
|
|
|
case 'light gray bg':
|
|
|
|
case 'bright grey bg':
|
|
|
|
case 'bright gray bg':
|
2013-01-27 15:06:31 +00:00
|
|
|
return val === false
|
2013-02-07 18:19:49 +00:00
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[47m';
|
2013-01-27 10:30:52 +00:00
|
|
|
case 'default bg':
|
2013-07-28 15:52:13 +00:00
|
|
|
if (val === false) return '';
|
2013-02-07 18:19:49 +00:00
|
|
|
return '\x1b[49m';
|
|
|
|
|
|
|
|
// 16-color foreground
|
|
|
|
case 'light black fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright black fg':
|
|
|
|
case 'grey fg':
|
|
|
|
case 'gray fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[90m';
|
|
|
|
case 'light red fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright red fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[91m';
|
|
|
|
case 'light green fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright green fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[92m';
|
|
|
|
case 'light yellow fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright yellow fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[93m';
|
|
|
|
case 'light blue fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright blue fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[94m';
|
|
|
|
case 'light magenta fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright magenta fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[95m';
|
|
|
|
case 'light cyan fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright cyan fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[96m';
|
|
|
|
case 'light white fg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright white fg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[39m'
|
|
|
|
: '\x1b[97m';
|
|
|
|
|
|
|
|
// 16-color background
|
|
|
|
case 'light black bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright black bg':
|
|
|
|
case 'grey bg':
|
|
|
|
case 'gray bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[100m';
|
|
|
|
case 'light red bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright red bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[101m';
|
|
|
|
case 'light green bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright green bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[102m';
|
|
|
|
case 'light yellow bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright yellow bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[103m';
|
|
|
|
case 'light blue bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright blue bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[104m';
|
|
|
|
case 'light magenta bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright magenta bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[105m';
|
|
|
|
case 'light cyan bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright cyan bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[106m';
|
|
|
|
case 'light white bg':
|
2015-05-01 08:23:47 +00:00
|
|
|
case 'bright white bg':
|
2013-02-07 18:19:49 +00:00
|
|
|
return val === false
|
|
|
|
? '\x1b[49m'
|
|
|
|
: '\x1b[107m';
|
|
|
|
|
|
|
|
// non-16-color rxvt default fg and bg
|
|
|
|
case 'default fg bg':
|
2013-07-28 15:52:13 +00:00
|
|
|
if (val === false) return '';
|
2013-02-07 18:36:26 +00:00
|
|
|
return this.term('rxvt')
|
|
|
|
? '\x1b[100m'
|
|
|
|
: '\x1b[39;49m';
|
2013-01-27 15:06:31 +00:00
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
default:
|
2013-02-07 18:19:49 +00:00
|
|
|
// 256-color fg and bg
|
2013-07-16 00:35:36 +00:00
|
|
|
if (param[0] === '#') {
|
2013-07-23 10:04:04 +00:00
|
|
|
param = param.replace(/#(?:[0-9a-f]{3}){1,2}/i, colors.match);
|
2013-07-16 00:35:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 10:04:04 +00:00
|
|
|
m = /^(-?\d+) (fg|bg)$/.exec(param);
|
2013-02-07 18:19:49 +00:00
|
|
|
if (m) {
|
2013-07-16 05:18:31 +00:00
|
|
|
color = +m[1];
|
2013-02-07 18:19:49 +00:00
|
|
|
|
2013-07-23 10:04:04 +00:00
|
|
|
if (val === false || color === -1) {
|
2013-02-07 18:19:49 +00:00
|
|
|
return this._attr('default ' + m[2]);
|
|
|
|
}
|
|
|
|
|
2013-06-11 18:13:49 +00:00
|
|
|
if (color < 16 || (this.tput && this.tput.colors <= 16)) {
|
2013-02-07 18:19:49 +00:00
|
|
|
if (m[2] === 'fg') {
|
|
|
|
if (color < 8) {
|
|
|
|
color += 30;
|
|
|
|
} else if (color < 16) {
|
2015-07-11 12:30:55 +00:00
|
|
|
color -= 8;
|
2013-02-07 18:19:49 +00:00
|
|
|
color += 90;
|
|
|
|
}
|
|
|
|
} else if (m[2] === 'bg') {
|
|
|
|
if (color < 8) {
|
|
|
|
color += 40;
|
|
|
|
} else if (color < 16) {
|
2015-07-11 12:30:55 +00:00
|
|
|
color -= 8;
|
2013-02-07 18:19:49 +00:00
|
|
|
color += 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '\x1b[' + color + 'm';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m[2] === 'fg') {
|
|
|
|
return '\x1b[38;5;' + color + 'm';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m[2] === 'bg') {
|
|
|
|
return '\x1b[48;5;' + color + 'm';
|
|
|
|
}
|
|
|
|
}
|
2013-07-28 15:52:13 +00:00
|
|
|
|
|
|
|
if (/^[\d;]*$/.test(param)) {
|
|
|
|
return '\x1b[' + param + 'm';
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2013-01-27 10:30:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.fg =
|
|
|
|
Program.prototype.setForeground = function(color, val) {
|
2013-02-07 18:19:49 +00:00
|
|
|
color = color.split(/\s*[,;]\s*/).join(' fg, ') + ' fg';
|
|
|
|
return this.attr(color, val);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.bg =
|
|
|
|
Program.prototype.setBackground = function(color, val) {
|
2013-02-07 18:19:49 +00:00
|
|
|
color = color.split(/\s*[,;]\s*/).join(' bg, ') + ' bg';
|
|
|
|
return this.attr(color, val);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps n Device Status Report (DSR).
|
|
|
|
// Ps = 5 -> Status Report. Result (``OK'') is
|
|
|
|
// CSI 0 n
|
|
|
|
// Ps = 6 -> Report Cursor Position (CPR) [row;column].
|
|
|
|
// Result is
|
|
|
|
// CSI r ; c R
|
|
|
|
// CSI ? Ps n
|
|
|
|
// Device Status Report (DSR, DEC-specific).
|
|
|
|
// Ps = 6 -> Report Cursor Position (CPR) [row;column] as CSI
|
|
|
|
// ? r ; c R (assumes page is zero).
|
|
|
|
// Ps = 1 5 -> Report Printer status as CSI ? 1 0 n (ready).
|
|
|
|
// or CSI ? 1 1 n (not ready).
|
|
|
|
// Ps = 2 5 -> Report UDK status as CSI ? 2 0 n (unlocked)
|
|
|
|
// or CSI ? 2 1 n (locked).
|
|
|
|
// Ps = 2 6 -> Report Keyboard status as
|
|
|
|
// CSI ? 2 7 ; 1 ; 0 ; 0 n (North American).
|
|
|
|
// The last two parameters apply to VT400 & up, and denote key-
|
|
|
|
// board ready and LK01 respectively.
|
|
|
|
// Ps = 5 3 -> Report Locator status as
|
|
|
|
// CSI ? 5 3 n Locator available, if compiled-in, or
|
|
|
|
// CSI ? 5 0 n No Locator, if not.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.dsr =
|
2015-03-19 11:16:59 +00:00
|
|
|
Program.prototype.deviceStatus = function(param, callback, dec, noBypass) {
|
2013-01-27 14:54:30 +00:00
|
|
|
if (dec) {
|
2013-07-18 19:52:56 +00:00
|
|
|
return this.response('device-status',
|
2015-03-19 11:16:59 +00:00
|
|
|
'\x1b[?' + (param || '0') + 'n', callback, noBypass);
|
2013-01-27 14:54:30 +00:00
|
|
|
}
|
2013-07-18 19:52:56 +00:00
|
|
|
return this.response('device-status',
|
2015-03-19 11:16:59 +00:00
|
|
|
'\x1b[' + (param || '0') + 'n', callback, noBypass);
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.getCursor = function(callback) {
|
2015-03-19 11:16:59 +00:00
|
|
|
return this.deviceStatus(6, callback, false, true);
|
2015-02-21 10:49:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.saveReportedCursor = function(callback) {
|
|
|
|
var self = this;
|
|
|
|
if (this.tput.strings.user7 === '\x1b[6n' || this.term('screen')) {
|
|
|
|
return this.getCursor(function(err, data) {
|
|
|
|
if (data) {
|
|
|
|
self._rx = data.status.x;
|
|
|
|
self._ry = data.status.y;
|
|
|
|
}
|
|
|
|
if (!callback) return;
|
|
|
|
return callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!callback) return;
|
|
|
|
return callback();
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.restoreReportedCursor = function() {
|
|
|
|
if (this._rx == null) return;
|
|
|
|
return this.cup(this._ry, this._rx);
|
|
|
|
// return this.nel();
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additions
|
|
|
|
*/
|
|
|
|
|
|
|
|
// CSI Ps @
|
|
|
|
// Insert Ps (Blank) Character(s) (default = 1) (ICH).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.ich =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.insertChars = function(param) {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.x += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.ich(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + '@');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps E
|
|
|
|
// Cursor Next Line Ps Times (default = 1) (CNL).
|
|
|
|
// same as CSI Ps B ?
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cnl =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.cursorNextLine = function(param) {
|
|
|
|
this.y += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'E');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps F
|
|
|
|
// Cursor Preceding Line Ps Times (default = 1) (CNL).
|
|
|
|
// reuse CSI Ps A ?
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cpl =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.cursorPrecedingLine = function(param) {
|
|
|
|
this.y -= param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'F');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps G
|
|
|
|
// Cursor Character Absolute [column] (default = [row,1]) (CHA).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cha =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.cursorCharAbsolute = function(param) {
|
2013-07-12 05:00:11 +00:00
|
|
|
if (!this.zero) {
|
|
|
|
param = (param || 1) - 1;
|
|
|
|
} else {
|
|
|
|
param = param || 0;
|
|
|
|
}
|
|
|
|
this.x = param;
|
|
|
|
this.y = 0;
|
|
|
|
this._ncoords();
|
2013-07-18 05:22:24 +00:00
|
|
|
if (this.tput) return this.put.hpa(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param + 1) + 'G');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps L
|
|
|
|
// Insert Ps Line(s) (default = 1) (IL).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.il =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.insertLines = function(param) {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.il(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'L');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps M
|
|
|
|
// Delete Ps Line(s) (default = 1) (DL).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.dl =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.deleteLines = function(param) {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.dl(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'M');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps P
|
|
|
|
// Delete Ps Character(s) (default = 1) (DCH).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.dch =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.deleteChars = function(param) {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.dch(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'P');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps X
|
|
|
|
// Erase Ps Character(s) (default = 1) (ECH).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.ech =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.eraseChars = function(param) {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.ech(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'X');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm ` Character Position Absolute
|
|
|
|
// [column] (default = [row,1]) (HPA).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.hpa =
|
2013-07-12 05:00:11 +00:00
|
|
|
Program.prototype.charPosAbsolute = function(param) {
|
|
|
|
this.x = param || 0;
|
|
|
|
this._ncoords();
|
|
|
|
if (this.tput) {
|
|
|
|
return this.put.hpa.apply(this.put, arguments);
|
|
|
|
}
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + '`');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 141 61 a * HPR -
|
|
|
|
// Horizontal Position Relative
|
|
|
|
// reuse CSI Ps C ?
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.hpr =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.HPositionRelative = function(param) {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.x += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
// Does not exist:
|
|
|
|
// if (this.tput) return this.put.hpr(param);
|
|
|
|
if (this.tput) return this.put.cuf(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'a');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps c Send Device Attributes (Primary DA).
|
|
|
|
// Ps = 0 or omitted -> request attributes from terminal. The
|
|
|
|
// response depends on the decTerminalID resource setting.
|
|
|
|
// -> CSI ? 1 ; 2 c (``VT100 with Advanced Video Option'')
|
|
|
|
// -> CSI ? 1 ; 0 c (``VT101 with No Options'')
|
|
|
|
// -> CSI ? 6 c (``VT102'')
|
|
|
|
// -> CSI ? 6 0 ; 1 ; 2 ; 6 ; 8 ; 9 ; 1 5 ; c (``VT220'')
|
|
|
|
// The VT100-style response parameters do not mean anything by
|
|
|
|
// themselves. VT220 parameters do, telling the host what fea-
|
|
|
|
// tures the terminal supports:
|
|
|
|
// Ps = 1 -> 132-columns.
|
|
|
|
// Ps = 2 -> Printer.
|
|
|
|
// Ps = 6 -> Selective erase.
|
|
|
|
// Ps = 8 -> User-defined keys.
|
|
|
|
// Ps = 9 -> National replacement character sets.
|
|
|
|
// Ps = 1 5 -> Technical characters.
|
|
|
|
// Ps = 2 2 -> ANSI color, e.g., VT525.
|
|
|
|
// Ps = 2 9 -> ANSI text locator (i.e., DEC Locator mode).
|
|
|
|
// CSI > Ps c
|
|
|
|
// Send Device Attributes (Secondary DA).
|
|
|
|
// Ps = 0 or omitted -> request the terminal's identification
|
|
|
|
// code. The response depends on the decTerminalID resource set-
|
|
|
|
// ting. It should apply only to VT220 and up, but xterm extends
|
|
|
|
// this to VT100.
|
|
|
|
// -> CSI > Pp ; Pv ; Pc c
|
|
|
|
// where Pp denotes the terminal type
|
|
|
|
// Pp = 0 -> ``VT100''.
|
|
|
|
// Pp = 1 -> ``VT220''.
|
|
|
|
// and Pv is the firmware version (for xterm, this was originally
|
|
|
|
// the XFree86 patch number, starting with 95). In a DEC termi-
|
|
|
|
// nal, Pc indicates the ROM cartridge registration number and is
|
|
|
|
// always zero.
|
|
|
|
// More information:
|
|
|
|
// xterm/charproc.c - line 2012, for more information.
|
|
|
|
// vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.da =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.sendDeviceAttributes = function(param, callback) {
|
2013-07-18 19:52:56 +00:00
|
|
|
return this.response('device-attributes',
|
|
|
|
'\x1b[' + (param || '') + 'c', callback);
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm d
|
|
|
|
// Line Position Absolute [row] (default = [1,column]) (VPA).
|
2013-07-12 05:00:11 +00:00
|
|
|
// NOTE: Can't find in terminfo, no idea why it has multiple params.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.vpa =
|
2013-07-12 05:00:11 +00:00
|
|
|
Program.prototype.linePosAbsolute = function(param) {
|
|
|
|
this.y = param || 1;
|
|
|
|
this._ncoords();
|
|
|
|
if (this.tput) {
|
|
|
|
return this.put.vpa.apply(this.put, arguments);
|
|
|
|
}
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'd');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 145 65 e * VPR - Vertical Position Relative
|
|
|
|
// reuse CSI Ps B ?
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.vpr =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.VPositionRelative = function(param) {
|
2013-01-27 14:54:30 +00:00
|
|
|
this.y += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
// Does not exist:
|
|
|
|
// if (this.tput) return this.put.vpr(param);
|
|
|
|
if (this.tput) return this.put.cud(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'e');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Ps f
|
|
|
|
// Horizontal and Vertical Position [row;column] (default =
|
|
|
|
// [1,1]) (HVP).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.hvp =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.HVPosition = function(row, col) {
|
2013-07-12 05:00:11 +00:00
|
|
|
if (!this.zero) {
|
|
|
|
row = (row || 1) - 1;
|
|
|
|
col = (col || 1) - 1;
|
|
|
|
} else {
|
|
|
|
row = row || 0;
|
|
|
|
col = col || 0;
|
|
|
|
}
|
|
|
|
this.y = row;
|
|
|
|
this.x = col;
|
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
// Does not exist (?):
|
|
|
|
// if (this.tput) return this.put.hvp(row, col);
|
2013-07-12 05:00:11 +00:00
|
|
|
if (this.tput) return this.put.cup(row, col);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (row + 1) + ';' + (col + 1) + 'f');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm h Set Mode (SM).
|
|
|
|
// Ps = 2 -> Keyboard Action Mode (AM).
|
|
|
|
// Ps = 4 -> Insert Mode (IRM).
|
|
|
|
// Ps = 1 2 -> Send/receive (SRM).
|
|
|
|
// Ps = 2 0 -> Automatic Newline (LNM).
|
|
|
|
// CSI ? Pm h
|
|
|
|
// DEC Private Mode Set (DECSET).
|
|
|
|
// Ps = 1 -> Application Cursor Keys (DECCKM).
|
|
|
|
// Ps = 2 -> Designate USASCII for character sets G0-G3
|
|
|
|
// (DECANM), and set VT100 mode.
|
|
|
|
// Ps = 3 -> 132 Column Mode (DECCOLM).
|
|
|
|
// Ps = 4 -> Smooth (Slow) Scroll (DECSCLM).
|
|
|
|
// Ps = 5 -> Reverse Video (DECSCNM).
|
|
|
|
// Ps = 6 -> Origin Mode (DECOM).
|
|
|
|
// Ps = 7 -> Wraparound Mode (DECAWM).
|
|
|
|
// Ps = 8 -> Auto-repeat Keys (DECARM).
|
|
|
|
// Ps = 9 -> Send Mouse X & Y on button press. See the sec-
|
|
|
|
// tion Mouse Tracking.
|
|
|
|
// Ps = 1 0 -> Show toolbar (rxvt).
|
|
|
|
// Ps = 1 2 -> Start Blinking Cursor (att610).
|
|
|
|
// Ps = 1 8 -> Print form feed (DECPFF).
|
|
|
|
// Ps = 1 9 -> Set print extent to full screen (DECPEX).
|
|
|
|
// Ps = 2 5 -> Show Cursor (DECTCEM).
|
|
|
|
// Ps = 3 0 -> Show scrollbar (rxvt).
|
|
|
|
// Ps = 3 5 -> Enable font-shifting functions (rxvt).
|
|
|
|
// Ps = 3 8 -> Enter Tektronix Mode (DECTEK).
|
|
|
|
// Ps = 4 0 -> Allow 80 -> 132 Mode.
|
|
|
|
// Ps = 4 1 -> more(1) fix (see curses resource).
|
|
|
|
// Ps = 4 2 -> Enable Nation Replacement Character sets (DECN-
|
|
|
|
// RCM).
|
|
|
|
// Ps = 4 4 -> Turn On Margin Bell.
|
|
|
|
// Ps = 4 5 -> Reverse-wraparound Mode.
|
|
|
|
// Ps = 4 6 -> Start Logging. This is normally disabled by a
|
|
|
|
// compile-time option.
|
|
|
|
// Ps = 4 7 -> Use Alternate Screen Buffer. (This may be dis-
|
|
|
|
// abled by the titeInhibit resource).
|
|
|
|
// Ps = 6 6 -> Application keypad (DECNKM).
|
|
|
|
// Ps = 6 7 -> Backarrow key sends backspace (DECBKM).
|
|
|
|
// Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
|
|
|
|
// release. See the section Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 1 -> Use Hilite Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 2 -> Use Cell Motion Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 3 -> Use All Motion Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 4 -> Send FocusIn/FocusOut events.
|
|
|
|
// Ps = 1 0 0 5 -> Enable Extended Mouse Mode.
|
|
|
|
// Ps = 1 0 1 0 -> Scroll to bottom on tty output (rxvt).
|
|
|
|
// Ps = 1 0 1 1 -> Scroll to bottom on key press (rxvt).
|
|
|
|
// Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
|
|
|
|
// (enables the eightBitInput resource).
|
|
|
|
// Ps = 1 0 3 5 -> Enable special modifiers for Alt and Num-
|
|
|
|
// Lock keys. (This enables the numLock resource).
|
|
|
|
// Ps = 1 0 3 6 -> Send ESC when Meta modifies a key. (This
|
|
|
|
// enables the metaSendsEscape resource).
|
|
|
|
// Ps = 1 0 3 7 -> Send DEL from the editing-keypad Delete
|
|
|
|
// key.
|
|
|
|
// Ps = 1 0 3 9 -> Send ESC when Alt modifies a key. (This
|
|
|
|
// enables the altSendsEscape resource).
|
|
|
|
// Ps = 1 0 4 0 -> Keep selection even if not highlighted.
|
|
|
|
// (This enables the keepSelection resource).
|
|
|
|
// Ps = 1 0 4 1 -> Use the CLIPBOARD selection. (This enables
|
|
|
|
// the selectToClipboard resource).
|
|
|
|
// Ps = 1 0 4 2 -> Enable Urgency window manager hint when
|
|
|
|
// Control-G is received. (This enables the bellIsUrgent
|
|
|
|
// resource).
|
|
|
|
// Ps = 1 0 4 3 -> Enable raising of the window when Control-G
|
|
|
|
// is received. (enables the popOnBell resource).
|
|
|
|
// Ps = 1 0 4 7 -> Use Alternate Screen Buffer. (This may be
|
|
|
|
// disabled by the titeInhibit resource).
|
|
|
|
// Ps = 1 0 4 8 -> Save cursor as in DECSC. (This may be dis-
|
|
|
|
// abled by the titeInhibit resource).
|
|
|
|
// Ps = 1 0 4 9 -> Save cursor as in DECSC and use Alternate
|
|
|
|
// Screen Buffer, clearing it first. (This may be disabled by
|
|
|
|
// the titeInhibit resource). This combines the effects of the 1
|
|
|
|
// 0 4 7 and 1 0 4 8 modes. Use this with terminfo-based
|
|
|
|
// applications rather than the 4 7 mode.
|
|
|
|
// Ps = 1 0 5 0 -> Set terminfo/termcap function-key mode.
|
|
|
|
// Ps = 1 0 5 1 -> Set Sun function-key mode.
|
|
|
|
// Ps = 1 0 5 2 -> Set HP function-key mode.
|
|
|
|
// Ps = 1 0 5 3 -> Set SCO function-key mode.
|
|
|
|
// Ps = 1 0 6 0 -> Set legacy keyboard emulation (X11R6).
|
|
|
|
// Ps = 1 0 6 1 -> Set VT220 keyboard emulation.
|
|
|
|
// Ps = 2 0 0 4 -> Set bracketed paste mode.
|
|
|
|
// Modes:
|
|
|
|
// http://vt100.net/docs/vt220-rm/chapter4.html
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.sm =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.setMode = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'h');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decset = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-01-27 16:01:30 +00:00
|
|
|
return this.setMode('?' + param);
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.dectcem =
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.cnorm =
|
|
|
|
Program.prototype.cvvis =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.showCursor = function() {
|
2013-06-25 11:34:10 +00:00
|
|
|
this.cursorHidden = false;
|
|
|
|
// NOTE: In xterm terminfo:
|
|
|
|
// cnorm stops blinking cursor
|
|
|
|
// cvvis starts blinking cursor
|
|
|
|
if (this.tput) return this.put.cnorm();
|
|
|
|
//if (this.tput) return this.put.cvvis();
|
2013-07-24 19:17:52 +00:00
|
|
|
// return this._write('\x1b[?12l\x1b[?25h'); // cursor_normal
|
|
|
|
// return this._write('\x1b[?12;25h'); // cursor_visible
|
2013-01-27 10:30:52 +00:00
|
|
|
return this.setMode('?25');
|
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.alternate =
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.smcup =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.alternateBuffer = function() {
|
2013-07-14 15:06:28 +00:00
|
|
|
this.isAlt = true;
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.smcup();
|
2013-06-20 11:43:56 +00:00
|
|
|
if (this.term('vt') || this.term('linux')) return;
|
2015-02-01 16:51:56 +00:00
|
|
|
this.setMode('?47');
|
2013-01-27 10:30:52 +00:00
|
|
|
return this.setMode('?1049');
|
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm l Reset Mode (RM).
|
|
|
|
// Ps = 2 -> Keyboard Action Mode (AM).
|
|
|
|
// Ps = 4 -> Replace Mode (IRM).
|
|
|
|
// Ps = 1 2 -> Send/receive (SRM).
|
|
|
|
// Ps = 2 0 -> Normal Linefeed (LNM).
|
|
|
|
// CSI ? Pm l
|
|
|
|
// DEC Private Mode Reset (DECRST).
|
|
|
|
// Ps = 1 -> Normal Cursor Keys (DECCKM).
|
|
|
|
// Ps = 2 -> Designate VT52 mode (DECANM).
|
|
|
|
// Ps = 3 -> 80 Column Mode (DECCOLM).
|
|
|
|
// Ps = 4 -> Jump (Fast) Scroll (DECSCLM).
|
|
|
|
// Ps = 5 -> Normal Video (DECSCNM).
|
|
|
|
// Ps = 6 -> Normal Cursor Mode (DECOM).
|
|
|
|
// Ps = 7 -> No Wraparound Mode (DECAWM).
|
|
|
|
// Ps = 8 -> No Auto-repeat Keys (DECARM).
|
|
|
|
// Ps = 9 -> Don't send Mouse X & Y on button press.
|
|
|
|
// Ps = 1 0 -> Hide toolbar (rxvt).
|
|
|
|
// Ps = 1 2 -> Stop Blinking Cursor (att610).
|
|
|
|
// Ps = 1 8 -> Don't print form feed (DECPFF).
|
|
|
|
// Ps = 1 9 -> Limit print to scrolling region (DECPEX).
|
|
|
|
// Ps = 2 5 -> Hide Cursor (DECTCEM).
|
|
|
|
// Ps = 3 0 -> Don't show scrollbar (rxvt).
|
|
|
|
// Ps = 3 5 -> Disable font-shifting functions (rxvt).
|
|
|
|
// Ps = 4 0 -> Disallow 80 -> 132 Mode.
|
|
|
|
// Ps = 4 1 -> No more(1) fix (see curses resource).
|
|
|
|
// Ps = 4 2 -> Disable Nation Replacement Character sets (DEC-
|
|
|
|
// NRCM).
|
|
|
|
// Ps = 4 4 -> Turn Off Margin Bell.
|
|
|
|
// Ps = 4 5 -> No Reverse-wraparound Mode.
|
|
|
|
// Ps = 4 6 -> Stop Logging. (This is normally disabled by a
|
|
|
|
// compile-time option).
|
|
|
|
// Ps = 4 7 -> Use Normal Screen Buffer.
|
|
|
|
// Ps = 6 6 -> Numeric keypad (DECNKM).
|
|
|
|
// Ps = 6 7 -> Backarrow key sends delete (DECBKM).
|
|
|
|
// Ps = 1 0 0 0 -> Don't send Mouse X & Y on button press and
|
|
|
|
// release. See the section Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 1 -> Don't use Hilite Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 2 -> Don't use Cell Motion Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 3 -> Don't use All Motion Mouse Tracking.
|
|
|
|
// Ps = 1 0 0 4 -> Don't send FocusIn/FocusOut events.
|
|
|
|
// Ps = 1 0 0 5 -> Disable Extended Mouse Mode.
|
|
|
|
// Ps = 1 0 1 0 -> Don't scroll to bottom on tty output
|
|
|
|
// (rxvt).
|
|
|
|
// Ps = 1 0 1 1 -> Don't scroll to bottom on key press (rxvt).
|
|
|
|
// Ps = 1 0 3 4 -> Don't interpret "meta" key. (This disables
|
|
|
|
// the eightBitInput resource).
|
|
|
|
// Ps = 1 0 3 5 -> Disable special modifiers for Alt and Num-
|
|
|
|
// Lock keys. (This disables the numLock resource).
|
|
|
|
// Ps = 1 0 3 6 -> Don't send ESC when Meta modifies a key.
|
|
|
|
// (This disables the metaSendsEscape resource).
|
|
|
|
// Ps = 1 0 3 7 -> Send VT220 Remove from the editing-keypad
|
|
|
|
// Delete key.
|
|
|
|
// Ps = 1 0 3 9 -> Don't send ESC when Alt modifies a key.
|
|
|
|
// (This disables the altSendsEscape resource).
|
|
|
|
// Ps = 1 0 4 0 -> Do not keep selection when not highlighted.
|
|
|
|
// (This disables the keepSelection resource).
|
|
|
|
// Ps = 1 0 4 1 -> Use the PRIMARY selection. (This disables
|
|
|
|
// the selectToClipboard resource).
|
|
|
|
// Ps = 1 0 4 2 -> Disable Urgency window manager hint when
|
|
|
|
// Control-G is received. (This disables the bellIsUrgent
|
|
|
|
// resource).
|
|
|
|
// Ps = 1 0 4 3 -> Disable raising of the window when Control-
|
|
|
|
// G is received. (This disables the popOnBell resource).
|
|
|
|
// Ps = 1 0 4 7 -> Use Normal Screen Buffer, clearing screen
|
|
|
|
// first if in the Alternate Screen. (This may be disabled by
|
|
|
|
// the titeInhibit resource).
|
|
|
|
// Ps = 1 0 4 8 -> Restore cursor as in DECRC. (This may be
|
|
|
|
// disabled by the titeInhibit resource).
|
|
|
|
// Ps = 1 0 4 9 -> Use Normal Screen Buffer and restore cursor
|
|
|
|
// as in DECRC. (This may be disabled by the titeInhibit
|
|
|
|
// resource). This combines the effects of the 1 0 4 7 and 1 0
|
|
|
|
// 4 8 modes. Use this with terminfo-based applications rather
|
|
|
|
// than the 4 7 mode.
|
|
|
|
// Ps = 1 0 5 0 -> Reset terminfo/termcap function-key mode.
|
|
|
|
// Ps = 1 0 5 1 -> Reset Sun function-key mode.
|
|
|
|
// Ps = 1 0 5 2 -> Reset HP function-key mode.
|
|
|
|
// Ps = 1 0 5 3 -> Reset SCO function-key mode.
|
|
|
|
// Ps = 1 0 6 0 -> Reset legacy keyboard emulation (X11R6).
|
|
|
|
// Ps = 1 0 6 1 -> Reset keyboard emulation to Sun/PC style.
|
|
|
|
// Ps = 2 0 0 4 -> Reset bracketed paste mode.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.rm =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.resetMode = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'l');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decrst = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var param = slice.call(arguments).join(';');
|
2013-01-27 16:01:30 +00:00
|
|
|
return this.resetMode('?' + param);
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.dectcemh =
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.cursor_invisible =
|
|
|
|
Program.prototype.vi =
|
|
|
|
Program.prototype.civis =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.hideCursor = function() {
|
2013-06-25 11:34:10 +00:00
|
|
|
this.cursorHidden = true;
|
|
|
|
if (this.tput) return this.put.civis();
|
2013-01-27 10:30:52 +00:00
|
|
|
return this.resetMode('?25');
|
|
|
|
};
|
|
|
|
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.rmcup =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.normalBuffer = function() {
|
2013-07-14 15:06:28 +00:00
|
|
|
this.isAlt = false;
|
2013-06-25 11:34:10 +00:00
|
|
|
if (this.tput) return this.put.rmcup();
|
2015-02-01 16:51:56 +00:00
|
|
|
this.resetMode('?47');
|
2013-01-27 10:30:52 +00:00
|
|
|
return this.resetMode('?1049');
|
|
|
|
};
|
|
|
|
|
2013-01-28 23:30:51 +00:00
|
|
|
Program.prototype.enableMouse = function() {
|
2015-02-01 12:16:29 +00:00
|
|
|
if (process.env.BLESSED_FORCE_MODES) {
|
2015-02-01 15:07:55 +00:00
|
|
|
var modes = process.env.BLESSED_FORCE_MODES.split(',');
|
|
|
|
var options = {};
|
|
|
|
for (var n = 0; n < modes.length; ++n) {
|
|
|
|
var pair = modes[n].split('=');
|
|
|
|
var v = pair[1] !== '0';
|
|
|
|
switch (pair[0].toUpperCase()) {
|
|
|
|
case 'SGRMOUSE':
|
|
|
|
options.sgrMouse = v;
|
|
|
|
break;
|
|
|
|
case 'UTFMOUSE':
|
|
|
|
options.utfMouse = v;
|
|
|
|
break;
|
|
|
|
case 'VT200MOUSE':
|
|
|
|
options.vt200Mouse = v;
|
|
|
|
break;
|
|
|
|
case 'URXVTMOUSE':
|
|
|
|
options.urxvtMouse = v;
|
|
|
|
break;
|
|
|
|
case 'X10MOUSE':
|
|
|
|
options.x10Mouse = v;
|
|
|
|
break;
|
2015-02-14 03:14:27 +00:00
|
|
|
case 'DECMOUSE':
|
|
|
|
options.decMouse = v;
|
|
|
|
break;
|
|
|
|
case 'PTERMMOUSE':
|
|
|
|
options.ptermMouse = v;
|
|
|
|
break;
|
|
|
|
case 'JSBTERMMOUSE':
|
|
|
|
options.jsbtermMouse = v;
|
|
|
|
break;
|
2015-02-01 15:47:00 +00:00
|
|
|
case 'VT200HILITE':
|
|
|
|
options.vt200Hilite = v;
|
|
|
|
break;
|
2015-02-01 15:07:55 +00:00
|
|
|
case 'GPMMOUSE':
|
2015-02-01 15:10:17 +00:00
|
|
|
options.gpmMouse = v;
|
2015-02-01 15:07:55 +00:00
|
|
|
break;
|
|
|
|
case 'CELLMOTION':
|
|
|
|
options.cellMotion = v;
|
|
|
|
break;
|
|
|
|
case 'ALLMOTION':
|
|
|
|
options.allMotion = v;
|
|
|
|
break;
|
|
|
|
case 'SENDFOCUS':
|
|
|
|
options.sendFocus = v;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.setMouse(options, true);
|
2015-02-01 12:16:29 +00:00
|
|
|
}
|
2015-02-01 14:46:22 +00:00
|
|
|
|
2015-02-01 02:36:43 +00:00
|
|
|
if (this.term('rxvt-unicode')) {
|
2013-07-14 12:16:33 +00:00
|
|
|
return this.setMouse({
|
2013-08-02 10:57:58 +00:00
|
|
|
urxvtMouse: true,
|
|
|
|
allMotion: true
|
2013-07-14 12:16:33 +00:00
|
|
|
}, true);
|
2013-01-28 23:30:51 +00:00
|
|
|
}
|
|
|
|
|
2015-02-01 02:49:15 +00:00
|
|
|
// rxvt does not support the X10 UTF extensions
|
|
|
|
if (this.term('rxvt')) {
|
|
|
|
return this.setMouse({
|
2015-02-01 02:54:23 +00:00
|
|
|
vt200Mouse: true,
|
2015-02-01 02:49:15 +00:00
|
|
|
x10Mouse: true,
|
|
|
|
allMotion: true
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2015-02-05 04:39:34 +00:00
|
|
|
// libvte is broken. Older versions do not support the
|
|
|
|
// X10 UTF extension. However, later versions do support
|
|
|
|
// SGR/URXVT.
|
2015-02-01 02:36:43 +00:00
|
|
|
if (this.isVTE) {
|
|
|
|
return this.setMouse({
|
2015-02-05 04:39:34 +00:00
|
|
|
// NOTE: Could also use urxvtMouse here.
|
2015-02-01 02:36:43 +00:00
|
|
|
sgrMouse: true,
|
|
|
|
allMotion: true
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2013-08-02 10:57:58 +00:00
|
|
|
if (this.term('linux')) {
|
2013-01-28 23:30:51 +00:00
|
|
|
return this.setMouse({
|
2015-02-01 15:10:17 +00:00
|
|
|
vt200Mouse: true,
|
|
|
|
gpmMouse: true
|
2013-06-25 11:34:10 +00:00
|
|
|
}, true);
|
2013-01-28 23:30:51 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 10:57:58 +00:00
|
|
|
if (this.term('xterm')
|
|
|
|
|| this.term('screen')
|
|
|
|
|| (this.tput && this.tput.strings.key_mouse)) {
|
2015-07-19 10:26:30 +00:00
|
|
|
return this.setMouse({
|
|
|
|
vt200Mouse: true,
|
|
|
|
utfMouse: true,
|
|
|
|
allMotion: true
|
|
|
|
}, true);
|
2013-01-28 23:30:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.disableMouse = function() {
|
2013-06-25 11:34:10 +00:00
|
|
|
if (!this._currentMouse) return;
|
|
|
|
|
|
|
|
var obj = {};
|
|
|
|
|
|
|
|
Object.keys(this._currentMouse).forEach(function(key) {
|
|
|
|
obj[key] = false;
|
2013-01-28 23:30:51 +00:00
|
|
|
});
|
2013-06-25 11:34:10 +00:00
|
|
|
|
|
|
|
return this.setMouse(obj, false);
|
2013-01-28 23:30:51 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
// Set Mouse
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.setMouse = function(opt, enable) {
|
2013-01-28 23:30:51 +00:00
|
|
|
if (opt.normalMouse != null) {
|
2013-08-02 10:57:58 +00:00
|
|
|
opt.vt200Mouse = opt.normalMouse;
|
2013-01-28 23:30:51 +00:00
|
|
|
opt.allMotion = opt.normalMouse;
|
|
|
|
}
|
|
|
|
|
2013-08-02 10:57:58 +00:00
|
|
|
if (opt.hiliteTracking != null) {
|
|
|
|
opt.vt200Hilite = opt.hiliteTracking;
|
|
|
|
}
|
|
|
|
|
2015-07-04 10:30:26 +00:00
|
|
|
if (enable === true) {
|
|
|
|
if (this._currentMouse) {
|
|
|
|
this.setMouse(opt);
|
|
|
|
Object.keys(opt).forEach(function(key) {
|
|
|
|
this._currentMouse[key] = opt[key];
|
|
|
|
}, this);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-25 11:34:10 +00:00
|
|
|
this._currentMouse = opt;
|
2013-07-24 19:17:52 +00:00
|
|
|
this.mouseEnabled = true;
|
2015-07-04 10:30:26 +00:00
|
|
|
} else if (enable === false) {
|
2013-06-25 11:34:10 +00:00
|
|
|
delete this._currentMouse;
|
2013-07-24 19:17:52 +00:00
|
|
|
this.mouseEnabled = false;
|
2013-06-25 11:34:10 +00:00
|
|
|
}
|
|
|
|
|
2013-01-27 17:00:02 +00:00
|
|
|
// Ps = 9 -> Send Mouse X & Y on button press. See the sec-
|
|
|
|
// tion Mouse Tracking.
|
|
|
|
// Ps = 9 -> Don't send Mouse X & Y on button press.
|
|
|
|
// x10 mouse
|
|
|
|
if (opt.x10Mouse != null) {
|
|
|
|
if (opt.x10Mouse) this.setMode('?9');
|
|
|
|
else this.resetMode('?9');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ps = 1 0 0 0 -> Send Mouse X & Y on button press and
|
|
|
|
// release. See the section Mouse Tracking.
|
|
|
|
// 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) 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.
|
2013-08-02 10:57:58 +00:00
|
|
|
if (opt.vt200Hilite != null) {
|
|
|
|
if (opt.vt200Hilite) this.setMode('?1001');
|
2013-01-27 17:00:02 +00:00
|
|
|
else this.resetMode('?1001');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2013-01-28 23:30:51 +00:00
|
|
|
if (opt.cellMotion != null) {
|
|
|
|
if (opt.cellMotion) this.setMode('?1002');
|
2013-01-27 17:00:02 +00:00
|
|
|
else this.resetMode('?1002');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2013-01-28 23:30:51 +00:00
|
|
|
if (opt.allMotion != null) {
|
2015-07-19 10:26:30 +00:00
|
|
|
// 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');
|
2015-07-19 10:20:25 +00:00
|
|
|
} else {
|
2015-07-19 10:26:30 +00:00
|
|
|
if (opt.allMotion) this.setMode('?1003');
|
|
|
|
else this.resetMode('?1003');
|
2015-07-19 10:20:25 +00:00
|
|
|
}
|
2013-01-27 17:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) 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) this.setMode('?1005');
|
|
|
|
else this.resetMode('?1005');
|
|
|
|
}
|
|
|
|
|
|
|
|
// sgr mouse
|
|
|
|
if (opt.sgrMouse != null) {
|
|
|
|
if (opt.sgrMouse) this.setMode('?1006');
|
|
|
|
else this.resetMode('?1006');
|
|
|
|
}
|
|
|
|
|
|
|
|
// urxvt mouse
|
|
|
|
if (opt.urxvtMouse != null) {
|
|
|
|
if (opt.urxvtMouse) this.setMode('?1015');
|
|
|
|
else this.resetMode('?1015');
|
|
|
|
}
|
2015-02-01 15:10:17 +00:00
|
|
|
|
2015-02-14 03:14:27 +00:00
|
|
|
// 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\\');
|
|
|
|
}
|
|
|
|
|
2015-02-01 15:10:17 +00:00
|
|
|
// gpm mouse
|
|
|
|
if (opt.gpmMouse != null) {
|
|
|
|
if (opt.gpmMouse) this.enableGpm();
|
|
|
|
else this.disableGpm();
|
|
|
|
}
|
2013-01-27 17:00:02 +00:00
|
|
|
};
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
// CSI Ps ; Ps r
|
|
|
|
// Set Scrolling Region [top;bottom] (default = full size of win-
|
|
|
|
// dow) (DECSTBM).
|
|
|
|
// CSI ? Pm r
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decstbm =
|
2013-06-13 06:33:10 +00:00
|
|
|
Program.prototype.csr =
|
2013-01-27 10:30:52 +00:00
|
|
|
Program.prototype.setScrollRegion = function(top, bottom) {
|
2013-07-12 05:00:11 +00:00
|
|
|
if (!this.zero) {
|
|
|
|
top = (top || 1) - 1;
|
|
|
|
bottom = (bottom || this.rows) - 1;
|
|
|
|
} else {
|
|
|
|
top = top || 0;
|
|
|
|
bottom = bottom || (this.rows - 1);
|
|
|
|
}
|
|
|
|
this.scrollTop = top;
|
|
|
|
this.scrollBottom = bottom;
|
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
|
|
|
this._ncoords();
|
|
|
|
if (this.tput) return this.put.csr(top, bottom);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (top + 1) + ';' + (bottom + 1) + 'r');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI s
|
|
|
|
// Save cursor (ANSI.SYS).
|
2013-07-03 23:46:06 +00:00
|
|
|
Program.prototype.scA =
|
|
|
|
Program.prototype.saveCursorA = function() {
|
2013-01-27 10:30:52 +00:00
|
|
|
this.savedX = this.x;
|
|
|
|
this.savedY = this.y;
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.sc();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[s');
|
2013-01-27 10:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI u
|
|
|
|
// Restore cursor (ANSI.SYS).
|
2013-07-03 23:46:06 +00:00
|
|
|
Program.prototype.rcA =
|
|
|
|
Program.prototype.restoreCursorA = function() {
|
2013-07-12 05:00:11 +00:00
|
|
|
this.x = this.savedX || 0;
|
|
|
|
this.y = this.savedY || 0;
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.rc();
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[u');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lesser Used
|
|
|
|
*/
|
|
|
|
|
|
|
|
// CSI Ps I
|
|
|
|
// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cht =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.cursorForwardTab = function(param) {
|
|
|
|
this.x += 8;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-18 05:22:24 +00:00
|
|
|
if (this.tput) return this.put.tab(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + 'I');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps S Scroll up Ps lines (default = 1) (SU).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.su =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.scrollUp = function(param) {
|
|
|
|
this.y -= param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-18 05:22:24 +00:00
|
|
|
if (this.tput) return this.put.parm_index(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + 'S');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps T Scroll down Ps lines (default = 1) (SD).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.sd =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.scrollDown = function(param) {
|
|
|
|
this.y += param || 1;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-07-18 05:22:24 +00:00
|
|
|
if (this.tput) return this.put.parm_rindex(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + 'T');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Ps ; Ps ; Ps ; Ps T
|
|
|
|
// Initiate highlight mouse tracking. Parameters are
|
|
|
|
// [func;startx;starty;firstrow;lastrow]. See the section Mouse
|
|
|
|
// Tracking.
|
|
|
|
Program.prototype.initMouseTracking = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + 'T');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI > Ps; Ps T
|
|
|
|
// Reset one or more features of the title modes to the default
|
|
|
|
// value. Normally, "reset" disables the feature. It is possi-
|
|
|
|
// ble to disable the ability to reset features by compiling a
|
|
|
|
// different default for the title modes into xterm.
|
|
|
|
// Ps = 0 -> Do not set window/icon labels using hexadecimal.
|
|
|
|
// Ps = 1 -> Do not query window/icon labels using hexadeci-
|
|
|
|
// mal.
|
|
|
|
// Ps = 2 -> Do not set window/icon labels using UTF-8.
|
|
|
|
// Ps = 3 -> Do not query window/icon labels using UTF-8.
|
|
|
|
// (See discussion of "Title Modes").
|
|
|
|
Program.prototype.resetTitleModes = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[>' + slice.call(arguments).join(';') + 'T');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.cbt =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.cursorBackwardTab = function(param) {
|
|
|
|
this.x -= 8;
|
2013-07-12 05:00:11 +00:00
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.cbt(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + 'Z');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps b Repeat the preceding graphic character Ps times (REP).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.rep =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.repeatPrecedingCharacter = function(param) {
|
2013-07-18 05:22:24 +00:00
|
|
|
this.x += param || 1;
|
|
|
|
this._ncoords();
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.rep(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + 'b');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps g Tab Clear (TBC).
|
|
|
|
// Ps = 0 -> Clear Current Column (default).
|
|
|
|
// Ps = 3 -> Clear All.
|
|
|
|
// Potentially:
|
|
|
|
// Ps = 2 -> Clear Stops on Line.
|
|
|
|
// http://vt100.net/annarbor/aaa-ug/section6.html
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.tbc =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.tabClear = function(param) {
|
2013-02-25 07:47:32 +00:00
|
|
|
if (this.tput) return this.put.tbc(param);
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 0) + 'g');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm i Media Copy (MC).
|
|
|
|
// Ps = 0 -> Print screen (default).
|
|
|
|
// Ps = 4 -> Turn off printer controller mode.
|
|
|
|
// Ps = 5 -> Turn on printer controller mode.
|
|
|
|
// CSI ? Pm i
|
|
|
|
// Media Copy (MC, DEC-specific).
|
|
|
|
// Ps = 1 -> Print line containing cursor.
|
|
|
|
// Ps = 4 -> Turn off autoprint mode.
|
|
|
|
// Ps = 5 -> Turn on autoprint mode.
|
|
|
|
// Ps = 1 0 -> Print composed display, ignores DECPEX.
|
|
|
|
// Ps = 1 1 -> Print all pages.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.mc =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.mediaCopy = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + 'i');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.print_screen =
|
|
|
|
Program.prototype.ps =
|
|
|
|
Program.prototype.mc0 = function() {
|
|
|
|
if (this.tput) return this.put.mc0();
|
|
|
|
return this.mc('0');
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.prtr_on =
|
|
|
|
Program.prototype.po =
|
|
|
|
Program.prototype.mc5 = function() {
|
|
|
|
if (this.tput) return this.put.mc5();
|
|
|
|
return this.mc('5');
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.prtr_off =
|
|
|
|
Program.prototype.pf =
|
|
|
|
Program.prototype.mc4 = function() {
|
|
|
|
if (this.tput) return this.put.mc4();
|
|
|
|
return this.mc('4');
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.prtr_non =
|
|
|
|
Program.prototype.pO =
|
|
|
|
Program.prototype.mc5p = function() {
|
|
|
|
if (this.tput) return this.put.mc5p();
|
|
|
|
return this.mc('?5');
|
|
|
|
};
|
|
|
|
|
2013-01-27 14:54:30 +00:00
|
|
|
// CSI > Ps; Ps m
|
|
|
|
// Set or reset resource-values used by xterm to decide whether
|
|
|
|
// to construct escape sequences holding information about the
|
|
|
|
// modifiers pressed with a given key. The first parameter iden-
|
|
|
|
// tifies the resource to set/reset. The second parameter is the
|
|
|
|
// value to assign to the resource. If the second parameter is
|
|
|
|
// omitted, the resource is reset to its initial value.
|
|
|
|
// Ps = 1 -> modifyCursorKeys.
|
|
|
|
// Ps = 2 -> modifyFunctionKeys.
|
|
|
|
// Ps = 4 -> modifyOtherKeys.
|
|
|
|
// If no parameters are given, all resources are reset to their
|
|
|
|
// initial values.
|
|
|
|
Program.prototype.setResources = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[>' + slice.call(arguments).join(';') + 'm');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI > Ps n
|
|
|
|
// Disable modifiers which may be enabled via the CSI > Ps; Ps m
|
|
|
|
// sequence. This corresponds to a resource value of "-1", which
|
|
|
|
// cannot be set with the other sequence. The parameter identi-
|
|
|
|
// fies the resource to be disabled:
|
|
|
|
// Ps = 1 -> modifyCursorKeys.
|
|
|
|
// Ps = 2 -> modifyFunctionKeys.
|
|
|
|
// Ps = 4 -> modifyOtherKeys.
|
|
|
|
// If the parameter is omitted, modifyFunctionKeys is disabled.
|
|
|
|
// When modifyFunctionKeys is disabled, xterm uses the modifier
|
|
|
|
// keys to make an extended sequence of functions rather than
|
|
|
|
// adding a parameter to each function key to denote the modi-
|
|
|
|
// fiers.
|
|
|
|
Program.prototype.disableModifiers = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[>' + (param || '') + 'n');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI > Ps p
|
|
|
|
// Set resource value pointerMode. This is used by xterm to
|
|
|
|
// decide whether to hide the pointer cursor as the user types.
|
|
|
|
// Valid values for the parameter:
|
|
|
|
// Ps = 0 -> never hide the pointer.
|
|
|
|
// Ps = 1 -> hide if the mouse tracking mode is not enabled.
|
|
|
|
// Ps = 2 -> always hide the pointer. If no parameter is
|
|
|
|
// given, xterm uses the default, which is 1 .
|
|
|
|
Program.prototype.setPointerMode = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[>' + (param || '') + 'p');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI ! p Soft terminal reset (DECSTR).
|
|
|
|
// http://vt100.net/docs/vt220-rm/table4-10.html
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decstr =
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.rs2 =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.softReset = function() {
|
2013-06-25 11:34:10 +00:00
|
|
|
//if (this.tput) return this.put.init_2string();
|
|
|
|
//if (this.tput) return this.put.reset_2string();
|
|
|
|
if (this.tput) return this.put.rs2();
|
2013-07-24 19:17:52 +00:00
|
|
|
//return this._write('\x1b[!p');
|
|
|
|
//return this._write('\x1b[!p\x1b[?3;4l\x1b[4l\x1b>'); // init
|
|
|
|
return this._write('\x1b[!p\x1b[?3;4l\x1b[4l\x1b>'); // reset
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps$ p
|
|
|
|
// Request ANSI mode (DECRQM). For VT300 and up, reply is
|
|
|
|
// CSI Ps; Pm$ y
|
|
|
|
// where Ps is the mode number as in RM, and Pm is the mode
|
|
|
|
// value:
|
|
|
|
// 0 - not recognized
|
|
|
|
// 1 - set
|
|
|
|
// 2 - reset
|
|
|
|
// 3 - permanently set
|
|
|
|
// 4 - permanently reset
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decrqm =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.requestAnsiMode = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + '$p');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI ? Ps$ p
|
|
|
|
// Request DEC private mode (DECRQM). For VT300 and up, reply is
|
|
|
|
// CSI ? Ps; Pm$ p
|
|
|
|
// where Ps is the mode number as in DECSET, Pm is the mode value
|
|
|
|
// as in the ANSI DECRQM.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decrqmp =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.requestPrivateMode = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[?' + (param || '') + '$p');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Ps " p
|
|
|
|
// Set conformance level (DECSCL). Valid values for the first
|
|
|
|
// parameter:
|
|
|
|
// Ps = 6 1 -> VT100.
|
|
|
|
// Ps = 6 2 -> VT200.
|
|
|
|
// Ps = 6 3 -> VT300.
|
|
|
|
// Valid values for the second parameter:
|
|
|
|
// Ps = 0 -> 8-bit controls.
|
|
|
|
// Ps = 1 -> 7-bit controls (always set for VT100).
|
|
|
|
// Ps = 2 -> 8-bit controls.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decscl =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setConformanceLevel = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '"p');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps q Load LEDs (DECLL).
|
|
|
|
// Ps = 0 -> Clear all LEDS (default).
|
|
|
|
// Ps = 1 -> Light Num Lock.
|
|
|
|
// Ps = 2 -> Light Caps Lock.
|
|
|
|
// Ps = 3 -> Light Scroll Lock.
|
|
|
|
// Ps = 2 1 -> Extinguish Num Lock.
|
|
|
|
// Ps = 2 2 -> Extinguish Caps Lock.
|
|
|
|
// Ps = 2 3 -> Extinguish Scroll Lock.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decll =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.loadLEDs = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + 'q');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps SP q
|
|
|
|
// Set cursor style (DECSCUSR, VT520).
|
|
|
|
// Ps = 0 -> blinking block.
|
|
|
|
// Ps = 1 -> blinking block (default).
|
|
|
|
// Ps = 2 -> steady block.
|
|
|
|
// Ps = 3 -> blinking underline.
|
|
|
|
// Ps = 4 -> steady underline.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decscusr =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setCursorStyle = function(param) {
|
|
|
|
switch (param) {
|
|
|
|
case 'blinking block':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 1;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
case 'block':
|
|
|
|
case 'steady block':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 2;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
case 'blinking underline':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 3;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
case 'underline':
|
|
|
|
case 'steady underline':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 4;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
case 'blinking bar':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 5;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
case 'bar':
|
|
|
|
case 'steady bar':
|
2013-07-26 05:19:57 +00:00
|
|
|
param = 6;
|
2013-01-27 14:54:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-26 05:19:57 +00:00
|
|
|
if (param === 2 && this.has('Se')) {
|
|
|
|
return this.put.Se();
|
|
|
|
}
|
2013-07-18 06:03:47 +00:00
|
|
|
if (this.has('Ss')) {
|
2013-03-06 10:27:42 +00:00
|
|
|
return this.put.Ss(param);
|
|
|
|
}
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 1) + ' q');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps " q
|
|
|
|
// Select character protection attribute (DECSCA). Valid values
|
|
|
|
// for the parameter:
|
|
|
|
// Ps = 0 -> DECSED and DECSEL can erase (default).
|
|
|
|
// Ps = 1 -> DECSED and DECSEL cannot erase.
|
|
|
|
// Ps = 2 -> DECSED and DECSEL can erase.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decsca =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setCharProtectionAttr = function(param) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 0) + '"q');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI ? Pm r
|
|
|
|
// Restore DEC Private Mode Values. The value of Ps previously
|
|
|
|
// saved is restored. Ps values are the same as for DECSET.
|
|
|
|
Program.prototype.restorePrivateValues = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[?' + slice.call(arguments).join(';') + 'r');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt; Pl; Pb; Pr; Ps$ r
|
|
|
|
// Change Attributes in Rectangular Area (DECCARA), VT400 and up.
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
|
|
|
// Ps denotes the SGR attributes to change: 0, 1, 4, 5, 7.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.deccara =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setAttrInRectangle = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '$r');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI ? Pm s
|
|
|
|
// Save DEC Private Mode Values. Ps values are the same as for
|
|
|
|
// DECSET.
|
|
|
|
Program.prototype.savePrivateValues = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[?' + slice.call(arguments).join(';') + 's');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Ps ; Ps t
|
|
|
|
// Window manipulation (from dtterm, as well as extensions).
|
|
|
|
// These controls may be disabled using the allowWindowOps
|
|
|
|
// resource. Valid values for the first (and any additional
|
|
|
|
// parameters) are:
|
|
|
|
// Ps = 1 -> De-iconify window.
|
|
|
|
// Ps = 2 -> Iconify window.
|
|
|
|
// Ps = 3 ; x ; y -> Move window to [x, y].
|
|
|
|
// Ps = 4 ; height ; width -> Resize the xterm window to
|
|
|
|
// height and width in pixels.
|
|
|
|
// Ps = 5 -> Raise the xterm window to the front of the stack-
|
|
|
|
// ing order.
|
|
|
|
// Ps = 6 -> Lower the xterm window to the bottom of the
|
|
|
|
// stacking order.
|
|
|
|
// Ps = 7 -> Refresh the xterm window.
|
|
|
|
// Ps = 8 ; height ; width -> Resize the text area to
|
|
|
|
// [height;width] in characters.
|
|
|
|
// Ps = 9 ; 0 -> Restore maximized window.
|
|
|
|
// Ps = 9 ; 1 -> Maximize window (i.e., resize to screen
|
|
|
|
// size).
|
|
|
|
// Ps = 1 0 ; 0 -> Undo full-screen mode.
|
|
|
|
// Ps = 1 0 ; 1 -> Change to full-screen.
|
|
|
|
// Ps = 1 1 -> Report xterm window state. If the xterm window
|
|
|
|
// is open (non-iconified), it returns CSI 1 t . If the xterm
|
|
|
|
// window is iconified, it returns CSI 2 t .
|
|
|
|
// Ps = 1 3 -> Report xterm window position. Result is CSI 3
|
|
|
|
// ; x ; y t
|
|
|
|
// Ps = 1 4 -> Report xterm window in pixels. Result is CSI
|
|
|
|
// 4 ; height ; width t
|
|
|
|
// Ps = 1 8 -> Report the size of the text area in characters.
|
|
|
|
// Result is CSI 8 ; height ; width t
|
|
|
|
// Ps = 1 9 -> Report the size of the screen in characters.
|
|
|
|
// Result is CSI 9 ; height ; width t
|
|
|
|
// Ps = 2 0 -> Report xterm window's icon label. Result is
|
|
|
|
// OSC L label ST
|
|
|
|
// Ps = 2 1 -> Report xterm window's title. Result is OSC l
|
|
|
|
// label ST
|
|
|
|
// Ps = 2 2 ; 0 -> Save xterm icon and window title on
|
|
|
|
// stack.
|
|
|
|
// Ps = 2 2 ; 1 -> Save xterm icon title on stack.
|
|
|
|
// Ps = 2 2 ; 2 -> Save xterm window title on stack.
|
|
|
|
// Ps = 2 3 ; 0 -> Restore xterm icon and window title from
|
|
|
|
// stack.
|
|
|
|
// Ps = 2 3 ; 1 -> Restore xterm icon title from stack.
|
|
|
|
// Ps = 2 3 ; 2 -> Restore xterm window title from stack.
|
|
|
|
// Ps >= 2 4 -> Resize to Ps lines (DECSLPP).
|
2013-01-27 15:41:41 +00:00
|
|
|
Program.prototype.manipulateWindow = function() {
|
2013-07-18 19:52:56 +00:00
|
|
|
var args = slice.call(arguments);
|
2013-01-27 15:41:41 +00:00
|
|
|
|
2015-03-31 13:12:14 +00:00
|
|
|
var callback = typeof args[args.length - 1] === 'function'
|
2013-01-27 15:41:41 +00:00
|
|
|
? args.pop()
|
|
|
|
: function() {};
|
|
|
|
|
2013-07-18 19:52:56 +00:00
|
|
|
return this.response('window-manipulation',
|
|
|
|
'\x1b[' + args.join(';') + 't', callback);
|
2013-01-27 15:41:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.getWindowSize = function(callback) {
|
2015-02-21 10:49:15 +00:00
|
|
|
return this.manipulateWindow(18, callback);
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt; Pl; Pb; Pr; Ps$ t
|
|
|
|
// Reverse Attributes in Rectangular Area (DECRARA), VT400 and
|
|
|
|
// up.
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
|
|
|
// Ps denotes the attributes to reverse, i.e., 1, 4, 5, 7.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decrara =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.reverseAttrInRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '$t');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI > Ps; Ps t
|
|
|
|
// Set one or more features of the title modes. Each parameter
|
|
|
|
// enables a single feature.
|
|
|
|
// Ps = 0 -> Set window/icon labels using hexadecimal.
|
|
|
|
// Ps = 1 -> Query window/icon labels using hexadecimal.
|
|
|
|
// Ps = 2 -> Set window/icon labels using UTF-8.
|
|
|
|
// Ps = 3 -> Query window/icon labels using UTF-8. (See dis-
|
|
|
|
// cussion of "Title Modes")
|
|
|
|
Program.prototype.setTitleModeFeature = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[>' + slice.call(arguments).join(';') + 't');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps SP t
|
|
|
|
// Set warning-bell volume (DECSWBV, VT520).
|
|
|
|
// Ps = 0 or 1 -> off.
|
|
|
|
// Ps = 2 , 3 or 4 -> low.
|
|
|
|
// Ps = 5 , 6 , 7 , or 8 -> high.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decswbv =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setWarningBellVolume = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + ' t');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps SP u
|
|
|
|
// Set margin-bell volume (DECSMBV, VT520).
|
|
|
|
// Ps = 1 -> off.
|
|
|
|
// Ps = 2 , 3 or 4 -> low.
|
|
|
|
// Ps = 0 , 5 , 6 , 7 , or 8 -> high.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decsmbv =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setMarginBellVolume = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || '') + ' u');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt; Pl; Pb; Pr; Pp; Pt; Pl; Pp$ v
|
|
|
|
// Copy Rectangular Area (DECCRA, VT400 and up).
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
|
|
|
// Pp denotes the source page.
|
|
|
|
// Pt; Pl denotes the target location.
|
|
|
|
// Pp denotes the target page.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.deccra =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.copyRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '$v');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt ; Pl ; Pb ; Pr ' w
|
|
|
|
// Enable Filter Rectangle (DECEFR), VT420 and up.
|
|
|
|
// Parameters are [top;left;bottom;right].
|
|
|
|
// Defines the coordinates of a filter rectangle and activates
|
|
|
|
// it. Anytime the locator is detected outside of the filter
|
|
|
|
// rectangle, an outside rectangle event is generated and the
|
|
|
|
// rectangle is disabled. Filter rectangles are always treated
|
|
|
|
// as "one-shot" events. Any parameters that are omitted default
|
|
|
|
// to the current locator position. If all parameters are omit-
|
|
|
|
// ted, any locator motion will be reported. DECELR always can-
|
|
|
|
// cels any prevous rectangle definition.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decefr =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.enableFilterRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '\'w');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps x Request Terminal Parameters (DECREQTPARM).
|
|
|
|
// if Ps is a "0" (default) or "1", and xterm is emulating VT100,
|
|
|
|
// the control sequence elicits a response of the same form whose
|
|
|
|
// parameters describe the terminal:
|
|
|
|
// Ps -> the given Ps incremented by 2.
|
|
|
|
// Pn = 1 <- no parity.
|
|
|
|
// Pn = 1 <- eight bits.
|
|
|
|
// Pn = 1 <- 2 8 transmit 38.4k baud.
|
|
|
|
// Pn = 1 <- 2 8 receive 38.4k baud.
|
|
|
|
// Pn = 1 <- clock multiplier.
|
|
|
|
// Pn = 0 <- STP flags.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decreqtparm =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.requestParameters = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 0) + 'x');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps x Select Attribute Change Extent (DECSACE).
|
|
|
|
// Ps = 0 -> from start to end position, wrapped.
|
|
|
|
// Ps = 1 -> from start to end position, wrapped.
|
|
|
|
// Ps = 2 -> rectangle (exact).
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decsace =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.selectChangeExtent = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + (param || 0) + 'x');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pc; Pt; Pl; Pb; Pr$ x
|
|
|
|
// Fill Rectangular Area (DECFRA), VT420 and up.
|
|
|
|
// Pc is the character to use.
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decfra =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.fillRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '$x');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ; Pu ' z
|
|
|
|
// Enable Locator Reporting (DECELR).
|
|
|
|
// Valid values for the first parameter:
|
|
|
|
// Ps = 0 -> Locator disabled (default).
|
|
|
|
// Ps = 1 -> Locator enabled.
|
|
|
|
// Ps = 2 -> Locator enabled for one report, then disabled.
|
|
|
|
// The second parameter specifies the coordinate unit for locator
|
|
|
|
// reports.
|
|
|
|
// Valid values for the second parameter:
|
|
|
|
// Pu = 0 <- or omitted -> default to character cells.
|
|
|
|
// Pu = 1 <- device physical pixels.
|
|
|
|
// Pu = 2 <- character cells.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decelr =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.enableLocatorReporting = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '\'z');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt; Pl; Pb; Pr$ z
|
|
|
|
// Erase Rectangular Area (DECERA), VT400 and up.
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decera =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.eraseRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '$z');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pm ' {
|
|
|
|
// Select Locator Events (DECSLE).
|
|
|
|
// Valid values for the first (and any additional parameters)
|
|
|
|
// are:
|
|
|
|
// Ps = 0 -> only respond to explicit host requests (DECRQLP).
|
|
|
|
// (This is default). It also cancels any filter
|
|
|
|
// rectangle.
|
|
|
|
// Ps = 1 -> report button down transitions.
|
|
|
|
// Ps = 2 -> do not report button down transitions.
|
|
|
|
// Ps = 3 -> report button up transitions.
|
|
|
|
// Ps = 4 -> do not report button up transitions.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decsle =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.setLocatorEvents = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '\'{');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Pt; Pl; Pb; Pr$ {
|
|
|
|
// Selective Erase Rectangular Area (DECSERA), VT400 and up.
|
|
|
|
// Pt; Pl; Pb; Pr denotes the rectangle.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decsera =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.selectiveEraseRectangle = function(params) {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + '${');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI Ps ' |
|
|
|
|
// Request Locator Position (DECRQLP).
|
|
|
|
// Valid values for the parameter are:
|
|
|
|
// Ps = 0 , 1 or omitted -> transmit a single DECLRP locator
|
|
|
|
// report.
|
|
|
|
|
|
|
|
// If Locator Reporting has been enabled by a DECELR, xterm will
|
|
|
|
// respond with a DECLRP Locator Report. This report is also
|
|
|
|
// generated on button up and down events if they have been
|
|
|
|
// enabled with a DECSLE, or when the locator is detected outside
|
|
|
|
// of a filter rectangle, if filter rectangles have been enabled
|
|
|
|
// with a DECEFR.
|
|
|
|
|
|
|
|
// -> CSI Pe ; Pb ; Pr ; Pc ; Pp & w
|
|
|
|
|
|
|
|
// Parameters are [event;button;row;column;page].
|
|
|
|
// Valid values for the event:
|
|
|
|
// Pe = 0 -> locator unavailable - no other parameters sent.
|
|
|
|
// Pe = 1 -> request - xterm received a DECRQLP.
|
|
|
|
// Pe = 2 -> left button down.
|
|
|
|
// Pe = 3 -> left button up.
|
|
|
|
// Pe = 4 -> middle button down.
|
|
|
|
// Pe = 5 -> middle button up.
|
|
|
|
// Pe = 6 -> right button down.
|
|
|
|
// Pe = 7 -> right button up.
|
|
|
|
// Pe = 8 -> M4 button down.
|
|
|
|
// Pe = 9 -> M4 button up.
|
|
|
|
// Pe = 1 0 -> locator outside filter rectangle.
|
|
|
|
// ``button'' parameter is a bitmask indicating which buttons are
|
|
|
|
// pressed:
|
|
|
|
// Pb = 0 <- no buttons down.
|
|
|
|
// Pb & 1 <- right button down.
|
|
|
|
// Pb & 2 <- middle button down.
|
|
|
|
// Pb & 4 <- left button down.
|
|
|
|
// Pb & 8 <- M4 button down.
|
|
|
|
// ``row'' and ``column'' parameters are the coordinates of the
|
|
|
|
// locator position in the xterm window, encoded as ASCII deci-
|
|
|
|
// mal.
|
|
|
|
// The ``page'' parameter is not used by xterm, and will be omit-
|
|
|
|
// ted.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decrqlp =
|
2013-06-25 11:34:10 +00:00
|
|
|
Program.prototype.req_mouse_pos =
|
|
|
|
Program.prototype.reqmp =
|
2013-01-27 15:41:41 +00:00
|
|
|
Program.prototype.requestLocatorPosition = function(params, callback) {
|
2013-07-18 06:03:47 +00:00
|
|
|
// See also:
|
|
|
|
// get_mouse / getm / Gm
|
|
|
|
// mouse_info / minfo / Mi
|
|
|
|
// Correct for tput?
|
|
|
|
if (this.has('req_mouse_pos')) {
|
2013-06-25 11:34:10 +00:00
|
|
|
var code = this.tput.req_mouse_pos.apply(this.tput, params);
|
2013-07-18 06:03:47 +00:00
|
|
|
return this.response('locator-position', code, callback);
|
2013-06-25 11:34:10 +00:00
|
|
|
}
|
2013-07-18 19:52:56 +00:00
|
|
|
return this.response('locator-position',
|
|
|
|
'\x1b[' + (param || '') + '\'|', callback);
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI P m SP }
|
|
|
|
// Insert P s Column(s) (default = 1) (DECIC), VT420 and up.
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decic =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.insertColumns = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + ' }');
|
2013-01-27 14:54:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// CSI P m SP ~
|
|
|
|
// Delete P s Column(s) (default = 1) (DECDC), VT420 and up
|
|
|
|
// NOTE: xterm doesn't enable this code by default.
|
2013-01-27 16:01:30 +00:00
|
|
|
Program.prototype.decdc =
|
2013-01-27 14:54:30 +00:00
|
|
|
Program.prototype.deleteColumns = function() {
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._write('\x1b[' + slice.call(arguments).join(';') + ' ~');
|
2013-07-12 05:08:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.out = function(name) {
|
2013-07-24 19:17:52 +00:00
|
|
|
this.ret = true;
|
|
|
|
var out = this[name].apply(this, args);
|
|
|
|
this.ret = false;
|
|
|
|
return out;
|
2013-07-12 05:08:36 +00:00
|
|
|
};
|
|
|
|
|
2013-07-14 15:06:28 +00:00
|
|
|
Program.prototype.sigtstp = function(callback) {
|
2013-07-24 19:17:52 +00:00
|
|
|
var resume = this.pause();
|
|
|
|
|
|
|
|
process.once('SIGCONT', function() {
|
|
|
|
resume();
|
|
|
|
if (callback) callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
process.kill(process.pid, 'SIGTSTP');
|
|
|
|
};
|
|
|
|
|
|
|
|
Program.prototype.pause = function(callback) {
|
2013-07-14 15:06:28 +00:00
|
|
|
var self = this
|
|
|
|
, isAlt = this.isAlt
|
2013-07-24 19:17:52 +00:00
|
|
|
, mouseEnabled = this.mouseEnabled;
|
2013-07-23 21:37:54 +00:00
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
this.lsaveCursor('pause');
|
2013-07-23 21:37:54 +00:00
|
|
|
//this.csr(0, screen.height - 1);
|
|
|
|
if (isAlt) this.normalBuffer();
|
|
|
|
this.showCursor();
|
2013-07-24 19:17:52 +00:00
|
|
|
if (mouseEnabled) this.disableMouse();
|
2013-07-14 15:06:28 +00:00
|
|
|
|
|
|
|
var write = this.output.write;
|
|
|
|
this.output.write = function() {};
|
2015-06-09 12:13:11 +00:00
|
|
|
if (this.input.setRawMode) {
|
|
|
|
this.input.setRawMode(false);
|
|
|
|
}
|
2013-07-23 21:37:54 +00:00
|
|
|
this.input.pause();
|
2013-07-14 15:06:28 +00:00
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
return this._resume = function() {
|
|
|
|
delete self._resume;
|
|
|
|
|
2015-06-09 12:13:11 +00:00
|
|
|
if (self.input.setRawMode) {
|
|
|
|
self.input.setRawMode(true);
|
|
|
|
}
|
2013-07-14 15:06:28 +00:00
|
|
|
self.input.resume();
|
|
|
|
self.output.write = write;
|
|
|
|
|
|
|
|
if (isAlt) self.alternateBuffer();
|
2013-07-23 21:37:54 +00:00
|
|
|
//self.csr(0, screen.height - 1);
|
2013-07-24 19:17:52 +00:00
|
|
|
if (mouseEnabled) self.enableMouse();
|
|
|
|
self.lrestoreCursor('pause', true);
|
2013-07-14 15:06:28 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
2013-07-24 19:17:52 +00:00
|
|
|
};
|
|
|
|
};
|
2013-07-14 15:06:28 +00:00
|
|
|
|
2013-07-24 19:17:52 +00:00
|
|
|
Program.prototype.resume = function(callback) {
|
|
|
|
if (this._resume) return this._resume();
|
2013-07-14 15:06:28 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 22:09:41 +00:00
|
|
|
/**
|
|
|
|
* Helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
// We could do this easier by just manipulating the _events object, or for
|
|
|
|
// older versions of node, manipulating the array returned by listeners(), but
|
|
|
|
// neither of these methods are guaranteed to work in future versions of node.
|
|
|
|
function unshiftEvent(obj, event, listener) {
|
|
|
|
var listeners = obj.listeners(event);
|
|
|
|
obj.removeAllListeners(event);
|
|
|
|
obj.on(event, listener);
|
|
|
|
listeners.forEach(function(listener) {
|
|
|
|
obj.on(event, listener);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-08-18 19:42:39 +00:00
|
|
|
function merge(out) {
|
|
|
|
slice.call(arguments, 1).forEach(function(obj) {
|
|
|
|
Object.keys(obj).forEach(function(key) {
|
|
|
|
out[key] = obj[key];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2013-01-27 10:30:52 +00:00
|
|
|
/**
|
|
|
|
* Expose
|
|
|
|
*/
|
|
|
|
|
2013-07-24 19:40:05 +00:00
|
|
|
module.exports = Program;
|