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

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 (45) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/terminal-link-provider.d.ts +1 -1
  3. package/lib/browser/terminal-link-provider.d.ts.map +1 -1
  4. package/lib/browser/terminal-widget-impl.js +4 -4
  5. package/package.json +10 -10
  6. package/src/browser/base/terminal-service.ts +60 -60
  7. package/src/browser/base/terminal-widget.ts +268 -268
  8. package/src/browser/index.ts +17 -17
  9. package/src/browser/search/terminal-search-container.ts +28 -28
  10. package/src/browser/search/terminal-search-widget.tsx +161 -161
  11. package/src/browser/shell-terminal-profile.ts +45 -45
  12. package/src/browser/style/terminal-search.css +99 -99
  13. package/src/browser/style/terminal.css +32 -32
  14. package/src/browser/terminal-contribution.ts +19 -19
  15. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  16. package/src/browser/terminal-file-link-provider.ts +289 -289
  17. package/src/browser/terminal-frontend-contribution.ts +1134 -1134
  18. package/src/browser/terminal-frontend-module.ts +138 -138
  19. package/src/browser/terminal-link-helpers.ts +187 -187
  20. package/src/browser/terminal-link-provider.ts +203 -203
  21. package/src/browser/terminal-preferences.ts +428 -428
  22. package/src/browser/terminal-profile-service.ts +180 -180
  23. package/src/browser/terminal-quick-open-service.ts +132 -132
  24. package/src/browser/terminal-theme-service.ts +213 -213
  25. package/src/browser/terminal-url-link-provider.ts +66 -66
  26. package/src/browser/terminal-widget-impl.ts +996 -996
  27. package/src/common/base-terminal-protocol.ts +125 -125
  28. package/src/common/shell-terminal-protocol.ts +103 -103
  29. package/src/common/terminal-common-module.ts +30 -30
  30. package/src/common/terminal-protocol.ts +32 -32
  31. package/src/common/terminal-watcher.ts +69 -69
  32. package/src/node/base-terminal-server.ts +173 -173
  33. package/src/node/buffering-stream.spec.ts +46 -46
  34. package/src/node/buffering-stream.ts +95 -95
  35. package/src/node/index.ts +17 -17
  36. package/src/node/shell-process.ts +102 -102
  37. package/src/node/shell-terminal-server.spec.ts +40 -40
  38. package/src/node/shell-terminal-server.ts +223 -223
  39. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  40. package/src/node/terminal-backend-contribution.ts +60 -60
  41. package/src/node/terminal-backend-module.ts +82 -82
  42. package/src/node/terminal-server.spec.ts +47 -47
  43. package/src/node/terminal-server.ts +52 -52
  44. package/src/node/test/terminal-test-container.ts +39 -39
  45. package/src/package.spec.ts +28 -28
@@ -1,203 +1,203 @@
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 { CancellationToken, ContributionProvider, DisposableCollection, disposableTimeout, isOSX } from '@theia/core';
18
- import { PreferenceService } from '@theia/core/lib/browser';
19
- import { inject, injectable, interfaces, named, postConstruct } from '@theia/core/shared/inversify';
20
- import { IBufferRange, ILink, ILinkDecorations } from 'xterm';
21
- import { TerminalWidget } from './base/terminal-widget';
22
- import { TerminalContribution } from './terminal-contribution';
23
- import { convertLinkRangeToBuffer, getLinkContext, LinkContext } from './terminal-link-helpers';
24
- import { TerminalWidgetImpl } from './terminal-widget-impl';
25
-
26
- export const TerminalLinkProvider = Symbol('TerminalLinkProvider');
27
- export interface TerminalLinkProvider {
28
- provideLinks(line: string, terminal: TerminalWidget, cancelationToken?: CancellationToken): Promise<TerminalLink[]>;
29
- }
30
-
31
- export const TerminalLink = Symbol('TerminalLink');
32
- export interface TerminalLink {
33
- startIndex: number;
34
- length: number;
35
- tooltip?: string;
36
- handle(): Promise<void>;
37
- }
38
-
39
- export const XtermLink = Symbol('XtermLink');
40
- export const XtermLinkFactory = Symbol('XtermLinkFactory');
41
- export type XtermLinkFactory = (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext) => ILink;
42
-
43
- export function createXtermLinkFactory(ctx: interfaces.Context): XtermLinkFactory {
44
- return (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext): ILink => {
45
- const container = ctx.container.createChild();
46
- container.bind(TerminalLink).toConstantValue(link);
47
- container.bind(TerminalWidgetImpl).toConstantValue(terminal);
48
- container.bind(LinkContext).toConstantValue(context);
49
- container.bind(XtermLinkAdapter).toSelf().inSingletonScope();
50
- container.bind(XtermLink).toService(XtermLinkAdapter);
51
- const provider = container.get<ILink>(XtermLink);
52
- return provider;
53
- };
54
- }
55
-
56
- @injectable()
57
- export class TerminalLinkProviderContribution implements TerminalContribution {
58
-
59
- @inject(ContributionProvider) @named(TerminalLinkProvider)
60
- protected readonly terminalLinkContributionProvider: ContributionProvider<TerminalLinkProvider>;
61
-
62
- @inject(XtermLinkFactory)
63
- protected readonly xtermLinkFactory: XtermLinkFactory;
64
-
65
- onCreate(terminalWidget: TerminalWidgetImpl): void {
66
- terminalWidget.getTerminal().registerLinkProvider({
67
- provideLinks: (line, provideLinks) => this.provideTerminalLinks(terminalWidget, line, provideLinks)
68
- });
69
- }
70
-
71
- protected async provideTerminalLinks(terminal: TerminalWidgetImpl, line: number, provideLinks: (links?: ILink[]) => void): Promise<void> {
72
- const context = getLinkContext(terminal.getTerminal(), line);
73
-
74
- const linkProviderPromises: Promise<TerminalLink[]>[] = [];
75
- for (const provider of this.terminalLinkContributionProvider.getContributions()) {
76
- linkProviderPromises.push(provider.provideLinks(context.text, terminal));
77
- }
78
-
79
- const xtermLinks: ILink[] = [];
80
- for (const providerResult of await Promise.allSettled(linkProviderPromises)) {
81
- if (providerResult.status === 'fulfilled') {
82
- const providedLinks = providerResult.value;
83
- xtermLinks.push(...providedLinks.map(link => this.xtermLinkFactory(link, terminal, context)));
84
- } else {
85
- console.warn('Terminal link provider failed to provide links', providerResult.reason);
86
- }
87
- }
88
-
89
- provideLinks(xtermLinks);
90
- }
91
-
92
- }
93
-
94
- const DELAY_PREFERENCE = 'workbench.hover.delay';
95
-
96
- @injectable()
97
- export class XtermLinkAdapter implements ILink {
98
-
99
- text: string;
100
- range: IBufferRange;
101
- decorations: ILinkDecorations;
102
-
103
- @inject(TerminalLink) protected link: TerminalLink;
104
- @inject(TerminalWidgetImpl) protected terminalWidget: TerminalWidgetImpl;
105
- @inject(LinkContext) protected context: LinkContext;
106
- @inject(PreferenceService) protected readonly preferences: PreferenceService;
107
-
108
- protected toDispose = new DisposableCollection();
109
-
110
- protected mouseEnteredHover = false;
111
- protected mouseLeftHover = false;
112
-
113
- @postConstruct()
114
- initializeLinkFields(): void {
115
- const range = {
116
- startColumn: this.link.startIndex + 1,
117
- startLineNumber: 1,
118
- endColumn: this.link.startIndex + this.link.length + 1,
119
- endLineNumber: 1
120
- };
121
- const terminal = this.terminalWidget.getTerminal();
122
- this.range = convertLinkRangeToBuffer(this.context.lines, terminal.cols, range, this.context.startLine);
123
- this.text = this.context.text.substring(this.link.startIndex, this.link.startIndex + this.link.length) || '';
124
- }
125
-
126
- hover(event: MouseEvent, text: string): void {
127
- this.scheduleHover(event);
128
- }
129
-
130
- protected scheduleHover(event: MouseEvent): void {
131
- this.cancelHover();
132
- const delay: number = this.preferences.get(DELAY_PREFERENCE) ?? 500;
133
- this.toDispose.push(disposableTimeout(() => this.showHover(event), delay));
134
- }
135
-
136
- protected showHover(event: MouseEvent): void {
137
- this.toDispose.push(this.terminalWidget.onMouseEnterLinkHover(() => this.mouseEnteredHover = true));
138
- this.toDispose.push(this.terminalWidget.onMouseLeaveLinkHover(mouseEvent => {
139
- this.mouseLeftHover = true;
140
- this.leave(mouseEvent);
141
- }));
142
- this.terminalWidget.showLinkHover(
143
- () => this.executeLinkHandler(),
144
- event.clientX,
145
- event.clientY,
146
- this.link.tooltip
147
- );
148
- }
149
-
150
- leave(event: MouseEvent): void {
151
- this.toDispose.push(disposableTimeout(() => {
152
- if (!this.mouseEnteredHover || this.mouseLeftHover) {
153
- this.cancelHover();
154
- }
155
- }, 50));
156
- }
157
-
158
- protected cancelHover(): void {
159
- this.mouseEnteredHover = false;
160
- this.mouseLeftHover = false;
161
- this.toDispose.dispose();
162
- this.terminalWidget.hideLinkHover();
163
- }
164
-
165
- activate(event: MouseEvent, text: string): void {
166
- event.preventDefault();
167
- if (this.isModifierKeyDown(event) || this.wasTouchEvent(event, this.terminalWidget.lastTouchEndEvent)) {
168
- this.executeLinkHandler();
169
- } else {
170
- this.terminalWidget.getTerminal().focus();
171
- }
172
- }
173
-
174
- protected executeLinkHandler(): void {
175
- this.link.handle();
176
- this.cancelHover();
177
- }
178
-
179
- protected isModifierKeyDown(event: MouseEvent | KeyboardEvent): boolean {
180
- return isOSX ? event.metaKey : event.ctrlKey;
181
- }
182
-
183
- protected wasTouchEvent(event: MouseEvent, lastTouchEnd?: TouchEvent): boolean {
184
- if (!lastTouchEnd) {
185
- return false;
186
- }
187
- if ((event.timeStamp - lastTouchEnd.timeStamp) > 400) {
188
- // A 'touchend' event typically precedes a matching 'click' event by 50ms.
189
- return false;
190
- }
191
- if (Math.abs(event.pageX - (lastTouchEnd as unknown as MouseEvent).pageX) > 5) {
192
- // Matching 'touchend' and 'click' events typically have the same page coordinates,
193
- // plus or minus 1 pixel.
194
- return false;
195
- }
196
- if (Math.abs(event.pageY - (lastTouchEnd as unknown as MouseEvent).pageY) > 5) {
197
- return false;
198
- }
199
- // We have a match! This link was tapped.
200
- return true;
201
- }
202
-
203
- }
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 { CancellationToken, ContributionProvider, DisposableCollection, disposableTimeout, isOSX } from '@theia/core';
18
+ import { PreferenceService } from '@theia/core/lib/browser';
19
+ import { inject, injectable, interfaces, named, postConstruct } from '@theia/core/shared/inversify';
20
+ import { IBufferRange, ILink, ILinkDecorations } from 'xterm';
21
+ import { TerminalWidget } from './base/terminal-widget';
22
+ import { TerminalContribution } from './terminal-contribution';
23
+ import { convertLinkRangeToBuffer, getLinkContext, LinkContext } from './terminal-link-helpers';
24
+ import { TerminalWidgetImpl } from './terminal-widget-impl';
25
+
26
+ export const TerminalLinkProvider = Symbol('TerminalLinkProvider');
27
+ export interface TerminalLinkProvider {
28
+ provideLinks(line: string, terminal: TerminalWidget, cancellationToken?: CancellationToken): Promise<TerminalLink[]>;
29
+ }
30
+
31
+ export const TerminalLink = Symbol('TerminalLink');
32
+ export interface TerminalLink {
33
+ startIndex: number;
34
+ length: number;
35
+ tooltip?: string;
36
+ handle(): Promise<void>;
37
+ }
38
+
39
+ export const XtermLink = Symbol('XtermLink');
40
+ export const XtermLinkFactory = Symbol('XtermLinkFactory');
41
+ export type XtermLinkFactory = (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext) => ILink;
42
+
43
+ export function createXtermLinkFactory(ctx: interfaces.Context): XtermLinkFactory {
44
+ return (link: TerminalLink, terminal: TerminalWidgetImpl, context: LinkContext): ILink => {
45
+ const container = ctx.container.createChild();
46
+ container.bind(TerminalLink).toConstantValue(link);
47
+ container.bind(TerminalWidgetImpl).toConstantValue(terminal);
48
+ container.bind(LinkContext).toConstantValue(context);
49
+ container.bind(XtermLinkAdapter).toSelf().inSingletonScope();
50
+ container.bind(XtermLink).toService(XtermLinkAdapter);
51
+ const provider = container.get<ILink>(XtermLink);
52
+ return provider;
53
+ };
54
+ }
55
+
56
+ @injectable()
57
+ export class TerminalLinkProviderContribution implements TerminalContribution {
58
+
59
+ @inject(ContributionProvider) @named(TerminalLinkProvider)
60
+ protected readonly terminalLinkContributionProvider: ContributionProvider<TerminalLinkProvider>;
61
+
62
+ @inject(XtermLinkFactory)
63
+ protected readonly xtermLinkFactory: XtermLinkFactory;
64
+
65
+ onCreate(terminalWidget: TerminalWidgetImpl): void {
66
+ terminalWidget.getTerminal().registerLinkProvider({
67
+ provideLinks: (line, provideLinks) => this.provideTerminalLinks(terminalWidget, line, provideLinks)
68
+ });
69
+ }
70
+
71
+ protected async provideTerminalLinks(terminal: TerminalWidgetImpl, line: number, provideLinks: (links?: ILink[]) => void): Promise<void> {
72
+ const context = getLinkContext(terminal.getTerminal(), line);
73
+
74
+ const linkProviderPromises: Promise<TerminalLink[]>[] = [];
75
+ for (const provider of this.terminalLinkContributionProvider.getContributions()) {
76
+ linkProviderPromises.push(provider.provideLinks(context.text, terminal));
77
+ }
78
+
79
+ const xtermLinks: ILink[] = [];
80
+ for (const providerResult of await Promise.allSettled(linkProviderPromises)) {
81
+ if (providerResult.status === 'fulfilled') {
82
+ const providedLinks = providerResult.value;
83
+ xtermLinks.push(...providedLinks.map(link => this.xtermLinkFactory(link, terminal, context)));
84
+ } else {
85
+ console.warn('Terminal link provider failed to provide links', providerResult.reason);
86
+ }
87
+ }
88
+
89
+ provideLinks(xtermLinks);
90
+ }
91
+
92
+ }
93
+
94
+ const DELAY_PREFERENCE = 'workbench.hover.delay';
95
+
96
+ @injectable()
97
+ export class XtermLinkAdapter implements ILink {
98
+
99
+ text: string;
100
+ range: IBufferRange;
101
+ decorations: ILinkDecorations;
102
+
103
+ @inject(TerminalLink) protected link: TerminalLink;
104
+ @inject(TerminalWidgetImpl) protected terminalWidget: TerminalWidgetImpl;
105
+ @inject(LinkContext) protected context: LinkContext;
106
+ @inject(PreferenceService) protected readonly preferences: PreferenceService;
107
+
108
+ protected toDispose = new DisposableCollection();
109
+
110
+ protected mouseEnteredHover = false;
111
+ protected mouseLeftHover = false;
112
+
113
+ @postConstruct()
114
+ initializeLinkFields(): void {
115
+ const range = {
116
+ startColumn: this.link.startIndex + 1,
117
+ startLineNumber: 1,
118
+ endColumn: this.link.startIndex + this.link.length + 1,
119
+ endLineNumber: 1
120
+ };
121
+ const terminal = this.terminalWidget.getTerminal();
122
+ this.range = convertLinkRangeToBuffer(this.context.lines, terminal.cols, range, this.context.startLine);
123
+ this.text = this.context.text.substring(this.link.startIndex, this.link.startIndex + this.link.length) || '';
124
+ }
125
+
126
+ hover(event: MouseEvent, text: string): void {
127
+ this.scheduleHover(event);
128
+ }
129
+
130
+ protected scheduleHover(event: MouseEvent): void {
131
+ this.cancelHover();
132
+ const delay: number = this.preferences.get(DELAY_PREFERENCE) ?? 500;
133
+ this.toDispose.push(disposableTimeout(() => this.showHover(event), delay));
134
+ }
135
+
136
+ protected showHover(event: MouseEvent): void {
137
+ this.toDispose.push(this.terminalWidget.onMouseEnterLinkHover(() => this.mouseEnteredHover = true));
138
+ this.toDispose.push(this.terminalWidget.onMouseLeaveLinkHover(mouseEvent => {
139
+ this.mouseLeftHover = true;
140
+ this.leave(mouseEvent);
141
+ }));
142
+ this.terminalWidget.showLinkHover(
143
+ () => this.executeLinkHandler(),
144
+ event.clientX,
145
+ event.clientY,
146
+ this.link.tooltip
147
+ );
148
+ }
149
+
150
+ leave(event: MouseEvent): void {
151
+ this.toDispose.push(disposableTimeout(() => {
152
+ if (!this.mouseEnteredHover || this.mouseLeftHover) {
153
+ this.cancelHover();
154
+ }
155
+ }, 50));
156
+ }
157
+
158
+ protected cancelHover(): void {
159
+ this.mouseEnteredHover = false;
160
+ this.mouseLeftHover = false;
161
+ this.toDispose.dispose();
162
+ this.terminalWidget.hideLinkHover();
163
+ }
164
+
165
+ activate(event: MouseEvent, text: string): void {
166
+ event.preventDefault();
167
+ if (this.isModifierKeyDown(event) || this.wasTouchEvent(event, this.terminalWidget.lastTouchEndEvent)) {
168
+ this.executeLinkHandler();
169
+ } else {
170
+ this.terminalWidget.getTerminal().focus();
171
+ }
172
+ }
173
+
174
+ protected executeLinkHandler(): void {
175
+ this.link.handle();
176
+ this.cancelHover();
177
+ }
178
+
179
+ protected isModifierKeyDown(event: MouseEvent | KeyboardEvent): boolean {
180
+ return isOSX ? event.metaKey : event.ctrlKey;
181
+ }
182
+
183
+ protected wasTouchEvent(event: MouseEvent, lastTouchEnd?: TouchEvent): boolean {
184
+ if (!lastTouchEnd) {
185
+ return false;
186
+ }
187
+ if ((event.timeStamp - lastTouchEnd.timeStamp) > 400) {
188
+ // A 'touchend' event typically precedes a matching 'click' event by 50ms.
189
+ return false;
190
+ }
191
+ if (Math.abs(event.pageX - (lastTouchEnd as unknown as MouseEvent).pageX) > 5) {
192
+ // Matching 'touchend' and 'click' events typically have the same page coordinates,
193
+ // plus or minus 1 pixel.
194
+ return false;
195
+ }
196
+ if (Math.abs(event.pageY - (lastTouchEnd as unknown as MouseEvent).pageY) > 5) {
197
+ return false;
198
+ }
199
+ // We have a match! This link was tapped.
200
+ return true;
201
+ }
202
+
203
+ }