@theia/external-terminal 1.53.0-next.55 → 1.53.0-next.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,109 +1,109 @@
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 { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
18
- import { PreferenceSchema, PreferenceProxy } from '@theia/core/lib/browser';
19
- import { PreferenceProxyFactory } from '@theia/core/lib/browser/preferences/injectable-preference-proxy';
20
- import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
21
- import { isWindows, isOSX } from '@theia/core/lib/common/os';
22
- import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
23
- import { nls } from '@theia/core/lib/common/nls';
24
-
25
- export const ExternalTerminalPreferences = Symbol('ExternalTerminalPreferences');
26
- export type ExternalTerminalPreferences = PreferenceProxy<ExternalTerminalConfiguration>;
27
-
28
- export const ExternalTerminalSchemaProvider = Symbol('ExternalTerminalSchemaPromise');
29
- export type ExternalTerminalSchemaProvider = () => Promise<PreferenceSchema>;
30
-
31
- export function bindExternalTerminalPreferences(bind: interfaces.Bind): void {
32
- bind(ExternalTerminalPreferenceService).toSelf().inSingletonScope();
33
- bind(ExternalTerminalSchemaProvider)
34
- .toProvider(ctx => {
35
- const schema = getExternalTerminalSchema(ctx.container.get(ExternalTerminalService));
36
- return () => schema;
37
- });
38
- bind(ExternalTerminalPreferences)
39
- .toDynamicValue(ctx => {
40
- const factory = ctx.container.get<PreferenceProxyFactory>(PreferenceProxyFactory);
41
- const schemaProvider = ctx.container.get<ExternalTerminalSchemaProvider>(ExternalTerminalSchemaProvider);
42
- return factory(schemaProvider());
43
- })
44
- .inSingletonScope();
45
- }
46
-
47
- @injectable()
48
- export class ExternalTerminalPreferenceService {
49
-
50
- @inject(ExternalTerminalPreferences)
51
- protected readonly preferences: ExternalTerminalPreferences;
52
-
53
- @inject(PreferenceSchemaProvider)
54
- protected readonly preferenceSchemaProvider: PreferenceSchemaProvider;
55
-
56
- @inject(ExternalTerminalSchemaProvider)
57
- protected readonly promisedSchema: ExternalTerminalSchemaProvider;
58
-
59
- @postConstruct()
60
- protected init(): void {
61
- this.doInit();
62
- }
63
-
64
- protected async doInit(): Promise<void> {
65
- this.preferenceSchemaProvider.setSchema(await this.promisedSchema());
66
- }
67
-
68
- /**
69
- * Get the external terminal configurations from preferences.
70
- */
71
- getExternalTerminalConfiguration(): ExternalTerminalConfiguration {
72
- return {
73
- 'terminal.external.linuxExec': this.preferences['terminal.external.linuxExec'],
74
- 'terminal.external.osxExec': this.preferences['terminal.external.osxExec'],
75
- 'terminal.external.windowsExec': this.preferences['terminal.external.windowsExec'],
76
- };
77
- }
78
- }
79
-
80
- /**
81
- * Use the backend {@link ExternalTerminalService} to establish the schema for the `ExternalTerminalPreferences`.
82
- *
83
- * @param externalTerminalService the external terminal backend service.
84
- * @returns a preference schema with the OS default exec set by the backend service.
85
- */
86
- export async function getExternalTerminalSchema(externalTerminalService: ExternalTerminalService): Promise<PreferenceSchema> {
87
- const hostExec = await externalTerminalService.getDefaultExec();
88
- return {
89
- type: 'object',
90
- properties: {
91
- 'terminal.external.windowsExec': {
92
- type: 'string',
93
- typeDetails: { isFilepath: true },
94
- description: nls.localizeByDefault('Customizes which terminal to run on Windows.'),
95
- default: `${isWindows ? hostExec : 'C:\\WINDOWS\\System32\\cmd.exe'}`
96
- },
97
- 'terminal.external.osxExec': {
98
- type: 'string',
99
- description: nls.localizeByDefault('Customizes which terminal application to run on macOS.'),
100
- default: `${isOSX ? hostExec : 'Terminal.app'}`
101
- },
102
- 'terminal.external.linuxExec': {
103
- type: 'string',
104
- description: nls.localizeByDefault('Customizes which terminal to run on Linux.'),
105
- default: `${!(isWindows || isOSX) ? hostExec : 'xterm'}`
106
- }
107
- }
108
- };
109
- }
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 { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
18
+ import { PreferenceSchema, PreferenceProxy } from '@theia/core/lib/browser';
19
+ import { PreferenceProxyFactory } from '@theia/core/lib/browser/preferences/injectable-preference-proxy';
20
+ import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
21
+ import { isWindows, isOSX } from '@theia/core/lib/common/os';
22
+ import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
23
+ import { nls } from '@theia/core/lib/common/nls';
24
+
25
+ export const ExternalTerminalPreferences = Symbol('ExternalTerminalPreferences');
26
+ export type ExternalTerminalPreferences = PreferenceProxy<ExternalTerminalConfiguration>;
27
+
28
+ export const ExternalTerminalSchemaProvider = Symbol('ExternalTerminalSchemaPromise');
29
+ export type ExternalTerminalSchemaProvider = () => Promise<PreferenceSchema>;
30
+
31
+ export function bindExternalTerminalPreferences(bind: interfaces.Bind): void {
32
+ bind(ExternalTerminalPreferenceService).toSelf().inSingletonScope();
33
+ bind(ExternalTerminalSchemaProvider)
34
+ .toProvider(ctx => {
35
+ const schema = getExternalTerminalSchema(ctx.container.get(ExternalTerminalService));
36
+ return () => schema;
37
+ });
38
+ bind(ExternalTerminalPreferences)
39
+ .toDynamicValue(ctx => {
40
+ const factory = ctx.container.get<PreferenceProxyFactory>(PreferenceProxyFactory);
41
+ const schemaProvider = ctx.container.get<ExternalTerminalSchemaProvider>(ExternalTerminalSchemaProvider);
42
+ return factory(schemaProvider());
43
+ })
44
+ .inSingletonScope();
45
+ }
46
+
47
+ @injectable()
48
+ export class ExternalTerminalPreferenceService {
49
+
50
+ @inject(ExternalTerminalPreferences)
51
+ protected readonly preferences: ExternalTerminalPreferences;
52
+
53
+ @inject(PreferenceSchemaProvider)
54
+ protected readonly preferenceSchemaProvider: PreferenceSchemaProvider;
55
+
56
+ @inject(ExternalTerminalSchemaProvider)
57
+ protected readonly promisedSchema: ExternalTerminalSchemaProvider;
58
+
59
+ @postConstruct()
60
+ protected init(): void {
61
+ this.doInit();
62
+ }
63
+
64
+ protected async doInit(): Promise<void> {
65
+ this.preferenceSchemaProvider.setSchema(await this.promisedSchema());
66
+ }
67
+
68
+ /**
69
+ * Get the external terminal configurations from preferences.
70
+ */
71
+ getExternalTerminalConfiguration(): ExternalTerminalConfiguration {
72
+ return {
73
+ 'terminal.external.linuxExec': this.preferences['terminal.external.linuxExec'],
74
+ 'terminal.external.osxExec': this.preferences['terminal.external.osxExec'],
75
+ 'terminal.external.windowsExec': this.preferences['terminal.external.windowsExec'],
76
+ };
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Use the backend {@link ExternalTerminalService} to establish the schema for the `ExternalTerminalPreferences`.
82
+ *
83
+ * @param externalTerminalService the external terminal backend service.
84
+ * @returns a preference schema with the OS default exec set by the backend service.
85
+ */
86
+ export async function getExternalTerminalSchema(externalTerminalService: ExternalTerminalService): Promise<PreferenceSchema> {
87
+ const hostExec = await externalTerminalService.getDefaultExec();
88
+ return {
89
+ type: 'object',
90
+ properties: {
91
+ 'terminal.external.windowsExec': {
92
+ type: 'string',
93
+ typeDetails: { isFilepath: true },
94
+ description: nls.localizeByDefault('Customizes which terminal to run on Windows.'),
95
+ default: `${isWindows ? hostExec : 'C:\\WINDOWS\\System32\\cmd.exe'}`
96
+ },
97
+ 'terminal.external.osxExec': {
98
+ type: 'string',
99
+ description: nls.localizeByDefault('Customizes which terminal application to run on macOS.'),
100
+ default: `${isOSX ? hostExec : 'Terminal.app'}`
101
+ },
102
+ 'terminal.external.linuxExec': {
103
+ type: 'string',
104
+ description: nls.localizeByDefault('Customizes which terminal to run on Linux.'),
105
+ default: `${!(isWindows || isOSX) ? hostExec : 'xterm'}`
106
+ }
107
+ }
108
+ };
109
+ }
@@ -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-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
- import { ConnectionHandler, RpcConnectionHandler } 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 RpcConnectionHandler(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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
+ import { ConnectionHandler, RpcConnectionHandler } 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 RpcConnectionHandler(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-only 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/common/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-only 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/common/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-only 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/common/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-only 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/common/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
+ }