@theia/external-terminal 1.34.3 → 1.34.4

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 (29) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +46 -46
  3. package/lib/common/external-terminal.d.ts +34 -34
  4. package/lib/common/external-terminal.js +20 -20
  5. package/lib/electron-browser/external-terminal-contribution.d.ts +35 -35
  6. package/lib/electron-browser/external-terminal-contribution.js +128 -128
  7. package/lib/electron-browser/external-terminal-frontend-module.d.ts +3 -3
  8. package/lib/electron-browser/external-terminal-frontend-module.js +29 -29
  9. package/lib/electron-browser/external-terminal-preference.d.ts +26 -26
  10. package/lib/electron-browser/external-terminal-preference.js +109 -109
  11. package/lib/electron-node/external-terminal-backend-module.d.ts +4 -4
  12. package/lib/electron-node/external-terminal-backend-module.js +35 -35
  13. package/lib/electron-node/linux-external-terminal-service.d.ts +20 -20
  14. package/lib/electron-node/linux-external-terminal-service.js +102 -102
  15. package/lib/electron-node/mac-external-terminal-service.d.ts +18 -18
  16. package/lib/electron-node/mac-external-terminal-service.js +74 -74
  17. package/lib/electron-node/windows-external-terminal-service.d.ts +25 -25
  18. package/lib/electron-node/windows-external-terminal-service.js +107 -107
  19. package/lib/package.spec.js +25 -25
  20. package/package.json +6 -6
  21. package/src/common/external-terminal.ts +55 -55
  22. package/src/electron-browser/external-terminal-contribution.ts +116 -116
  23. package/src/electron-browser/external-terminal-frontend-module.ts +33 -33
  24. package/src/electron-browser/external-terminal-preference.ts +106 -106
  25. package/src/electron-node/external-terminal-backend-module.ts +40 -40
  26. package/src/electron-node/linux-external-terminal-service.ts +95 -95
  27. package/src/electron-node/mac-external-terminal-service.ts +70 -70
  28. package/src/electron-node/windows-external-terminal-service.ts +110 -110
  29. package/src/package.spec.ts +29 -29
@@ -1,40 +1,40 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
- import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core/lib/common';
19
- import { isWindows, isOSX } from '@theia/core/lib/common/os';
20
- import { ExternalTerminalService, externalTerminalServicePath } from '../common/external-terminal';
21
- import { MacExternalTerminalService } from './mac-external-terminal-service';
22
- import { LinuxExternalTerminalService } from './linux-external-terminal-service';
23
- import { WindowsExternalTerminalService } from './windows-external-terminal-service';
24
-
25
- export function bindExternalTerminalService(bind: interfaces.Bind): void {
26
- const serviceProvider: interfaces.ServiceIdentifier<ExternalTerminalService> =
27
- isWindows ? WindowsExternalTerminalService : isOSX ? MacExternalTerminalService : LinuxExternalTerminalService;
28
- bind(serviceProvider).toSelf().inSingletonScope();
29
- bind(ExternalTerminalService).toService(serviceProvider);
30
-
31
- bind(ConnectionHandler).toDynamicValue(ctx =>
32
- new JsonRpcConnectionHandler(externalTerminalServicePath, () =>
33
- ctx.container.get(ExternalTerminalService)
34
- )
35
- ).inSingletonScope();
36
- }
37
-
38
- export default new ContainerModule(bind => {
39
- bindExternalTerminalService(bind);
40
- });
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
+ import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core/lib/common';
19
+ import { isWindows, isOSX } from '@theia/core/lib/common/os';
20
+ import { ExternalTerminalService, externalTerminalServicePath } from '../common/external-terminal';
21
+ import { MacExternalTerminalService } from './mac-external-terminal-service';
22
+ import { LinuxExternalTerminalService } from './linux-external-terminal-service';
23
+ import { WindowsExternalTerminalService } from './windows-external-terminal-service';
24
+
25
+ export function bindExternalTerminalService(bind: interfaces.Bind): void {
26
+ const serviceProvider: interfaces.ServiceIdentifier<ExternalTerminalService> =
27
+ isWindows ? WindowsExternalTerminalService : isOSX ? MacExternalTerminalService : LinuxExternalTerminalService;
28
+ bind(serviceProvider).toSelf().inSingletonScope();
29
+ bind(ExternalTerminalService).toService(serviceProvider);
30
+
31
+ bind(ConnectionHandler).toDynamicValue(ctx =>
32
+ new JsonRpcConnectionHandler(externalTerminalServicePath, () =>
33
+ ctx.container.get(ExternalTerminalService)
34
+ )
35
+ ).inSingletonScope();
36
+ }
37
+
38
+ export default new ContainerModule(bind => {
39
+ bindExternalTerminalService(bind);
40
+ });
@@ -1,95 +1,95 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as cp from 'child_process';
18
- import * as fs from '@theia/core/shared/fs-extra';
19
- import { injectable } from '@theia/core/shared/inversify';
20
- import { OS } from '@theia/core/lib/common/os';
21
- import { FileUri } from '@theia/core/lib/node/file-uri';
22
- import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
23
-
24
- /*---------------------------------------------------------------------------------------------
25
- * Copyright (c) Microsoft Corporation. All rights reserved.
26
- * Licensed under the MIT License. See License.txt in the project root for license information.
27
- *--------------------------------------------------------------------------------------------*/
28
- // some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
29
-
30
- @injectable()
31
- export class LinuxExternalTerminalService implements ExternalTerminalService {
32
- protected DEFAULT_TERMINAL_LINUX_READY: Promise<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.getDefaultTerminalLinux();
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.linuxExec'];
52
- const execPromise = terminalConfig ? Promise.resolve(terminalConfig) : this.getDefaultTerminalLinux();
53
-
54
- return new Promise<void>((resolve, reject) => {
55
- execPromise.then(exec => {
56
- const env = cwd ? { cwd } : undefined;
57
- const child = cp.spawn(exec, [], env);
58
- child.on('error', reject);
59
- child.on('exit', resolve);
60
- });
61
- });
62
- }
63
-
64
- /**
65
- * Get the default terminal application on Linux.
66
- * - The following method uses environment variables to identify the best default possible for each distro.
67
- *
68
- * @returns the default application on Linux.
69
- */
70
- protected async getDefaultTerminalLinux(): Promise<string> {
71
- if (!this.DEFAULT_TERMINAL_LINUX_READY) {
72
- this.DEFAULT_TERMINAL_LINUX_READY = new Promise(async resolve => {
73
- if (OS.type() === OS.Type.Linux) {
74
- const isDebian = await fs.pathExists('/etc/debian_version');
75
- if (isDebian) {
76
- resolve('x-terminal-emulator');
77
- } else if (process.env.DESKTOP_SESSION === 'gnome' || process.env.DESKTOP_SESSION === 'gnome-classic') {
78
- resolve('gnome-terminal');
79
- } else if (process.env.DESKTOP_SESSION === 'kde-plasma') {
80
- resolve('konsole');
81
- } else if (process.env.COLORTERM) {
82
- resolve(process.env.COLORTERM);
83
- } else if (process.env.TERM) {
84
- resolve(process.env.TERM);
85
- } else {
86
- resolve('xterm');
87
- }
88
- } else {
89
- resolve('xterm');
90
- }
91
- });
92
- }
93
- return this.DEFAULT_TERMINAL_LINUX_READY;
94
- }
95
- }
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as cp from 'child_process';
18
+ import * as fs from '@theia/core/shared/fs-extra';
19
+ import { injectable } from '@theia/core/shared/inversify';
20
+ import { OS } from '@theia/core/lib/common/os';
21
+ import { FileUri } from '@theia/core/lib/node/file-uri';
22
+ import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
23
+
24
+ /*---------------------------------------------------------------------------------------------
25
+ * Copyright (c) Microsoft Corporation. All rights reserved.
26
+ * Licensed under the MIT License. See License.txt in the project root for license information.
27
+ *--------------------------------------------------------------------------------------------*/
28
+ // some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
29
+
30
+ @injectable()
31
+ export class LinuxExternalTerminalService implements ExternalTerminalService {
32
+ protected DEFAULT_TERMINAL_LINUX_READY: Promise<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.getDefaultTerminalLinux();
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.linuxExec'];
52
+ const execPromise = terminalConfig ? Promise.resolve(terminalConfig) : this.getDefaultTerminalLinux();
53
+
54
+ return new Promise<void>((resolve, reject) => {
55
+ execPromise.then(exec => {
56
+ const env = cwd ? { cwd } : undefined;
57
+ const child = cp.spawn(exec, [], env);
58
+ child.on('error', reject);
59
+ child.on('exit', resolve);
60
+ });
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Get the default terminal application on Linux.
66
+ * - The following method uses environment variables to identify the best default possible for each distro.
67
+ *
68
+ * @returns the default application on Linux.
69
+ */
70
+ protected async getDefaultTerminalLinux(): Promise<string> {
71
+ if (!this.DEFAULT_TERMINAL_LINUX_READY) {
72
+ this.DEFAULT_TERMINAL_LINUX_READY = new Promise(async resolve => {
73
+ if (OS.type() === OS.Type.Linux) {
74
+ const isDebian = await fs.pathExists('/etc/debian_version');
75
+ if (isDebian) {
76
+ resolve('x-terminal-emulator');
77
+ } else if (process.env.DESKTOP_SESSION === 'gnome' || process.env.DESKTOP_SESSION === 'gnome-classic') {
78
+ resolve('gnome-terminal');
79
+ } else if (process.env.DESKTOP_SESSION === 'kde-plasma') {
80
+ resolve('konsole');
81
+ } else if (process.env.COLORTERM) {
82
+ resolve(process.env.COLORTERM);
83
+ } else if (process.env.TERM) {
84
+ resolve(process.env.TERM);
85
+ } else {
86
+ resolve('xterm');
87
+ }
88
+ } else {
89
+ resolve('xterm');
90
+ }
91
+ });
92
+ }
93
+ return this.DEFAULT_TERMINAL_LINUX_READY;
94
+ }
95
+ }
@@ -1,70 +1,70 @@
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 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as cp from 'child_process';
18
- import { injectable } from '@theia/core/shared/inversify';
19
- import { FileUri } from '@theia/core/lib/node/file-uri';
20
- import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
21
-
22
- /*---------------------------------------------------------------------------------------------
23
- * Copyright (c) Microsoft Corporation. All rights reserved.
24
- * Licensed under the MIT License. See License.txt in the project root for license information.
25
- *--------------------------------------------------------------------------------------------*/
26
- // some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
27
-
28
- @injectable()
29
- export class MacExternalTerminalService implements ExternalTerminalService {
30
- protected osxOpener = '/usr/bin/open';
31
- protected defaultTerminalApp = 'Terminal.app';
32
-
33
- async openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void> {
34
- await this.spawnTerminal(configuration, FileUri.fsPath(cwd));
35
- }
36
-
37
- async getDefaultExec(): Promise<string> {
38
- return this.getDefaultTerminalOSX();
39
- }
40
-
41
- /**
42
- * Spawn the external terminal for the given options.
43
- * - The method spawns the terminal application based on the preferences, else uses the default value.
44
- * @param configuration the preference configuration.
45
- * @param cwd the optional current working directory to spawn from.
46
- */
47
- protected async spawnTerminal(configuration: ExternalTerminalConfiguration, cwd?: string): Promise<void> {
48
-
49
- // Use the executable value from the preferences if available, else fallback to the default.
50
- const terminalConfig = configuration['terminal.external.osxExec'];
51
- const terminalApp = terminalConfig || this.getDefaultTerminalOSX();
52
-
53
- return new Promise<void>((resolve, reject) => {
54
- const args = ['-a', terminalApp];
55
- if (cwd) {
56
- args.push(cwd);
57
- }
58
- const child = cp.spawn(this.osxOpener, args);
59
- child.on('error', reject);
60
- child.on('exit', () => resolve());
61
- });
62
- }
63
-
64
- /**
65
- * Get the default terminal app on OSX.
66
- */
67
- protected getDefaultTerminalOSX(): string {
68
- return this.defaultTerminalApp;
69
- }
70
- }
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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as cp from 'child_process';
18
+ import { injectable } from '@theia/core/shared/inversify';
19
+ import { FileUri } from '@theia/core/lib/node/file-uri';
20
+ import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
21
+
22
+ /*---------------------------------------------------------------------------------------------
23
+ * Copyright (c) Microsoft Corporation. All rights reserved.
24
+ * Licensed under the MIT License. See License.txt in the project root for license information.
25
+ *--------------------------------------------------------------------------------------------*/
26
+ // some code copied and modified from https://github.com/microsoft/vscode/blob/1.52.1/src/vs/workbench/contrib/externalTerminal/node/externalTerminalService.ts
27
+
28
+ @injectable()
29
+ export class MacExternalTerminalService implements ExternalTerminalService {
30
+ protected osxOpener = '/usr/bin/open';
31
+ protected defaultTerminalApp = 'Terminal.app';
32
+
33
+ async openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void> {
34
+ await this.spawnTerminal(configuration, FileUri.fsPath(cwd));
35
+ }
36
+
37
+ async getDefaultExec(): Promise<string> {
38
+ return this.getDefaultTerminalOSX();
39
+ }
40
+
41
+ /**
42
+ * Spawn the external terminal for the given options.
43
+ * - The method spawns the terminal application based on the preferences, else uses the default value.
44
+ * @param configuration the preference configuration.
45
+ * @param cwd the optional current working directory to spawn from.
46
+ */
47
+ protected async spawnTerminal(configuration: ExternalTerminalConfiguration, cwd?: string): Promise<void> {
48
+
49
+ // Use the executable value from the preferences if available, else fallback to the default.
50
+ const terminalConfig = configuration['terminal.external.osxExec'];
51
+ const terminalApp = terminalConfig || this.getDefaultTerminalOSX();
52
+
53
+ return new Promise<void>((resolve, reject) => {
54
+ const args = ['-a', terminalApp];
55
+ if (cwd) {
56
+ args.push(cwd);
57
+ }
58
+ const child = cp.spawn(this.osxOpener, args);
59
+ child.on('error', reject);
60
+ child.on('exit', () => resolve());
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Get the default terminal app on OSX.
66
+ */
67
+ protected getDefaultTerminalOSX(): string {
68
+ return this.defaultTerminalApp;
69
+ }
70
+ }
@@ -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 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/node/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.substr(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 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/node/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.substr(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
+ }