@lydell/node-pty 1.1.0 → 1.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,199 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
4
- * Copyright (c) 2016, Daniel Imms (MIT License).
5
- * Copyright (c) 2018, Microsoft Corporation (MIT License).
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 = /** @class */ (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
- // Initialize arguments
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
- // If the terminal is ready
46
- _this._isReady = false;
47
- // Functions that need to run after `ready` event is emitted.
48
- _this._deferreds = [];
49
- // Create new termal.
50
- _this._agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, _this._cols, _this._rows, false, opt.conptyInheritCursor);
51
- _this._socket = _this._agent.outSocket;
52
- // Not available until `ready` event emitted.
53
- _this._pid = _this._agent.innerPid;
54
- _this._fd = _this._agent.fd;
55
- _this._pty = _this._agent.pty;
56
- // The forked windows terminal is not available until `ready` event is
57
- // emitted.
58
- _this._socket.on('ready_datapipe', function () {
59
- // These events needs to be forwarded.
60
- ['connect', 'data', 'end', 'timeout', 'drain'].forEach(function (event) {
61
- _this._socket.on(event, function () {
62
- // Wait until the first data event is fired then we can run deferreds.
63
- if (!_this._isReady && event === 'data') {
64
- // Terminal is now ready and we can avoid having to defer method
65
- // calls.
66
- _this._isReady = true;
67
- // Execute all deferred methods
68
- _this._deferreds.forEach(function (fn) {
69
- // NB! In order to ensure that `this` has all its references
70
- // updated any variable that need to be available in `this` before
71
- // the deferred is run has to be declared above this forEach
72
- // statement.
73
- fn.run();
74
- });
75
- // Reset
76
- _this._deferreds = [];
77
- }
78
- });
79
- });
80
- // Shutdown if `error` event is emitted.
81
- _this._socket.on('error', function (err) {
82
- // Close terminal session.
83
- _this._close();
84
- // EIO, happens when someone closes our child process: the only process
85
- // in the terminal.
86
- // node < 0.6.14: errno 5
87
- // node >= 0.6.14: read EIO
88
- if (err.code) {
89
- if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO'))
90
- return;
91
- }
92
- // Throw anything else.
93
- if (_this.listeners('error').length < 2) {
94
- throw err;
95
- }
96
- });
97
- // Cleanup after the socket is closed.
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
- * openpty
118
- */
119
- WindowsTerminal.open = function (options) {
120
- throw new Error('open() not supported on windows, use Fork() instead.');
121
- };
122
- /**
123
- * TTY
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._deferNoArgs(function () {
131
- _this._agent.resize(cols, rows);
132
- _this._cols = cols;
133
- _this._rows = rows;
134
- });
135
- };
136
- WindowsTerminal.prototype.clear = function () {
137
- var _this = this;
138
- this._deferNoArgs(function () {
139
- _this._agent.clear();
140
- });
141
- };
142
- WindowsTerminal.prototype.destroy = function () {
143
- var _this = this;
144
- this._deferNoArgs(function () {
145
- _this.kill();
146
- });
147
- };
148
- WindowsTerminal.prototype.kill = function (signal) {
149
- var _this = this;
150
- this._deferNoArgs(function () {
151
- if (signal) {
152
- throw new Error('Signals not supported on windows.');
153
- }
154
- _this._close();
155
- _this._agent.kill();
156
- });
157
- };
158
- WindowsTerminal.prototype._deferNoArgs = function (deferredFn) {
159
- var _this = this;
160
- // If the terminal is ready, execute.
161
- if (this._isReady) {
162
- deferredFn.call(this);
163
- return;
164
- }
165
- // Queue until terminal is ready.
166
- this._deferreds.push({
167
- run: function () { return deferredFn.call(_this); }
168
- });
169
- };
170
- WindowsTerminal.prototype._defer = function (deferredFn, arg) {
171
- var _this = this;
172
- // If the terminal is ready, execute.
173
- if (this._isReady) {
174
- deferredFn.call(this, arg);
175
- return;
176
- }
177
- // Queue until terminal is ready.
178
- this._deferreds.push({
179
- run: function () { return deferredFn.call(_this, arg); }
180
- });
181
- };
182
- Object.defineProperty(WindowsTerminal.prototype, "process", {
183
- get: function () { return this._name; },
184
- enumerable: true,
185
- configurable: true
186
- });
187
- Object.defineProperty(WindowsTerminal.prototype, "master", {
188
- get: function () { throw new Error('master is not supported on Windows'); },
189
- enumerable: true,
190
- configurable: true
191
- });
192
- Object.defineProperty(WindowsTerminal.prototype, "slave", {
193
- get: function () { throw new Error('slave is not supported on Windows'); },
194
- enumerable: true,
195
- configurable: true
196
- });
197
- return WindowsTerminal;
198
- }(terminal_1.Terminal));
199
- exports.WindowsTerminal = WindowsTerminal;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) 2020, Microsoft Corporation (MIT License).
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var worker_threads_1 = require("worker_threads");
7
- var net_1 = require("net");
8
- var conout_1 = require("../shared/conout");
9
- var conoutPipeName = worker_threads_1.workerData.conoutPipeName;
10
- var conoutSocket = new net_1.Socket();
11
- conoutSocket.setEncoding('utf8');
12
- conoutSocket.connect(conoutPipeName, function () {
13
- var server = net_1.createServer(function (workerSocket) {
14
- conoutSocket.pipe(workerSocket);
15
- });
16
- server.listen(conout_1.getWorkerPipeName(conoutPipeName));
17
- if (!worker_threads_1.parentPort) {
18
- throw new Error('worker_threads parentPort is null');
19
- }
20
- worker_threads_1.parentPort.postMessage(1 /* READY */);
21
- });