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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/terminal-widget-impl.js +4 -4
  3. package/package.json +9 -9
  4. package/src/browser/base/terminal-service.ts +60 -60
  5. package/src/browser/base/terminal-widget.ts +268 -268
  6. package/src/browser/index.ts +17 -17
  7. package/src/browser/search/terminal-search-container.ts +28 -28
  8. package/src/browser/search/terminal-search-widget.tsx +161 -161
  9. package/src/browser/shell-terminal-profile.ts +45 -45
  10. package/src/browser/style/terminal-search.css +99 -99
  11. package/src/browser/style/terminal.css +32 -32
  12. package/src/browser/terminal-contribution.ts +19 -19
  13. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  14. package/src/browser/terminal-file-link-provider.ts +289 -289
  15. package/src/browser/terminal-frontend-contribution.ts +1134 -1134
  16. package/src/browser/terminal-frontend-module.ts +138 -138
  17. package/src/browser/terminal-link-helpers.ts +187 -187
  18. package/src/browser/terminal-link-provider.ts +203 -203
  19. package/src/browser/terminal-preferences.ts +428 -428
  20. package/src/browser/terminal-profile-service.ts +180 -180
  21. package/src/browser/terminal-quick-open-service.ts +132 -132
  22. package/src/browser/terminal-theme-service.ts +213 -213
  23. package/src/browser/terminal-url-link-provider.ts +66 -66
  24. package/src/browser/terminal-widget-impl.ts +996 -996
  25. package/src/common/base-terminal-protocol.ts +125 -125
  26. package/src/common/shell-terminal-protocol.ts +103 -103
  27. package/src/common/terminal-common-module.ts +30 -30
  28. package/src/common/terminal-protocol.ts +32 -32
  29. package/src/common/terminal-watcher.ts +69 -69
  30. package/src/node/base-terminal-server.ts +173 -173
  31. package/src/node/buffering-stream.spec.ts +46 -46
  32. package/src/node/buffering-stream.ts +95 -95
  33. package/src/node/index.ts +17 -17
  34. package/src/node/shell-process.ts +102 -102
  35. package/src/node/shell-terminal-server.spec.ts +40 -40
  36. package/src/node/shell-terminal-server.ts +223 -223
  37. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  38. package/src/node/terminal-backend-contribution.ts +60 -60
  39. package/src/node/terminal-backend-module.ts +82 -82
  40. package/src/node/terminal-server.spec.ts +47 -47
  41. package/src/node/terminal-server.ts +52 -52
  42. package/src/node/test/terminal-test-container.ts +39 -39
  43. package/src/package.spec.ts +28 -28
@@ -1,180 +1,180 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 STMicroelectronics and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Emitter, Event } from '@theia/core';
18
- import { injectable } from '@theia/core/shared/inversify';
19
- import { TerminalWidget } from './base/terminal-widget';
20
- import { ShellTerminalProfile } from './shell-terminal-profile';
21
-
22
- export const TerminalProfileService = Symbol('TerminalProfileService');
23
- export const ContributedTerminalProfileStore = Symbol('ContributedTerminalProfileStore');
24
- export const UserTerminalProfileStore = Symbol('UserTerminalProfileStore');
25
-
26
- export interface TerminalProfile {
27
- start(): Promise<TerminalWidget>;
28
- }
29
-
30
- export const NULL_PROFILE: TerminalProfile = {
31
- start: async () => { throw new Error('you cannot start a null profile'); }
32
- };
33
-
34
- export interface TerminalProfileService {
35
- onAdded: Event<string>;
36
- onRemoved: Event<string>;
37
- getProfile(id: string): TerminalProfile | undefined
38
- readonly all: [string, TerminalProfile][];
39
- setDefaultProfile(id: string): void;
40
- readonly onDidChangeDefaultShell: Event<string>;
41
- readonly defaultProfile: TerminalProfile | undefined;
42
- }
43
-
44
- export interface TerminalProfileStore {
45
- onAdded: Event<[string, TerminalProfile]>;
46
- onRemoved: Event<string>;
47
- registerTerminalProfile(id: string, profile: TerminalProfile): void;
48
- unregisterTerminalProfile(id: string): void;
49
- hasProfile(id: string): boolean;
50
- getProfile(id: string): TerminalProfile | undefined
51
- readonly all: [string, TerminalProfile][];
52
- }
53
-
54
- @injectable()
55
- export class DefaultProfileStore implements TerminalProfileStore {
56
- protected readonly onAddedEmitter: Emitter<[string, TerminalProfile]> = new Emitter();
57
- protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
58
- protected readonly profiles: Map<string, TerminalProfile> = new Map();
59
-
60
- onAdded: Event<[string, TerminalProfile]> = this.onAddedEmitter.event;
61
- onRemoved: Event<string> = this.onRemovedEmitter.event;
62
-
63
- registerTerminalProfile(id: string, profile: TerminalProfile): void {
64
- this.profiles.set(id, profile);
65
- this.onAddedEmitter.fire([id, profile]);
66
- }
67
- unregisterTerminalProfile(id: string): void {
68
- this.profiles.delete(id);
69
- this.onRemovedEmitter.fire(id);
70
- }
71
-
72
- hasProfile(id: string): boolean {
73
- return this.profiles.has(id);
74
- }
75
-
76
- getProfile(id: string): TerminalProfile | undefined {
77
- return this.profiles.get(id);
78
- }
79
- get all(): [string, TerminalProfile][] {
80
- return [...this.profiles.entries()];
81
- }
82
- }
83
-
84
- @injectable()
85
- export class DefaultTerminalProfileService implements TerminalProfileService {
86
- protected defaultProfileIndex = 0;
87
- protected order: string[] = [];
88
- protected readonly stores: TerminalProfileStore[];
89
-
90
- protected readonly onAddedEmitter: Emitter<string> = new Emitter();
91
- protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
92
- protected readonly onDidChangeDefaultShellEmitter: Emitter<string> = new Emitter();
93
-
94
- onAdded: Event<string> = this.onAddedEmitter.event;
95
- onRemoved: Event<string> = this.onRemovedEmitter.event;
96
- onDidChangeDefaultShell: Event<string> = this.onDidChangeDefaultShellEmitter.event;
97
-
98
- constructor(...stores: TerminalProfileStore[]) {
99
- this.stores = stores;
100
- for (const store of this.stores) {
101
- store.onAdded(e => {
102
- if (e[1] === NULL_PROFILE) {
103
- this.handleRemoved(e[0]);
104
- } else {
105
- this.handleAdded(e[0]);
106
- }
107
- });
108
- store.onRemoved(id => {
109
- if (!this.getProfile(id)) {
110
- this.handleRemoved(id);
111
- } else {
112
- // we may have removed a null profile
113
- this.handleAdded(id);
114
- }
115
- });
116
- }
117
- }
118
-
119
- handleRemoved(id: string): void {
120
- const index = this.order.indexOf(id);
121
- if (index >= 0 && !this.getProfile(id)) {
122
- // the profile was removed, but it's still in the `order` array
123
- this.order.splice(index, 1);
124
- this.defaultProfileIndex = Math.max(0, Math.min(this.order.length - 1, index));
125
- this.onRemovedEmitter.fire(id);
126
- }
127
- }
128
-
129
- handleAdded(id: string): void {
130
- const index = this.order.indexOf(id);
131
- if (index < 0) {
132
- this.order.push(id);
133
- this.onAddedEmitter.fire(id);
134
- }
135
- }
136
-
137
- get defaultProfile(): TerminalProfile | undefined {
138
- const id = this.order[this.defaultProfileIndex];
139
- if (id) {
140
- return this.getProfile(id);
141
- }
142
- return undefined;
143
- }
144
-
145
- setDefaultProfile(id: string): void {
146
- const profile = this.getProfile(id);
147
- if (!profile) {
148
- throw new Error(`Cannot set default to unknown profile '${id}' `);
149
- }
150
- this.defaultProfileIndex = this.order.indexOf(id);
151
-
152
- if (profile instanceof ShellTerminalProfile && profile.shellPath) {
153
- this.onDidChangeDefaultShellEmitter.fire(profile.shellPath);
154
- } else {
155
- this.onDidChangeDefaultShellEmitter.fire('');
156
- }
157
- }
158
-
159
- getProfile(id: string): TerminalProfile | undefined {
160
- for (const store of this.stores) {
161
- if (store.hasProfile(id)) {
162
- const found = store.getProfile(id);
163
- return found === NULL_PROFILE ? undefined : found;
164
- }
165
- }
166
- return undefined;
167
- }
168
-
169
- getId(profile: TerminalProfile): string | undefined {
170
- for (const [id, p] of this.all) {
171
- if (p === profile) {
172
- return id;
173
- }
174
- }
175
- }
176
-
177
- get all(): [string, TerminalProfile][] {
178
- return this.order.filter(id => !!this.getProfile(id)).map(id => [id, this.getProfile(id)!]);
179
- }
180
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Emitter, Event } from '@theia/core';
18
+ import { injectable } from '@theia/core/shared/inversify';
19
+ import { TerminalWidget } from './base/terminal-widget';
20
+ import { ShellTerminalProfile } from './shell-terminal-profile';
21
+
22
+ export const TerminalProfileService = Symbol('TerminalProfileService');
23
+ export const ContributedTerminalProfileStore = Symbol('ContributedTerminalProfileStore');
24
+ export const UserTerminalProfileStore = Symbol('UserTerminalProfileStore');
25
+
26
+ export interface TerminalProfile {
27
+ start(): Promise<TerminalWidget>;
28
+ }
29
+
30
+ export const NULL_PROFILE: TerminalProfile = {
31
+ start: async () => { throw new Error('you cannot start a null profile'); }
32
+ };
33
+
34
+ export interface TerminalProfileService {
35
+ onAdded: Event<string>;
36
+ onRemoved: Event<string>;
37
+ getProfile(id: string): TerminalProfile | undefined
38
+ readonly all: [string, TerminalProfile][];
39
+ setDefaultProfile(id: string): void;
40
+ readonly onDidChangeDefaultShell: Event<string>;
41
+ readonly defaultProfile: TerminalProfile | undefined;
42
+ }
43
+
44
+ export interface TerminalProfileStore {
45
+ onAdded: Event<[string, TerminalProfile]>;
46
+ onRemoved: Event<string>;
47
+ registerTerminalProfile(id: string, profile: TerminalProfile): void;
48
+ unregisterTerminalProfile(id: string): void;
49
+ hasProfile(id: string): boolean;
50
+ getProfile(id: string): TerminalProfile | undefined
51
+ readonly all: [string, TerminalProfile][];
52
+ }
53
+
54
+ @injectable()
55
+ export class DefaultProfileStore implements TerminalProfileStore {
56
+ protected readonly onAddedEmitter: Emitter<[string, TerminalProfile]> = new Emitter();
57
+ protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
58
+ protected readonly profiles: Map<string, TerminalProfile> = new Map();
59
+
60
+ onAdded: Event<[string, TerminalProfile]> = this.onAddedEmitter.event;
61
+ onRemoved: Event<string> = this.onRemovedEmitter.event;
62
+
63
+ registerTerminalProfile(id: string, profile: TerminalProfile): void {
64
+ this.profiles.set(id, profile);
65
+ this.onAddedEmitter.fire([id, profile]);
66
+ }
67
+ unregisterTerminalProfile(id: string): void {
68
+ this.profiles.delete(id);
69
+ this.onRemovedEmitter.fire(id);
70
+ }
71
+
72
+ hasProfile(id: string): boolean {
73
+ return this.profiles.has(id);
74
+ }
75
+
76
+ getProfile(id: string): TerminalProfile | undefined {
77
+ return this.profiles.get(id);
78
+ }
79
+ get all(): [string, TerminalProfile][] {
80
+ return [...this.profiles.entries()];
81
+ }
82
+ }
83
+
84
+ @injectable()
85
+ export class DefaultTerminalProfileService implements TerminalProfileService {
86
+ protected defaultProfileIndex = 0;
87
+ protected order: string[] = [];
88
+ protected readonly stores: TerminalProfileStore[];
89
+
90
+ protected readonly onAddedEmitter: Emitter<string> = new Emitter();
91
+ protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
92
+ protected readonly onDidChangeDefaultShellEmitter: Emitter<string> = new Emitter();
93
+
94
+ onAdded: Event<string> = this.onAddedEmitter.event;
95
+ onRemoved: Event<string> = this.onRemovedEmitter.event;
96
+ onDidChangeDefaultShell: Event<string> = this.onDidChangeDefaultShellEmitter.event;
97
+
98
+ constructor(...stores: TerminalProfileStore[]) {
99
+ this.stores = stores;
100
+ for (const store of this.stores) {
101
+ store.onAdded(e => {
102
+ if (e[1] === NULL_PROFILE) {
103
+ this.handleRemoved(e[0]);
104
+ } else {
105
+ this.handleAdded(e[0]);
106
+ }
107
+ });
108
+ store.onRemoved(id => {
109
+ if (!this.getProfile(id)) {
110
+ this.handleRemoved(id);
111
+ } else {
112
+ // we may have removed a null profile
113
+ this.handleAdded(id);
114
+ }
115
+ });
116
+ }
117
+ }
118
+
119
+ handleRemoved(id: string): void {
120
+ const index = this.order.indexOf(id);
121
+ if (index >= 0 && !this.getProfile(id)) {
122
+ // the profile was removed, but it's still in the `order` array
123
+ this.order.splice(index, 1);
124
+ this.defaultProfileIndex = Math.max(0, Math.min(this.order.length - 1, index));
125
+ this.onRemovedEmitter.fire(id);
126
+ }
127
+ }
128
+
129
+ handleAdded(id: string): void {
130
+ const index = this.order.indexOf(id);
131
+ if (index < 0) {
132
+ this.order.push(id);
133
+ this.onAddedEmitter.fire(id);
134
+ }
135
+ }
136
+
137
+ get defaultProfile(): TerminalProfile | undefined {
138
+ const id = this.order[this.defaultProfileIndex];
139
+ if (id) {
140
+ return this.getProfile(id);
141
+ }
142
+ return undefined;
143
+ }
144
+
145
+ setDefaultProfile(id: string): void {
146
+ const profile = this.getProfile(id);
147
+ if (!profile) {
148
+ throw new Error(`Cannot set default to unknown profile '${id}' `);
149
+ }
150
+ this.defaultProfileIndex = this.order.indexOf(id);
151
+
152
+ if (profile instanceof ShellTerminalProfile && profile.shellPath) {
153
+ this.onDidChangeDefaultShellEmitter.fire(profile.shellPath);
154
+ } else {
155
+ this.onDidChangeDefaultShellEmitter.fire('');
156
+ }
157
+ }
158
+
159
+ getProfile(id: string): TerminalProfile | undefined {
160
+ for (const store of this.stores) {
161
+ if (store.hasProfile(id)) {
162
+ const found = store.getProfile(id);
163
+ return found === NULL_PROFILE ? undefined : found;
164
+ }
165
+ }
166
+ return undefined;
167
+ }
168
+
169
+ getId(profile: TerminalProfile): string | undefined {
170
+ for (const [id, p] of this.all) {
171
+ if (p === profile) {
172
+ return id;
173
+ }
174
+ }
175
+ }
176
+
177
+ get all(): [string, TerminalProfile][] {
178
+ return this.order.filter(id => !!this.getProfile(id)).map(id => [id, this.getProfile(id)!]);
179
+ }
180
+ }
@@ -1,132 +1,132 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { inject, injectable, optional } from '@theia/core/shared/inversify';
18
- import {
19
- codiconArray,
20
- QuickAccessContribution,
21
- QuickAccessProvider,
22
- QuickAccessRegistry,
23
- QuickInputService
24
- } from '@theia/core/lib/browser';
25
- import { CancellationToken, CommandContribution, CommandRegistry, CommandService, nls } from '@theia/core/lib/common';
26
- import { TerminalWidget } from './base/terminal-widget';
27
- import { TerminalService } from './base/terminal-service';
28
- import { TerminalCommands } from './terminal-frontend-contribution';
29
- import { filterItems, QuickPickItem, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
30
-
31
- @injectable()
32
- export class TerminalQuickOpenService implements QuickAccessProvider {
33
- static readonly PREFIX = 'term ';
34
-
35
- @inject(QuickInputService) @optional()
36
- protected readonly quickInputService: QuickInputService;
37
-
38
- @inject(QuickAccessRegistry)
39
- protected readonly quickAccessRegistry: QuickAccessRegistry;
40
-
41
- @inject(CommandService)
42
- protected readonly commandService: CommandService;
43
-
44
- @inject(TerminalService)
45
- protected readonly terminalService: TerminalService;
46
-
47
- open(): void {
48
- this.quickInputService?.open(TerminalQuickOpenService.PREFIX);
49
- }
50
-
51
- async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
52
- const items: QuickPickItem[] = [];
53
-
54
- // Get the sorted list of currently opened terminal widgets that aren't hidden from users
55
- const widgets: TerminalWidget[] = this.terminalService.all.filter(widget => !widget.hiddenFromUser)
56
- .sort((a: TerminalWidget, b: TerminalWidget) => this.compareItems(a, b));
57
-
58
- for (const widget of widgets) {
59
- items.push(this.toItem(widget));
60
- }
61
- // Append a quick open item to create a new terminal.
62
- items.push({
63
- label: nls.localizeByDefault('Create New Terminal'),
64
- iconClasses: codiconArray('add'),
65
- execute: () => this.doCreateNewTerminal()
66
- });
67
-
68
- return filterItems(items, filter);
69
- }
70
-
71
- registerQuickAccessProvider(): void {
72
- this.quickAccessRegistry.registerQuickAccessProvider({
73
- getInstance: () => this,
74
- prefix: TerminalQuickOpenService.PREFIX,
75
- placeholder: '',
76
- helpEntries: [{ description: nls.localizeByDefault('Show All Opened Terminals'), needsEditor: false }]
77
- });
78
- }
79
-
80
- /**
81
- * Compare two terminal widgets by label. If labels are identical, compare by the widget id.
82
- * @param a `TerminalWidget` for comparison
83
- * @param b `TerminalWidget` for comparison
84
- */
85
- protected compareItems(a: TerminalWidget, b: TerminalWidget): number {
86
- const normalize = (str: string) => str.trim().toLowerCase();
87
-
88
- if (normalize(a.title.label) !== normalize(b.title.label)) {
89
- return normalize(a.title.label).localeCompare(normalize(b.title.label));
90
- } else {
91
- return normalize(a.id).localeCompare(normalize(b.id));
92
- }
93
- }
94
-
95
- protected doCreateNewTerminal(): void {
96
- this.commandService.executeCommand(TerminalCommands.NEW.id);
97
- }
98
-
99
- /**
100
- * Convert the terminal widget to the quick pick item.
101
- * @param {TerminalWidget} widget - the terminal widget.
102
- * @returns quick pick item.
103
- */
104
- protected toItem(widget: TerminalWidget): QuickPickItem {
105
- return {
106
- label: widget.title.label,
107
- description: widget.id,
108
- ariaLabel: widget.title.label,
109
- execute: () => this.terminalService.open(widget)
110
- };
111
- }
112
- }
113
-
114
- /**
115
- * TODO: merge it to TerminalFrontendContribution.
116
- */
117
- @injectable()
118
- export class TerminalQuickOpenContribution implements CommandContribution, QuickAccessContribution {
119
-
120
- @inject(TerminalQuickOpenService)
121
- protected readonly terminalQuickOpenService: TerminalQuickOpenService;
122
-
123
- registerQuickAccessProvider(): void {
124
- this.terminalQuickOpenService.registerQuickAccessProvider();
125
- }
126
-
127
- registerCommands(commands: CommandRegistry): void {
128
- commands.registerCommand(TerminalCommands.SHOW_ALL_OPENED_TERMINALS, {
129
- execute: () => this.terminalQuickOpenService.open()
130
- });
131
- }
132
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable, optional } from '@theia/core/shared/inversify';
18
+ import {
19
+ codiconArray,
20
+ QuickAccessContribution,
21
+ QuickAccessProvider,
22
+ QuickAccessRegistry,
23
+ QuickInputService
24
+ } from '@theia/core/lib/browser';
25
+ import { CancellationToken, CommandContribution, CommandRegistry, CommandService, nls } from '@theia/core/lib/common';
26
+ import { TerminalWidget } from './base/terminal-widget';
27
+ import { TerminalService } from './base/terminal-service';
28
+ import { TerminalCommands } from './terminal-frontend-contribution';
29
+ import { filterItems, QuickPickItem, QuickPicks } from '@theia/core/lib/browser/quick-input/quick-input-service';
30
+
31
+ @injectable()
32
+ export class TerminalQuickOpenService implements QuickAccessProvider {
33
+ static readonly PREFIX = 'term ';
34
+
35
+ @inject(QuickInputService) @optional()
36
+ protected readonly quickInputService: QuickInputService;
37
+
38
+ @inject(QuickAccessRegistry)
39
+ protected readonly quickAccessRegistry: QuickAccessRegistry;
40
+
41
+ @inject(CommandService)
42
+ protected readonly commandService: CommandService;
43
+
44
+ @inject(TerminalService)
45
+ protected readonly terminalService: TerminalService;
46
+
47
+ open(): void {
48
+ this.quickInputService?.open(TerminalQuickOpenService.PREFIX);
49
+ }
50
+
51
+ async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
52
+ const items: QuickPickItem[] = [];
53
+
54
+ // Get the sorted list of currently opened terminal widgets that aren't hidden from users
55
+ const widgets: TerminalWidget[] = this.terminalService.all.filter(widget => !widget.hiddenFromUser)
56
+ .sort((a: TerminalWidget, b: TerminalWidget) => this.compareItems(a, b));
57
+
58
+ for (const widget of widgets) {
59
+ items.push(this.toItem(widget));
60
+ }
61
+ // Append a quick open item to create a new terminal.
62
+ items.push({
63
+ label: nls.localizeByDefault('Create New Terminal'),
64
+ iconClasses: codiconArray('add'),
65
+ execute: () => this.doCreateNewTerminal()
66
+ });
67
+
68
+ return filterItems(items, filter);
69
+ }
70
+
71
+ registerQuickAccessProvider(): void {
72
+ this.quickAccessRegistry.registerQuickAccessProvider({
73
+ getInstance: () => this,
74
+ prefix: TerminalQuickOpenService.PREFIX,
75
+ placeholder: '',
76
+ helpEntries: [{ description: nls.localizeByDefault('Show All Opened Terminals'), needsEditor: false }]
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Compare two terminal widgets by label. If labels are identical, compare by the widget id.
82
+ * @param a `TerminalWidget` for comparison
83
+ * @param b `TerminalWidget` for comparison
84
+ */
85
+ protected compareItems(a: TerminalWidget, b: TerminalWidget): number {
86
+ const normalize = (str: string) => str.trim().toLowerCase();
87
+
88
+ if (normalize(a.title.label) !== normalize(b.title.label)) {
89
+ return normalize(a.title.label).localeCompare(normalize(b.title.label));
90
+ } else {
91
+ return normalize(a.id).localeCompare(normalize(b.id));
92
+ }
93
+ }
94
+
95
+ protected doCreateNewTerminal(): void {
96
+ this.commandService.executeCommand(TerminalCommands.NEW.id);
97
+ }
98
+
99
+ /**
100
+ * Convert the terminal widget to the quick pick item.
101
+ * @param {TerminalWidget} widget - the terminal widget.
102
+ * @returns quick pick item.
103
+ */
104
+ protected toItem(widget: TerminalWidget): QuickPickItem {
105
+ return {
106
+ label: widget.title.label,
107
+ description: widget.id,
108
+ ariaLabel: widget.title.label,
109
+ execute: () => this.terminalService.open(widget)
110
+ };
111
+ }
112
+ }
113
+
114
+ /**
115
+ * TODO: merge it to TerminalFrontendContribution.
116
+ */
117
+ @injectable()
118
+ export class TerminalQuickOpenContribution implements CommandContribution, QuickAccessContribution {
119
+
120
+ @inject(TerminalQuickOpenService)
121
+ protected readonly terminalQuickOpenService: TerminalQuickOpenService;
122
+
123
+ registerQuickAccessProvider(): void {
124
+ this.terminalQuickOpenService.registerQuickAccessProvider();
125
+ }
126
+
127
+ registerCommands(commands: CommandRegistry): void {
128
+ commands.registerCommand(TerminalCommands.SHOW_ALL_OPENED_TERMINALS, {
129
+ execute: () => this.terminalQuickOpenService.open()
130
+ });
131
+ }
132
+ }