@theia/terminal 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.
- package/README.md +30 -30
- package/lib/browser/base/terminal-service.d.ts +34 -34
- package/lib/browser/base/terminal-service.js +7 -7
- package/lib/browser/base/terminal-widget.d.ts +192 -192
- package/lib/browser/base/terminal-widget.js +34 -34
- package/lib/browser/index.d.ts +1 -1
- package/lib/browser/index.js +28 -28
- package/lib/browser/search/terminal-search-container.d.ts +3 -3
- package/lib/browser/search/terminal-search-container.js +28 -28
- package/lib/browser/search/terminal-search-widget.d.ts +30 -30
- package/lib/browser/search/terminal-search-widget.js +147 -147
- package/lib/browser/shell-terminal-profile.d.ts +20 -20
- package/lib/browser/shell-terminal-profile.js +42 -42
- package/lib/browser/terminal-contribution.d.ts +3 -3
- package/lib/browser/terminal-contribution.js +20 -20
- package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
- package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
- package/lib/browser/terminal-file-link-provider.d.ts +24 -24
- package/lib/browser/terminal-file-link-provider.js +200 -200
- package/lib/browser/terminal-frontend-contribution.d.ts +115 -115
- package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/terminal-frontend-contribution.js +1078 -1056
- package/lib/browser/terminal-frontend-contribution.js.map +1 -1
- package/lib/browser/terminal-frontend-module.d.ts +5 -5
- package/lib/browser/terminal-frontend-module.js +117 -117
- package/lib/browser/terminal-link-helpers.d.ts +27 -27
- package/lib/browser/terminal-link-helpers.js +155 -155
- package/lib/browser/terminal-link-provider.d.ts +51 -51
- package/lib/browser/terminal-link-provider.js +197 -197
- package/lib/browser/terminal-preferences.d.ts +61 -61
- package/lib/browser/terminal-preferences.d.ts.map +1 -1
- package/lib/browser/terminal-preferences.js +357 -356
- package/lib/browser/terminal-preferences.js.map +1 -1
- package/lib/browser/terminal-profile-service.d.ts +58 -58
- package/lib/browser/terminal-profile-service.js +158 -158
- package/lib/browser/terminal-quick-open-service.d.ts +36 -36
- package/lib/browser/terminal-quick-open-service.js +137 -137
- package/lib/browser/terminal-theme-service.d.ts +21 -21
- package/lib/browser/terminal-theme-service.d.ts.map +1 -1
- package/lib/browser/terminal-theme-service.js +222 -218
- package/lib/browser/terminal-theme-service.js.map +1 -1
- package/lib/browser/terminal-url-link-provider.d.ts +11 -11
- package/lib/browser/terminal-url-link-provider.js +76 -76
- package/lib/browser/terminal-widget-impl.d.ts +180 -187
- package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
- package/lib/browser/terminal-widget-impl.js +857 -867
- package/lib/browser/terminal-widget-impl.js.map +1 -1
- package/lib/common/base-terminal-protocol.d.ts +55 -55
- package/lib/common/base-terminal-protocol.js +84 -84
- package/lib/common/shell-terminal-protocol.d.ts +66 -66
- package/lib/common/shell-terminal-protocol.js +35 -35
- package/lib/common/terminal-common-module.d.ts +7 -7
- package/lib/common/terminal-common-module.js +31 -31
- package/lib/common/terminal-protocol.d.ts +12 -12
- package/lib/common/terminal-protocol.js +21 -21
- package/lib/common/terminal-watcher.d.ts +13 -13
- package/lib/common/terminal-watcher.js +70 -70
- package/lib/node/base-terminal-server.d.ts +24 -24
- package/lib/node/base-terminal-server.js +168 -168
- package/lib/node/buffering-stream.d.ts +39 -39
- package/lib/node/buffering-stream.js +75 -75
- package/lib/node/buffering-stream.spec.d.ts +1 -1
- package/lib/node/buffering-stream.spec.js +43 -43
- package/lib/node/index.d.ts +1 -1
- package/lib/node/index.js +28 -28
- package/lib/node/shell-process.d.ts +27 -27
- package/lib/node/shell-process.js +107 -107
- package/lib/node/shell-process.js.map +1 -1
- package/lib/node/shell-terminal-server.d.ts +30 -30
- package/lib/node/shell-terminal-server.js +212 -212
- package/lib/node/shell-terminal-server.spec.d.ts +1 -1
- package/lib/node/shell-terminal-server.spec.js +35 -35
- package/lib/node/terminal-backend-contribution.d.ts +9 -9
- package/lib/node/terminal-backend-contribution.js +75 -75
- package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
- package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
- package/lib/node/terminal-backend-module.d.ts +11 -11
- package/lib/node/terminal-backend-module.js +69 -69
- package/lib/node/terminal-server.d.ts +9 -9
- package/lib/node/terminal-server.js +64 -64
- package/lib/node/terminal-server.spec.d.ts +1 -1
- package/lib/node/terminal-server.spec.js +41 -41
- package/lib/node/test/terminal-test-container.d.ts +2 -2
- package/lib/node/test/terminal-test-container.js +40 -40
- package/lib/package.spec.js +25 -25
- package/package.json +12 -12
- package/src/browser/base/terminal-service.ts +60 -60
- package/src/browser/base/terminal-widget.ts +254 -254
- package/src/browser/index.ts +17 -17
- package/src/browser/search/terminal-search-container.ts +28 -28
- package/src/browser/search/terminal-search-widget.tsx +161 -161
- package/src/browser/shell-terminal-profile.ts +45 -45
- package/src/browser/style/terminal-search.css +99 -99
- package/src/browser/style/terminal.css +32 -32
- package/src/browser/terminal-contribution.ts +19 -19
- package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
- package/src/browser/terminal-file-link-provider.ts +200 -200
- package/src/browser/terminal-frontend-contribution.ts +1120 -1098
- package/src/browser/terminal-frontend-module.ts +136 -136
- package/src/browser/terminal-link-helpers.ts +187 -187
- package/src/browser/terminal-link-provider.ts +203 -203
- package/src/browser/terminal-preferences.ts +428 -427
- package/src/browser/terminal-profile-service.ts +180 -180
- package/src/browser/terminal-quick-open-service.ts +132 -132
- package/src/browser/terminal-theme-service.ts +213 -209
- package/src/browser/terminal-url-link-provider.ts +66 -66
- package/src/browser/terminal-widget-impl.ts +939 -936
- package/src/common/base-terminal-protocol.ts +125 -125
- package/src/common/shell-terminal-protocol.ts +103 -103
- package/src/common/terminal-common-module.ts +30 -30
- package/src/common/terminal-protocol.ts +32 -32
- package/src/common/terminal-watcher.ts +69 -69
- package/src/node/base-terminal-server.ts +173 -173
- package/src/node/buffering-stream.spec.ts +46 -46
- package/src/node/buffering-stream.ts +95 -95
- package/src/node/index.ts +17 -17
- package/src/node/shell-process.ts +101 -101
- package/src/node/shell-terminal-server.spec.ts +40 -40
- package/src/node/shell-terminal-server.ts +221 -221
- package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
- package/src/node/terminal-backend-contribution.ts +60 -60
- package/src/node/terminal-backend-module.ts +82 -82
- package/src/node/terminal-server.spec.ts +47 -47
- package/src/node/terminal-server.ts +52 -52
- package/src/node/test/terminal-test-container.ts +39 -39
- package/src/package.spec.ts +28 -28
|
@@ -1,213 +1,213 @@
|
|
|
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.ShellTerminalServer = void 0;
|
|
31
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
32
|
-
const logger_1 = require("@theia/core/lib/common/logger");
|
|
33
|
-
const environment_utils_1 = require("@theia/core/lib/node/environment-utils");
|
|
34
|
-
const base_terminal_server_1 = require("./base-terminal-server");
|
|
35
|
-
const shell_process_1 = require("./shell-process");
|
|
36
|
-
const node_1 = require("@theia/process/lib/node");
|
|
37
|
-
const os_1 = require("@theia/core/lib/common/os");
|
|
38
|
-
const cp = require("child_process");
|
|
39
|
-
const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
|
|
40
|
-
const core_1 = require("@theia/core");
|
|
41
|
-
const collections_1 = require("@theia/core/lib/common/collections");
|
|
42
|
-
let ShellTerminalServer = class ShellTerminalServer extends base_terminal_server_1.BaseTerminalServer {
|
|
43
|
-
constructor(shellFactory, processManager, logger) {
|
|
44
|
-
super(processManager, logger);
|
|
45
|
-
this.shellFactory = shellFactory;
|
|
46
|
-
this.collections = new collections_1.MultiKeyMap(2);
|
|
47
|
-
}
|
|
48
|
-
async create(options) {
|
|
49
|
-
try {
|
|
50
|
-
if (options.strictEnv !== true) {
|
|
51
|
-
options.env = this.environmentUtils.mergeProcessEnv(options.env);
|
|
52
|
-
this.applyToProcessEnvironment(core_1.URI.fromFilePath((0, shell_process_1.getRootPath)(options.rootURI)), options.env);
|
|
53
|
-
}
|
|
54
|
-
const term = this.shellFactory(options);
|
|
55
|
-
this.postCreate(term);
|
|
56
|
-
return term.id;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
this.logger.error('Error while creating terminal', error);
|
|
60
|
-
return -1;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
|
|
64
|
-
spawnAsPromised(command, args) {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
let stdout = '';
|
|
67
|
-
const child = cp.spawn(command, args);
|
|
68
|
-
if (child.pid) {
|
|
69
|
-
child.stdout.on('data', (data) => {
|
|
70
|
-
stdout += data.toString();
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
child.on('error', err => {
|
|
74
|
-
reject(err);
|
|
75
|
-
});
|
|
76
|
-
child.on('close', code => {
|
|
77
|
-
resolve(stdout);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
hasChildProcesses(processId) {
|
|
82
|
-
if (processId) {
|
|
83
|
-
// if shell has at least one child process, assume that shell is busy
|
|
84
|
-
if (os_1.isWindows) {
|
|
85
|
-
return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
|
|
86
|
-
const pids = stdout.split('\r\n');
|
|
87
|
-
return pids.some(p => parseInt(p) === processId);
|
|
88
|
-
}, error => true);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
|
|
92
|
-
const r = stdout.trim();
|
|
93
|
-
if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}, error => true);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// fall back to safe side
|
|
103
|
-
return Promise.resolve(true);
|
|
104
|
-
}
|
|
105
|
-
applyToProcessEnvironment(cwdUri, env) {
|
|
106
|
-
let lowerToActualVariableNames;
|
|
107
|
-
if (os_1.isWindows) {
|
|
108
|
-
lowerToActualVariableNames = {};
|
|
109
|
-
Object.keys(env).forEach(e => lowerToActualVariableNames[e.toLowerCase()] = e);
|
|
110
|
-
}
|
|
111
|
-
this.collections.forEach((mutators, [extensionIdentifier, rootUri]) => {
|
|
112
|
-
if (rootUri === shell_terminal_protocol_1.NO_ROOT_URI || this.matchesRootUri(cwdUri, rootUri)) {
|
|
113
|
-
mutators.variableMutators.forEach((mutator, variable) => {
|
|
114
|
-
const actualVariable = os_1.isWindows ? lowerToActualVariableNames[variable.toLowerCase()] || variable : variable;
|
|
115
|
-
switch (mutator.type) {
|
|
116
|
-
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Append:
|
|
117
|
-
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
|
118
|
-
break;
|
|
119
|
-
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Prepend:
|
|
120
|
-
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
|
121
|
-
break;
|
|
122
|
-
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Replace:
|
|
123
|
-
env[actualVariable] = mutator.value;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
matchesRootUri(cwdUri, rootUri) {
|
|
131
|
-
return new core_1.URI(rootUri).isEqualOrParent(cwdUri);
|
|
132
|
-
}
|
|
133
|
-
/*---------------------------------------------------------------------------------------------
|
|
134
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
135
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
136
|
-
*--------------------------------------------------------------------------------------------*/
|
|
137
|
-
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
|
|
138
|
-
setCollection(extensionIdentifier, baseUri, persistent, collection) {
|
|
139
|
-
this.doSetCollection(extensionIdentifier, baseUri, persistent, collection);
|
|
140
|
-
this.updateCollections();
|
|
141
|
-
}
|
|
142
|
-
doSetCollection(extensionIdentifier, baseUri, persistent, collection) {
|
|
143
|
-
this.collections.set([extensionIdentifier, baseUri], {
|
|
144
|
-
persistent: persistent,
|
|
145
|
-
description: collection.description,
|
|
146
|
-
variableMutators: new Map(collection.mutators)
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
restorePersisted(jsonValue) {
|
|
150
|
-
const collectionsJson = JSON.parse(jsonValue);
|
|
151
|
-
collectionsJson.forEach(c => { var _a; return this.doSetCollection(c.extensionIdentifier, (_a = c.rootUri) !== null && _a !== void 0 ? _a : shell_terminal_protocol_1.NO_ROOT_URI, true, c.collection); });
|
|
152
|
-
}
|
|
153
|
-
deleteCollection(extensionIdentifier) {
|
|
154
|
-
this.collections.delete([extensionIdentifier]);
|
|
155
|
-
this.updateCollections();
|
|
156
|
-
}
|
|
157
|
-
updateCollections() {
|
|
158
|
-
this.persistCollections();
|
|
159
|
-
}
|
|
160
|
-
persistCollections() {
|
|
161
|
-
const collectionsJson = [];
|
|
162
|
-
this.collections.forEach((collection, [extensionIdentifier, rootUri]) => {
|
|
163
|
-
if (collection.persistent) {
|
|
164
|
-
collectionsJson.push({
|
|
165
|
-
extensionIdentifier,
|
|
166
|
-
rootUri,
|
|
167
|
-
collection: {
|
|
168
|
-
description: collection.description,
|
|
169
|
-
mutators: [...this.collections.get([extensionIdentifier, rootUri]).variableMutators.entries()]
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
if (this.client) {
|
|
175
|
-
const stringifiedJson = JSON.stringify(collectionsJson);
|
|
176
|
-
this.client.storeTerminalEnvVariables(stringifiedJson);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
async getEnvVarCollectionDescriptionsByExtension(id) {
|
|
180
|
-
const terminal = this.processManager.get(id);
|
|
181
|
-
if (!(terminal instanceof node_1.TerminalProcess)) {
|
|
182
|
-
throw new Error(`terminal "${id}" does not exist`);
|
|
183
|
-
}
|
|
184
|
-
const result = new Map();
|
|
185
|
-
this.collections.forEach((value, key) => {
|
|
186
|
-
const prev = result.get(key[0]) || [];
|
|
187
|
-
prev.push(value.description);
|
|
188
|
-
result.set(key[0], prev);
|
|
189
|
-
});
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
192
|
-
async getEnvVarCollections() {
|
|
193
|
-
const result = [];
|
|
194
|
-
this.collections.forEach((value, [extensionIdentifier, rootUri]) => {
|
|
195
|
-
result.push([extensionIdentifier, rootUri, value.persistent, { description: value.description, mutators: [...value.variableMutators.entries()] }]);
|
|
196
|
-
});
|
|
197
|
-
return result;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
__decorate([
|
|
201
|
-
(0, inversify_1.inject)(environment_utils_1.EnvironmentUtils),
|
|
202
|
-
__metadata("design:type", environment_utils_1.EnvironmentUtils)
|
|
203
|
-
], ShellTerminalServer.prototype, "environmentUtils", void 0);
|
|
204
|
-
ShellTerminalServer = __decorate([
|
|
205
|
-
(0, inversify_1.injectable)(),
|
|
206
|
-
__param(0, (0, inversify_1.inject)(shell_process_1.ShellProcessFactory)),
|
|
207
|
-
__param(1, (0, inversify_1.inject)(node_1.ProcessManager)),
|
|
208
|
-
__param(2, (0, inversify_1.inject)(logger_1.ILogger)),
|
|
209
|
-
__param(2, (0, inversify_1.named)('terminal')),
|
|
210
|
-
__metadata("design:paramtypes", [Function, node_1.ProcessManager, Object])
|
|
211
|
-
], ShellTerminalServer);
|
|
212
|
-
exports.ShellTerminalServer = ShellTerminalServer;
|
|
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.ShellTerminalServer = void 0;
|
|
31
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
32
|
+
const logger_1 = require("@theia/core/lib/common/logger");
|
|
33
|
+
const environment_utils_1 = require("@theia/core/lib/node/environment-utils");
|
|
34
|
+
const base_terminal_server_1 = require("./base-terminal-server");
|
|
35
|
+
const shell_process_1 = require("./shell-process");
|
|
36
|
+
const node_1 = require("@theia/process/lib/node");
|
|
37
|
+
const os_1 = require("@theia/core/lib/common/os");
|
|
38
|
+
const cp = require("child_process");
|
|
39
|
+
const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
|
|
40
|
+
const core_1 = require("@theia/core");
|
|
41
|
+
const collections_1 = require("@theia/core/lib/common/collections");
|
|
42
|
+
let ShellTerminalServer = class ShellTerminalServer extends base_terminal_server_1.BaseTerminalServer {
|
|
43
|
+
constructor(shellFactory, processManager, logger) {
|
|
44
|
+
super(processManager, logger);
|
|
45
|
+
this.shellFactory = shellFactory;
|
|
46
|
+
this.collections = new collections_1.MultiKeyMap(2);
|
|
47
|
+
}
|
|
48
|
+
async create(options) {
|
|
49
|
+
try {
|
|
50
|
+
if (options.strictEnv !== true) {
|
|
51
|
+
options.env = this.environmentUtils.mergeProcessEnv(options.env);
|
|
52
|
+
this.applyToProcessEnvironment(core_1.URI.fromFilePath((0, shell_process_1.getRootPath)(options.rootURI)), options.env);
|
|
53
|
+
}
|
|
54
|
+
const term = this.shellFactory(options);
|
|
55
|
+
this.postCreate(term);
|
|
56
|
+
return term.id;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.logger.error('Error while creating terminal', error);
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
|
|
64
|
+
spawnAsPromised(command, args) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
let stdout = '';
|
|
67
|
+
const child = cp.spawn(command, args);
|
|
68
|
+
if (child.pid) {
|
|
69
|
+
child.stdout.on('data', (data) => {
|
|
70
|
+
stdout += data.toString();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
child.on('error', err => {
|
|
74
|
+
reject(err);
|
|
75
|
+
});
|
|
76
|
+
child.on('close', code => {
|
|
77
|
+
resolve(stdout);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
hasChildProcesses(processId) {
|
|
82
|
+
if (processId) {
|
|
83
|
+
// if shell has at least one child process, assume that shell is busy
|
|
84
|
+
if (os_1.isWindows) {
|
|
85
|
+
return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
|
|
86
|
+
const pids = stdout.split('\r\n');
|
|
87
|
+
return pids.some(p => parseInt(p) === processId);
|
|
88
|
+
}, error => true);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
|
|
92
|
+
const r = stdout.trim();
|
|
93
|
+
if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}, error => true);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// fall back to safe side
|
|
103
|
+
return Promise.resolve(true);
|
|
104
|
+
}
|
|
105
|
+
applyToProcessEnvironment(cwdUri, env) {
|
|
106
|
+
let lowerToActualVariableNames;
|
|
107
|
+
if (os_1.isWindows) {
|
|
108
|
+
lowerToActualVariableNames = {};
|
|
109
|
+
Object.keys(env).forEach(e => lowerToActualVariableNames[e.toLowerCase()] = e);
|
|
110
|
+
}
|
|
111
|
+
this.collections.forEach((mutators, [extensionIdentifier, rootUri]) => {
|
|
112
|
+
if (rootUri === shell_terminal_protocol_1.NO_ROOT_URI || this.matchesRootUri(cwdUri, rootUri)) {
|
|
113
|
+
mutators.variableMutators.forEach((mutator, variable) => {
|
|
114
|
+
const actualVariable = os_1.isWindows ? lowerToActualVariableNames[variable.toLowerCase()] || variable : variable;
|
|
115
|
+
switch (mutator.type) {
|
|
116
|
+
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Append:
|
|
117
|
+
env[actualVariable] = (env[actualVariable] || '') + mutator.value;
|
|
118
|
+
break;
|
|
119
|
+
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Prepend:
|
|
120
|
+
env[actualVariable] = mutator.value + (env[actualVariable] || '');
|
|
121
|
+
break;
|
|
122
|
+
case shell_terminal_protocol_1.EnvironmentVariableMutatorType.Replace:
|
|
123
|
+
env[actualVariable] = mutator.value;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
matchesRootUri(cwdUri, rootUri) {
|
|
131
|
+
return new core_1.URI(rootUri).isEqualOrParent(cwdUri);
|
|
132
|
+
}
|
|
133
|
+
/*---------------------------------------------------------------------------------------------
|
|
134
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
135
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
136
|
+
*--------------------------------------------------------------------------------------------*/
|
|
137
|
+
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
|
|
138
|
+
setCollection(extensionIdentifier, baseUri, persistent, collection) {
|
|
139
|
+
this.doSetCollection(extensionIdentifier, baseUri, persistent, collection);
|
|
140
|
+
this.updateCollections();
|
|
141
|
+
}
|
|
142
|
+
doSetCollection(extensionIdentifier, baseUri, persistent, collection) {
|
|
143
|
+
this.collections.set([extensionIdentifier, baseUri], {
|
|
144
|
+
persistent: persistent,
|
|
145
|
+
description: collection.description,
|
|
146
|
+
variableMutators: new Map(collection.mutators)
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
restorePersisted(jsonValue) {
|
|
150
|
+
const collectionsJson = JSON.parse(jsonValue);
|
|
151
|
+
collectionsJson.forEach(c => { var _a; return this.doSetCollection(c.extensionIdentifier, (_a = c.rootUri) !== null && _a !== void 0 ? _a : shell_terminal_protocol_1.NO_ROOT_URI, true, c.collection); });
|
|
152
|
+
}
|
|
153
|
+
deleteCollection(extensionIdentifier) {
|
|
154
|
+
this.collections.delete([extensionIdentifier]);
|
|
155
|
+
this.updateCollections();
|
|
156
|
+
}
|
|
157
|
+
updateCollections() {
|
|
158
|
+
this.persistCollections();
|
|
159
|
+
}
|
|
160
|
+
persistCollections() {
|
|
161
|
+
const collectionsJson = [];
|
|
162
|
+
this.collections.forEach((collection, [extensionIdentifier, rootUri]) => {
|
|
163
|
+
if (collection.persistent) {
|
|
164
|
+
collectionsJson.push({
|
|
165
|
+
extensionIdentifier,
|
|
166
|
+
rootUri,
|
|
167
|
+
collection: {
|
|
168
|
+
description: collection.description,
|
|
169
|
+
mutators: [...this.collections.get([extensionIdentifier, rootUri]).variableMutators.entries()]
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
if (this.client) {
|
|
175
|
+
const stringifiedJson = JSON.stringify(collectionsJson);
|
|
176
|
+
this.client.storeTerminalEnvVariables(stringifiedJson);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async getEnvVarCollectionDescriptionsByExtension(id) {
|
|
180
|
+
const terminal = this.processManager.get(id);
|
|
181
|
+
if (!(terminal instanceof node_1.TerminalProcess)) {
|
|
182
|
+
throw new Error(`terminal "${id}" does not exist`);
|
|
183
|
+
}
|
|
184
|
+
const result = new Map();
|
|
185
|
+
this.collections.forEach((value, key) => {
|
|
186
|
+
const prev = result.get(key[0]) || [];
|
|
187
|
+
prev.push(value.description);
|
|
188
|
+
result.set(key[0], prev);
|
|
189
|
+
});
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
async getEnvVarCollections() {
|
|
193
|
+
const result = [];
|
|
194
|
+
this.collections.forEach((value, [extensionIdentifier, rootUri]) => {
|
|
195
|
+
result.push([extensionIdentifier, rootUri, value.persistent, { description: value.description, mutators: [...value.variableMutators.entries()] }]);
|
|
196
|
+
});
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
__decorate([
|
|
201
|
+
(0, inversify_1.inject)(environment_utils_1.EnvironmentUtils),
|
|
202
|
+
__metadata("design:type", environment_utils_1.EnvironmentUtils)
|
|
203
|
+
], ShellTerminalServer.prototype, "environmentUtils", void 0);
|
|
204
|
+
ShellTerminalServer = __decorate([
|
|
205
|
+
(0, inversify_1.injectable)(),
|
|
206
|
+
__param(0, (0, inversify_1.inject)(shell_process_1.ShellProcessFactory)),
|
|
207
|
+
__param(1, (0, inversify_1.inject)(node_1.ProcessManager)),
|
|
208
|
+
__param(2, (0, inversify_1.inject)(logger_1.ILogger)),
|
|
209
|
+
__param(2, (0, inversify_1.named)('terminal')),
|
|
210
|
+
__metadata("design:paramtypes", [Function, node_1.ProcessManager, Object])
|
|
211
|
+
], ShellTerminalServer);
|
|
212
|
+
exports.ShellTerminalServer = ShellTerminalServer;
|
|
213
213
|
//# sourceMappingURL=shell-terminal-server.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=shell-terminal-server.spec.d.ts.map
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// *****************************************************************************
|
|
4
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
5
|
-
//
|
|
6
|
-
// This program and the accompanying materials are made available under the
|
|
7
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
8
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
9
|
-
//
|
|
10
|
-
// This Source Code may also be made available under the following Secondary
|
|
11
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
12
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
13
|
-
// with the GNU Classpath Exception which is available at
|
|
14
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
15
|
-
//
|
|
16
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
17
|
-
// *****************************************************************************
|
|
18
|
-
const chai = require("chai");
|
|
19
|
-
const terminal_test_container_1 = require("./test/terminal-test-container");
|
|
20
|
-
const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
|
|
21
|
-
/**
|
|
22
|
-
* Globals
|
|
23
|
-
*/
|
|
24
|
-
const expect = chai.expect;
|
|
25
|
-
describe('ShellServer', function () {
|
|
26
|
-
this.timeout(5000);
|
|
27
|
-
let shellTerminalServer;
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
shellTerminalServer = (0, terminal_test_container_1.createTerminalTestContainer)().get(shell_terminal_protocol_1.IShellTerminalServer);
|
|
30
|
-
});
|
|
31
|
-
it('test shell terminal create', async function () {
|
|
32
|
-
const createResult = shellTerminalServer.create({});
|
|
33
|
-
expect(await createResult).to.be.greaterThan(-1);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// *****************************************************************************
|
|
4
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
5
|
+
//
|
|
6
|
+
// This program and the accompanying materials are made available under the
|
|
7
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
8
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
9
|
+
//
|
|
10
|
+
// This Source Code may also be made available under the following Secondary
|
|
11
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
12
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
13
|
+
// with the GNU Classpath Exception which is available at
|
|
14
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
15
|
+
//
|
|
16
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
17
|
+
// *****************************************************************************
|
|
18
|
+
const chai = require("chai");
|
|
19
|
+
const terminal_test_container_1 = require("./test/terminal-test-container");
|
|
20
|
+
const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
|
|
21
|
+
/**
|
|
22
|
+
* Globals
|
|
23
|
+
*/
|
|
24
|
+
const expect = chai.expect;
|
|
25
|
+
describe('ShellServer', function () {
|
|
26
|
+
this.timeout(5000);
|
|
27
|
+
let shellTerminalServer;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
shellTerminalServer = (0, terminal_test_container_1.createTerminalTestContainer)().get(shell_terminal_protocol_1.IShellTerminalServer);
|
|
30
|
+
});
|
|
31
|
+
it('test shell terminal create', async function () {
|
|
32
|
+
const createResult = shellTerminalServer.create({});
|
|
33
|
+
expect(await createResult).to.be.greaterThan(-1);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
36
|
//# sourceMappingURL=shell-terminal-server.spec.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ILogger } from '@theia/core/lib/common';
|
|
2
|
-
import { ProcessManager } from '@theia/process/lib/node';
|
|
3
|
-
import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service';
|
|
4
|
-
export declare class TerminalBackendContribution implements MessagingService.Contribution {
|
|
5
|
-
protected readonly decoder: TextDecoder;
|
|
6
|
-
protected readonly processManager: ProcessManager;
|
|
7
|
-
protected readonly logger: ILogger;
|
|
8
|
-
configure(service: MessagingService): void;
|
|
9
|
-
}
|
|
1
|
+
import { ILogger } from '@theia/core/lib/common';
|
|
2
|
+
import { ProcessManager } from '@theia/process/lib/node';
|
|
3
|
+
import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service';
|
|
4
|
+
export declare class TerminalBackendContribution implements MessagingService.Contribution {
|
|
5
|
+
protected readonly decoder: TextDecoder;
|
|
6
|
+
protected readonly processManager: ProcessManager;
|
|
7
|
+
protected readonly logger: ILogger;
|
|
8
|
+
configure(service: MessagingService): void;
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=terminal-backend-contribution.d.ts.map
|