@theia/terminal 1.34.2 → 1.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/browser/base/terminal-service.d.ts +34 -34
  4. package/lib/browser/base/terminal-service.js +7 -7
  5. package/lib/browser/base/terminal-widget.d.ts +184 -184
  6. package/lib/browser/base/terminal-widget.js +34 -34
  7. package/lib/browser/index.d.ts +1 -1
  8. package/lib/browser/index.js +28 -28
  9. package/lib/browser/search/terminal-search-container.d.ts +3 -3
  10. package/lib/browser/search/terminal-search-container.js +28 -28
  11. package/lib/browser/search/terminal-search-widget.d.ts +30 -30
  12. package/lib/browser/search/terminal-search-widget.js +147 -147
  13. package/lib/browser/shell-terminal-profile.d.ts +19 -19
  14. package/lib/browser/shell-terminal-profile.js +39 -39
  15. package/lib/browser/terminal-contribution.d.ts +3 -3
  16. package/lib/browser/terminal-contribution.js +20 -20
  17. package/lib/browser/terminal-copy-on-selection-handler.d.ts +10 -10
  18. package/lib/browser/terminal-copy-on-selection-handler.js +103 -103
  19. package/lib/browser/terminal-file-link-provider.d.ts +24 -24
  20. package/lib/browser/terminal-file-link-provider.js +200 -200
  21. package/lib/browser/terminal-frontend-contribution.d.ts +112 -112
  22. package/lib/browser/terminal-frontend-contribution.js +994 -994
  23. package/lib/browser/terminal-frontend-module.d.ts +5 -5
  24. package/lib/browser/terminal-frontend-module.js +115 -115
  25. package/lib/browser/terminal-keybinding-contexts.d.ts +15 -15
  26. package/lib/browser/terminal-keybinding-contexts.js +71 -71
  27. package/lib/browser/terminal-link-helpers.d.ts +27 -27
  28. package/lib/browser/terminal-link-helpers.js +155 -155
  29. package/lib/browser/terminal-link-provider.d.ts +51 -51
  30. package/lib/browser/terminal-link-provider.js +197 -197
  31. package/lib/browser/terminal-preferences.d.ts +61 -61
  32. package/lib/browser/terminal-preferences.js +329 -329
  33. package/lib/browser/terminal-profile-service.d.ts +55 -55
  34. package/lib/browser/terminal-profile-service.js +149 -149
  35. package/lib/browser/terminal-quick-open-service.d.ts +36 -36
  36. package/lib/browser/terminal-quick-open-service.js +137 -137
  37. package/lib/browser/terminal-theme-service.d.ts +21 -21
  38. package/lib/browser/terminal-theme-service.js +218 -218
  39. package/lib/browser/terminal-url-link-provider.d.ts +11 -11
  40. package/lib/browser/terminal-url-link-provider.js +76 -76
  41. package/lib/browser/terminal-widget-impl.d.ts +173 -173
  42. package/lib/browser/terminal-widget-impl.js +769 -769
  43. package/lib/common/base-terminal-protocol.d.ts +100 -100
  44. package/lib/common/base-terminal-protocol.js +88 -88
  45. package/lib/common/shell-terminal-protocol.d.ts +29 -29
  46. package/lib/common/shell-terminal-protocol.js +22 -22
  47. package/lib/common/terminal-common-module.d.ts +7 -7
  48. package/lib/common/terminal-common-module.js +31 -31
  49. package/lib/common/terminal-protocol.d.ts +12 -12
  50. package/lib/common/terminal-protocol.js +21 -21
  51. package/lib/common/terminal-watcher.d.ts +13 -13
  52. package/lib/common/terminal-watcher.js +70 -70
  53. package/lib/node/base-terminal-server.d.ts +36 -36
  54. package/lib/node/base-terminal-server.js +252 -252
  55. package/lib/node/buffering-stream.d.ts +39 -39
  56. package/lib/node/buffering-stream.js +75 -75
  57. package/lib/node/buffering-stream.spec.d.ts +1 -1
  58. package/lib/node/buffering-stream.spec.js +43 -43
  59. package/lib/node/index.d.ts +1 -1
  60. package/lib/node/index.js +28 -28
  61. package/lib/node/shell-process.d.ts +26 -26
  62. package/lib/node/shell-process.js +106 -106
  63. package/lib/node/shell-terminal-server.d.ts +14 -14
  64. package/lib/node/shell-terminal-server.js +114 -114
  65. package/lib/node/shell-terminal-server.spec.d.ts +1 -1
  66. package/lib/node/shell-terminal-server.spec.js +35 -35
  67. package/lib/node/terminal-backend-contribution.d.ts +9 -9
  68. package/lib/node/terminal-backend-contribution.js +75 -75
  69. package/lib/node/terminal-backend-contribution.slow-spec.d.ts +1 -1
  70. package/lib/node/terminal-backend-contribution.slow-spec.js +54 -54
  71. package/lib/node/terminal-backend-module.d.ts +11 -11
  72. package/lib/node/terminal-backend-module.js +69 -69
  73. package/lib/node/terminal-server.d.ts +9 -9
  74. package/lib/node/terminal-server.js +64 -64
  75. package/lib/node/terminal-server.spec.d.ts +1 -1
  76. package/lib/node/terminal-server.spec.js +41 -41
  77. package/lib/node/test/terminal-test-container.d.ts +2 -2
  78. package/lib/node/test/terminal-test-container.js +40 -40
  79. package/lib/package.spec.js +25 -25
  80. package/package.json +9 -9
  81. package/src/browser/base/terminal-service.ts +60 -60
  82. package/src/browser/base/terminal-widget.ts +244 -244
  83. package/src/browser/index.ts +17 -17
  84. package/src/browser/search/terminal-search-container.ts +28 -28
  85. package/src/browser/search/terminal-search-widget.tsx +161 -161
  86. package/src/browser/shell-terminal-profile.ts +40 -40
  87. package/src/browser/style/terminal-search.css +93 -93
  88. package/src/browser/style/terminal.css +33 -33
  89. package/src/browser/terminal-contribution.ts +19 -19
  90. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  91. package/src/browser/terminal-file-link-provider.ts +200 -200
  92. package/src/browser/terminal-frontend-contribution.ts +1048 -1048
  93. package/src/browser/terminal-frontend-module.ts +139 -139
  94. package/src/browser/terminal-keybinding-contexts.ts +52 -52
  95. package/src/browser/terminal-link-helpers.ts +187 -187
  96. package/src/browser/terminal-link-provider.ts +203 -203
  97. package/src/browser/terminal-preferences.ts +427 -427
  98. package/src/browser/terminal-profile-service.ts +170 -170
  99. package/src/browser/terminal-quick-open-service.ts +132 -132
  100. package/src/browser/terminal-theme-service.ts +209 -209
  101. package/src/browser/terminal-url-link-provider.ts +66 -66
  102. package/src/browser/terminal-widget-impl.ts +827 -827
  103. package/src/common/base-terminal-protocol.ts +183 -183
  104. package/src/common/shell-terminal-protocol.ts +50 -50
  105. package/src/common/terminal-common-module.ts +30 -30
  106. package/src/common/terminal-protocol.ts +32 -32
  107. package/src/common/terminal-watcher.ts +69 -69
  108. package/src/node/base-terminal-server.ts +279 -279
  109. package/src/node/buffering-stream.spec.ts +46 -46
  110. package/src/node/buffering-stream.ts +95 -95
  111. package/src/node/index.ts +17 -17
  112. package/src/node/shell-process.ts +101 -101
  113. package/src/node/shell-terminal-server.spec.ts +40 -40
  114. package/src/node/shell-terminal-server.ts +95 -95
  115. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  116. package/src/node/terminal-backend-contribution.ts +60 -60
  117. package/src/node/terminal-backend-module.ts +82 -82
  118. package/src/node/terminal-server.spec.ts +47 -47
  119. package/src/node/terminal-server.ts +52 -52
  120. package/src/node/test/terminal-test-container.ts +39 -39
  121. package/src/package.spec.ts +28 -28
@@ -1,170 +1,170 @@
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 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
-
21
- export const TerminalProfileService = Symbol('TerminalProfileService');
22
- export const ContributedTerminalProfileStore = Symbol('ContributedTerminalProfileStore');
23
- export const UserTerminalProfileStore = Symbol('UserTerminalProfileStore');
24
-
25
- export interface TerminalProfile {
26
- start(): Promise<TerminalWidget>;
27
- }
28
-
29
- export const NULL_PROFILE: TerminalProfile = {
30
- start: async () => { throw new Error('you cannot start a null profile'); }
31
- };
32
-
33
- export interface TerminalProfileService {
34
- onAdded: Event<string>;
35
- onRemoved: Event<string>;
36
- getProfile(id: string): TerminalProfile | undefined
37
- readonly all: [string, TerminalProfile][];
38
- setDefaultProfile(id: string): void;
39
- readonly defaultProfile: TerminalProfile | undefined;
40
- }
41
-
42
- export interface TerminalProfileStore {
43
- onAdded: Event<[string, TerminalProfile]>;
44
- onRemoved: Event<string>;
45
- registerTerminalProfile(id: string, profile: TerminalProfile): void;
46
- unregisterTerminalProfile(id: string): void;
47
- hasProfile(id: string): boolean;
48
- getProfile(id: string): TerminalProfile | undefined
49
- readonly all: [string, TerminalProfile][];
50
- }
51
-
52
- @injectable()
53
- export class DefaultProfileStore implements TerminalProfileStore {
54
- protected readonly onAddedEmitter: Emitter<[string, TerminalProfile]> = new Emitter();
55
- protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
56
- protected readonly profiles: Map<string, TerminalProfile> = new Map();
57
-
58
- onAdded: Event<[string, TerminalProfile]> = this.onAddedEmitter.event;
59
- onRemoved: Event<string> = this.onRemovedEmitter.event;
60
-
61
- registerTerminalProfile(id: string, profile: TerminalProfile): void {
62
- this.profiles.set(id, profile);
63
- this.onAddedEmitter.fire([id, profile]);
64
- }
65
- unregisterTerminalProfile(id: string): void {
66
- this.profiles.delete(id);
67
- this.onRemovedEmitter.fire(id);
68
- }
69
-
70
- hasProfile(id: string): boolean {
71
- return this.profiles.has(id);
72
- }
73
-
74
- getProfile(id: string): TerminalProfile | undefined {
75
- return this.profiles.get(id);
76
- }
77
- get all(): [string, TerminalProfile][] {
78
- return [...this.profiles.entries()];
79
- }
80
- }
81
-
82
- @injectable()
83
- export class DefaultTerminalProfileService implements TerminalProfileService {
84
- protected defaultProfileIndex = 0;
85
- protected order: string[] = [];
86
- protected readonly stores: TerminalProfileStore[];
87
-
88
- protected readonly onAddedEmitter: Emitter<string> = new Emitter();
89
- protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
90
-
91
- onAdded: Event<string> = this.onAddedEmitter.event;
92
- onRemoved: Event<string> = this.onRemovedEmitter.event;
93
-
94
- constructor(...stores: TerminalProfileStore[]) {
95
- this.stores = stores;
96
- for (const store of this.stores) {
97
- store.onAdded(e => {
98
- if (e[1] === NULL_PROFILE) {
99
- this.handleRemoved(e[0]);
100
- } else {
101
- this.handleAdded(e[0]);
102
- }
103
- });
104
- store.onRemoved(id => {
105
- if (!this.getProfile(id)) {
106
- this.handleRemoved(id);
107
- } else {
108
- // we may have removed a null profile
109
- this.handleAdded(id);
110
- }
111
- });
112
- }
113
- }
114
-
115
- handleRemoved(id: string): void {
116
- const index = this.order.indexOf(id);
117
- if (index >= 0 && !this.getProfile(id)) {
118
- // the profile was removed, but it's still in the `order` array
119
- this.order.splice(index, 1);
120
- this.defaultProfileIndex = Math.max(0, Math.min(this.order.length - 1, index));
121
- this.onRemovedEmitter.fire(id);
122
- }
123
- }
124
-
125
- handleAdded(id: string): void {
126
- const index = this.order.indexOf(id);
127
- if (index < 0) {
128
- this.order.push(id);
129
- this.onAddedEmitter.fire(id);
130
- }
131
- }
132
-
133
- get defaultProfile(): TerminalProfile | undefined {
134
- const id = this.order[this.defaultProfileIndex];
135
- if (id) {
136
- return this.getProfile(id);
137
- }
138
- return undefined;
139
- }
140
-
141
- setDefaultProfile(id: string): void {
142
- const profile = this.getProfile(id);
143
- if (!profile) {
144
- throw new Error(`Cannot set default to unknown profile '${id}' `);
145
- }
146
- this.defaultProfileIndex = this.order.indexOf(id);
147
- }
148
-
149
- getProfile(id: string): TerminalProfile | undefined {
150
- for (const store of this.stores) {
151
- if (store.hasProfile(id)) {
152
- const found = store.getProfile(id);
153
- return found === NULL_PROFILE ? undefined : found;
154
- }
155
- }
156
- return undefined;
157
- }
158
-
159
- getId(profile: TerminalProfile): string | undefined {
160
- for (const [id, p] of this.all) {
161
- if (p === profile) {
162
- return id;
163
- }
164
- }
165
- }
166
-
167
- get all(): [string, TerminalProfile][] {
168
- return this.order.filter(id => !!this.getProfile(id)).map(id => [id, this.getProfile(id)!]);
169
- }
170
- }
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 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
+
21
+ export const TerminalProfileService = Symbol('TerminalProfileService');
22
+ export const ContributedTerminalProfileStore = Symbol('ContributedTerminalProfileStore');
23
+ export const UserTerminalProfileStore = Symbol('UserTerminalProfileStore');
24
+
25
+ export interface TerminalProfile {
26
+ start(): Promise<TerminalWidget>;
27
+ }
28
+
29
+ export const NULL_PROFILE: TerminalProfile = {
30
+ start: async () => { throw new Error('you cannot start a null profile'); }
31
+ };
32
+
33
+ export interface TerminalProfileService {
34
+ onAdded: Event<string>;
35
+ onRemoved: Event<string>;
36
+ getProfile(id: string): TerminalProfile | undefined
37
+ readonly all: [string, TerminalProfile][];
38
+ setDefaultProfile(id: string): void;
39
+ readonly defaultProfile: TerminalProfile | undefined;
40
+ }
41
+
42
+ export interface TerminalProfileStore {
43
+ onAdded: Event<[string, TerminalProfile]>;
44
+ onRemoved: Event<string>;
45
+ registerTerminalProfile(id: string, profile: TerminalProfile): void;
46
+ unregisterTerminalProfile(id: string): void;
47
+ hasProfile(id: string): boolean;
48
+ getProfile(id: string): TerminalProfile | undefined
49
+ readonly all: [string, TerminalProfile][];
50
+ }
51
+
52
+ @injectable()
53
+ export class DefaultProfileStore implements TerminalProfileStore {
54
+ protected readonly onAddedEmitter: Emitter<[string, TerminalProfile]> = new Emitter();
55
+ protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
56
+ protected readonly profiles: Map<string, TerminalProfile> = new Map();
57
+
58
+ onAdded: Event<[string, TerminalProfile]> = this.onAddedEmitter.event;
59
+ onRemoved: Event<string> = this.onRemovedEmitter.event;
60
+
61
+ registerTerminalProfile(id: string, profile: TerminalProfile): void {
62
+ this.profiles.set(id, profile);
63
+ this.onAddedEmitter.fire([id, profile]);
64
+ }
65
+ unregisterTerminalProfile(id: string): void {
66
+ this.profiles.delete(id);
67
+ this.onRemovedEmitter.fire(id);
68
+ }
69
+
70
+ hasProfile(id: string): boolean {
71
+ return this.profiles.has(id);
72
+ }
73
+
74
+ getProfile(id: string): TerminalProfile | undefined {
75
+ return this.profiles.get(id);
76
+ }
77
+ get all(): [string, TerminalProfile][] {
78
+ return [...this.profiles.entries()];
79
+ }
80
+ }
81
+
82
+ @injectable()
83
+ export class DefaultTerminalProfileService implements TerminalProfileService {
84
+ protected defaultProfileIndex = 0;
85
+ protected order: string[] = [];
86
+ protected readonly stores: TerminalProfileStore[];
87
+
88
+ protected readonly onAddedEmitter: Emitter<string> = new Emitter();
89
+ protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
90
+
91
+ onAdded: Event<string> = this.onAddedEmitter.event;
92
+ onRemoved: Event<string> = this.onRemovedEmitter.event;
93
+
94
+ constructor(...stores: TerminalProfileStore[]) {
95
+ this.stores = stores;
96
+ for (const store of this.stores) {
97
+ store.onAdded(e => {
98
+ if (e[1] === NULL_PROFILE) {
99
+ this.handleRemoved(e[0]);
100
+ } else {
101
+ this.handleAdded(e[0]);
102
+ }
103
+ });
104
+ store.onRemoved(id => {
105
+ if (!this.getProfile(id)) {
106
+ this.handleRemoved(id);
107
+ } else {
108
+ // we may have removed a null profile
109
+ this.handleAdded(id);
110
+ }
111
+ });
112
+ }
113
+ }
114
+
115
+ handleRemoved(id: string): void {
116
+ const index = this.order.indexOf(id);
117
+ if (index >= 0 && !this.getProfile(id)) {
118
+ // the profile was removed, but it's still in the `order` array
119
+ this.order.splice(index, 1);
120
+ this.defaultProfileIndex = Math.max(0, Math.min(this.order.length - 1, index));
121
+ this.onRemovedEmitter.fire(id);
122
+ }
123
+ }
124
+
125
+ handleAdded(id: string): void {
126
+ const index = this.order.indexOf(id);
127
+ if (index < 0) {
128
+ this.order.push(id);
129
+ this.onAddedEmitter.fire(id);
130
+ }
131
+ }
132
+
133
+ get defaultProfile(): TerminalProfile | undefined {
134
+ const id = this.order[this.defaultProfileIndex];
135
+ if (id) {
136
+ return this.getProfile(id);
137
+ }
138
+ return undefined;
139
+ }
140
+
141
+ setDefaultProfile(id: string): void {
142
+ const profile = this.getProfile(id);
143
+ if (!profile) {
144
+ throw new Error(`Cannot set default to unknown profile '${id}' `);
145
+ }
146
+ this.defaultProfileIndex = this.order.indexOf(id);
147
+ }
148
+
149
+ getProfile(id: string): TerminalProfile | undefined {
150
+ for (const store of this.stores) {
151
+ if (store.hasProfile(id)) {
152
+ const found = store.getProfile(id);
153
+ return found === NULL_PROFILE ? undefined : found;
154
+ }
155
+ }
156
+ return undefined;
157
+ }
158
+
159
+ getId(profile: TerminalProfile): string | undefined {
160
+ for (const [id, p] of this.all) {
161
+ if (p === profile) {
162
+ return id;
163
+ }
164
+ }
165
+ }
166
+
167
+ get all(): [string, TerminalProfile][] {
168
+ return this.order.filter(id => !!this.getProfile(id)).map(id => [id, this.getProfile(id)!]);
169
+ }
170
+ }
@@ -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 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 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
+ }