@theia/external-terminal 1.34.1 → 1.34.3

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,55 +1,55 @@
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
- export const ExternalTerminalService = Symbol('ExternalTerminalService');
18
- export const externalTerminalServicePath = '/services/external-terminal';
19
-
20
- /**
21
- * Represents the external terminal configuration options.
22
- */
23
- export interface ExternalTerminalConfiguration {
24
- /**
25
- * The external terminal executable for Windows.
26
- */
27
- 'terminal.external.windowsExec': string;
28
- /**
29
- * The external terminal executable for OSX.
30
- */
31
- 'terminal.external.osxExec': string;
32
- /**
33
- * The external terminal executable for Linux.
34
- */
35
- 'terminal.external.linuxExec': string;
36
- }
37
-
38
- export interface ExternalTerminalService {
39
-
40
- /**
41
- * Open a native terminal in the designated working directory.
42
- *
43
- * @param configuration the configuration for opening external terminals.
44
- * @param cwd the string URI of the current working directory where the terminal should open from.
45
- */
46
- openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void>;
47
-
48
- /**
49
- * Get the default executable.
50
- *
51
- * @returns the default terminal executable.
52
- */
53
- getDefaultExec(): Promise<string>;
54
-
55
- }
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
+ export const ExternalTerminalService = Symbol('ExternalTerminalService');
18
+ export const externalTerminalServicePath = '/services/external-terminal';
19
+
20
+ /**
21
+ * Represents the external terminal configuration options.
22
+ */
23
+ export interface ExternalTerminalConfiguration {
24
+ /**
25
+ * The external terminal executable for Windows.
26
+ */
27
+ 'terminal.external.windowsExec': string;
28
+ /**
29
+ * The external terminal executable for OSX.
30
+ */
31
+ 'terminal.external.osxExec': string;
32
+ /**
33
+ * The external terminal executable for Linux.
34
+ */
35
+ 'terminal.external.linuxExec': string;
36
+ }
37
+
38
+ export interface ExternalTerminalService {
39
+
40
+ /**
41
+ * Open a native terminal in the designated working directory.
42
+ *
43
+ * @param configuration the configuration for opening external terminals.
44
+ * @param cwd the string URI of the current working directory where the terminal should open from.
45
+ */
46
+ openTerminal(configuration: ExternalTerminalConfiguration, cwd: string): Promise<void>;
47
+
48
+ /**
49
+ * Get the default executable.
50
+ *
51
+ * @returns the default terminal executable.
52
+ */
53
+ getDefaultExec(): Promise<string>;
54
+
55
+ }
@@ -1,116 +1,116 @@
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 { inject, injectable } from '@theia/core/shared/inversify';
18
- import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common';
19
- import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
20
- import { KeybindingContribution, KeybindingRegistry, LabelProvider } from '@theia/core/lib/browser';
21
- import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
22
- import { WorkspaceService } from '@theia/workspace/lib/browser';
23
- import { ExternalTerminalService } from '../common/external-terminal';
24
- import { ExternalTerminalPreferenceService } from './external-terminal-preference';
25
- import { QuickPickService } from '@theia/core/lib/common/quick-pick-service';
26
- import { nls } from '@theia/core/lib/common/nls';
27
-
28
- export namespace ExternalTerminalCommands {
29
- export const OPEN_NATIVE_CONSOLE = Command.toDefaultLocalizedCommand({
30
- id: 'workbench.action.terminal.openNativeConsole',
31
- label: 'Open New External Terminal'
32
- });
33
- }
34
-
35
- @injectable()
36
- export class ExternalTerminalFrontendContribution implements CommandContribution, KeybindingContribution {
37
-
38
- @inject(EditorManager)
39
- protected readonly editorManager: EditorManager;
40
-
41
- @inject(EnvVariablesServer)
42
- protected readonly envVariablesServer: EnvVariablesServer;
43
-
44
- @inject(LabelProvider)
45
- protected readonly labelProvider: LabelProvider;
46
-
47
- @inject(QuickPickService)
48
- protected readonly quickPickService: QuickPickService;
49
-
50
- @inject(ExternalTerminalService)
51
- protected readonly externalTerminalService: ExternalTerminalService;
52
-
53
- @inject(ExternalTerminalPreferenceService)
54
- protected readonly externalTerminalPreferences: ExternalTerminalPreferenceService;
55
-
56
- @inject(WorkspaceService)
57
- protected readonly workspaceService: WorkspaceService;
58
-
59
- registerCommands(commands: CommandRegistry): void {
60
- commands.registerCommand(ExternalTerminalCommands.OPEN_NATIVE_CONSOLE, {
61
- execute: () => this.openExternalTerminal()
62
- });
63
- }
64
-
65
- registerKeybindings(keybindings: KeybindingRegistry): void {
66
- keybindings.registerKeybinding({
67
- command: ExternalTerminalCommands.OPEN_NATIVE_CONSOLE.id,
68
- keybinding: 'ctrlcmd+shift+c',
69
- when: '!terminalFocus'
70
- });
71
- }
72
-
73
- /**
74
- * Open a native console on the host machine.
75
- *
76
- * - If multi-root workspace is open, displays a quick pick to let users choose which workspace to spawn the terminal.
77
- * - If only one workspace is open, the terminal spawns at the root of the current workspace.
78
- * - If no workspace is open and there is an active editor, the terminal spawns at the parent folder of that file.
79
- * - If no workspace is open and there are no active editors, the terminal spawns at user home directory.
80
- */
81
- protected async openExternalTerminal(): Promise<void> {
82
- const configuration = this.externalTerminalPreferences.getExternalTerminalConfiguration();
83
-
84
- if (this.workspaceService.isMultiRootWorkspaceOpened) {
85
- const chosenWorkspaceRoot = await this.selectCwd();
86
- if (chosenWorkspaceRoot) {
87
- await this.externalTerminalService.openTerminal(configuration, chosenWorkspaceRoot);
88
- }
89
- return;
90
- }
91
-
92
- if (this.workspaceService.opened) {
93
- const workspaceRootUri = this.workspaceService.tryGetRoots()[0].resource;
94
- await this.externalTerminalService.openTerminal(configuration, workspaceRootUri.toString());
95
- return;
96
- }
97
-
98
- const fallbackUri = this.editorManager.activeEditor?.editor.uri.parent ?? await this.envVariablesServer.getHomeDirUri();
99
- await this.externalTerminalService.openTerminal(configuration, fallbackUri.toString());
100
- }
101
-
102
- /**
103
- * Display a quick pick for user to choose a target workspace in opened workspaces.
104
- */
105
- protected async selectCwd(): Promise<string | undefined> {
106
- const roots = this.workspaceService.tryGetRoots();
107
- const selectedItem = await this.quickPickService.show(roots.map(
108
- ({ resource }) => ({
109
- label: this.labelProvider.getName(resource),
110
- description: this.labelProvider.getLongName(resource),
111
- value: resource.toString()
112
- })
113
- ), { placeholder: nls.localize('theia/external-terminal/cwd', 'Select current working directory for new external terminal') });
114
- return selectedItem?.value;
115
- }
116
- }
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 { inject, injectable } from '@theia/core/shared/inversify';
18
+ import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common';
19
+ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
20
+ import { KeybindingContribution, KeybindingRegistry, LabelProvider } from '@theia/core/lib/browser';
21
+ import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
22
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
23
+ import { ExternalTerminalService } from '../common/external-terminal';
24
+ import { ExternalTerminalPreferenceService } from './external-terminal-preference';
25
+ import { QuickPickService } from '@theia/core/lib/common/quick-pick-service';
26
+ import { nls } from '@theia/core/lib/common/nls';
27
+
28
+ export namespace ExternalTerminalCommands {
29
+ export const OPEN_NATIVE_CONSOLE = Command.toDefaultLocalizedCommand({
30
+ id: 'workbench.action.terminal.openNativeConsole',
31
+ label: 'Open New External Terminal'
32
+ });
33
+ }
34
+
35
+ @injectable()
36
+ export class ExternalTerminalFrontendContribution implements CommandContribution, KeybindingContribution {
37
+
38
+ @inject(EditorManager)
39
+ protected readonly editorManager: EditorManager;
40
+
41
+ @inject(EnvVariablesServer)
42
+ protected readonly envVariablesServer: EnvVariablesServer;
43
+
44
+ @inject(LabelProvider)
45
+ protected readonly labelProvider: LabelProvider;
46
+
47
+ @inject(QuickPickService)
48
+ protected readonly quickPickService: QuickPickService;
49
+
50
+ @inject(ExternalTerminalService)
51
+ protected readonly externalTerminalService: ExternalTerminalService;
52
+
53
+ @inject(ExternalTerminalPreferenceService)
54
+ protected readonly externalTerminalPreferences: ExternalTerminalPreferenceService;
55
+
56
+ @inject(WorkspaceService)
57
+ protected readonly workspaceService: WorkspaceService;
58
+
59
+ registerCommands(commands: CommandRegistry): void {
60
+ commands.registerCommand(ExternalTerminalCommands.OPEN_NATIVE_CONSOLE, {
61
+ execute: () => this.openExternalTerminal()
62
+ });
63
+ }
64
+
65
+ registerKeybindings(keybindings: KeybindingRegistry): void {
66
+ keybindings.registerKeybinding({
67
+ command: ExternalTerminalCommands.OPEN_NATIVE_CONSOLE.id,
68
+ keybinding: 'ctrlcmd+shift+c',
69
+ when: '!terminalFocus'
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Open a native console on the host machine.
75
+ *
76
+ * - If multi-root workspace is open, displays a quick pick to let users choose which workspace to spawn the terminal.
77
+ * - If only one workspace is open, the terminal spawns at the root of the current workspace.
78
+ * - If no workspace is open and there is an active editor, the terminal spawns at the parent folder of that file.
79
+ * - If no workspace is open and there are no active editors, the terminal spawns at user home directory.
80
+ */
81
+ protected async openExternalTerminal(): Promise<void> {
82
+ const configuration = this.externalTerminalPreferences.getExternalTerminalConfiguration();
83
+
84
+ if (this.workspaceService.isMultiRootWorkspaceOpened) {
85
+ const chosenWorkspaceRoot = await this.selectCwd();
86
+ if (chosenWorkspaceRoot) {
87
+ await this.externalTerminalService.openTerminal(configuration, chosenWorkspaceRoot);
88
+ }
89
+ return;
90
+ }
91
+
92
+ if (this.workspaceService.opened) {
93
+ const workspaceRootUri = this.workspaceService.tryGetRoots()[0].resource;
94
+ await this.externalTerminalService.openTerminal(configuration, workspaceRootUri.toString());
95
+ return;
96
+ }
97
+
98
+ const fallbackUri = this.editorManager.activeEditor?.editor.uri.parent ?? await this.envVariablesServer.getHomeDirUri();
99
+ await this.externalTerminalService.openTerminal(configuration, fallbackUri.toString());
100
+ }
101
+
102
+ /**
103
+ * Display a quick pick for user to choose a target workspace in opened workspaces.
104
+ */
105
+ protected async selectCwd(): Promise<string | undefined> {
106
+ const roots = this.workspaceService.tryGetRoots();
107
+ const selectedItem = await this.quickPickService.show(roots.map(
108
+ ({ resource }) => ({
109
+ label: this.labelProvider.getName(resource),
110
+ description: this.labelProvider.getLongName(resource),
111
+ value: resource.toString()
112
+ })
113
+ ), { placeholder: nls.localize('theia/external-terminal/cwd', 'Select current working directory for new external terminal') });
114
+ return selectedItem?.value;
115
+ }
116
+ }
@@ -1,33 +1,33 @@
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 { CommandContribution } from '@theia/core/lib/common';
19
- import { KeybindingContribution, WebSocketConnectionProvider } from '@theia/core/lib/browser';
20
- import { bindExternalTerminalPreferences } from './external-terminal-preference';
21
- import { ExternalTerminalFrontendContribution } from './external-terminal-contribution';
22
- import { ExternalTerminalService, externalTerminalServicePath } from '../common/external-terminal';
23
-
24
- export default new ContainerModule((bind: interfaces.Bind) => {
25
- bind(ExternalTerminalFrontendContribution).toSelf().inSingletonScope();
26
- bindExternalTerminalPreferences(bind);
27
- [CommandContribution, KeybindingContribution].forEach(serviceIdentifier =>
28
- bind(serviceIdentifier).toService(ExternalTerminalFrontendContribution)
29
- );
30
- bind(ExternalTerminalService).toDynamicValue(ctx =>
31
- WebSocketConnectionProvider.createProxy<ExternalTerminalService>(ctx.container, externalTerminalServicePath)
32
- ).inSingletonScope();
33
- });
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 { CommandContribution } from '@theia/core/lib/common';
19
+ import { KeybindingContribution, WebSocketConnectionProvider } from '@theia/core/lib/browser';
20
+ import { bindExternalTerminalPreferences } from './external-terminal-preference';
21
+ import { ExternalTerminalFrontendContribution } from './external-terminal-contribution';
22
+ import { ExternalTerminalService, externalTerminalServicePath } from '../common/external-terminal';
23
+
24
+ export default new ContainerModule((bind: interfaces.Bind) => {
25
+ bind(ExternalTerminalFrontendContribution).toSelf().inSingletonScope();
26
+ bindExternalTerminalPreferences(bind);
27
+ [CommandContribution, KeybindingContribution].forEach(serviceIdentifier =>
28
+ bind(serviceIdentifier).toService(ExternalTerminalFrontendContribution)
29
+ );
30
+ bind(ExternalTerminalService).toDynamicValue(ctx =>
31
+ WebSocketConnectionProvider.createProxy<ExternalTerminalService>(ctx.container, externalTerminalServicePath)
32
+ ).inSingletonScope();
33
+ });
@@ -1,106 +1,106 @@
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 { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
18
- import {
19
- createPreferenceProxy,
20
- PreferenceSchema,
21
- PreferenceService,
22
- PreferenceProxy
23
- } from '@theia/core/lib/browser';
24
- import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
25
- import { isWindows, isOSX } from '@theia/core/lib/common/os';
26
- import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
27
- import { nls } from '@theia/core/lib/common/nls';
28
-
29
- export const ExternalTerminalPreferences = Symbol('ExternalTerminalPreferences');
30
- export type ExternalTerminalPreferences = PreferenceProxy<ExternalTerminalConfiguration>;
31
-
32
- export const ExternalTerminalSchemaPromise = Symbol('ExternalTerminalSchemaPromise');
33
- export type ExternalTerminalSchemaPromise = Promise<PreferenceSchema>;
34
-
35
- export function bindExternalTerminalPreferences(bind: interfaces.Bind): void {
36
- bind(ExternalTerminalSchemaPromise).toDynamicValue(
37
- ctx => getExternalTerminalSchema(ctx.container.get(ExternalTerminalService))
38
- ).inSingletonScope();
39
- bind(ExternalTerminalPreferences).toDynamicValue(
40
- ctx => createPreferenceProxy(
41
- ctx.container.get(PreferenceService),
42
- ctx.container.get(ExternalTerminalSchemaPromise),
43
- )
44
- ).inSingletonScope();
45
- bind(ExternalTerminalPreferenceService).toSelf().inSingletonScope();
46
- }
47
-
48
- @injectable()
49
- export class ExternalTerminalPreferenceService {
50
-
51
- @inject(ExternalTerminalPreferences)
52
- protected readonly preferences: ExternalTerminalPreferences;
53
-
54
- @inject(PreferenceSchemaProvider)
55
- protected readonly preferenceSchemaProvider: PreferenceSchemaProvider;
56
-
57
- @inject(ExternalTerminalSchemaPromise)
58
- protected readonly promisedSchema: ExternalTerminalSchemaPromise;
59
-
60
- @postConstruct()
61
- protected init(): void {
62
- this.promisedSchema.then(schema => this.preferenceSchemaProvider.setSchema(schema));
63
- }
64
-
65
- /**
66
- * Get the external terminal configurations from preferences.
67
- */
68
- getExternalTerminalConfiguration(): ExternalTerminalConfiguration {
69
- return {
70
- 'terminal.external.linuxExec': this.preferences['terminal.external.linuxExec'],
71
- 'terminal.external.osxExec': this.preferences['terminal.external.osxExec'],
72
- 'terminal.external.windowsExec': this.preferences['terminal.external.windowsExec'],
73
- };
74
- }
75
- }
76
-
77
- /**
78
- * Use the backend {@link ExternalTerminalService} to establish the schema for the `ExternalTerminalPreferences`.
79
- *
80
- * @param externalTerminalService the external terminal backend service.
81
- * @returns a preference schema with the OS default exec set by the backend service.
82
- */
83
- export async function getExternalTerminalSchema(externalTerminalService: ExternalTerminalService): Promise<PreferenceSchema> {
84
- const hostExec = await externalTerminalService.getDefaultExec();
85
- return {
86
- type: 'object',
87
- properties: {
88
- 'terminal.external.windowsExec': {
89
- type: 'string',
90
- typeDetails: { isFilepath: true },
91
- description: nls.localizeByDefault('Customizes which terminal to run on Windows.'),
92
- default: `${isWindows ? hostExec : 'C:\\WINDOWS\\System32\\cmd.exe'}`
93
- },
94
- 'terminal.external.osxExec': {
95
- type: 'string',
96
- description: nls.localizeByDefault('Customizes which terminal application to run on macOS.'),
97
- default: `${isOSX ? hostExec : 'Terminal.app'}`
98
- },
99
- 'terminal.external.linuxExec': {
100
- type: 'string',
101
- description: nls.localizeByDefault('Customizes which terminal to run on Linux.'),
102
- default: `${!(isWindows || isOSX) ? hostExec : 'xterm'}`
103
- }
104
- }
105
- };
106
- }
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 { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
18
+ import {
19
+ createPreferenceProxy,
20
+ PreferenceSchema,
21
+ PreferenceService,
22
+ PreferenceProxy
23
+ } from '@theia/core/lib/browser';
24
+ import { PreferenceSchemaProvider } from '@theia/core/lib/browser/preferences/preference-contribution';
25
+ import { isWindows, isOSX } from '@theia/core/lib/common/os';
26
+ import { ExternalTerminalService, ExternalTerminalConfiguration } from '../common/external-terminal';
27
+ import { nls } from '@theia/core/lib/common/nls';
28
+
29
+ export const ExternalTerminalPreferences = Symbol('ExternalTerminalPreferences');
30
+ export type ExternalTerminalPreferences = PreferenceProxy<ExternalTerminalConfiguration>;
31
+
32
+ export const ExternalTerminalSchemaPromise = Symbol('ExternalTerminalSchemaPromise');
33
+ export type ExternalTerminalSchemaPromise = Promise<PreferenceSchema>;
34
+
35
+ export function bindExternalTerminalPreferences(bind: interfaces.Bind): void {
36
+ bind(ExternalTerminalSchemaPromise).toDynamicValue(
37
+ ctx => getExternalTerminalSchema(ctx.container.get(ExternalTerminalService))
38
+ ).inSingletonScope();
39
+ bind(ExternalTerminalPreferences).toDynamicValue(
40
+ ctx => createPreferenceProxy(
41
+ ctx.container.get(PreferenceService),
42
+ ctx.container.get(ExternalTerminalSchemaPromise),
43
+ )
44
+ ).inSingletonScope();
45
+ bind(ExternalTerminalPreferenceService).toSelf().inSingletonScope();
46
+ }
47
+
48
+ @injectable()
49
+ export class ExternalTerminalPreferenceService {
50
+
51
+ @inject(ExternalTerminalPreferences)
52
+ protected readonly preferences: ExternalTerminalPreferences;
53
+
54
+ @inject(PreferenceSchemaProvider)
55
+ protected readonly preferenceSchemaProvider: PreferenceSchemaProvider;
56
+
57
+ @inject(ExternalTerminalSchemaPromise)
58
+ protected readonly promisedSchema: ExternalTerminalSchemaPromise;
59
+
60
+ @postConstruct()
61
+ protected init(): void {
62
+ this.promisedSchema.then(schema => this.preferenceSchemaProvider.setSchema(schema));
63
+ }
64
+
65
+ /**
66
+ * Get the external terminal configurations from preferences.
67
+ */
68
+ getExternalTerminalConfiguration(): ExternalTerminalConfiguration {
69
+ return {
70
+ 'terminal.external.linuxExec': this.preferences['terminal.external.linuxExec'],
71
+ 'terminal.external.osxExec': this.preferences['terminal.external.osxExec'],
72
+ 'terminal.external.windowsExec': this.preferences['terminal.external.windowsExec'],
73
+ };
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Use the backend {@link ExternalTerminalService} to establish the schema for the `ExternalTerminalPreferences`.
79
+ *
80
+ * @param externalTerminalService the external terminal backend service.
81
+ * @returns a preference schema with the OS default exec set by the backend service.
82
+ */
83
+ export async function getExternalTerminalSchema(externalTerminalService: ExternalTerminalService): Promise<PreferenceSchema> {
84
+ const hostExec = await externalTerminalService.getDefaultExec();
85
+ return {
86
+ type: 'object',
87
+ properties: {
88
+ 'terminal.external.windowsExec': {
89
+ type: 'string',
90
+ typeDetails: { isFilepath: true },
91
+ description: nls.localizeByDefault('Customizes which terminal to run on Windows.'),
92
+ default: `${isWindows ? hostExec : 'C:\\WINDOWS\\System32\\cmd.exe'}`
93
+ },
94
+ 'terminal.external.osxExec': {
95
+ type: 'string',
96
+ description: nls.localizeByDefault('Customizes which terminal application to run on macOS.'),
97
+ default: `${isOSX ? hostExec : 'Terminal.app'}`
98
+ },
99
+ 'terminal.external.linuxExec': {
100
+ type: 'string',
101
+ description: nls.localizeByDefault('Customizes which terminal to run on Linux.'),
102
+ default: `${!(isWindows || isOSX) ? hostExec : 'xterm'}`
103
+ }
104
+ }
105
+ };
106
+ }