@theia/terminal 1.67.0-next.56 → 1.67.0-next.86

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