@theia/terminal 1.45.0 → 1.46.0-next.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/base/terminal-service.d.ts +34 -34
  3. package/lib/browser/base/terminal-service.js +7 -7
  4. package/lib/browser/base/terminal-widget.d.ts +192 -192
  5. package/lib/browser/base/terminal-widget.js +34 -34
  6. package/lib/browser/index.d.ts +1 -1
  7. package/lib/browser/index.js +28 -28
  8. package/lib/browser/search/terminal-search-container.d.ts +3 -3
  9. package/lib/browser/search/terminal-search-container.js +28 -28
  10. package/lib/browser/search/terminal-search-widget.d.ts +30 -30
  11. package/lib/browser/search/terminal-search-widget.js +147 -147
  12. package/lib/browser/shell-terminal-profile.d.ts +20 -20
  13. package/lib/browser/shell-terminal-profile.js +42 -42
  14. package/lib/browser/terminal-contribution.d.ts +3 -3
  15. package/lib/browser/terminal-contribution.js +20 -20
  16. package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
  17. package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
  18. package/lib/browser/terminal-file-link-provider.d.ts +24 -24
  19. package/lib/browser/terminal-file-link-provider.js +200 -200
  20. package/lib/browser/terminal-frontend-contribution.d.ts +115 -115
  21. package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
  22. package/lib/browser/terminal-frontend-contribution.js +1078 -1056
  23. package/lib/browser/terminal-frontend-contribution.js.map +1 -1
  24. package/lib/browser/terminal-frontend-module.d.ts +5 -5
  25. package/lib/browser/terminal-frontend-module.js +117 -117
  26. package/lib/browser/terminal-link-helpers.d.ts +27 -27
  27. package/lib/browser/terminal-link-helpers.js +155 -155
  28. package/lib/browser/terminal-link-provider.d.ts +51 -51
  29. package/lib/browser/terminal-link-provider.js +197 -197
  30. package/lib/browser/terminal-preferences.d.ts +61 -61
  31. package/lib/browser/terminal-preferences.d.ts.map +1 -1
  32. package/lib/browser/terminal-preferences.js +357 -356
  33. package/lib/browser/terminal-preferences.js.map +1 -1
  34. package/lib/browser/terminal-profile-service.d.ts +58 -58
  35. package/lib/browser/terminal-profile-service.js +158 -158
  36. package/lib/browser/terminal-quick-open-service.d.ts +36 -36
  37. package/lib/browser/terminal-quick-open-service.js +137 -137
  38. package/lib/browser/terminal-theme-service.d.ts +21 -21
  39. package/lib/browser/terminal-theme-service.d.ts.map +1 -1
  40. package/lib/browser/terminal-theme-service.js +222 -218
  41. package/lib/browser/terminal-theme-service.js.map +1 -1
  42. package/lib/browser/terminal-url-link-provider.d.ts +11 -11
  43. package/lib/browser/terminal-url-link-provider.js +76 -76
  44. package/lib/browser/terminal-widget-impl.d.ts +180 -187
  45. package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
  46. package/lib/browser/terminal-widget-impl.js +857 -867
  47. package/lib/browser/terminal-widget-impl.js.map +1 -1
  48. package/lib/common/base-terminal-protocol.d.ts +55 -55
  49. package/lib/common/base-terminal-protocol.js +84 -84
  50. package/lib/common/shell-terminal-protocol.d.ts +66 -66
  51. package/lib/common/shell-terminal-protocol.js +35 -35
  52. package/lib/common/terminal-common-module.d.ts +7 -7
  53. package/lib/common/terminal-common-module.js +31 -31
  54. package/lib/common/terminal-protocol.d.ts +12 -12
  55. package/lib/common/terminal-protocol.js +21 -21
  56. package/lib/common/terminal-watcher.d.ts +13 -13
  57. package/lib/common/terminal-watcher.js +70 -70
  58. package/lib/node/base-terminal-server.d.ts +24 -24
  59. package/lib/node/base-terminal-server.js +168 -168
  60. package/lib/node/buffering-stream.d.ts +39 -39
  61. package/lib/node/buffering-stream.js +75 -75
  62. package/lib/node/buffering-stream.spec.d.ts +1 -1
  63. package/lib/node/buffering-stream.spec.js +43 -43
  64. package/lib/node/index.d.ts +1 -1
  65. package/lib/node/index.js +28 -28
  66. package/lib/node/shell-process.d.ts +27 -27
  67. package/lib/node/shell-process.js +107 -107
  68. package/lib/node/shell-process.js.map +1 -1
  69. package/lib/node/shell-terminal-server.d.ts +30 -30
  70. package/lib/node/shell-terminal-server.js +212 -212
  71. package/lib/node/shell-terminal-server.spec.d.ts +1 -1
  72. package/lib/node/shell-terminal-server.spec.js +35 -35
  73. package/lib/node/terminal-backend-contribution.d.ts +9 -9
  74. package/lib/node/terminal-backend-contribution.js +75 -75
  75. package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
  76. package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
  77. package/lib/node/terminal-backend-module.d.ts +11 -11
  78. package/lib/node/terminal-backend-module.js +69 -69
  79. package/lib/node/terminal-server.d.ts +9 -9
  80. package/lib/node/terminal-server.js +64 -64
  81. package/lib/node/terminal-server.spec.d.ts +1 -1
  82. package/lib/node/terminal-server.spec.js +41 -41
  83. package/lib/node/test/terminal-test-container.d.ts +2 -2
  84. package/lib/node/test/terminal-test-container.js +40 -40
  85. package/lib/package.spec.js +25 -25
  86. package/package.json +12 -12
  87. package/src/browser/base/terminal-service.ts +60 -60
  88. package/src/browser/base/terminal-widget.ts +254 -254
  89. package/src/browser/index.ts +17 -17
  90. package/src/browser/search/terminal-search-container.ts +28 -28
  91. package/src/browser/search/terminal-search-widget.tsx +161 -161
  92. package/src/browser/shell-terminal-profile.ts +45 -45
  93. package/src/browser/style/terminal-search.css +99 -99
  94. package/src/browser/style/terminal.css +32 -32
  95. package/src/browser/terminal-contribution.ts +19 -19
  96. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  97. package/src/browser/terminal-file-link-provider.ts +200 -200
  98. package/src/browser/terminal-frontend-contribution.ts +1120 -1098
  99. package/src/browser/terminal-frontend-module.ts +136 -136
  100. package/src/browser/terminal-link-helpers.ts +187 -187
  101. package/src/browser/terminal-link-provider.ts +203 -203
  102. package/src/browser/terminal-preferences.ts +428 -427
  103. package/src/browser/terminal-profile-service.ts +180 -180
  104. package/src/browser/terminal-quick-open-service.ts +132 -132
  105. package/src/browser/terminal-theme-service.ts +213 -209
  106. package/src/browser/terminal-url-link-provider.ts +66 -66
  107. package/src/browser/terminal-widget-impl.ts +939 -936
  108. package/src/common/base-terminal-protocol.ts +125 -125
  109. package/src/common/shell-terminal-protocol.ts +103 -103
  110. package/src/common/terminal-common-module.ts +30 -30
  111. package/src/common/terminal-protocol.ts +32 -32
  112. package/src/common/terminal-watcher.ts +69 -69
  113. package/src/node/base-terminal-server.ts +173 -173
  114. package/src/node/buffering-stream.spec.ts +46 -46
  115. package/src/node/buffering-stream.ts +95 -95
  116. package/src/node/index.ts +17 -17
  117. package/src/node/shell-process.ts +101 -101
  118. package/src/node/shell-terminal-server.spec.ts +40 -40
  119. package/src/node/shell-terminal-server.ts +221 -221
  120. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  121. package/src/node/terminal-backend-contribution.ts +60 -60
  122. package/src/node/terminal-backend-module.ts +82 -82
  123. package/src/node/terminal-server.spec.ts +47 -47
  124. package/src/node/terminal-server.ts +52 -52
  125. package/src/node/test/terminal-test-container.ts +39 -39
  126. package/src/package.spec.ts +28 -28
@@ -1,1057 +1,1079 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2017 TypeFox and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
- return c > 3 && r && Object.defineProperty(target, key, r), r;
22
- };
23
- var __metadata = (this && this.__metadata) || function (k, v) {
24
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.TerminalFrontendContribution = exports.TerminalCommands = exports.TerminalMenus = void 0;
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const common_1 = require("@theia/core/lib/common");
30
- const browser_1 = require("@theia/core/lib/browser");
31
- const terminal_widget_impl_1 = require("./terminal-widget-impl");
32
- const terminal_widget_1 = require("./base/terminal-widget");
33
- const terminal_profile_service_1 = require("./terminal-profile-service");
34
- const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
35
- const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
36
- const uri_1 = require("@theia/core/lib/common/uri");
37
- const core_1 = require("@theia/core");
38
- const browser_2 = require("@theia/workspace/lib/browser");
39
- const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
40
- const terminal_theme_service_1 = require("./terminal-theme-service");
41
- const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
42
- const terminal_watcher_1 = require("../common/terminal-watcher");
43
- const nls_1 = require("@theia/core/lib/common/nls");
44
- const terminal_preferences_1 = require("./terminal-preferences");
45
- const shell_terminal_profile_1 = require("./shell-terminal-profile");
46
- const browser_3 = require("@theia/variable-resolver/lib/browser");
47
- var TerminalMenus;
48
- (function (TerminalMenus) {
49
- TerminalMenus.TERMINAL = [...core_1.MAIN_MENU_BAR, '7_terminal'];
50
- TerminalMenus.TERMINAL_NEW = [...TerminalMenus.TERMINAL, '1_terminal'];
51
- TerminalMenus.TERMINAL_TASKS = [...TerminalMenus.TERMINAL, '2_terminal'];
52
- TerminalMenus.TERMINAL_TASKS_INFO = [...TerminalMenus.TERMINAL_TASKS, '3_terminal'];
53
- TerminalMenus.TERMINAL_TASKS_CONFIG = [...TerminalMenus.TERMINAL_TASKS, '4_terminal'];
54
- TerminalMenus.TERMINAL_NAVIGATOR_CONTEXT_MENU = ['navigator-context-menu', 'navigation'];
55
- TerminalMenus.TERMINAL_OPEN_EDITORS_CONTEXT_MENU = ['open-editors-context-menu', 'navigation'];
56
- TerminalMenus.TERMINAL_CONTEXT_MENU = ['terminal-context-menu'];
57
- })(TerminalMenus = exports.TerminalMenus || (exports.TerminalMenus = {}));
58
- var TerminalCommands;
59
- (function (TerminalCommands) {
60
- const TERMINAL_CATEGORY = 'Terminal';
61
- TerminalCommands.NEW = common_1.Command.toDefaultLocalizedCommand({
62
- id: 'terminal:new',
63
- category: TERMINAL_CATEGORY,
64
- label: 'Create New Terminal'
65
- });
66
- TerminalCommands.PROFILE_NEW = common_1.Command.toLocalizedCommand({
67
- id: 'terminal:new:profile',
68
- category: TERMINAL_CATEGORY,
69
- label: 'Create New Integrated Terminal from a Profile'
70
- });
71
- TerminalCommands.PROFILE_DEFAULT = common_1.Command.toLocalizedCommand({
72
- id: 'terminal:profile:default',
73
- category: TERMINAL_CATEGORY,
74
- label: 'Choose the default Terminal Profile'
75
- });
76
- TerminalCommands.NEW_ACTIVE_WORKSPACE = common_1.Command.toDefaultLocalizedCommand({
77
- id: 'terminal:new:active:workspace',
78
- category: TERMINAL_CATEGORY,
79
- label: 'Create New Terminal (In Active Workspace)'
80
- });
81
- TerminalCommands.TERMINAL_CLEAR = common_1.Command.toDefaultLocalizedCommand({
82
- id: 'terminal:clear',
83
- category: TERMINAL_CATEGORY,
84
- label: 'Clear'
85
- });
86
- TerminalCommands.TERMINAL_CONTEXT = common_1.Command.toDefaultLocalizedCommand({
87
- id: 'terminal:context',
88
- category: TERMINAL_CATEGORY,
89
- label: 'Open in Integrated Terminal'
90
- });
91
- TerminalCommands.SPLIT = common_1.Command.toDefaultLocalizedCommand({
92
- id: 'terminal:split',
93
- category: TERMINAL_CATEGORY,
94
- label: 'Split Terminal'
95
- });
96
- TerminalCommands.TERMINAL_FIND_TEXT = common_1.Command.toDefaultLocalizedCommand({
97
- id: 'terminal:find',
98
- category: TERMINAL_CATEGORY,
99
- label: 'Find'
100
- });
101
- TerminalCommands.TERMINAL_FIND_TEXT_CANCEL = common_1.Command.toDefaultLocalizedCommand({
102
- id: 'terminal:find:cancel',
103
- category: TERMINAL_CATEGORY,
104
- label: 'Hide Find'
105
- });
106
- TerminalCommands.SCROLL_LINE_UP = common_1.Command.toDefaultLocalizedCommand({
107
- id: 'terminal:scroll:line:up',
108
- category: TERMINAL_CATEGORY,
109
- label: 'Scroll Up (Line)'
110
- });
111
- TerminalCommands.SCROLL_LINE_DOWN = common_1.Command.toDefaultLocalizedCommand({
112
- id: 'terminal:scroll:line:down',
113
- category: TERMINAL_CATEGORY,
114
- label: 'Scroll Down (Line)'
115
- });
116
- TerminalCommands.SCROLL_TO_TOP = common_1.Command.toDefaultLocalizedCommand({
117
- id: 'terminal:scroll:top',
118
- category: TERMINAL_CATEGORY,
119
- label: 'Scroll to Top'
120
- });
121
- TerminalCommands.SCROLL_PAGE_UP = common_1.Command.toDefaultLocalizedCommand({
122
- id: 'terminal:scroll:page:up',
123
- category: TERMINAL_CATEGORY,
124
- label: 'Scroll Up (Page)'
125
- });
126
- TerminalCommands.SCROLL_PAGE_DOWN = common_1.Command.toDefaultLocalizedCommand({
127
- id: 'terminal:scroll:page:down',
128
- category: TERMINAL_CATEGORY,
129
- label: 'Scroll Down (Page)'
130
- });
131
- TerminalCommands.TOGGLE_TERMINAL = common_1.Command.toDefaultLocalizedCommand({
132
- id: 'workbench.action.terminal.toggleTerminal',
133
- category: TERMINAL_CATEGORY,
134
- label: 'Toggle Terminal'
135
- });
136
- TerminalCommands.KILL_TERMINAL = common_1.Command.toDefaultLocalizedCommand({
137
- id: 'terminal:kill',
138
- category: TERMINAL_CATEGORY,
139
- label: 'Kill Terminal'
140
- });
141
- TerminalCommands.SELECT_ALL = {
142
- id: 'terminal:select:all',
143
- label: browser_1.CommonCommands.SELECT_ALL.label,
144
- category: TERMINAL_CATEGORY,
145
- };
146
- /**
147
- * Command that displays all terminals that are currently opened
148
- */
149
- TerminalCommands.SHOW_ALL_OPENED_TERMINALS = common_1.Command.toDefaultLocalizedCommand({
150
- id: 'workbench.action.showAllTerminals',
151
- category: browser_1.CommonCommands.VIEW_CATEGORY,
152
- label: 'Show All Opened Terminals'
153
- });
154
- })(TerminalCommands = exports.TerminalCommands || (exports.TerminalCommands = {}));
155
- const ENVIRONMENT_VARIABLE_COLLECTIONS_KEY = 'terminal.integrated.environmentVariableCollections';
156
- let TerminalFrontendContribution = class TerminalFrontendContribution {
157
- constructor() {
158
- this.mergePreferencesPromise = Promise.resolve();
159
- this.onDidCreateTerminalEmitter = new common_1.Emitter();
160
- this.onDidCreateTerminal = this.onDidCreateTerminalEmitter.event;
161
- this.onDidChangeCurrentTerminalEmitter = new common_1.Emitter();
162
- this.onDidChangeCurrentTerminal = this.onDidChangeCurrentTerminalEmitter.event;
163
- // IDs of the most recently used terminals
164
- this.mostRecentlyUsedTerminalEntries = [];
165
- }
166
- init() {
167
- this.shell.onDidChangeCurrentWidget(() => this.updateCurrentTerminal());
168
- this.widgetManager.onDidCreateWidget(({ widget }) => {
169
- if (widget instanceof terminal_widget_1.TerminalWidget) {
170
- this.updateCurrentTerminal();
171
- this.onDidCreateTerminalEmitter.fire(widget);
172
- this.setLastUsedTerminal(widget);
173
- }
174
- });
175
- const terminalFocusKey = this.contextKeyService.createKey('terminalFocus', false);
176
- const terminalSearchToggle = this.contextKeyService.createKey('terminalHideSearch', false);
177
- const updateFocusKey = () => {
178
- terminalFocusKey.set(this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget);
179
- terminalSearchToggle.set(this.terminalHideSearch);
180
- };
181
- updateFocusKey();
182
- this.shell.onDidChangeActiveWidget(updateFocusKey);
183
- this.terminalWatcher.onStoreTerminalEnvVariablesRequested(data => {
184
- this.storageService.setData(ENVIRONMENT_VARIABLE_COLLECTIONS_KEY, data);
185
- });
186
- this.terminalWatcher.onUpdateTerminalEnvVariablesRequested(() => {
187
- this.storageService.getData(ENVIRONMENT_VARIABLE_COLLECTIONS_KEY).then(data => {
188
- if (data) {
189
- this.shellTerminalServer.restorePersisted(data);
190
- }
191
- });
192
- });
193
- }
194
- get terminalHideSearch() {
195
- if (!(this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget)) {
196
- return false;
197
- }
198
- const searchWidget = this.shell.activeWidget.getSearchBox();
199
- return searchWidget.isVisible;
200
- }
201
- async onStart(app) {
202
- this.contributeDefaultProfiles();
203
- this.terminalPreferences.onPreferenceChanged(e => {
204
- if (e.preferenceName.startsWith('terminal.integrated.')) {
205
- this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
206
- }
207
- });
208
- this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
209
- // extension contributions get read after this point: need to set the default profile if necessary
210
- this.profileService.onAdded(id => {
211
- let defaultProfileId;
212
- switch (common_1.OS.backend.type()) {
213
- case common_1.OS.Type.Windows: {
214
- defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.windows'];
215
- break;
216
- }
217
- case common_1.OS.Type.Linux: {
218
- defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.linux'];
219
- break;
220
- }
221
- case common_1.OS.Type.OSX: {
222
- defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.osx'];
223
- break;
224
- }
225
- }
226
- if (defaultProfileId) {
227
- this.profileService.setDefaultProfile(defaultProfileId);
228
- }
229
- });
230
- }
231
- async contributeDefaultProfiles() {
232
- if (common_1.OS.backend.isWindows) {
233
- this.contributedProfileStore.registerTerminalProfile('cmd', new shell_terminal_profile_1.ShellTerminalProfile(this, {
234
- shellPath: await this.resolveShellPath([
235
- '${env:windir}\\Sysnative\\cmd.exe',
236
- '${env:windir}\\System32\\cmd.exe'
237
- ])
238
- }));
239
- }
240
- else {
241
- this.contributedProfileStore.registerTerminalProfile('SHELL', new shell_terminal_profile_1.ShellTerminalProfile(this, {
242
- shellPath: await this.resolveShellPath('${SHELL}'),
243
- shellArgs: ['-l']
244
- }));
245
- }
246
- // contribute default profiles based on legacy preferences
247
- }
248
- async mergePreferences() {
249
- var _a, _b, _c;
250
- let profiles;
251
- let defaultProfile;
252
- let legacyShellPath;
253
- let legacyShellArgs;
254
- const removed = new Set(this.userProfileStore.all.map(([id, profile]) => id));
255
- switch (common_1.OS.backend.type()) {
256
- case common_1.OS.Type.Windows: {
257
- profiles = this.terminalPreferences['terminal.integrated.profiles.windows'];
258
- defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.windows'];
259
- legacyShellPath = (_a = this.terminalPreferences['terminal.integrated.shell.windows']) !== null && _a !== void 0 ? _a : undefined;
260
- legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.windows'];
261
- break;
262
- }
263
- case common_1.OS.Type.Linux: {
264
- profiles = this.terminalPreferences['terminal.integrated.profiles.linux'];
265
- defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.linux'];
266
- legacyShellPath = (_b = this.terminalPreferences['terminal.integrated.shell.linux']) !== null && _b !== void 0 ? _b : undefined;
267
- legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.linux'];
268
- break;
269
- }
270
- case common_1.OS.Type.OSX: {
271
- profiles = this.terminalPreferences['terminal.integrated.profiles.osx'];
272
- defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.osx'];
273
- legacyShellPath = (_c = this.terminalPreferences['terminal.integrated.shell.osx']) !== null && _c !== void 0 ? _c : undefined;
274
- legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.osx'];
275
- break;
276
- }
277
- }
278
- if (profiles) {
279
- for (const id of Object.getOwnPropertyNames(profiles)) {
280
- const profile = profiles[id];
281
- removed.delete(id);
282
- if (profile) {
283
- const shellPath = await this.resolveShellPath(profile.path);
284
- if (shellPath) {
285
- const options = {
286
- shellPath: shellPath,
287
- shellArgs: profile.args ? await this.variableResolver.resolve(profile.args) : undefined,
288
- useServerTitle: profile.overrideName ? false : undefined,
289
- env: profile.env ? await this.variableResolver.resolve(profile.env) : undefined,
290
- title: profile.overrideName ? id : undefined
291
- };
292
- this.userProfileStore.registerTerminalProfile(id, new shell_terminal_profile_1.ShellTerminalProfile(this, options));
293
- }
294
- }
295
- else {
296
- this.userProfileStore.registerTerminalProfile(id, terminal_profile_service_1.NULL_PROFILE);
297
- }
298
- }
299
- }
300
- if (legacyShellPath) {
301
- this.userProfileStore.registerTerminalProfile('Legacy Shell Preferences', new shell_terminal_profile_1.ShellTerminalProfile(this, {
302
- shellPath: legacyShellPath,
303
- shellArgs: legacyShellArgs
304
- }));
305
- // if no other default is set, use the legacy preferences as default if they exist
306
- this.profileService.setDefaultProfile('Legacy Shell Preferences');
307
- }
308
- if (defaultProfile && this.profileService.getProfile(defaultProfile)) {
309
- this.profileService.setDefaultProfile(defaultProfile);
310
- }
311
- for (const id of removed) {
312
- this.userProfileStore.unregisterTerminalProfile(id);
313
- }
314
- }
315
- async resolveShellPath(path) {
316
- if (!path) {
317
- return undefined;
318
- }
319
- if (typeof path === 'string') {
320
- path = [path];
321
- }
322
- for (const p of path) {
323
- const resolved = await this.variableResolver.resolve(p);
324
- if (resolved) {
325
- const resolvedURI = uri_1.default.fromFilePath(resolved);
326
- if (await this.fileService.exists(resolvedURI)) {
327
- return resolved;
328
- }
329
- }
330
- }
331
- return undefined;
332
- }
333
- onWillStop() {
334
- const preferenceValue = this.terminalPreferences['terminal.integrated.confirmOnExit'];
335
- if (preferenceValue !== 'never') {
336
- const allTerminals = this.widgetManager.getWidgets(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID);
337
- if (allTerminals.length) {
338
- return {
339
- prepare: async () => {
340
- if (preferenceValue === 'always') {
341
- return allTerminals.length;
342
- }
343
- else {
344
- const activeTerminals = await Promise.all(allTerminals.map(widget => widget.hasChildProcesses()))
345
- .then(hasChildProcesses => hasChildProcesses.filter(hasChild => hasChild));
346
- return activeTerminals.length;
347
- }
348
- },
349
- action: async (activeTerminalCount) => activeTerminalCount === 0 || this.confirmExitWithActiveTerminals(activeTerminalCount),
350
- reason: 'Active integrated terminal',
351
- };
352
- }
353
- }
354
- }
355
- async confirmExitWithActiveTerminals(activeTerminalCount) {
356
- const msg = activeTerminalCount === 1
357
- ? nls_1.nls.localizeByDefault('Do you want to terminate the active terminal session?')
358
- : nls_1.nls.localizeByDefault('Do you want to terminate the {0} active terminal sessions?', activeTerminalCount);
359
- const safeToExit = await new browser_1.ConfirmDialog({
360
- title: '',
361
- msg,
362
- ok: nls_1.nls.localizeByDefault('Terminate'),
363
- cancel: browser_1.Dialog.CANCEL,
364
- }).open();
365
- return safeToExit === true;
366
- }
367
- get currentTerminal() {
368
- return this._currentTerminal;
369
- }
370
- setCurrentTerminal(current) {
371
- if (this._currentTerminal !== current) {
372
- this._currentTerminal = current;
373
- this.onDidChangeCurrentTerminalEmitter.fire(this._currentTerminal);
374
- }
375
- }
376
- updateCurrentTerminal() {
377
- const widget = this.shell.currentWidget;
378
- if (widget instanceof terminal_widget_1.TerminalWidget) {
379
- this.setCurrentTerminal(widget);
380
- }
381
- else if (!this._currentTerminal || !this._currentTerminal.isVisible) {
382
- this.setCurrentTerminal(undefined);
383
- }
384
- }
385
- getLastUsedTerminalId() {
386
- const mostRecent = this.mostRecentlyUsedTerminalEntries[this.mostRecentlyUsedTerminalEntries.length - 1];
387
- if (mostRecent) {
388
- return mostRecent.id;
389
- }
390
- }
391
- get lastUsedTerminal() {
392
- const id = this.getLastUsedTerminalId();
393
- if (id) {
394
- return this.getById(id);
395
- }
396
- }
397
- setLastUsedTerminal(lastUsedTerminal) {
398
- const lastUsedTerminalId = lastUsedTerminal.id;
399
- const entryIndex = this.mostRecentlyUsedTerminalEntries.findIndex(entry => entry.id === lastUsedTerminalId);
400
- let toDispose;
401
- if (entryIndex >= 0) {
402
- toDispose = this.mostRecentlyUsedTerminalEntries[entryIndex].disposables;
403
- this.mostRecentlyUsedTerminalEntries.splice(entryIndex, 1);
404
- }
405
- else {
406
- toDispose = new common_1.DisposableCollection();
407
- toDispose.push(lastUsedTerminal.onDidChangeVisibility((isVisible) => {
408
- if (isVisible) {
409
- this.setLastUsedTerminal(lastUsedTerminal);
410
- }
411
- }));
412
- toDispose.push(lastUsedTerminal.onDidDispose(() => {
413
- const index = this.mostRecentlyUsedTerminalEntries.findIndex(entry => entry.id === lastUsedTerminalId);
414
- if (index >= 0) {
415
- this.mostRecentlyUsedTerminalEntries[index].disposables.dispose();
416
- this.mostRecentlyUsedTerminalEntries.splice(index, 1);
417
- }
418
- }));
419
- }
420
- const newEntry = { id: lastUsedTerminalId, disposables: toDispose };
421
- if (lastUsedTerminal.isVisible) {
422
- this.mostRecentlyUsedTerminalEntries.push(newEntry);
423
- }
424
- else {
425
- this.mostRecentlyUsedTerminalEntries = [newEntry, ...this.mostRecentlyUsedTerminalEntries];
426
- }
427
- }
428
- get all() {
429
- return this.widgetManager.getWidgets(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID);
430
- }
431
- getById(id) {
432
- return this.all.find(terminal => terminal.id === id);
433
- }
434
- getByTerminalId(terminalId) {
435
- return this.all.find(terminal => terminal.terminalId === terminalId);
436
- }
437
- getDefaultShell() {
438
- return this.shellTerminalServer.getDefaultShell();
439
- }
440
- registerCommands(commands) {
441
- commands.registerCommand(TerminalCommands.NEW, {
442
- execute: () => this.openTerminal()
443
- });
444
- commands.registerCommand(TerminalCommands.PROFILE_NEW, {
445
- execute: async () => {
446
- const profile = await this.selectTerminalProfile(nls_1.nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
447
- if (!profile) {
448
- return;
449
- }
450
- this.openTerminal(undefined, profile[1]);
451
- }
452
- });
453
- commands.registerCommand(TerminalCommands.PROFILE_DEFAULT, {
454
- execute: () => this.chooseDefaultProfile()
455
- });
456
- commands.registerCommand(TerminalCommands.NEW_ACTIVE_WORKSPACE, {
457
- execute: () => this.openActiveWorkspaceTerminal()
458
- });
459
- commands.registerCommand(TerminalCommands.SPLIT, {
460
- execute: () => this.splitTerminal(),
461
- isEnabled: w => this.withWidget(w, () => true),
462
- isVisible: w => this.withWidget(w, () => true),
463
- });
464
- commands.registerCommand(TerminalCommands.TERMINAL_CLEAR);
465
- commands.registerHandler(TerminalCommands.TERMINAL_CLEAR.id, {
466
- execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.clearOutput(); }
467
- });
468
- commands.registerCommand(TerminalCommands.TERMINAL_CONTEXT, uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, {
469
- execute: uri => this.openInTerminal(uri)
470
- }));
471
- commands.registerCommand(TerminalCommands.TERMINAL_FIND_TEXT);
472
- commands.registerHandler(TerminalCommands.TERMINAL_FIND_TEXT.id, {
473
- isEnabled: () => {
474
- if (this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget) {
475
- return !this.shell.activeWidget.getSearchBox().isVisible;
476
- }
477
- return false;
478
- },
479
- execute: () => {
480
- const termWidget = this.shell.activeWidget;
481
- const terminalSearchBox = termWidget.getSearchBox();
482
- terminalSearchBox.show();
483
- }
484
- });
485
- commands.registerCommand(TerminalCommands.TERMINAL_FIND_TEXT_CANCEL);
486
- commands.registerHandler(TerminalCommands.TERMINAL_FIND_TEXT_CANCEL.id, {
487
- isEnabled: () => {
488
- if (this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget) {
489
- return this.shell.activeWidget.getSearchBox().isVisible;
490
- }
491
- return false;
492
- },
493
- execute: () => {
494
- const termWidget = this.shell.activeWidget;
495
- const terminalSearchBox = termWidget.getSearchBox();
496
- terminalSearchBox.hide();
497
- }
498
- });
499
- commands.registerCommand(TerminalCommands.SCROLL_LINE_UP, {
500
- isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
501
- isVisible: () => false,
502
- execute: () => {
503
- this.shell.activeWidget.scrollLineUp();
504
- }
505
- });
506
- commands.registerCommand(TerminalCommands.SCROLL_LINE_DOWN, {
507
- isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
508
- isVisible: () => false,
509
- execute: () => {
510
- this.shell.activeWidget.scrollLineDown();
511
- }
512
- });
513
- commands.registerCommand(TerminalCommands.SCROLL_TO_TOP, {
514
- isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
515
- isVisible: () => false,
516
- execute: () => {
517
- this.shell.activeWidget.scrollToTop();
518
- }
519
- });
520
- commands.registerCommand(TerminalCommands.SCROLL_PAGE_UP, {
521
- isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
522
- isVisible: () => false,
523
- execute: () => {
524
- this.shell.activeWidget.scrollPageUp();
525
- }
526
- });
527
- commands.registerCommand(TerminalCommands.SCROLL_PAGE_DOWN, {
528
- isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
529
- isVisible: () => false,
530
- execute: () => {
531
- this.shell.activeWidget.scrollPageDown();
532
- }
533
- });
534
- commands.registerCommand(TerminalCommands.TOGGLE_TERMINAL, {
535
- execute: () => this.toggleTerminal()
536
- });
537
- commands.registerCommand(TerminalCommands.KILL_TERMINAL, {
538
- isEnabled: () => !!this.currentTerminal,
539
- execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.close(); }
540
- });
541
- commands.registerCommand(TerminalCommands.SELECT_ALL, {
542
- isEnabled: () => !!this.currentTerminal,
543
- execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.selectAll(); }
544
- });
545
- }
546
- toggleTerminal() {
547
- const terminals = this.shell.getWidgets('bottom').filter(w => w instanceof terminal_widget_1.TerminalWidget);
548
- if (terminals.length === 0) {
549
- this.openTerminal();
550
- return;
551
- }
552
- if (!this.shell.isExpanded('bottom')) {
553
- this.shell.expandPanel('bottom');
554
- terminals[0].activate();
555
- }
556
- else {
557
- const visibleTerminal = terminals.find(t => t.isVisible);
558
- if (!visibleTerminal) {
559
- this.shell.bottomPanel.activateWidget(terminals[0]);
560
- }
561
- else if (this.shell.activeWidget !== visibleTerminal) {
562
- this.shell.bottomPanel.activateWidget(visibleTerminal);
563
- }
564
- else {
565
- this.shell.collapsePanel('bottom');
566
- }
567
- }
568
- }
569
- async openInTerminal(uri) {
570
- // Determine folder path of URI
571
- let stat;
572
- try {
573
- stat = await this.fileService.resolve(uri);
574
- }
575
- catch {
576
- return;
577
- }
578
- // Use folder if a file was selected
579
- const cwd = (stat.isDirectory) ? uri.toString() : uri.parent.toString();
580
- // Open terminal
581
- const termWidget = await this.newTerminal({ cwd });
582
- termWidget.start();
583
- this.open(termWidget);
584
- }
585
- registerMenus(menus) {
586
- menus.registerSubmenu(TerminalMenus.TERMINAL, terminal_widget_impl_1.TerminalWidgetImpl.LABEL);
587
- menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
588
- commandId: TerminalCommands.NEW.id,
589
- label: nls_1.nls.localizeByDefault('New Terminal'),
590
- order: '0'
591
- });
592
- menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
593
- commandId: TerminalCommands.PROFILE_NEW.id,
594
- label: nls_1.nls.localize('theia/terminal/profileNew', 'New Terminal (With Profile)...'),
595
- order: '1'
596
- });
597
- menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
598
- commandId: TerminalCommands.PROFILE_DEFAULT.id,
599
- label: nls_1.nls.localize('theia/terminal/profileDefault', 'Choose Default Profile...'),
600
- order: '3'
601
- });
602
- menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
603
- commandId: TerminalCommands.SPLIT.id,
604
- order: '3'
605
- });
606
- menus.registerMenuAction(TerminalMenus.TERMINAL_NAVIGATOR_CONTEXT_MENU, {
607
- commandId: TerminalCommands.TERMINAL_CONTEXT.id,
608
- order: 'z'
609
- });
610
- menus.registerMenuAction(TerminalMenus.TERMINAL_OPEN_EDITORS_CONTEXT_MENU, {
611
- commandId: TerminalCommands.TERMINAL_CONTEXT.id,
612
- order: 'z'
613
- });
614
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_1'], {
615
- commandId: TerminalCommands.NEW_ACTIVE_WORKSPACE.id,
616
- label: nls_1.nls.localizeByDefault('New Terminal')
617
- });
618
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_1'], {
619
- commandId: TerminalCommands.SPLIT.id
620
- });
621
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
622
- commandId: browser_1.CommonCommands.COPY.id
623
- });
624
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
625
- commandId: browser_1.CommonCommands.PASTE.id
626
- });
627
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
628
- commandId: TerminalCommands.SELECT_ALL.id
629
- });
630
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_3'], {
631
- commandId: TerminalCommands.TERMINAL_CLEAR.id
632
- });
633
- menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_4'], {
634
- commandId: TerminalCommands.KILL_TERMINAL.id
635
- });
636
- }
637
- registerToolbarItems(toolbar) {
638
- toolbar.registerItem({
639
- id: TerminalCommands.SPLIT.id,
640
- command: TerminalCommands.SPLIT.id,
641
- icon: (0, browser_1.codicon)('split-horizontal'),
642
- tooltip: TerminalCommands.SPLIT.label
643
- });
644
- }
645
- registerKeybindings(keybindings) {
646
- /* Register passthrough keybindings for combinations recognized by
647
- xterm.js and converted to control characters.
648
- See: https://github.com/xtermjs/xterm.js/blob/v3/src/Terminal.ts#L1684 */
649
- /* Register ctrl + k (the passed Key) as a passthrough command in the
650
- context of the terminal. */
651
- const regCtrl = (k) => {
652
- keybindings.registerKeybinding({
653
- command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
654
- keybinding: browser_1.KeyCode.createKeyCode({ key: k, ctrl: true }).toString(),
655
- when: 'terminalFocus',
656
- });
657
- };
658
- /* Register alt + k (the passed Key) as a passthrough command in the
659
- context of the terminal. */
660
- const regAlt = (k) => {
661
- keybindings.registerKeybinding({
662
- command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
663
- keybinding: browser_1.KeyCode.createKeyCode({ key: k, alt: true }).toString(),
664
- when: 'terminalFocus'
665
- });
666
- };
667
- /* ctrl-space (000 - NUL). */
668
- regCtrl(browser_1.Key.SPACE);
669
- /* ctrl-A (001/1/0x1) through ctrl-Z (032/26/0x1A). */
670
- for (let i = 0; i < 26; i++) {
671
- regCtrl({
672
- keyCode: browser_1.Key.KEY_A.keyCode + i,
673
- code: 'Key' + String.fromCharCode('A'.charCodeAt(0) + i)
674
- });
675
- }
676
- /* ctrl-[ or ctrl-3 (033/27/0x1B - ESC). */
677
- regCtrl(browser_1.Key.BRACKET_LEFT);
678
- regCtrl(browser_1.Key.DIGIT3);
679
- /* ctrl-\ or ctrl-4 (034/28/0x1C - FS). */
680
- regCtrl(browser_1.Key.BACKSLASH);
681
- regCtrl(browser_1.Key.DIGIT4);
682
- /* ctrl-] or ctrl-5 (035/29/0x1D - GS). */
683
- regCtrl(browser_1.Key.BRACKET_RIGHT);
684
- regCtrl(browser_1.Key.DIGIT5);
685
- /* ctrl-6 (036/30/0x1E - RS). */
686
- regCtrl(browser_1.Key.DIGIT6);
687
- /* ctrl-7 (037/31/0x1F - US). */
688
- regCtrl(browser_1.Key.DIGIT7);
689
- /* ctrl-8 (177/127/0x7F - DEL). */
690
- regCtrl(browser_1.Key.DIGIT8);
691
- /* alt-A (0x1B 0x62) through alt-Z (0x1B 0x7A). */
692
- for (let i = 0; i < 26; i++) {
693
- regAlt({
694
- keyCode: browser_1.Key.KEY_A.keyCode + i,
695
- code: 'Key' + String.fromCharCode('A'.charCodeAt(0) + i)
696
- });
697
- }
698
- /* alt-` (0x1B 0x60). */
699
- regAlt(browser_1.Key.BACKQUOTE);
700
- /* alt-0 (0x1B 0x30) through alt-9 (0x1B 0x39). */
701
- for (let i = 0; i < 10; i++) {
702
- regAlt({
703
- keyCode: browser_1.Key.DIGIT0.keyCode + i,
704
- code: 'Digit' + String.fromCharCode('0'.charCodeAt(0) + i)
705
- });
706
- }
707
- if (common_1.isOSX) {
708
- // selectAll on OSX
709
- keybindings.registerKeybinding({
710
- command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
711
- keybinding: 'ctrlcmd+a',
712
- when: 'terminalFocus'
713
- });
714
- }
715
- keybindings.registerKeybinding({
716
- command: TerminalCommands.NEW.id,
717
- keybinding: 'ctrl+shift+`'
718
- });
719
- keybindings.registerKeybinding({
720
- command: TerminalCommands.NEW_ACTIVE_WORKSPACE.id,
721
- keybinding: 'ctrl+`'
722
- });
723
- keybindings.registerKeybinding({
724
- command: TerminalCommands.TERMINAL_CLEAR.id,
725
- keybinding: 'ctrlcmd+k',
726
- when: 'terminalFocus'
727
- });
728
- keybindings.registerKeybinding({
729
- command: TerminalCommands.TERMINAL_FIND_TEXT.id,
730
- keybinding: 'ctrlcmd+f',
731
- when: 'terminalFocus'
732
- });
733
- keybindings.registerKeybinding({
734
- command: TerminalCommands.TERMINAL_FIND_TEXT_CANCEL.id,
735
- keybinding: 'esc',
736
- when: 'terminalHideSearch'
737
- });
738
- keybindings.registerKeybinding({
739
- command: TerminalCommands.SCROLL_LINE_UP.id,
740
- keybinding: 'ctrl+shift+up',
741
- when: 'terminalFocus'
742
- });
743
- keybindings.registerKeybinding({
744
- command: TerminalCommands.SCROLL_LINE_DOWN.id,
745
- keybinding: 'ctrl+shift+down',
746
- when: 'terminalFocus'
747
- });
748
- keybindings.registerKeybinding({
749
- command: TerminalCommands.SCROLL_TO_TOP.id,
750
- keybinding: 'shift-home',
751
- when: 'terminalFocus'
752
- });
753
- keybindings.registerKeybinding({
754
- command: TerminalCommands.SCROLL_PAGE_UP.id,
755
- keybinding: 'shift-pageUp',
756
- when: 'terminalFocus'
757
- });
758
- keybindings.registerKeybinding({
759
- command: TerminalCommands.SCROLL_PAGE_DOWN.id,
760
- keybinding: 'shift-pageDown',
761
- when: 'terminalFocus'
762
- });
763
- keybindings.registerKeybinding({
764
- command: TerminalCommands.TOGGLE_TERMINAL.id,
765
- keybinding: 'ctrl+`',
766
- });
767
- keybindings.registerKeybinding({
768
- command: TerminalCommands.SELECT_ALL.id,
769
- keybinding: 'ctrlcmd+a',
770
- when: 'terminalFocus'
771
- });
772
- }
773
- async newTerminal(options) {
774
- const widget = await this.widgetManager.getOrCreateWidget(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID, {
775
- created: new Date().toISOString(),
776
- ...options
777
- });
778
- return widget;
779
- }
780
- // TODO: reuse WidgetOpenHandler.open
781
- open(widget, options) {
782
- var _a;
783
- const area = widget.location === terminal_widget_1.TerminalLocation.Editor ? 'main' : 'bottom';
784
- const widgetOptions = { area: area, ...options === null || options === void 0 ? void 0 : options.widgetOptions };
785
- let preserveFocus = false;
786
- if (typeof widget.location === 'object') {
787
- if ('parentTerminal' in widget.location) {
788
- widgetOptions.ref = this.getById(widget.location.parentTerminal);
789
- widgetOptions.mode = 'split-right';
790
- }
791
- else if ('viewColumn' in widget.location) {
792
- preserveFocus = (_a = widget.location.preserveFocus) !== null && _a !== void 0 ? _a : false;
793
- switch (widget.location.viewColumn) {
794
- case common_1.ViewColumn.Active:
795
- widgetOptions.ref = this.shell.currentWidget;
796
- widgetOptions.mode = 'tab-after';
797
- break;
798
- case common_1.ViewColumn.Beside:
799
- widgetOptions.ref = this.shell.currentWidget;
800
- widgetOptions.mode = 'split-right';
801
- break;
802
- default:
803
- widgetOptions.area = 'main';
804
- const mainAreaTerminals = this.shell.getWidgets('main').filter(w => w instanceof terminal_widget_1.TerminalWidget && w.isVisible);
805
- const column = Math.min(widget.location.viewColumn, mainAreaTerminals.length);
806
- widgetOptions.mode = widget.location.viewColumn <= mainAreaTerminals.length ? 'split-left' : 'split-right';
807
- widgetOptions.ref = mainAreaTerminals[column - 1];
808
- }
809
- }
810
- }
811
- const op = {
812
- mode: 'activate',
813
- ...options,
814
- widgetOptions: widgetOptions
815
- };
816
- if (!widget.isAttached) {
817
- this.shell.addWidget(widget, op.widgetOptions);
818
- }
819
- if (op.mode === 'activate' && !preserveFocus) {
820
- this.shell.activateWidget(widget.id);
821
- }
822
- else if (op.mode === 'reveal' || preserveFocus) {
823
- this.shell.revealWidget(widget.id);
824
- }
825
- }
826
- async selectTerminalCwd() {
827
- return new Promise(async (resolve) => {
828
- var _a, _b;
829
- const roots = this.workspaceService.tryGetRoots();
830
- if (roots.length === 0) {
831
- resolve(undefined);
832
- }
833
- else if (roots.length === 1) {
834
- resolve(roots[0].resource.toString());
835
- }
836
- else {
837
- const items = roots.map(({ resource }) => ({
838
- label: this.labelProvider.getName(resource),
839
- description: this.labelProvider.getLongName(resource),
840
- resource
841
- }));
842
- const selectedItem = await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, {
843
- placeholder: nls_1.nls.localizeByDefault('Select current working directory for new terminal')
844
- }));
845
- resolve((_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.resource) === null || _b === void 0 ? void 0 : _b.toString());
846
- }
847
- });
848
- }
849
- async selectTerminalProfile(placeholder) {
850
- return new Promise(async (resolve) => {
851
- var _a;
852
- const profiles = this.profileService.all;
853
- if (profiles.length === 0) {
854
- resolve(undefined);
855
- }
856
- else {
857
- const items = profiles.map(([id, profile]) => ({
858
- label: id,
859
- profile
860
- }));
861
- const selectedItem = await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, {
862
- placeholder
863
- }));
864
- resolve(selectedItem ? [selectedItem.label, selectedItem.profile] : undefined);
865
- }
866
- });
867
- }
868
- async splitTerminal(referenceTerminal) {
869
- if (referenceTerminal || this.currentTerminal) {
870
- const ref = referenceTerminal !== null && referenceTerminal !== void 0 ? referenceTerminal : this.currentTerminal;
871
- await this.openTerminal({ ref, mode: 'split-right' });
872
- }
873
- }
874
- async openTerminal(options, terminalProfile) {
875
- let profile = terminalProfile;
876
- if (!terminalProfile) {
877
- profile = this.profileService.defaultProfile;
878
- if (!profile) {
879
- throw new Error('There are not profiles registered');
880
- }
881
- }
882
- if (profile instanceof shell_terminal_profile_1.ShellTerminalProfile) {
883
- if (this.workspaceService.workspace) {
884
- const cwd = await this.selectTerminalCwd();
885
- if (!cwd) {
886
- return;
887
- }
888
- profile = profile.modify({ cwd });
889
- }
890
- }
891
- const termWidget = await (profile === null || profile === void 0 ? void 0 : profile.start());
892
- if (!!termWidget) {
893
- this.open(termWidget, { widgetOptions: options });
894
- }
895
- }
896
- async chooseDefaultProfile() {
897
- const result = await this.selectTerminalProfile(nls_1.nls.localizeByDefault('Select your default terminal profile'));
898
- if (!result) {
899
- return;
900
- }
901
- this.preferenceService.set(`terminal.integrated.defaultProfile.${common_1.OS.backend.type().toLowerCase()}`, result[0], browser_1.PreferenceScope.User);
902
- }
903
- async openActiveWorkspaceTerminal(options) {
904
- const termWidget = await this.newTerminal({});
905
- termWidget.start();
906
- this.open(termWidget, { widgetOptions: options });
907
- }
908
- withWidget(widget, fn) {
909
- if (widget instanceof terminal_widget_1.TerminalWidget) {
910
- return fn(widget);
911
- }
912
- return false;
913
- }
914
- /**
915
- * It should be aligned with https://code.visualstudio.com/api/references/theme-color#integrated-terminal-colors
916
- */
917
- registerColors(colors) {
918
- colors.register({
919
- id: 'terminal.background',
920
- defaults: {
921
- dark: 'panel.background',
922
- light: 'panel.background',
923
- hcDark: 'panel.background',
924
- hcLight: 'panel.background'
925
- },
926
- description: 'The background color of the terminal, this allows coloring the terminal differently to the panel.'
927
- });
928
- colors.register({
929
- id: 'terminal.foreground',
930
- defaults: {
931
- light: '#333333',
932
- dark: '#CCCCCC',
933
- hcDark: '#FFFFFF',
934
- hcLight: '#292929'
935
- },
936
- description: 'The foreground color of the terminal.'
937
- });
938
- colors.register({
939
- id: 'terminalCursor.foreground',
940
- description: 'The foreground color of the terminal cursor.'
941
- });
942
- colors.register({
943
- id: 'terminalCursor.background',
944
- description: 'The background color of the terminal cursor. Allows customizing the color of a character overlapped by a block cursor.'
945
- });
946
- colors.register({
947
- id: 'terminal.selectionBackground',
948
- defaults: {
949
- light: 'editor.selectionBackground',
950
- dark: 'editor.selectionBackground',
951
- hcDark: 'editor.selectionBackground',
952
- hcLight: 'editor.selectionBackground'
953
- },
954
- description: 'The selection background color of the terminal.'
955
- });
956
- colors.register({
957
- id: 'terminal.border',
958
- defaults: {
959
- light: 'panel.border',
960
- dark: 'panel.border',
961
- hcDark: 'panel.border',
962
- hcLight: 'panel.border'
963
- },
964
- description: 'The color of the border that separates split panes within the terminal. This defaults to panel.border.'
965
- });
966
- // eslint-disable-next-line guard-for-in
967
- for (const id in terminal_theme_service_1.terminalAnsiColorMap) {
968
- const entry = terminal_theme_service_1.terminalAnsiColorMap[id];
969
- const colorName = id.substring(13);
970
- colors.register({
971
- id,
972
- defaults: entry.defaults,
973
- description: `'${colorName}' ANSI color in the terminal.`
974
- });
975
- }
976
- }
977
- };
978
- __decorate([
979
- (0, inversify_1.inject)(browser_1.ApplicationShell),
980
- __metadata("design:type", browser_1.ApplicationShell)
981
- ], TerminalFrontendContribution.prototype, "shell", void 0);
982
- __decorate([
983
- (0, inversify_1.inject)(shell_terminal_protocol_1.ShellTerminalServerProxy),
984
- __metadata("design:type", Object)
985
- ], TerminalFrontendContribution.prototype, "shellTerminalServer", void 0);
986
- __decorate([
987
- (0, inversify_1.inject)(browser_1.WidgetManager),
988
- __metadata("design:type", browser_1.WidgetManager)
989
- ], TerminalFrontendContribution.prototype, "widgetManager", void 0);
990
- __decorate([
991
- (0, inversify_1.inject)(file_service_1.FileService),
992
- __metadata("design:type", file_service_1.FileService)
993
- ], TerminalFrontendContribution.prototype, "fileService", void 0);
994
- __decorate([
995
- (0, inversify_1.inject)(common_1.SelectionService),
996
- __metadata("design:type", common_1.SelectionService)
997
- ], TerminalFrontendContribution.prototype, "selectionService", void 0);
998
- __decorate([
999
- (0, inversify_1.inject)(browser_1.LabelProvider),
1000
- __metadata("design:type", browser_1.LabelProvider)
1001
- ], TerminalFrontendContribution.prototype, "labelProvider", void 0);
1002
- __decorate([
1003
- (0, inversify_1.inject)(browser_1.QuickInputService),
1004
- (0, inversify_1.optional)(),
1005
- __metadata("design:type", Object)
1006
- ], TerminalFrontendContribution.prototype, "quickInputService", void 0);
1007
- __decorate([
1008
- (0, inversify_1.inject)(browser_2.WorkspaceService),
1009
- __metadata("design:type", browser_2.WorkspaceService)
1010
- ], TerminalFrontendContribution.prototype, "workspaceService", void 0);
1011
- __decorate([
1012
- (0, inversify_1.inject)(terminal_profile_service_1.TerminalProfileService),
1013
- __metadata("design:type", Object)
1014
- ], TerminalFrontendContribution.prototype, "profileService", void 0);
1015
- __decorate([
1016
- (0, inversify_1.inject)(terminal_profile_service_1.UserTerminalProfileStore),
1017
- __metadata("design:type", Object)
1018
- ], TerminalFrontendContribution.prototype, "userProfileStore", void 0);
1019
- __decorate([
1020
- (0, inversify_1.inject)(terminal_profile_service_1.ContributedTerminalProfileStore),
1021
- __metadata("design:type", Object)
1022
- ], TerminalFrontendContribution.prototype, "contributedProfileStore", void 0);
1023
- __decorate([
1024
- (0, inversify_1.inject)(terminal_watcher_1.TerminalWatcher),
1025
- __metadata("design:type", terminal_watcher_1.TerminalWatcher)
1026
- ], TerminalFrontendContribution.prototype, "terminalWatcher", void 0);
1027
- __decorate([
1028
- (0, inversify_1.inject)(browser_3.VariableResolverService),
1029
- __metadata("design:type", browser_3.VariableResolverService)
1030
- ], TerminalFrontendContribution.prototype, "variableResolver", void 0);
1031
- __decorate([
1032
- (0, inversify_1.inject)(browser_1.StorageService),
1033
- __metadata("design:type", Object)
1034
- ], TerminalFrontendContribution.prototype, "storageService", void 0);
1035
- __decorate([
1036
- (0, inversify_1.inject)(browser_1.PreferenceService),
1037
- __metadata("design:type", Object)
1038
- ], TerminalFrontendContribution.prototype, "preferenceService", void 0);
1039
- __decorate([
1040
- (0, inversify_1.inject)(terminal_preferences_1.TerminalPreferences),
1041
- __metadata("design:type", Object)
1042
- ], TerminalFrontendContribution.prototype, "terminalPreferences", void 0);
1043
- __decorate([
1044
- (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
1045
- __metadata("design:type", Object)
1046
- ], TerminalFrontendContribution.prototype, "contextKeyService", void 0);
1047
- __decorate([
1048
- (0, inversify_1.postConstruct)(),
1049
- __metadata("design:type", Function),
1050
- __metadata("design:paramtypes", []),
1051
- __metadata("design:returntype", void 0)
1052
- ], TerminalFrontendContribution.prototype, "init", null);
1053
- TerminalFrontendContribution = __decorate([
1054
- (0, inversify_1.injectable)()
1055
- ], TerminalFrontendContribution);
1056
- exports.TerminalFrontendContribution = TerminalFrontendContribution;
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2017 TypeFox and others.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.TerminalFrontendContribution = exports.TerminalCommands = exports.TerminalMenus = void 0;
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const common_1 = require("@theia/core/lib/common");
30
+ const browser_1 = require("@theia/core/lib/browser");
31
+ const terminal_widget_impl_1 = require("./terminal-widget-impl");
32
+ const terminal_widget_1 = require("./base/terminal-widget");
33
+ const terminal_profile_service_1 = require("./terminal-profile-service");
34
+ const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
35
+ const shell_terminal_protocol_1 = require("../common/shell-terminal-protocol");
36
+ const uri_1 = require("@theia/core/lib/common/uri");
37
+ const core_1 = require("@theia/core");
38
+ const browser_2 = require("@theia/workspace/lib/browser");
39
+ const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
40
+ const terminal_theme_service_1 = require("./terminal-theme-service");
41
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
42
+ const terminal_watcher_1 = require("../common/terminal-watcher");
43
+ const nls_1 = require("@theia/core/lib/common/nls");
44
+ const terminal_preferences_1 = require("./terminal-preferences");
45
+ const shell_terminal_profile_1 = require("./shell-terminal-profile");
46
+ const browser_3 = require("@theia/variable-resolver/lib/browser");
47
+ const color_1 = require("@theia/core/lib/common/color");
48
+ var TerminalMenus;
49
+ (function (TerminalMenus) {
50
+ TerminalMenus.TERMINAL = [...core_1.MAIN_MENU_BAR, '7_terminal'];
51
+ TerminalMenus.TERMINAL_NEW = [...TerminalMenus.TERMINAL, '1_terminal'];
52
+ TerminalMenus.TERMINAL_TASKS = [...TerminalMenus.TERMINAL, '2_terminal'];
53
+ TerminalMenus.TERMINAL_TASKS_INFO = [...TerminalMenus.TERMINAL_TASKS, '3_terminal'];
54
+ TerminalMenus.TERMINAL_TASKS_CONFIG = [...TerminalMenus.TERMINAL_TASKS, '4_terminal'];
55
+ TerminalMenus.TERMINAL_NAVIGATOR_CONTEXT_MENU = ['navigator-context-menu', 'navigation'];
56
+ TerminalMenus.TERMINAL_OPEN_EDITORS_CONTEXT_MENU = ['open-editors-context-menu', 'navigation'];
57
+ TerminalMenus.TERMINAL_CONTEXT_MENU = ['terminal-context-menu'];
58
+ })(TerminalMenus = exports.TerminalMenus || (exports.TerminalMenus = {}));
59
+ var TerminalCommands;
60
+ (function (TerminalCommands) {
61
+ const TERMINAL_CATEGORY = 'Terminal';
62
+ TerminalCommands.NEW = common_1.Command.toDefaultLocalizedCommand({
63
+ id: 'terminal:new',
64
+ category: TERMINAL_CATEGORY,
65
+ label: 'Create New Terminal'
66
+ });
67
+ TerminalCommands.PROFILE_NEW = common_1.Command.toLocalizedCommand({
68
+ id: 'terminal:new:profile',
69
+ category: TERMINAL_CATEGORY,
70
+ label: 'Create New Integrated Terminal from a Profile'
71
+ });
72
+ TerminalCommands.PROFILE_DEFAULT = common_1.Command.toLocalizedCommand({
73
+ id: 'terminal:profile:default',
74
+ category: TERMINAL_CATEGORY,
75
+ label: 'Choose the default Terminal Profile'
76
+ });
77
+ TerminalCommands.NEW_ACTIVE_WORKSPACE = common_1.Command.toDefaultLocalizedCommand({
78
+ id: 'terminal:new:active:workspace',
79
+ category: TERMINAL_CATEGORY,
80
+ label: 'Create New Terminal (In Active Workspace)'
81
+ });
82
+ TerminalCommands.TERMINAL_CLEAR = common_1.Command.toDefaultLocalizedCommand({
83
+ id: 'terminal:clear',
84
+ category: TERMINAL_CATEGORY,
85
+ label: 'Clear'
86
+ });
87
+ TerminalCommands.TERMINAL_CONTEXT = common_1.Command.toDefaultLocalizedCommand({
88
+ id: 'terminal:context',
89
+ category: TERMINAL_CATEGORY,
90
+ label: 'Open in Integrated Terminal'
91
+ });
92
+ TerminalCommands.SPLIT = common_1.Command.toDefaultLocalizedCommand({
93
+ id: 'terminal:split',
94
+ category: TERMINAL_CATEGORY,
95
+ label: 'Split Terminal'
96
+ });
97
+ TerminalCommands.TERMINAL_FIND_TEXT = common_1.Command.toDefaultLocalizedCommand({
98
+ id: 'terminal:find',
99
+ category: TERMINAL_CATEGORY,
100
+ label: 'Find'
101
+ });
102
+ TerminalCommands.TERMINAL_FIND_TEXT_CANCEL = common_1.Command.toDefaultLocalizedCommand({
103
+ id: 'terminal:find:cancel',
104
+ category: TERMINAL_CATEGORY,
105
+ label: 'Hide Find'
106
+ });
107
+ TerminalCommands.SCROLL_LINE_UP = common_1.Command.toDefaultLocalizedCommand({
108
+ id: 'terminal:scroll:line:up',
109
+ category: TERMINAL_CATEGORY,
110
+ label: 'Scroll Up (Line)'
111
+ });
112
+ TerminalCommands.SCROLL_LINE_DOWN = common_1.Command.toDefaultLocalizedCommand({
113
+ id: 'terminal:scroll:line:down',
114
+ category: TERMINAL_CATEGORY,
115
+ label: 'Scroll Down (Line)'
116
+ });
117
+ TerminalCommands.SCROLL_TO_TOP = common_1.Command.toDefaultLocalizedCommand({
118
+ id: 'terminal:scroll:top',
119
+ category: TERMINAL_CATEGORY,
120
+ label: 'Scroll to Top'
121
+ });
122
+ TerminalCommands.SCROLL_PAGE_UP = common_1.Command.toDefaultLocalizedCommand({
123
+ id: 'terminal:scroll:page:up',
124
+ category: TERMINAL_CATEGORY,
125
+ label: 'Scroll Up (Page)'
126
+ });
127
+ TerminalCommands.SCROLL_PAGE_DOWN = common_1.Command.toDefaultLocalizedCommand({
128
+ id: 'terminal:scroll:page:down',
129
+ category: TERMINAL_CATEGORY,
130
+ label: 'Scroll Down (Page)'
131
+ });
132
+ TerminalCommands.TOGGLE_TERMINAL = common_1.Command.toDefaultLocalizedCommand({
133
+ id: 'workbench.action.terminal.toggleTerminal',
134
+ category: TERMINAL_CATEGORY,
135
+ label: 'Toggle Terminal'
136
+ });
137
+ TerminalCommands.KILL_TERMINAL = common_1.Command.toDefaultLocalizedCommand({
138
+ id: 'terminal:kill',
139
+ category: TERMINAL_CATEGORY,
140
+ label: 'Kill Terminal'
141
+ });
142
+ TerminalCommands.SELECT_ALL = {
143
+ id: 'terminal:select:all',
144
+ label: browser_1.CommonCommands.SELECT_ALL.label,
145
+ category: TERMINAL_CATEGORY,
146
+ };
147
+ /**
148
+ * Command that displays all terminals that are currently opened
149
+ */
150
+ TerminalCommands.SHOW_ALL_OPENED_TERMINALS = common_1.Command.toDefaultLocalizedCommand({
151
+ id: 'workbench.action.showAllTerminals',
152
+ category: browser_1.CommonCommands.VIEW_CATEGORY,
153
+ label: 'Show All Opened Terminals'
154
+ });
155
+ })(TerminalCommands = exports.TerminalCommands || (exports.TerminalCommands = {}));
156
+ const ENVIRONMENT_VARIABLE_COLLECTIONS_KEY = 'terminal.integrated.environmentVariableCollections';
157
+ let TerminalFrontendContribution = class TerminalFrontendContribution {
158
+ constructor() {
159
+ this.mergePreferencesPromise = Promise.resolve();
160
+ this.onDidCreateTerminalEmitter = new common_1.Emitter();
161
+ this.onDidCreateTerminal = this.onDidCreateTerminalEmitter.event;
162
+ this.onDidChangeCurrentTerminalEmitter = new common_1.Emitter();
163
+ this.onDidChangeCurrentTerminal = this.onDidChangeCurrentTerminalEmitter.event;
164
+ // IDs of the most recently used terminals
165
+ this.mostRecentlyUsedTerminalEntries = [];
166
+ }
167
+ init() {
168
+ this.shell.onDidChangeCurrentWidget(() => this.updateCurrentTerminal());
169
+ this.widgetManager.onDidCreateWidget(({ widget }) => {
170
+ if (widget instanceof terminal_widget_1.TerminalWidget) {
171
+ this.updateCurrentTerminal();
172
+ this.onDidCreateTerminalEmitter.fire(widget);
173
+ this.setLastUsedTerminal(widget);
174
+ }
175
+ });
176
+ const terminalFocusKey = this.contextKeyService.createKey('terminalFocus', false);
177
+ const terminalSearchToggle = this.contextKeyService.createKey('terminalHideSearch', false);
178
+ const updateFocusKey = () => {
179
+ terminalFocusKey.set(this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget);
180
+ terminalSearchToggle.set(this.terminalHideSearch);
181
+ };
182
+ updateFocusKey();
183
+ this.shell.onDidChangeActiveWidget(updateFocusKey);
184
+ this.terminalWatcher.onStoreTerminalEnvVariablesRequested(data => {
185
+ this.storageService.setData(ENVIRONMENT_VARIABLE_COLLECTIONS_KEY, data);
186
+ });
187
+ this.terminalWatcher.onUpdateTerminalEnvVariablesRequested(() => {
188
+ this.storageService.getData(ENVIRONMENT_VARIABLE_COLLECTIONS_KEY).then(data => {
189
+ if (data) {
190
+ this.shellTerminalServer.restorePersisted(data);
191
+ }
192
+ });
193
+ });
194
+ }
195
+ get terminalHideSearch() {
196
+ if (!(this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget)) {
197
+ return false;
198
+ }
199
+ const searchWidget = this.shell.activeWidget.getSearchBox();
200
+ return searchWidget.isVisible;
201
+ }
202
+ async onStart(app) {
203
+ this.contributeDefaultProfiles();
204
+ this.terminalPreferences.onPreferenceChanged(e => {
205
+ if (e.preferenceName.startsWith('terminal.integrated.')) {
206
+ this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
207
+ }
208
+ });
209
+ this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
210
+ // extension contributions get read after this point: need to set the default profile if necessary
211
+ this.profileService.onAdded(id => {
212
+ let defaultProfileId;
213
+ switch (common_1.OS.backend.type()) {
214
+ case common_1.OS.Type.Windows: {
215
+ defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.windows'];
216
+ break;
217
+ }
218
+ case common_1.OS.Type.Linux: {
219
+ defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.linux'];
220
+ break;
221
+ }
222
+ case common_1.OS.Type.OSX: {
223
+ defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.osx'];
224
+ break;
225
+ }
226
+ }
227
+ if (defaultProfileId) {
228
+ this.profileService.setDefaultProfile(defaultProfileId);
229
+ }
230
+ });
231
+ }
232
+ async contributeDefaultProfiles() {
233
+ if (common_1.OS.backend.isWindows) {
234
+ this.contributedProfileStore.registerTerminalProfile('cmd', new shell_terminal_profile_1.ShellTerminalProfile(this, {
235
+ shellPath: await this.resolveShellPath([
236
+ '${env:windir}\\Sysnative\\cmd.exe',
237
+ '${env:windir}\\System32\\cmd.exe'
238
+ ])
239
+ }));
240
+ }
241
+ else {
242
+ this.contributedProfileStore.registerTerminalProfile('SHELL', new shell_terminal_profile_1.ShellTerminalProfile(this, {
243
+ shellPath: await this.resolveShellPath('${SHELL}'),
244
+ shellArgs: ['-l']
245
+ }));
246
+ }
247
+ // contribute default profiles based on legacy preferences
248
+ }
249
+ async mergePreferences() {
250
+ var _a, _b, _c;
251
+ let profiles;
252
+ let defaultProfile;
253
+ let legacyShellPath;
254
+ let legacyShellArgs;
255
+ const removed = new Set(this.userProfileStore.all.map(([id, profile]) => id));
256
+ switch (common_1.OS.backend.type()) {
257
+ case common_1.OS.Type.Windows: {
258
+ profiles = this.terminalPreferences['terminal.integrated.profiles.windows'];
259
+ defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.windows'];
260
+ legacyShellPath = (_a = this.terminalPreferences['terminal.integrated.shell.windows']) !== null && _a !== void 0 ? _a : undefined;
261
+ legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.windows'];
262
+ break;
263
+ }
264
+ case common_1.OS.Type.Linux: {
265
+ profiles = this.terminalPreferences['terminal.integrated.profiles.linux'];
266
+ defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.linux'];
267
+ legacyShellPath = (_b = this.terminalPreferences['terminal.integrated.shell.linux']) !== null && _b !== void 0 ? _b : undefined;
268
+ legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.linux'];
269
+ break;
270
+ }
271
+ case common_1.OS.Type.OSX: {
272
+ profiles = this.terminalPreferences['terminal.integrated.profiles.osx'];
273
+ defaultProfile = this.terminalPreferences['terminal.integrated.defaultProfile.osx'];
274
+ legacyShellPath = (_c = this.terminalPreferences['terminal.integrated.shell.osx']) !== null && _c !== void 0 ? _c : undefined;
275
+ legacyShellArgs = this.terminalPreferences['terminal.integrated.shellArgs.osx'];
276
+ break;
277
+ }
278
+ }
279
+ if (profiles) {
280
+ for (const id of Object.getOwnPropertyNames(profiles)) {
281
+ const profile = profiles[id];
282
+ removed.delete(id);
283
+ if (profile) {
284
+ const shellPath = await this.resolveShellPath(profile.path);
285
+ if (shellPath) {
286
+ const options = {
287
+ shellPath: shellPath,
288
+ shellArgs: profile.args ? await this.variableResolver.resolve(profile.args) : undefined,
289
+ useServerTitle: profile.overrideName ? false : undefined,
290
+ env: profile.env ? await this.variableResolver.resolve(profile.env) : undefined,
291
+ title: profile.overrideName ? id : undefined
292
+ };
293
+ this.userProfileStore.registerTerminalProfile(id, new shell_terminal_profile_1.ShellTerminalProfile(this, options));
294
+ }
295
+ }
296
+ else {
297
+ this.userProfileStore.registerTerminalProfile(id, terminal_profile_service_1.NULL_PROFILE);
298
+ }
299
+ }
300
+ }
301
+ if (legacyShellPath) {
302
+ this.userProfileStore.registerTerminalProfile('Legacy Shell Preferences', new shell_terminal_profile_1.ShellTerminalProfile(this, {
303
+ shellPath: legacyShellPath,
304
+ shellArgs: legacyShellArgs
305
+ }));
306
+ // if no other default is set, use the legacy preferences as default if they exist
307
+ this.profileService.setDefaultProfile('Legacy Shell Preferences');
308
+ }
309
+ if (defaultProfile && this.profileService.getProfile(defaultProfile)) {
310
+ this.profileService.setDefaultProfile(defaultProfile);
311
+ }
312
+ for (const id of removed) {
313
+ this.userProfileStore.unregisterTerminalProfile(id);
314
+ }
315
+ }
316
+ async resolveShellPath(path) {
317
+ if (!path) {
318
+ return undefined;
319
+ }
320
+ if (typeof path === 'string') {
321
+ path = [path];
322
+ }
323
+ for (const p of path) {
324
+ const resolved = await this.variableResolver.resolve(p);
325
+ if (resolved) {
326
+ const resolvedURI = uri_1.default.fromFilePath(resolved);
327
+ if (await this.fileService.exists(resolvedURI)) {
328
+ return resolved;
329
+ }
330
+ }
331
+ }
332
+ return undefined;
333
+ }
334
+ onWillStop() {
335
+ const preferenceValue = this.terminalPreferences['terminal.integrated.confirmOnExit'];
336
+ if (preferenceValue !== 'never') {
337
+ const allTerminals = this.widgetManager.getWidgets(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID);
338
+ if (allTerminals.length) {
339
+ return {
340
+ prepare: async () => {
341
+ if (preferenceValue === 'always') {
342
+ return allTerminals.length;
343
+ }
344
+ else {
345
+ const activeTerminals = await Promise.all(allTerminals.map(widget => widget.hasChildProcesses()))
346
+ .then(hasChildProcesses => hasChildProcesses.filter(hasChild => hasChild));
347
+ return activeTerminals.length;
348
+ }
349
+ },
350
+ action: async (activeTerminalCount) => activeTerminalCount === 0 || this.confirmExitWithActiveTerminals(activeTerminalCount),
351
+ reason: 'Active integrated terminal',
352
+ };
353
+ }
354
+ }
355
+ }
356
+ async confirmExitWithActiveTerminals(activeTerminalCount) {
357
+ const msg = activeTerminalCount === 1
358
+ ? nls_1.nls.localizeByDefault('Do you want to terminate the active terminal session?')
359
+ : nls_1.nls.localizeByDefault('Do you want to terminate the {0} active terminal sessions?', activeTerminalCount);
360
+ const safeToExit = await new browser_1.ConfirmDialog({
361
+ title: '',
362
+ msg,
363
+ ok: nls_1.nls.localizeByDefault('Terminate'),
364
+ cancel: browser_1.Dialog.CANCEL,
365
+ }).open();
366
+ return safeToExit === true;
367
+ }
368
+ get currentTerminal() {
369
+ return this._currentTerminal;
370
+ }
371
+ setCurrentTerminal(current) {
372
+ if (this._currentTerminal !== current) {
373
+ this._currentTerminal = current;
374
+ this.onDidChangeCurrentTerminalEmitter.fire(this._currentTerminal);
375
+ }
376
+ }
377
+ updateCurrentTerminal() {
378
+ const widget = this.shell.currentWidget;
379
+ if (widget instanceof terminal_widget_1.TerminalWidget) {
380
+ this.setCurrentTerminal(widget);
381
+ }
382
+ else if (!this._currentTerminal || !this._currentTerminal.isVisible) {
383
+ this.setCurrentTerminal(undefined);
384
+ }
385
+ }
386
+ getLastUsedTerminalId() {
387
+ const mostRecent = this.mostRecentlyUsedTerminalEntries[this.mostRecentlyUsedTerminalEntries.length - 1];
388
+ if (mostRecent) {
389
+ return mostRecent.id;
390
+ }
391
+ }
392
+ get lastUsedTerminal() {
393
+ const id = this.getLastUsedTerminalId();
394
+ if (id) {
395
+ return this.getById(id);
396
+ }
397
+ }
398
+ setLastUsedTerminal(lastUsedTerminal) {
399
+ const lastUsedTerminalId = lastUsedTerminal.id;
400
+ const entryIndex = this.mostRecentlyUsedTerminalEntries.findIndex(entry => entry.id === lastUsedTerminalId);
401
+ let toDispose;
402
+ if (entryIndex >= 0) {
403
+ toDispose = this.mostRecentlyUsedTerminalEntries[entryIndex].disposables;
404
+ this.mostRecentlyUsedTerminalEntries.splice(entryIndex, 1);
405
+ }
406
+ else {
407
+ toDispose = new common_1.DisposableCollection();
408
+ toDispose.push(lastUsedTerminal.onDidChangeVisibility((isVisible) => {
409
+ if (isVisible) {
410
+ this.setLastUsedTerminal(lastUsedTerminal);
411
+ }
412
+ }));
413
+ toDispose.push(lastUsedTerminal.onDidDispose(() => {
414
+ const index = this.mostRecentlyUsedTerminalEntries.findIndex(entry => entry.id === lastUsedTerminalId);
415
+ if (index >= 0) {
416
+ this.mostRecentlyUsedTerminalEntries[index].disposables.dispose();
417
+ this.mostRecentlyUsedTerminalEntries.splice(index, 1);
418
+ }
419
+ }));
420
+ }
421
+ const newEntry = { id: lastUsedTerminalId, disposables: toDispose };
422
+ if (lastUsedTerminal.isVisible) {
423
+ this.mostRecentlyUsedTerminalEntries.push(newEntry);
424
+ }
425
+ else {
426
+ this.mostRecentlyUsedTerminalEntries = [newEntry, ...this.mostRecentlyUsedTerminalEntries];
427
+ }
428
+ }
429
+ get all() {
430
+ return this.widgetManager.getWidgets(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID);
431
+ }
432
+ getById(id) {
433
+ return this.all.find(terminal => terminal.id === id);
434
+ }
435
+ getByTerminalId(terminalId) {
436
+ return this.all.find(terminal => terminal.terminalId === terminalId);
437
+ }
438
+ getDefaultShell() {
439
+ return this.shellTerminalServer.getDefaultShell();
440
+ }
441
+ registerCommands(commands) {
442
+ commands.registerCommand(TerminalCommands.NEW, {
443
+ execute: () => this.openTerminal()
444
+ });
445
+ commands.registerCommand(TerminalCommands.PROFILE_NEW, {
446
+ execute: async () => {
447
+ const profile = await this.selectTerminalProfile(nls_1.nls.localize('theia/terminal/selectProfile', 'Select a profile for the new terminal'));
448
+ if (!profile) {
449
+ return;
450
+ }
451
+ this.openTerminal(undefined, profile[1]);
452
+ }
453
+ });
454
+ commands.registerCommand(TerminalCommands.PROFILE_DEFAULT, {
455
+ execute: () => this.chooseDefaultProfile()
456
+ });
457
+ commands.registerCommand(TerminalCommands.NEW_ACTIVE_WORKSPACE, {
458
+ execute: () => this.openActiveWorkspaceTerminal()
459
+ });
460
+ commands.registerCommand(TerminalCommands.SPLIT, {
461
+ execute: () => this.splitTerminal(),
462
+ isEnabled: w => this.withWidget(w, () => true),
463
+ isVisible: w => this.withWidget(w, () => true),
464
+ });
465
+ commands.registerCommand(TerminalCommands.TERMINAL_CLEAR);
466
+ commands.registerHandler(TerminalCommands.TERMINAL_CLEAR.id, {
467
+ execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.clearOutput(); }
468
+ });
469
+ commands.registerCommand(TerminalCommands.TERMINAL_CONTEXT, uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, {
470
+ execute: uri => this.openInTerminal(uri)
471
+ }));
472
+ commands.registerCommand(TerminalCommands.TERMINAL_FIND_TEXT);
473
+ commands.registerHandler(TerminalCommands.TERMINAL_FIND_TEXT.id, {
474
+ isEnabled: () => {
475
+ if (this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget) {
476
+ return !this.shell.activeWidget.getSearchBox().isVisible;
477
+ }
478
+ return false;
479
+ },
480
+ execute: () => {
481
+ const termWidget = this.shell.activeWidget;
482
+ const terminalSearchBox = termWidget.getSearchBox();
483
+ terminalSearchBox.show();
484
+ }
485
+ });
486
+ commands.registerCommand(TerminalCommands.TERMINAL_FIND_TEXT_CANCEL);
487
+ commands.registerHandler(TerminalCommands.TERMINAL_FIND_TEXT_CANCEL.id, {
488
+ isEnabled: () => {
489
+ if (this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget) {
490
+ return this.shell.activeWidget.getSearchBox().isVisible;
491
+ }
492
+ return false;
493
+ },
494
+ execute: () => {
495
+ const termWidget = this.shell.activeWidget;
496
+ const terminalSearchBox = termWidget.getSearchBox();
497
+ terminalSearchBox.hide();
498
+ }
499
+ });
500
+ commands.registerCommand(TerminalCommands.SCROLL_LINE_UP, {
501
+ isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
502
+ isVisible: () => false,
503
+ execute: () => {
504
+ this.shell.activeWidget.scrollLineUp();
505
+ }
506
+ });
507
+ commands.registerCommand(TerminalCommands.SCROLL_LINE_DOWN, {
508
+ isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
509
+ isVisible: () => false,
510
+ execute: () => {
511
+ this.shell.activeWidget.scrollLineDown();
512
+ }
513
+ });
514
+ commands.registerCommand(TerminalCommands.SCROLL_TO_TOP, {
515
+ isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
516
+ isVisible: () => false,
517
+ execute: () => {
518
+ this.shell.activeWidget.scrollToTop();
519
+ }
520
+ });
521
+ commands.registerCommand(TerminalCommands.SCROLL_PAGE_UP, {
522
+ isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
523
+ isVisible: () => false,
524
+ execute: () => {
525
+ this.shell.activeWidget.scrollPageUp();
526
+ }
527
+ });
528
+ commands.registerCommand(TerminalCommands.SCROLL_PAGE_DOWN, {
529
+ isEnabled: () => this.shell.activeWidget instanceof terminal_widget_1.TerminalWidget,
530
+ isVisible: () => false,
531
+ execute: () => {
532
+ this.shell.activeWidget.scrollPageDown();
533
+ }
534
+ });
535
+ commands.registerCommand(TerminalCommands.TOGGLE_TERMINAL, {
536
+ execute: () => this.toggleTerminal()
537
+ });
538
+ commands.registerCommand(TerminalCommands.KILL_TERMINAL, {
539
+ isEnabled: () => !!this.currentTerminal,
540
+ execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.close(); }
541
+ });
542
+ commands.registerCommand(TerminalCommands.SELECT_ALL, {
543
+ isEnabled: () => !!this.currentTerminal,
544
+ execute: () => { var _a; return (_a = this.currentTerminal) === null || _a === void 0 ? void 0 : _a.selectAll(); }
545
+ });
546
+ }
547
+ toggleTerminal() {
548
+ const terminals = this.shell.getWidgets('bottom').filter(w => w instanceof terminal_widget_1.TerminalWidget);
549
+ if (terminals.length === 0) {
550
+ this.openTerminal();
551
+ return;
552
+ }
553
+ if (!this.shell.isExpanded('bottom')) {
554
+ this.shell.expandPanel('bottom');
555
+ terminals[0].activate();
556
+ }
557
+ else {
558
+ const visibleTerminal = terminals.find(t => t.isVisible);
559
+ if (!visibleTerminal) {
560
+ this.shell.bottomPanel.activateWidget(terminals[0]);
561
+ }
562
+ else if (this.shell.activeWidget !== visibleTerminal) {
563
+ this.shell.bottomPanel.activateWidget(visibleTerminal);
564
+ }
565
+ else {
566
+ this.shell.collapsePanel('bottom');
567
+ }
568
+ }
569
+ }
570
+ async openInTerminal(uri) {
571
+ // Determine folder path of URI
572
+ let stat;
573
+ try {
574
+ stat = await this.fileService.resolve(uri);
575
+ }
576
+ catch {
577
+ return;
578
+ }
579
+ // Use folder if a file was selected
580
+ const cwd = (stat.isDirectory) ? uri.toString() : uri.parent.toString();
581
+ // Open terminal
582
+ const termWidget = await this.newTerminal({ cwd });
583
+ termWidget.start();
584
+ this.open(termWidget);
585
+ }
586
+ registerMenus(menus) {
587
+ menus.registerSubmenu(TerminalMenus.TERMINAL, terminal_widget_impl_1.TerminalWidgetImpl.LABEL);
588
+ menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
589
+ commandId: TerminalCommands.NEW.id,
590
+ label: nls_1.nls.localizeByDefault('New Terminal'),
591
+ order: '0'
592
+ });
593
+ menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
594
+ commandId: TerminalCommands.PROFILE_NEW.id,
595
+ label: nls_1.nls.localize('theia/terminal/profileNew', 'New Terminal (With Profile)...'),
596
+ order: '1'
597
+ });
598
+ menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
599
+ commandId: TerminalCommands.PROFILE_DEFAULT.id,
600
+ label: nls_1.nls.localize('theia/terminal/profileDefault', 'Choose Default Profile...'),
601
+ order: '3'
602
+ });
603
+ menus.registerMenuAction(TerminalMenus.TERMINAL_NEW, {
604
+ commandId: TerminalCommands.SPLIT.id,
605
+ order: '3'
606
+ });
607
+ menus.registerMenuAction(TerminalMenus.TERMINAL_NAVIGATOR_CONTEXT_MENU, {
608
+ commandId: TerminalCommands.TERMINAL_CONTEXT.id,
609
+ order: 'z'
610
+ });
611
+ menus.registerMenuAction(TerminalMenus.TERMINAL_OPEN_EDITORS_CONTEXT_MENU, {
612
+ commandId: TerminalCommands.TERMINAL_CONTEXT.id,
613
+ order: 'z'
614
+ });
615
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_1'], {
616
+ commandId: TerminalCommands.NEW_ACTIVE_WORKSPACE.id,
617
+ label: nls_1.nls.localizeByDefault('New Terminal')
618
+ });
619
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_1'], {
620
+ commandId: TerminalCommands.SPLIT.id
621
+ });
622
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
623
+ commandId: browser_1.CommonCommands.COPY.id
624
+ });
625
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
626
+ commandId: browser_1.CommonCommands.PASTE.id
627
+ });
628
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_2'], {
629
+ commandId: TerminalCommands.SELECT_ALL.id
630
+ });
631
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_3'], {
632
+ commandId: TerminalCommands.TERMINAL_CLEAR.id
633
+ });
634
+ menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_4'], {
635
+ commandId: TerminalCommands.KILL_TERMINAL.id
636
+ });
637
+ }
638
+ registerToolbarItems(toolbar) {
639
+ toolbar.registerItem({
640
+ id: TerminalCommands.SPLIT.id,
641
+ command: TerminalCommands.SPLIT.id,
642
+ icon: (0, browser_1.codicon)('split-horizontal'),
643
+ tooltip: TerminalCommands.SPLIT.label
644
+ });
645
+ }
646
+ registerKeybindings(keybindings) {
647
+ /* Register passthrough keybindings for combinations recognized by
648
+ xterm.js and converted to control characters.
649
+ See: https://github.com/xtermjs/xterm.js/blob/v3/src/Terminal.ts#L1684 */
650
+ /* Register ctrl + k (the passed Key) as a passthrough command in the
651
+ context of the terminal. */
652
+ const regCtrl = (k) => {
653
+ keybindings.registerKeybinding({
654
+ command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
655
+ keybinding: browser_1.KeyCode.createKeyCode({ key: k, ctrl: true }).toString(),
656
+ when: 'terminalFocus',
657
+ });
658
+ };
659
+ /* Register alt + k (the passed Key) as a passthrough command in the
660
+ context of the terminal. */
661
+ const regAlt = (k) => {
662
+ keybindings.registerKeybinding({
663
+ command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
664
+ keybinding: browser_1.KeyCode.createKeyCode({ key: k, alt: true }).toString(),
665
+ when: 'terminalFocus'
666
+ });
667
+ };
668
+ /* ctrl-space (000 - NUL). */
669
+ regCtrl(browser_1.Key.SPACE);
670
+ /* ctrl-A (001/1/0x1) through ctrl-Z (032/26/0x1A). */
671
+ for (let i = 0; i < 26; i++) {
672
+ regCtrl({
673
+ keyCode: browser_1.Key.KEY_A.keyCode + i,
674
+ code: 'Key' + String.fromCharCode('A'.charCodeAt(0) + i)
675
+ });
676
+ }
677
+ /* ctrl-[ or ctrl-3 (033/27/0x1B - ESC). */
678
+ regCtrl(browser_1.Key.BRACKET_LEFT);
679
+ regCtrl(browser_1.Key.DIGIT3);
680
+ /* ctrl-\ or ctrl-4 (034/28/0x1C - FS). */
681
+ regCtrl(browser_1.Key.BACKSLASH);
682
+ regCtrl(browser_1.Key.DIGIT4);
683
+ /* ctrl-] or ctrl-5 (035/29/0x1D - GS). */
684
+ regCtrl(browser_1.Key.BRACKET_RIGHT);
685
+ regCtrl(browser_1.Key.DIGIT5);
686
+ /* ctrl-6 (036/30/0x1E - RS). */
687
+ regCtrl(browser_1.Key.DIGIT6);
688
+ /* ctrl-7 (037/31/0x1F - US). */
689
+ regCtrl(browser_1.Key.DIGIT7);
690
+ /* ctrl-8 (177/127/0x7F - DEL). */
691
+ regCtrl(browser_1.Key.DIGIT8);
692
+ /* alt-A (0x1B 0x62) through alt-Z (0x1B 0x7A). */
693
+ for (let i = 0; i < 26; i++) {
694
+ regAlt({
695
+ keyCode: browser_1.Key.KEY_A.keyCode + i,
696
+ code: 'Key' + String.fromCharCode('A'.charCodeAt(0) + i)
697
+ });
698
+ }
699
+ /* alt-` (0x1B 0x60). */
700
+ regAlt(browser_1.Key.BACKQUOTE);
701
+ /* alt-0 (0x1B 0x30) through alt-9 (0x1B 0x39). */
702
+ for (let i = 0; i < 10; i++) {
703
+ regAlt({
704
+ keyCode: browser_1.Key.DIGIT0.keyCode + i,
705
+ code: 'Digit' + String.fromCharCode('0'.charCodeAt(0) + i)
706
+ });
707
+ }
708
+ if (common_1.isOSX) {
709
+ // selectAll on OSX
710
+ keybindings.registerKeybinding({
711
+ command: browser_1.KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND,
712
+ keybinding: 'ctrlcmd+a',
713
+ when: 'terminalFocus'
714
+ });
715
+ }
716
+ keybindings.registerKeybinding({
717
+ command: TerminalCommands.NEW.id,
718
+ keybinding: 'ctrl+shift+`'
719
+ });
720
+ keybindings.registerKeybinding({
721
+ command: TerminalCommands.NEW_ACTIVE_WORKSPACE.id,
722
+ keybinding: 'ctrl+`'
723
+ });
724
+ keybindings.registerKeybinding({
725
+ command: TerminalCommands.TERMINAL_CLEAR.id,
726
+ keybinding: 'ctrlcmd+k',
727
+ when: 'terminalFocus'
728
+ });
729
+ keybindings.registerKeybinding({
730
+ command: TerminalCommands.TERMINAL_FIND_TEXT.id,
731
+ keybinding: 'ctrlcmd+f',
732
+ when: 'terminalFocus'
733
+ });
734
+ keybindings.registerKeybinding({
735
+ command: TerminalCommands.TERMINAL_FIND_TEXT_CANCEL.id,
736
+ keybinding: 'esc',
737
+ when: 'terminalHideSearch'
738
+ });
739
+ keybindings.registerKeybinding({
740
+ command: TerminalCommands.SCROLL_LINE_UP.id,
741
+ keybinding: 'ctrl+shift+up',
742
+ when: 'terminalFocus'
743
+ });
744
+ keybindings.registerKeybinding({
745
+ command: TerminalCommands.SCROLL_LINE_DOWN.id,
746
+ keybinding: 'ctrl+shift+down',
747
+ when: 'terminalFocus'
748
+ });
749
+ keybindings.registerKeybinding({
750
+ command: TerminalCommands.SCROLL_TO_TOP.id,
751
+ keybinding: 'shift-home',
752
+ when: 'terminalFocus'
753
+ });
754
+ keybindings.registerKeybinding({
755
+ command: TerminalCommands.SCROLL_PAGE_UP.id,
756
+ keybinding: 'shift-pageUp',
757
+ when: 'terminalFocus'
758
+ });
759
+ keybindings.registerKeybinding({
760
+ command: TerminalCommands.SCROLL_PAGE_DOWN.id,
761
+ keybinding: 'shift-pageDown',
762
+ when: 'terminalFocus'
763
+ });
764
+ keybindings.registerKeybinding({
765
+ command: TerminalCommands.TOGGLE_TERMINAL.id,
766
+ keybinding: 'ctrl+`',
767
+ });
768
+ keybindings.registerKeybinding({
769
+ command: TerminalCommands.SELECT_ALL.id,
770
+ keybinding: 'ctrlcmd+a',
771
+ when: 'terminalFocus'
772
+ });
773
+ }
774
+ async newTerminal(options) {
775
+ const widget = await this.widgetManager.getOrCreateWidget(terminal_widget_impl_1.TERMINAL_WIDGET_FACTORY_ID, {
776
+ created: new Date().toISOString(),
777
+ ...options
778
+ });
779
+ return widget;
780
+ }
781
+ // TODO: reuse WidgetOpenHandler.open
782
+ open(widget, options) {
783
+ var _a;
784
+ const area = widget.location === terminal_widget_1.TerminalLocation.Editor ? 'main' : 'bottom';
785
+ const widgetOptions = { area: area, ...options === null || options === void 0 ? void 0 : options.widgetOptions };
786
+ let preserveFocus = false;
787
+ if (typeof widget.location === 'object') {
788
+ if ('parentTerminal' in widget.location) {
789
+ widgetOptions.ref = this.getById(widget.location.parentTerminal);
790
+ widgetOptions.mode = 'split-right';
791
+ }
792
+ else if ('viewColumn' in widget.location) {
793
+ preserveFocus = (_a = widget.location.preserveFocus) !== null && _a !== void 0 ? _a : false;
794
+ switch (widget.location.viewColumn) {
795
+ case common_1.ViewColumn.Active:
796
+ widgetOptions.ref = this.shell.currentWidget;
797
+ widgetOptions.mode = 'tab-after';
798
+ break;
799
+ case common_1.ViewColumn.Beside:
800
+ widgetOptions.ref = this.shell.currentWidget;
801
+ widgetOptions.mode = 'split-right';
802
+ break;
803
+ default:
804
+ widgetOptions.area = 'main';
805
+ const mainAreaTerminals = this.shell.getWidgets('main').filter(w => w instanceof terminal_widget_1.TerminalWidget && w.isVisible);
806
+ const column = Math.min(widget.location.viewColumn, mainAreaTerminals.length);
807
+ widgetOptions.mode = widget.location.viewColumn <= mainAreaTerminals.length ? 'split-left' : 'split-right';
808
+ widgetOptions.ref = mainAreaTerminals[column - 1];
809
+ }
810
+ }
811
+ }
812
+ const op = {
813
+ mode: 'activate',
814
+ ...options,
815
+ widgetOptions: widgetOptions
816
+ };
817
+ if (!widget.isAttached) {
818
+ this.shell.addWidget(widget, op.widgetOptions);
819
+ }
820
+ if (op.mode === 'activate' && !preserveFocus) {
821
+ this.shell.activateWidget(widget.id);
822
+ }
823
+ else if (op.mode === 'reveal' || preserveFocus) {
824
+ this.shell.revealWidget(widget.id);
825
+ }
826
+ }
827
+ async selectTerminalCwd() {
828
+ return new Promise(async (resolve) => {
829
+ var _a, _b;
830
+ const roots = this.workspaceService.tryGetRoots();
831
+ if (roots.length === 0) {
832
+ resolve(undefined);
833
+ }
834
+ else if (roots.length === 1) {
835
+ resolve(roots[0].resource.toString());
836
+ }
837
+ else {
838
+ const items = roots.map(({ resource }) => ({
839
+ label: this.labelProvider.getName(resource),
840
+ description: this.labelProvider.getLongName(resource),
841
+ resource
842
+ }));
843
+ const selectedItem = await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, {
844
+ placeholder: nls_1.nls.localizeByDefault('Select current working directory for new terminal')
845
+ }));
846
+ resolve((_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.resource) === null || _b === void 0 ? void 0 : _b.toString());
847
+ }
848
+ });
849
+ }
850
+ async selectTerminalProfile(placeholder) {
851
+ return new Promise(async (resolve) => {
852
+ var _a;
853
+ const profiles = this.profileService.all;
854
+ if (profiles.length === 0) {
855
+ resolve(undefined);
856
+ }
857
+ else {
858
+ const items = profiles.map(([id, profile]) => ({
859
+ label: id,
860
+ profile
861
+ }));
862
+ const selectedItem = await ((_a = this.quickInputService) === null || _a === void 0 ? void 0 : _a.showQuickPick(items, {
863
+ placeholder
864
+ }));
865
+ resolve(selectedItem ? [selectedItem.label, selectedItem.profile] : undefined);
866
+ }
867
+ });
868
+ }
869
+ async splitTerminal(referenceTerminal) {
870
+ if (referenceTerminal || this.currentTerminal) {
871
+ const ref = referenceTerminal !== null && referenceTerminal !== void 0 ? referenceTerminal : this.currentTerminal;
872
+ await this.openTerminal({ ref, mode: 'split-right' });
873
+ }
874
+ }
875
+ async openTerminal(options, terminalProfile) {
876
+ let profile = terminalProfile;
877
+ if (!terminalProfile) {
878
+ profile = this.profileService.defaultProfile;
879
+ if (!profile) {
880
+ throw new Error('There are no profiles registered');
881
+ }
882
+ }
883
+ if (profile instanceof shell_terminal_profile_1.ShellTerminalProfile) {
884
+ if (this.workspaceService.workspace) {
885
+ const cwd = await this.selectTerminalCwd();
886
+ if (!cwd) {
887
+ return;
888
+ }
889
+ profile = profile.modify({ cwd });
890
+ }
891
+ }
892
+ const termWidget = await (profile === null || profile === void 0 ? void 0 : profile.start());
893
+ if (!!termWidget) {
894
+ this.open(termWidget, { widgetOptions: options });
895
+ }
896
+ }
897
+ async chooseDefaultProfile() {
898
+ const result = await this.selectTerminalProfile(nls_1.nls.localizeByDefault('Select your default terminal profile'));
899
+ if (!result) {
900
+ return;
901
+ }
902
+ this.preferenceService.set(`terminal.integrated.defaultProfile.${common_1.OS.backend.type().toLowerCase()}`, result[0], browser_1.PreferenceScope.User);
903
+ }
904
+ async openActiveWorkspaceTerminal(options) {
905
+ const termWidget = await this.newTerminal({});
906
+ termWidget.start();
907
+ this.open(termWidget, { widgetOptions: options });
908
+ }
909
+ withWidget(widget, fn) {
910
+ if (widget instanceof terminal_widget_1.TerminalWidget) {
911
+ return fn(widget);
912
+ }
913
+ return false;
914
+ }
915
+ /**
916
+ * It should be aligned with https://code.visualstudio.com/api/references/theme-color#integrated-terminal-colors
917
+ */
918
+ registerColors(colors) {
919
+ colors.register({
920
+ id: 'terminal.background',
921
+ defaults: {
922
+ dark: 'panel.background',
923
+ light: 'panel.background',
924
+ hcDark: 'panel.background',
925
+ hcLight: 'panel.background'
926
+ },
927
+ description: 'The background color of the terminal, this allows coloring the terminal differently to the panel.'
928
+ });
929
+ colors.register({
930
+ id: 'terminal.foreground',
931
+ defaults: {
932
+ light: '#333333',
933
+ dark: '#CCCCCC',
934
+ hcDark: '#FFFFFF',
935
+ hcLight: '#292929'
936
+ },
937
+ description: 'The foreground color of the terminal.'
938
+ });
939
+ colors.register({
940
+ id: 'terminalCursor.foreground',
941
+ description: 'The foreground color of the terminal cursor.'
942
+ });
943
+ colors.register({
944
+ id: 'terminalCursor.background',
945
+ description: 'The background color of the terminal cursor. Allows customizing the color of a character overlapped by a block cursor.'
946
+ });
947
+ colors.register({
948
+ id: 'terminal.selectionBackground',
949
+ defaults: {
950
+ light: 'editor.selectionBackground',
951
+ dark: 'editor.selectionBackground',
952
+ hcDark: 'editor.selectionBackground',
953
+ hcLight: 'editor.selectionBackground'
954
+ },
955
+ description: 'The selection background color of the terminal.'
956
+ });
957
+ colors.register({
958
+ id: 'terminal.inactiveSelectionBackground',
959
+ defaults: {
960
+ light: color_1.Color.transparent('terminal.selectionBackground', 0.5),
961
+ dark: color_1.Color.transparent('terminal.selectionBackground', 0.5),
962
+ hcDark: color_1.Color.transparent('terminal.selectionBackground', 0.7),
963
+ hcLight: color_1.Color.transparent('terminal.selectionBackground', 0.5),
964
+ },
965
+ description: 'The selection background color of the terminal when it does not have focus.'
966
+ });
967
+ colors.register({
968
+ id: 'terminal.selectionForeground',
969
+ defaults: {
970
+ light: undefined,
971
+ dark: undefined,
972
+ hcDark: '#000000',
973
+ hcLight: '#ffffff'
974
+ },
975
+ // eslint-disable-next-line max-len
976
+ description: 'The selection foreground color of the terminal. When this is null the selection foreground will be retained and have the minimum contrast ratio feature applied.'
977
+ });
978
+ colors.register({
979
+ id: 'terminal.border',
980
+ defaults: {
981
+ light: 'panel.border',
982
+ dark: 'panel.border',
983
+ hcDark: 'panel.border',
984
+ hcLight: 'panel.border'
985
+ },
986
+ description: 'The color of the border that separates split panes within the terminal. This defaults to panel.border.'
987
+ });
988
+ // eslint-disable-next-line guard-for-in
989
+ for (const id in terminal_theme_service_1.terminalAnsiColorMap) {
990
+ const entry = terminal_theme_service_1.terminalAnsiColorMap[id];
991
+ const colorName = id.substring(13);
992
+ colors.register({
993
+ id,
994
+ defaults: entry.defaults,
995
+ description: `'${colorName}' ANSI color in the terminal.`
996
+ });
997
+ }
998
+ }
999
+ };
1000
+ __decorate([
1001
+ (0, inversify_1.inject)(browser_1.ApplicationShell),
1002
+ __metadata("design:type", browser_1.ApplicationShell)
1003
+ ], TerminalFrontendContribution.prototype, "shell", void 0);
1004
+ __decorate([
1005
+ (0, inversify_1.inject)(shell_terminal_protocol_1.ShellTerminalServerProxy),
1006
+ __metadata("design:type", Object)
1007
+ ], TerminalFrontendContribution.prototype, "shellTerminalServer", void 0);
1008
+ __decorate([
1009
+ (0, inversify_1.inject)(browser_1.WidgetManager),
1010
+ __metadata("design:type", browser_1.WidgetManager)
1011
+ ], TerminalFrontendContribution.prototype, "widgetManager", void 0);
1012
+ __decorate([
1013
+ (0, inversify_1.inject)(file_service_1.FileService),
1014
+ __metadata("design:type", file_service_1.FileService)
1015
+ ], TerminalFrontendContribution.prototype, "fileService", void 0);
1016
+ __decorate([
1017
+ (0, inversify_1.inject)(common_1.SelectionService),
1018
+ __metadata("design:type", common_1.SelectionService)
1019
+ ], TerminalFrontendContribution.prototype, "selectionService", void 0);
1020
+ __decorate([
1021
+ (0, inversify_1.inject)(browser_1.LabelProvider),
1022
+ __metadata("design:type", browser_1.LabelProvider)
1023
+ ], TerminalFrontendContribution.prototype, "labelProvider", void 0);
1024
+ __decorate([
1025
+ (0, inversify_1.inject)(browser_1.QuickInputService),
1026
+ (0, inversify_1.optional)(),
1027
+ __metadata("design:type", Object)
1028
+ ], TerminalFrontendContribution.prototype, "quickInputService", void 0);
1029
+ __decorate([
1030
+ (0, inversify_1.inject)(browser_2.WorkspaceService),
1031
+ __metadata("design:type", browser_2.WorkspaceService)
1032
+ ], TerminalFrontendContribution.prototype, "workspaceService", void 0);
1033
+ __decorate([
1034
+ (0, inversify_1.inject)(terminal_profile_service_1.TerminalProfileService),
1035
+ __metadata("design:type", Object)
1036
+ ], TerminalFrontendContribution.prototype, "profileService", void 0);
1037
+ __decorate([
1038
+ (0, inversify_1.inject)(terminal_profile_service_1.UserTerminalProfileStore),
1039
+ __metadata("design:type", Object)
1040
+ ], TerminalFrontendContribution.prototype, "userProfileStore", void 0);
1041
+ __decorate([
1042
+ (0, inversify_1.inject)(terminal_profile_service_1.ContributedTerminalProfileStore),
1043
+ __metadata("design:type", Object)
1044
+ ], TerminalFrontendContribution.prototype, "contributedProfileStore", void 0);
1045
+ __decorate([
1046
+ (0, inversify_1.inject)(terminal_watcher_1.TerminalWatcher),
1047
+ __metadata("design:type", terminal_watcher_1.TerminalWatcher)
1048
+ ], TerminalFrontendContribution.prototype, "terminalWatcher", void 0);
1049
+ __decorate([
1050
+ (0, inversify_1.inject)(browser_3.VariableResolverService),
1051
+ __metadata("design:type", browser_3.VariableResolverService)
1052
+ ], TerminalFrontendContribution.prototype, "variableResolver", void 0);
1053
+ __decorate([
1054
+ (0, inversify_1.inject)(browser_1.StorageService),
1055
+ __metadata("design:type", Object)
1056
+ ], TerminalFrontendContribution.prototype, "storageService", void 0);
1057
+ __decorate([
1058
+ (0, inversify_1.inject)(browser_1.PreferenceService),
1059
+ __metadata("design:type", Object)
1060
+ ], TerminalFrontendContribution.prototype, "preferenceService", void 0);
1061
+ __decorate([
1062
+ (0, inversify_1.inject)(terminal_preferences_1.TerminalPreferences),
1063
+ __metadata("design:type", Object)
1064
+ ], TerminalFrontendContribution.prototype, "terminalPreferences", void 0);
1065
+ __decorate([
1066
+ (0, inversify_1.inject)(context_key_service_1.ContextKeyService),
1067
+ __metadata("design:type", Object)
1068
+ ], TerminalFrontendContribution.prototype, "contextKeyService", void 0);
1069
+ __decorate([
1070
+ (0, inversify_1.postConstruct)(),
1071
+ __metadata("design:type", Function),
1072
+ __metadata("design:paramtypes", []),
1073
+ __metadata("design:returntype", void 0)
1074
+ ], TerminalFrontendContribution.prototype, "init", null);
1075
+ TerminalFrontendContribution = __decorate([
1076
+ (0, inversify_1.injectable)()
1077
+ ], TerminalFrontendContribution);
1078
+ exports.TerminalFrontendContribution = TerminalFrontendContribution;
1057
1079
  //# sourceMappingURL=terminal-frontend-contribution.js.map