@theia/external-terminal 1.53.0-next.5 → 1.53.0-next.55
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 +46 -46
- package/package.json +6 -6
- package/src/common/external-terminal.ts +55 -55
- package/src/electron-browser/external-terminal-contribution.ts +116 -116
- package/src/electron-browser/external-terminal-frontend-module.ts +33 -33
- package/src/electron-browser/external-terminal-preference.ts +109 -109
- package/src/electron-node/external-terminal-backend-module.ts +40 -40
- package/src/electron-node/linux-external-terminal-service.ts +95 -95
- package/src/electron-node/mac-external-terminal-service.ts +70 -70
- package/src/electron-node/windows-external-terminal-service.ts +110 -110
- package/src/package.spec.ts +29 -29
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as cp from 'child_process';
|
|
18
|
-
import * as path from 'path';
|
|
19
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
20
|
-
import { FileUri } from '@theia/core/lib/common/file-uri';
|
|
21
|
-
import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
|
|
22
|
-
|
|
23
|
-
/*---------------------------------------------------------------------------------------------
|
|
24
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
25
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
26
|
-
*--------------------------------------------------------------------------------------------*/
|
|
27
|
-
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
|
|
28
|
-
|
|
29
|
-
@injectable()
|
|
30
|
-
export class WindowsExternalTerminalService implements ExternalTerminalService {
|
|
31
|
-
protected readonly CMD = 'cmd.exe';
|
|
32
|
-
protected DEFAULT_TERMINAL_WINDOWS: string;
|
|
33
|
-
|
|
34
|
-
async openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void> {
|
|
35
|
-
await this.spawnTerminal(configuration, FileUri.fsPath(cwd));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async getDefaultExec(): Promise<string> {
|
|
39
|
-
return this.getDefaultTerminalWindows();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Spawn the external terminal for the given options.
|
|
44
|
-
* - The method spawns the terminal application based on the preferences, else uses the default value.
|
|
45
|
-
* @param configuration the preference configuration.
|
|
46
|
-
* @param cwd the optional current working directory to spawn from.
|
|
47
|
-
*/
|
|
48
|
-
protected async spawnTerminal(configuration: ExternalTerminalConfiguration, cwd?: string): Promise<void> {
|
|
49
|
-
|
|
50
|
-
// Use the executable value from the preferences if available, else fallback to the default.
|
|
51
|
-
const terminalConfig = configuration['terminal.external.windowsExec'];
|
|
52
|
-
const exec = terminalConfig || this.getDefaultTerminalWindows();
|
|
53
|
-
|
|
54
|
-
// Make the drive letter uppercase on Windows (https://github.com/microsoft/vscode/issues/9448).
|
|
55
|
-
if (cwd && cwd[1] === ':') {
|
|
56
|
-
cwd = cwd[0].toUpperCase() + cwd.substring(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// cmder ignores the environment cwd and instead opts to always open in %USERPROFILE%
|
|
60
|
-
// unless otherwise specified.
|
|
61
|
-
const basename = path.basename(exec).toLowerCase();
|
|
62
|
-
if (basename === 'cmder' || basename === 'cmder.exe') {
|
|
63
|
-
cp.spawn(exec, cwd ? [cwd] : undefined);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const cmdArgs = ['/c', 'start', '/wait'];
|
|
68
|
-
// The "" argument is the window title. Without this, exec doesn't work when the path contains spaces.
|
|
69
|
-
if (exec.indexOf(' ') >= 0) {
|
|
70
|
-
cmdArgs.push('""');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
cmdArgs.push(exec);
|
|
74
|
-
|
|
75
|
-
// Add starting directory parameter for Windows Terminal app.
|
|
76
|
-
if (basename === 'wt' || basename === 'wt.exe') {
|
|
77
|
-
cmdArgs.push('-d .');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return new Promise<void>(async (resolve, reject) => {
|
|
81
|
-
const env = cwd ? { cwd } : undefined;
|
|
82
|
-
const command = this.getWindowsShell();
|
|
83
|
-
const child = cp.spawn(command, cmdArgs, env);
|
|
84
|
-
child.on('error', reject);
|
|
85
|
-
child.on('exit', resolve);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Get the default terminal application on Windows.
|
|
91
|
-
* - The following method uses environment variables to identify the best default possible value.
|
|
92
|
-
*
|
|
93
|
-
* @returns the default application on Windows.
|
|
94
|
-
*/
|
|
95
|
-
protected getDefaultTerminalWindows(): string {
|
|
96
|
-
if (!this.DEFAULT_TERMINAL_WINDOWS) {
|
|
97
|
-
const isWoW64 = !!process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
|
|
98
|
-
this.DEFAULT_TERMINAL_WINDOWS = `${process.env.windir ? process.env.windir : 'C:\\Windows'}\\${isWoW64 ? 'Sysnative' : 'System32'}\\cmd.exe`;
|
|
99
|
-
}
|
|
100
|
-
return this.DEFAULT_TERMINAL_WINDOWS;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Find the Windows Shell process to start up (defaults to cmd.exe).
|
|
105
|
-
*/
|
|
106
|
-
protected getWindowsShell(): string {
|
|
107
|
-
// Find the path to cmd.exe if possible (%compsec% environment variable).
|
|
108
|
-
return process.env.compsec || this.CMD;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as cp from 'child_process';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { FileUri } from '@theia/core/lib/common/file-uri';
|
|
21
|
+
import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
|
|
22
|
+
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
25
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
// some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
|
|
28
|
+
|
|
29
|
+
@injectable()
|
|
30
|
+
export class WindowsExternalTerminalService implements ExternalTerminalService {
|
|
31
|
+
protected readonly CMD = 'cmd.exe';
|
|
32
|
+
protected DEFAULT_TERMINAL_WINDOWS: string;
|
|
33
|
+
|
|
34
|
+
async openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void> {
|
|
35
|
+
await this.spawnTerminal(configuration, FileUri.fsPath(cwd));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getDefaultExec(): Promise<string> {
|
|
39
|
+
return this.getDefaultTerminalWindows();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Spawn the external terminal for the given options.
|
|
44
|
+
* - The method spawns the terminal application based on the preferences, else uses the default value.
|
|
45
|
+
* @param configuration the preference configuration.
|
|
46
|
+
* @param cwd the optional current working directory to spawn from.
|
|
47
|
+
*/
|
|
48
|
+
protected async spawnTerminal(configuration: ExternalTerminalConfiguration, cwd?: string): Promise<void> {
|
|
49
|
+
|
|
50
|
+
// Use the executable value from the preferences if available, else fallback to the default.
|
|
51
|
+
const terminalConfig = configuration['terminal.external.windowsExec'];
|
|
52
|
+
const exec = terminalConfig || this.getDefaultTerminalWindows();
|
|
53
|
+
|
|
54
|
+
// Make the drive letter uppercase on Windows (https://github.com/microsoft/vscode/issues/9448).
|
|
55
|
+
if (cwd && cwd[1] === ':') {
|
|
56
|
+
cwd = cwd[0].toUpperCase() + cwd.substring(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// cmder ignores the environment cwd and instead opts to always open in %USERPROFILE%
|
|
60
|
+
// unless otherwise specified.
|
|
61
|
+
const basename = path.basename(exec).toLowerCase();
|
|
62
|
+
if (basename === 'cmder' || basename === 'cmder.exe') {
|
|
63
|
+
cp.spawn(exec, cwd ? [cwd] : undefined);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const cmdArgs = ['/c', 'start', '/wait'];
|
|
68
|
+
// The "" argument is the window title. Without this, exec doesn't work when the path contains spaces.
|
|
69
|
+
if (exec.indexOf(' ') >= 0) {
|
|
70
|
+
cmdArgs.push('""');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
cmdArgs.push(exec);
|
|
74
|
+
|
|
75
|
+
// Add starting directory parameter for Windows Terminal app.
|
|
76
|
+
if (basename === 'wt' || basename === 'wt.exe') {
|
|
77
|
+
cmdArgs.push('-d .');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return new Promise<void>(async (resolve, reject) => {
|
|
81
|
+
const env = cwd ? { cwd } : undefined;
|
|
82
|
+
const command = this.getWindowsShell();
|
|
83
|
+
const child = cp.spawn(command, cmdArgs, env);
|
|
84
|
+
child.on('error', reject);
|
|
85
|
+
child.on('exit', resolve);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the default terminal application on Windows.
|
|
91
|
+
* - The following method uses environment variables to identify the best default possible value.
|
|
92
|
+
*
|
|
93
|
+
* @returns the default application on Windows.
|
|
94
|
+
*/
|
|
95
|
+
protected getDefaultTerminalWindows(): string {
|
|
96
|
+
if (!this.DEFAULT_TERMINAL_WINDOWS) {
|
|
97
|
+
const isWoW64 = !!process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
|
|
98
|
+
this.DEFAULT_TERMINAL_WINDOWS = `${process.env.windir ? process.env.windir : 'C:\\Windows'}\\${isWoW64 ? 'Sysnative' : 'System32'}\\cmd.exe`;
|
|
99
|
+
}
|
|
100
|
+
return this.DEFAULT_TERMINAL_WINDOWS;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Find the Windows Shell process to start up (defaults to cmd.exe).
|
|
105
|
+
*/
|
|
106
|
+
protected getWindowsShell(): string {
|
|
107
|
+
// Find the path to cmd.exe if possible (%compsec% environment variable).
|
|
108
|
+
return process.env.compsec || this.CMD;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/package.spec.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
/* note: this bogus test file is required so that
|
|
18
|
-
we are able to run mocha unit tests on this
|
|
19
|
-
package, without having any actual unit tests in it.
|
|
20
|
-
This way a coverage report will be generated,
|
|
21
|
-
showing 0% coverage, instead of no report.
|
|
22
|
-
This file can be removed once we have real unit
|
|
23
|
-
tests in place. */
|
|
24
|
-
|
|
25
|
-
describe('external-terminal package', () => {
|
|
26
|
-
|
|
27
|
-
it('support code coverage statistics', () => true);
|
|
28
|
-
|
|
29
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2021 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
/* note: this bogus test file is required so that
|
|
18
|
+
we are able to run mocha unit tests on this
|
|
19
|
+
package, without having any actual unit tests in it.
|
|
20
|
+
This way a coverage report will be generated,
|
|
21
|
+
showing 0% coverage, instead of no report.
|
|
22
|
+
This file can be removed once we have real unit
|
|
23
|
+
tests in place. */
|
|
24
|
+
|
|
25
|
+
describe('external-terminal package', () => {
|
|
26
|
+
|
|
27
|
+
it('support code coverage statistics', () => true);
|
|
28
|
+
|
|
29
|
+
});
|