@theia/process 1.45.0 → 1.46.0-next.72

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.
Files changed (69) hide show
  1. package/README.md +30 -30
  2. package/lib/common/process-common-module.d.ts +3 -3
  3. package/lib/common/process-common-module.js +22 -22
  4. package/lib/common/process-manager-types.d.ts +35 -35
  5. package/lib/common/process-manager-types.js +23 -23
  6. package/lib/common/shell-command-builder.d.ts +49 -49
  7. package/lib/common/shell-command-builder.js +174 -174
  8. package/lib/common/shell-command-builder.slow-spec.d.ts +9 -9
  9. package/lib/common/shell-command-builder.slow-spec.js +404 -404
  10. package/lib/common/shell-quoting.d.ts +91 -91
  11. package/lib/common/shell-quoting.js +145 -145
  12. package/lib/common/shell-quoting.spec.d.ts +1 -1
  13. package/lib/common/shell-quoting.spec.js +170 -170
  14. package/lib/node/dev-null-stream.d.ts +17 -17
  15. package/lib/node/dev-null-stream.js +41 -41
  16. package/lib/node/index.d.ts +6 -6
  17. package/lib/node/index.js +33 -33
  18. package/lib/node/multi-ring-buffer.d.ts +68 -68
  19. package/lib/node/multi-ring-buffer.js +310 -310
  20. package/lib/node/multi-ring-buffer.spec.d.ts +1 -1
  21. package/lib/node/multi-ring-buffer.spec.js +422 -422
  22. package/lib/node/process-backend-module.d.ts +3 -3
  23. package/lib/node/process-backend-module.js +56 -56
  24. package/lib/node/process-manager.d.ts +33 -33
  25. package/lib/node/process-manager.js +113 -113
  26. package/lib/node/process.d.ts +95 -95
  27. package/lib/node/process.js +153 -153
  28. package/lib/node/pseudo-pty.d.ts +22 -22
  29. package/lib/node/pseudo-pty.js +38 -38
  30. package/lib/node/raw-process.d.ts +45 -45
  31. package/lib/node/raw-process.js +115 -115
  32. package/lib/node/raw-process.spec.d.ts +1 -1
  33. package/lib/node/raw-process.spec.js +164 -164
  34. package/lib/node/task-terminal-process.d.ts +10 -10
  35. package/lib/node/task-terminal-process.js +47 -47
  36. package/lib/node/terminal-process.d.ts +60 -60
  37. package/lib/node/terminal-process.js +259 -259
  38. package/lib/node/terminal-process.spec.d.ts +1 -1
  39. package/lib/node/terminal-process.spec.js +103 -103
  40. package/lib/node/test/process-test-container.d.ts +2 -2
  41. package/lib/node/test/process-test-container.js +28 -28
  42. package/lib/node/utils.d.ts +16 -16
  43. package/lib/node/utils.js +77 -77
  44. package/package.json +4 -4
  45. package/src/common/process-common-module.ts +22 -22
  46. package/src/common/process-manager-types.ts +58 -58
  47. package/src/common/shell-command-builder.slow-spec.ts +486 -486
  48. package/src/common/shell-command-builder.ts +187 -187
  49. package/src/common/shell-quoting.spec.ts +176 -176
  50. package/src/common/shell-quoting.ts +236 -236
  51. package/src/common/tests/$weird(),file=name.js +1 -1
  52. package/src/common/tests/white space.js +1 -1
  53. package/src/node/dev-null-stream.ts +47 -47
  54. package/src/node/index.ts +22 -22
  55. package/src/node/multi-ring-buffer.spec.ts +486 -486
  56. package/src/node/multi-ring-buffer.ts +348 -348
  57. package/src/node/process-backend-module.ts +67 -67
  58. package/src/node/process-manager.ts +107 -107
  59. package/src/node/process.ts +207 -207
  60. package/src/node/pseudo-pty.ts +54 -54
  61. package/src/node/raw-process.spec.ts +199 -199
  62. package/src/node/raw-process.ts +156 -156
  63. package/src/node/string-argv.d.ts +21 -21
  64. package/src/node/task-terminal-process.ts +41 -41
  65. package/src/node/terminal-process.spec.ts +121 -121
  66. package/src/node/terminal-process.ts +290 -290
  67. package/src/node/test/process-fork-test.js +22 -22
  68. package/src/node/test/process-test-container.ts +27 -27
  69. package/src/node/utils.ts +79 -79
@@ -1,260 +1,260 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 Ericsson and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- var __param = (this && this.__param) || function (paramIndex, decorator) {
27
- return function (target, key) { decorator(target, key, paramIndex); }
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
31
- const inversify_1 = require("@theia/core/shared/inversify");
32
- const core_1 = require("@theia/core");
33
- const common_1 = require("@theia/core/lib/common");
34
- const process_1 = require("./process");
35
- const process_manager_1 = require("./process-manager");
36
- const node_pty_1 = require("node-pty");
37
- const multi_ring_buffer_1 = require("./multi-ring-buffer");
38
- const dev_null_stream_1 = require("./dev-null-stream");
39
- const utils_1 = require("./utils");
40
- const pseudo_pty_1 = require("./pseudo-pty");
41
- const stream_1 = require("stream");
42
- exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
43
- exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
44
- var NodePtyErrors;
45
- (function (NodePtyErrors) {
46
- NodePtyErrors["EACCES"] = "Permission denied";
47
- NodePtyErrors["ENOENT"] = "No such file or directory";
48
- })(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
49
- /**
50
- * Run arbitrary processes inside pseudo-terminals (PTY).
51
- *
52
- * Note: a PTY is not a shell process (bash/pwsh/cmd...)
53
- */
54
- let TerminalProcess = class TerminalProcess extends process_1.Process {
55
- constructor(// eslint-disable-next-line @typescript-eslint/indent
56
- options, processManager, ringBuffer, logger) {
57
- super(processManager, logger, process_1.ProcessType.Terminal, options);
58
- this.options = options;
59
- this.ringBuffer = ringBuffer;
60
- this.outputStream = this.createOutputStream();
61
- this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
62
- if (options.isPseudo) {
63
- // do not need to spawn a process, new a pseudo pty instead
64
- this.terminal = new pseudo_pty_1.PseudoPty();
65
- this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
66
- return;
67
- }
68
- if (this.isForkOptions(this.options)) {
69
- throw new Error('terminal processes cannot be forked as of today');
70
- }
71
- this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
72
- // Delay resizes to avoid conpty not respecting very early resize calls
73
- // see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
74
- if (core_1.isWindows) {
75
- this._delayedResizer = new DelayedResizer();
76
- this._delayedResizer.onTrigger(dimensions => {
77
- var _a;
78
- (_a = this._delayedResizer) === null || _a === void 0 ? void 0 : _a.dispose();
79
- this._delayedResizer = undefined;
80
- if (dimensions.cols && dimensions.rows) {
81
- this.resize(dimensions.cols, dimensions.rows);
82
- }
83
- });
84
- }
85
- const startTerminal = (command) => {
86
- try {
87
- return this.createPseudoTerminal(command, options, ringBuffer);
88
- }
89
- catch (error) {
90
- // Normalize the error to make it as close as possible as what
91
- // node's child_process.spawn would generate in the same
92
- // situation.
93
- const message = error.message;
94
- if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
95
- if (core_1.isWindows && command && !command.toLowerCase().endsWith('.exe')) {
96
- const commandExe = command + '.exe';
97
- this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
98
- return startTerminal(commandExe);
99
- }
100
- // Proceed with failure, reporting the original command because it was
101
- // the intended command and it was not found
102
- error.errno = 'ENOENT';
103
- error.code = 'ENOENT';
104
- error.path = options.command;
105
- }
106
- else if (message.endsWith(NodePtyErrors.EACCES)) {
107
- // The shell program exists but was not accessible, so just fail
108
- error.errno = 'EACCES';
109
- error.code = 'EACCES';
110
- error.path = options.command;
111
- }
112
- // node-pty throws exceptions on Windows.
113
- // Call the client error handler, but first give them a chance to register it.
114
- this.emitOnErrorAsync(error);
115
- return { terminal: undefined, inputStream: new dev_null_stream_1.DevNullStream({ autoDestroy: true }) };
116
- }
117
- };
118
- const { terminal, inputStream } = startTerminal(options.command);
119
- this.terminal = terminal;
120
- this.inputStream = inputStream;
121
- }
122
- /**
123
- * Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
124
- *
125
- * @param command the shell command to launch
126
- * @param options options for the shell process
127
- * @param ringBuffer a ring buffer in which to collect terminal output
128
- * @returns the terminal PTY and a stream by which it may be sent input
129
- */
130
- createPseudoTerminal(command, options, ringBuffer) {
131
- const terminal = (0, node_pty_1.spawn)(command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
132
- process.nextTick(() => this.emitOnStarted());
133
- // node-pty actually wait for the underlying streams to be closed before emitting exit.
134
- // We should emulate the `exit` and `close` sequence.
135
- terminal.onExit(({ exitCode, signal }) => {
136
- // Make sure to only pass either code or signal as !undefined, not
137
- // both.
138
- //
139
- // node-pty quirk: On Linux/macOS, if the process exited through the
140
- // exit syscall (with an exit code), signal will be 0 (an invalid
141
- // signal value). If it was terminated because of a signal, the
142
- // signal parameter will hold the signal number and code should
143
- // be ignored.
144
- this._exitCode = exitCode;
145
- if (signal === undefined || signal === 0) {
146
- this.onTerminalExit(exitCode, undefined);
147
- }
148
- else {
149
- this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
150
- }
151
- process.nextTick(() => {
152
- if (signal === undefined || signal === 0) {
153
- this.emitOnClose(exitCode, undefined);
154
- }
155
- else {
156
- this.emitOnClose(undefined, (0, utils_1.signame)(signal));
157
- }
158
- });
159
- });
160
- terminal.onData((data) => {
161
- ringBuffer.enq(data);
162
- });
163
- const inputStream = new stream_1.Writable({
164
- write: (chunk) => {
165
- this.write(chunk);
166
- },
167
- });
168
- return { terminal, inputStream };
169
- }
170
- createOutputStream() {
171
- return this.ringBuffer.getStream();
172
- }
173
- get pid() {
174
- this.checkTerminal();
175
- return this.terminal.pid;
176
- }
177
- get executable() {
178
- return this.options.command;
179
- }
180
- get arguments() {
181
- return this.options.args || [];
182
- }
183
- onTerminalExit(code, signal) {
184
- this.emitOnExit(code, signal);
185
- this.unregisterProcess();
186
- }
187
- unregisterProcess() {
188
- this.processManager.unregister(this);
189
- }
190
- kill(signal) {
191
- if (this.terminal && this.killed === false) {
192
- this.terminal.kill(signal);
193
- }
194
- }
195
- resize(cols, rows) {
196
- if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
197
- return;
198
- }
199
- this.checkTerminal();
200
- try {
201
- // Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
202
- cols = Math.max(cols, 1);
203
- rows = Math.max(rows, 1);
204
- // Delay resize if needed
205
- if (this._delayedResizer) {
206
- this._delayedResizer.cols = cols;
207
- this._delayedResizer.rows = rows;
208
- return;
209
- }
210
- this.terminal.resize(cols, rows);
211
- }
212
- catch (error) {
213
- // swallow error if the pty has already exited
214
- // see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
215
- if (this._exitCode !== undefined &&
216
- error.message !== 'ioctl(2) failed, EBADF' &&
217
- error.message !== 'Cannot resize a pty that has already exited') {
218
- throw error;
219
- }
220
- }
221
- }
222
- write(data) {
223
- this.checkTerminal();
224
- this.terminal.write(data);
225
- }
226
- checkTerminal() {
227
- if (!this.terminal) {
228
- throw new Error('pty process did not start correctly');
229
- }
230
- }
231
- };
232
- TerminalProcess = __decorate([
233
- (0, inversify_1.injectable)(),
234
- __param(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
235
- __param(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
236
- __param(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
237
- __param(3, (0, inversify_1.inject)(common_1.ILogger)),
238
- __param(3, (0, inversify_1.named)('process')),
239
- __metadata("design:paramtypes", [Object, process_manager_1.ProcessManager,
240
- multi_ring_buffer_1.MultiRingBuffer, Object])
241
- ], TerminalProcess);
242
- exports.TerminalProcess = TerminalProcess;
243
- /**
244
- * Tracks the latest resize event to be trigger at a later point.
245
- */
246
- class DelayedResizer extends core_1.DisposableCollection {
247
- constructor() {
248
- super();
249
- this._onTrigger = new core_1.Emitter();
250
- this.push(this._onTrigger);
251
- this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
252
- this.push(core_1.Disposable.create(() => clearTimeout(this._timeout)));
253
- }
254
- get onTrigger() { return this._onTrigger.event; }
255
- dispose() {
256
- super.dispose();
257
- clearTimeout(this._timeout);
258
- }
259
- }
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 Ericsson and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
27
+ return function (target, key) { decorator(target, key, paramIndex); }
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.TerminalProcess = exports.NodePtyErrors = exports.TerminalProcessFactory = exports.TerminalProcessOptions = void 0;
31
+ const inversify_1 = require("@theia/core/shared/inversify");
32
+ const core_1 = require("@theia/core");
33
+ const common_1 = require("@theia/core/lib/common");
34
+ const process_1 = require("./process");
35
+ const process_manager_1 = require("./process-manager");
36
+ const node_pty_1 = require("node-pty");
37
+ const multi_ring_buffer_1 = require("./multi-ring-buffer");
38
+ const dev_null_stream_1 = require("./dev-null-stream");
39
+ const utils_1 = require("./utils");
40
+ const pseudo_pty_1 = require("./pseudo-pty");
41
+ const stream_1 = require("stream");
42
+ exports.TerminalProcessOptions = Symbol('TerminalProcessOptions');
43
+ exports.TerminalProcessFactory = Symbol('TerminalProcessFactory');
44
+ var NodePtyErrors;
45
+ (function (NodePtyErrors) {
46
+ NodePtyErrors["EACCES"] = "Permission denied";
47
+ NodePtyErrors["ENOENT"] = "No such file or directory";
48
+ })(NodePtyErrors = exports.NodePtyErrors || (exports.NodePtyErrors = {}));
49
+ /**
50
+ * Run arbitrary processes inside pseudo-terminals (PTY).
51
+ *
52
+ * Note: a PTY is not a shell process (bash/pwsh/cmd...)
53
+ */
54
+ let TerminalProcess = class TerminalProcess extends process_1.Process {
55
+ constructor(// eslint-disable-next-line @typescript-eslint/indent
56
+ options, processManager, ringBuffer, logger) {
57
+ super(processManager, logger, process_1.ProcessType.Terminal, options);
58
+ this.options = options;
59
+ this.ringBuffer = ringBuffer;
60
+ this.outputStream = this.createOutputStream();
61
+ this.errorStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
62
+ if (options.isPseudo) {
63
+ // do not need to spawn a process, new a pseudo pty instead
64
+ this.terminal = new pseudo_pty_1.PseudoPty();
65
+ this.inputStream = new dev_null_stream_1.DevNullStream({ autoDestroy: true });
66
+ return;
67
+ }
68
+ if (this.isForkOptions(this.options)) {
69
+ throw new Error('terminal processes cannot be forked as of today');
70
+ }
71
+ this.logger.debug('Starting terminal process', JSON.stringify(options, undefined, 2));
72
+ // Delay resizes to avoid conpty not respecting very early resize calls
73
+ // see https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L177
74
+ if (core_1.isWindows) {
75
+ this._delayedResizer = new DelayedResizer();
76
+ this._delayedResizer.onTrigger(dimensions => {
77
+ var _a;
78
+ (_a = this._delayedResizer) === null || _a === void 0 ? void 0 : _a.dispose();
79
+ this._delayedResizer = undefined;
80
+ if (dimensions.cols && dimensions.rows) {
81
+ this.resize(dimensions.cols, dimensions.rows);
82
+ }
83
+ });
84
+ }
85
+ const startTerminal = (command) => {
86
+ try {
87
+ return this.createPseudoTerminal(command, options, ringBuffer);
88
+ }
89
+ catch (error) {
90
+ // Normalize the error to make it as close as possible as what
91
+ // node's child_process.spawn would generate in the same
92
+ // situation.
93
+ const message = error.message;
94
+ if (message.startsWith('File not found: ') || message.endsWith(NodePtyErrors.ENOENT)) {
95
+ if (core_1.isWindows && command && !command.toLowerCase().endsWith('.exe')) {
96
+ const commandExe = command + '.exe';
97
+ this.logger.debug(`Trying terminal command '${commandExe}' because '${command}' was not found.`);
98
+ return startTerminal(commandExe);
99
+ }
100
+ // Proceed with failure, reporting the original command because it was
101
+ // the intended command and it was not found
102
+ error.errno = 'ENOENT';
103
+ error.code = 'ENOENT';
104
+ error.path = options.command;
105
+ }
106
+ else if (message.endsWith(NodePtyErrors.EACCES)) {
107
+ // The shell program exists but was not accessible, so just fail
108
+ error.errno = 'EACCES';
109
+ error.code = 'EACCES';
110
+ error.path = options.command;
111
+ }
112
+ // node-pty throws exceptions on Windows.
113
+ // Call the client error handler, but first give them a chance to register it.
114
+ this.emitOnErrorAsync(error);
115
+ return { terminal: undefined, inputStream: new dev_null_stream_1.DevNullStream({ autoDestroy: true }) };
116
+ }
117
+ };
118
+ const { terminal, inputStream } = startTerminal(options.command);
119
+ this.terminal = terminal;
120
+ this.inputStream = inputStream;
121
+ }
122
+ /**
123
+ * Helper for the constructor to attempt to create the pseudo-terminal encapsulating the shell process.
124
+ *
125
+ * @param command the shell command to launch
126
+ * @param options options for the shell process
127
+ * @param ringBuffer a ring buffer in which to collect terminal output
128
+ * @returns the terminal PTY and a stream by which it may be sent input
129
+ */
130
+ createPseudoTerminal(command, options, ringBuffer) {
131
+ const terminal = (0, node_pty_1.spawn)(command, (core_1.isWindows && options.commandLine) || options.args || [], options.options || {});
132
+ process.nextTick(() => this.emitOnStarted());
133
+ // node-pty actually wait for the underlying streams to be closed before emitting exit.
134
+ // We should emulate the `exit` and `close` sequence.
135
+ terminal.onExit(({ exitCode, signal }) => {
136
+ // Make sure to only pass either code or signal as !undefined, not
137
+ // both.
138
+ //
139
+ // node-pty quirk: On Linux/macOS, if the process exited through the
140
+ // exit syscall (with an exit code), signal will be 0 (an invalid
141
+ // signal value). If it was terminated because of a signal, the
142
+ // signal parameter will hold the signal number and code should
143
+ // be ignored.
144
+ this._exitCode = exitCode;
145
+ if (signal === undefined || signal === 0) {
146
+ this.onTerminalExit(exitCode, undefined);
147
+ }
148
+ else {
149
+ this.onTerminalExit(undefined, (0, utils_1.signame)(signal));
150
+ }
151
+ process.nextTick(() => {
152
+ if (signal === undefined || signal === 0) {
153
+ this.emitOnClose(exitCode, undefined);
154
+ }
155
+ else {
156
+ this.emitOnClose(undefined, (0, utils_1.signame)(signal));
157
+ }
158
+ });
159
+ });
160
+ terminal.onData((data) => {
161
+ ringBuffer.enq(data);
162
+ });
163
+ const inputStream = new stream_1.Writable({
164
+ write: (chunk) => {
165
+ this.write(chunk);
166
+ },
167
+ });
168
+ return { terminal, inputStream };
169
+ }
170
+ createOutputStream() {
171
+ return this.ringBuffer.getStream();
172
+ }
173
+ get pid() {
174
+ this.checkTerminal();
175
+ return this.terminal.pid;
176
+ }
177
+ get executable() {
178
+ return this.options.command;
179
+ }
180
+ get arguments() {
181
+ return this.options.args || [];
182
+ }
183
+ onTerminalExit(code, signal) {
184
+ this.emitOnExit(code, signal);
185
+ this.unregisterProcess();
186
+ }
187
+ unregisterProcess() {
188
+ this.processManager.unregister(this);
189
+ }
190
+ kill(signal) {
191
+ if (this.terminal && this.killed === false) {
192
+ this.terminal.kill(signal);
193
+ }
194
+ }
195
+ resize(cols, rows) {
196
+ if (typeof cols !== 'number' || typeof rows !== 'number' || isNaN(cols) || isNaN(rows)) {
197
+ return;
198
+ }
199
+ this.checkTerminal();
200
+ try {
201
+ // Ensure that cols and rows are always >= 1, this prevents a native exception in winpty.
202
+ cols = Math.max(cols, 1);
203
+ rows = Math.max(rows, 1);
204
+ // Delay resize if needed
205
+ if (this._delayedResizer) {
206
+ this._delayedResizer.cols = cols;
207
+ this._delayedResizer.rows = rows;
208
+ return;
209
+ }
210
+ this.terminal.resize(cols, rows);
211
+ }
212
+ catch (error) {
213
+ // swallow error if the pty has already exited
214
+ // see also https://github.com/microsoft/vscode/blob/a1c783c/src/vs/platform/terminal/node/terminalProcess.ts#L549
215
+ if (this._exitCode !== undefined &&
216
+ error.message !== 'ioctl(2) failed, EBADF' &&
217
+ error.message !== 'Cannot resize a pty that has already exited') {
218
+ throw error;
219
+ }
220
+ }
221
+ }
222
+ write(data) {
223
+ this.checkTerminal();
224
+ this.terminal.write(data);
225
+ }
226
+ checkTerminal() {
227
+ if (!this.terminal) {
228
+ throw new Error('pty process did not start correctly');
229
+ }
230
+ }
231
+ };
232
+ TerminalProcess = __decorate([
233
+ (0, inversify_1.injectable)(),
234
+ __param(0, (0, inversify_1.inject)(exports.TerminalProcessOptions)),
235
+ __param(1, (0, inversify_1.inject)(process_manager_1.ProcessManager)),
236
+ __param(2, (0, inversify_1.inject)(multi_ring_buffer_1.MultiRingBuffer)),
237
+ __param(3, (0, inversify_1.inject)(common_1.ILogger)),
238
+ __param(3, (0, inversify_1.named)('process')),
239
+ __metadata("design:paramtypes", [Object, process_manager_1.ProcessManager,
240
+ multi_ring_buffer_1.MultiRingBuffer, Object])
241
+ ], TerminalProcess);
242
+ exports.TerminalProcess = TerminalProcess;
243
+ /**
244
+ * Tracks the latest resize event to be trigger at a later point.
245
+ */
246
+ class DelayedResizer extends core_1.DisposableCollection {
247
+ constructor() {
248
+ super();
249
+ this._onTrigger = new core_1.Emitter();
250
+ this.push(this._onTrigger);
251
+ this._timeout = setTimeout(() => this._onTrigger.fire({ rows: this.rows, cols: this.cols }), 1000);
252
+ this.push(core_1.Disposable.create(() => clearTimeout(this._timeout)));
253
+ }
254
+ get onTrigger() { return this._onTrigger.event; }
255
+ dispose() {
256
+ super.dispose();
257
+ clearTimeout(this._timeout);
258
+ }
259
+ }
260
260
  //# sourceMappingURL=terminal-process.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=terminal-process.spec.d.ts.map