| | "use strict"; |
| | |
| | |
| | |
| | |
| | |
| | var __extends = (this && this.__extends) || (function () { |
| | var extendStatics = function (d, b) { |
| | extendStatics = Object.setPrototypeOf || |
| | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| | return extendStatics(d, b); |
| | }; |
| | return function (d, b) { |
| | extendStatics(d, b); |
| | function __() { this.constructor = d; } |
| | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| | }; |
| | })(); |
| | Object.defineProperty(exports, "__esModule", { value: true }); |
| | var terminal_1 = require("./terminal"); |
| | var windowsPtyAgent_1 = require("./windowsPtyAgent"); |
| | var utils_1 = require("./utils"); |
| | var DEFAULT_FILE = 'cmd.exe'; |
| | var DEFAULT_NAME = 'Windows Shell'; |
| | var WindowsTerminal = (function (_super) { |
| | __extends(WindowsTerminal, _super); |
| | function WindowsTerminal(file, args, opt) { |
| | var _this = _super.call(this, opt) || this; |
| | |
| | args = args || []; |
| | file = file || DEFAULT_FILE; |
| | opt = opt || {}; |
| | opt.env = opt.env || process.env; |
| | if (opt.encoding) { |
| | console.warn('Setting encoding on Windows is not supported'); |
| | } |
| | var env = utils_1.assign({}, opt.env); |
| | _this._cols = opt.cols || terminal_1.DEFAULT_COLS; |
| | _this._rows = opt.rows || terminal_1.DEFAULT_ROWS; |
| | var cwd = opt.cwd || process.cwd(); |
| | var name = opt.name || env.TERM || DEFAULT_NAME; |
| | var parsedEnv = _this._parseEnv(env); |
| | |
| | _this._isReady = false; |
| | |
| | _this._deferreds = []; |
| | |
| | _this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, _this._cols, _this._rows, false, opt.useConpty, opt.conptyInheritCursor); |
| | _this._socket = _this._agent.outSocket; |
| | |
| | _this._pid = _this._agent.innerPid; |
| | _this._fd = _this._agent.fd; |
| | _this._pty = _this._agent.pty; |
| | |
| | |
| | _this._socket.on('ready_datapipe', function () { |
| | |
| | ['connect', 'data', 'end', 'timeout', 'drain'].forEach(function (event) { |
| | _this._socket.on(event, function () { |
| | |
| | if (!_this._isReady && event === 'data') { |
| | |
| | |
| | _this._isReady = true; |
| | |
| | _this._deferreds.forEach(function (fn) { |
| | |
| | |
| | |
| | |
| | fn.run(); |
| | }); |
| | |
| | _this._deferreds = []; |
| | } |
| | }); |
| | }); |
| | |
| | _this._socket.on('error', function (err) { |
| | |
| | _this._close(); |
| | |
| | |
| | |
| | |
| | if (err.code) { |
| | if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) |
| | return; |
| | } |
| | |
| | if (_this.listeners('error').length < 2) { |
| | throw err; |
| | } |
| | }); |
| | |
| | _this._socket.on('close', function () { |
| | _this.emit('exit', _this._agent.exitCode); |
| | _this._close(); |
| | }); |
| | }); |
| | _this._file = file; |
| | _this._name = name; |
| | _this._readable = true; |
| | _this._writable = true; |
| | _this._forwardEvents(); |
| | return _this; |
| | } |
| | WindowsTerminal.prototype._write = function (data) { |
| | this._defer(this._doWrite, data); |
| | }; |
| | WindowsTerminal.prototype._doWrite = function (data) { |
| | this._agent.inSocket.write(data); |
| | }; |
| | |
| | |
| | |
| | WindowsTerminal.open = function (options) { |
| | throw new Error('open() not supported on windows, use Fork() instead.'); |
| | }; |
| | |
| | |
| | |
| | WindowsTerminal.prototype.resize = function (cols, rows) { |
| | var _this = this; |
| | if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) { |
| | throw new Error('resizing must be done using positive cols and rows'); |
| | } |
| | this._defer(function () { |
| | _this._agent.resize(cols, rows); |
| | _this._cols = cols; |
| | _this._rows = rows; |
| | }); |
| | }; |
| | WindowsTerminal.prototype.destroy = function () { |
| | var _this = this; |
| | this._defer(function () { |
| | _this.kill(); |
| | }); |
| | }; |
| | WindowsTerminal.prototype.kill = function (signal) { |
| | var _this = this; |
| | this._defer(function () { |
| | if (signal) { |
| | throw new Error('Signals not supported on windows.'); |
| | } |
| | _this._close(); |
| | _this._agent.kill(); |
| | }); |
| | }; |
| | WindowsTerminal.prototype._defer = function (deferredFn, arg) { |
| | var _this = this; |
| | |
| | if (this._isReady) { |
| | deferredFn.call(this, arg); |
| | return; |
| | } |
| | |
| | this._deferreds.push({ |
| | run: function () { return deferredFn.call(_this, arg); } |
| | }); |
| | }; |
| | Object.defineProperty(WindowsTerminal.prototype, "process", { |
| | get: function () { return this._name; }, |
| | enumerable: true, |
| | configurable: true |
| | }); |
| | Object.defineProperty(WindowsTerminal.prototype, "master", { |
| | get: function () { throw new Error('master is not supported on Windows'); }, |
| | enumerable: true, |
| | configurable: true |
| | }); |
| | Object.defineProperty(WindowsTerminal.prototype, "slave", { |
| | get: function () { throw new Error('slave is not supported on Windows'); }, |
| | enumerable: true, |
| | configurable: true |
| | }); |
| | return WindowsTerminal; |
| | }(terminal_1.Terminal)); |
| | exports.WindowsTerminal = WindowsTerminal; |
| | |