1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var __extends = (this && this.__extends) || (function () {
|
8 | var extendStatics = function (d, b) {
|
9 | extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return extendStatics(d, b);
|
13 | };
|
14 | return function (d, b) {
|
15 | extendStatics(d, b);
|
16 | function __() { this.constructor = d; }
|
17 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
18 | };
|
19 | })();
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | var terminal_1 = require("./terminal");
|
22 | var windowsPtyAgent_1 = require("./windowsPtyAgent");
|
23 | var utils_1 = require("./utils");
|
24 | var DEFAULT_FILE = 'cmd.exe';
|
25 | var DEFAULT_NAME = 'Windows Shell';
|
26 | var WindowsTerminal = (function (_super) {
|
27 | __extends(WindowsTerminal, _super);
|
28 | function WindowsTerminal(file, args, opt) {
|
29 | var _this = _super.call(this, opt) || this;
|
30 | _this._checkType('args', args, 'string', true);
|
31 |
|
32 | args = args || [];
|
33 | file = file || DEFAULT_FILE;
|
34 | opt = opt || {};
|
35 | opt.env = opt.env || process.env;
|
36 | if (opt.encoding) {
|
37 | console.warn('Setting encoding on Windows is not supported');
|
38 | }
|
39 | var env = utils_1.assign({}, opt.env);
|
40 | _this._cols = opt.cols || terminal_1.DEFAULT_COLS;
|
41 | _this._rows = opt.rows || terminal_1.DEFAULT_ROWS;
|
42 | var cwd = opt.cwd || process.cwd();
|
43 | var name = opt.name || env.TERM || DEFAULT_NAME;
|
44 | var parsedEnv = _this._parseEnv(env);
|
45 |
|
46 | _this._isReady = false;
|
47 |
|
48 | _this._deferreds = [];
|
49 |
|
50 | _this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, _this._cols, _this._rows, false, opt.useConpty, opt.conptyInheritCursor);
|
51 | _this._socket = _this._agent.outSocket;
|
52 |
|
53 | _this._pid = _this._agent.innerPid;
|
54 | _this._fd = _this._agent.fd;
|
55 | _this._pty = _this._agent.pty;
|
56 |
|
57 |
|
58 | _this._socket.on('ready_datapipe', function () {
|
59 |
|
60 | ['connect', 'data', 'end', 'timeout', 'drain'].forEach(function (event) {
|
61 | _this._socket.on(event, function () {
|
62 |
|
63 | if (!_this._isReady && event === 'data') {
|
64 |
|
65 |
|
66 | _this._isReady = true;
|
67 |
|
68 | _this._deferreds.forEach(function (fn) {
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | fn.run();
|
74 | });
|
75 |
|
76 | _this._deferreds = [];
|
77 | }
|
78 | });
|
79 | });
|
80 |
|
81 | _this._socket.on('error', function (err) {
|
82 |
|
83 | _this._close();
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | if (err.code) {
|
89 | if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO'))
|
90 | return;
|
91 | }
|
92 |
|
93 | if (_this.listeners('error').length < 2) {
|
94 | throw err;
|
95 | }
|
96 | });
|
97 |
|
98 | _this._socket.on('close', function () {
|
99 | _this.emit('exit', _this._agent.exitCode);
|
100 | _this._close();
|
101 | });
|
102 | });
|
103 | _this._file = file;
|
104 | _this._name = name;
|
105 | _this._readable = true;
|
106 | _this._writable = true;
|
107 | _this._forwardEvents();
|
108 | return _this;
|
109 | }
|
110 | WindowsTerminal.prototype._write = function (data) {
|
111 | this._defer(this._doWrite, data);
|
112 | };
|
113 | WindowsTerminal.prototype._doWrite = function (data) {
|
114 | this._agent.inSocket.write(data);
|
115 | };
|
116 | |
117 |
|
118 |
|
119 | WindowsTerminal.open = function (options) {
|
120 | throw new Error('open() not supported on windows, use Fork() instead.');
|
121 | };
|
122 | |
123 |
|
124 |
|
125 | WindowsTerminal.prototype.resize = function (cols, rows) {
|
126 | var _this = this;
|
127 | if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
|
128 | throw new Error('resizing must be done using positive cols and rows');
|
129 | }
|
130 | this._defer(function () {
|
131 | _this._agent.resize(cols, rows);
|
132 | _this._cols = cols;
|
133 | _this._rows = rows;
|
134 | });
|
135 | };
|
136 | WindowsTerminal.prototype.destroy = function () {
|
137 | var _this = this;
|
138 | this._defer(function () {
|
139 | _this.kill();
|
140 | });
|
141 | };
|
142 | WindowsTerminal.prototype.kill = function (signal) {
|
143 | var _this = this;
|
144 | this._defer(function () {
|
145 | if (signal) {
|
146 | throw new Error('Signals not supported on windows.');
|
147 | }
|
148 | _this._close();
|
149 | _this._agent.kill();
|
150 | });
|
151 | };
|
152 | WindowsTerminal.prototype._defer = function (deferredFn, arg) {
|
153 | var _this = this;
|
154 |
|
155 | if (this._isReady) {
|
156 | deferredFn.call(this, arg);
|
157 | return;
|
158 | }
|
159 |
|
160 | this._deferreds.push({
|
161 | run: function () { return deferredFn.call(_this, arg); }
|
162 | });
|
163 | };
|
164 | Object.defineProperty(WindowsTerminal.prototype, "process", {
|
165 | get: function () { return this._name; },
|
166 | enumerable: true,
|
167 | configurable: true
|
168 | });
|
169 | Object.defineProperty(WindowsTerminal.prototype, "master", {
|
170 | get: function () { throw new Error('master is not supported on Windows'); },
|
171 | enumerable: true,
|
172 | configurable: true
|
173 | });
|
174 | Object.defineProperty(WindowsTerminal.prototype, "slave", {
|
175 | get: function () { throw new Error('slave is not supported on Windows'); },
|
176 | enumerable: true,
|
177 | configurable: true
|
178 | });
|
179 | return WindowsTerminal;
|
180 | }(terminal_1.Terminal));
|
181 | exports.WindowsTerminal = WindowsTerminal;
|
182 |
|
\ | No newline at end of file |