@xterm/xterm 5.4.0-beta.1

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/css/xterm.css +209 -0
  4. package/lib/xterm.js +2 -0
  5. package/lib/xterm.js.map +1 -0
  6. package/package.json +101 -0
  7. package/src/browser/AccessibilityManager.ts +278 -0
  8. package/src/browser/Clipboard.ts +93 -0
  9. package/src/browser/ColorContrastCache.ts +34 -0
  10. package/src/browser/Lifecycle.ts +33 -0
  11. package/src/browser/Linkifier2.ts +416 -0
  12. package/src/browser/LocalizableStrings.ts +12 -0
  13. package/src/browser/OscLinkProvider.ts +128 -0
  14. package/src/browser/RenderDebouncer.ts +83 -0
  15. package/src/browser/Terminal.ts +1317 -0
  16. package/src/browser/TimeBasedDebouncer.ts +86 -0
  17. package/src/browser/Types.d.ts +181 -0
  18. package/src/browser/Viewport.ts +401 -0
  19. package/src/browser/decorations/BufferDecorationRenderer.ts +134 -0
  20. package/src/browser/decorations/ColorZoneStore.ts +117 -0
  21. package/src/browser/decorations/OverviewRulerRenderer.ts +218 -0
  22. package/src/browser/input/CompositionHelper.ts +246 -0
  23. package/src/browser/input/Mouse.ts +54 -0
  24. package/src/browser/input/MoveToCell.ts +249 -0
  25. package/src/browser/public/Terminal.ts +260 -0
  26. package/src/browser/renderer/dom/DomRenderer.ts +509 -0
  27. package/src/browser/renderer/dom/DomRendererRowFactory.ts +526 -0
  28. package/src/browser/renderer/dom/WidthCache.ts +160 -0
  29. package/src/browser/renderer/shared/CellColorResolver.ts +137 -0
  30. package/src/browser/renderer/shared/CharAtlasCache.ts +96 -0
  31. package/src/browser/renderer/shared/CharAtlasUtils.ts +75 -0
  32. package/src/browser/renderer/shared/Constants.ts +14 -0
  33. package/src/browser/renderer/shared/CursorBlinkStateManager.ts +146 -0
  34. package/src/browser/renderer/shared/CustomGlyphs.ts +687 -0
  35. package/src/browser/renderer/shared/DevicePixelObserver.ts +41 -0
  36. package/src/browser/renderer/shared/README.md +1 -0
  37. package/src/browser/renderer/shared/RendererUtils.ts +58 -0
  38. package/src/browser/renderer/shared/SelectionRenderModel.ts +91 -0
  39. package/src/browser/renderer/shared/TextureAtlas.ts +1082 -0
  40. package/src/browser/renderer/shared/Types.d.ts +173 -0
  41. package/src/browser/selection/SelectionModel.ts +144 -0
  42. package/src/browser/selection/Types.d.ts +15 -0
  43. package/src/browser/services/CharSizeService.ts +102 -0
  44. package/src/browser/services/CharacterJoinerService.ts +339 -0
  45. package/src/browser/services/CoreBrowserService.ts +137 -0
  46. package/src/browser/services/MouseService.ts +46 -0
  47. package/src/browser/services/RenderService.ts +279 -0
  48. package/src/browser/services/SelectionService.ts +1031 -0
  49. package/src/browser/services/Services.ts +147 -0
  50. package/src/browser/services/ThemeService.ts +237 -0
  51. package/src/common/CircularList.ts +241 -0
  52. package/src/common/Clone.ts +23 -0
  53. package/src/common/Color.ts +357 -0
  54. package/src/common/CoreTerminal.ts +284 -0
  55. package/src/common/EventEmitter.ts +78 -0
  56. package/src/common/InputHandler.ts +3461 -0
  57. package/src/common/Lifecycle.ts +108 -0
  58. package/src/common/MultiKeyMap.ts +42 -0
  59. package/src/common/Platform.ts +44 -0
  60. package/src/common/SortedList.ts +118 -0
  61. package/src/common/TaskQueue.ts +166 -0
  62. package/src/common/TypedArrayUtils.ts +17 -0
  63. package/src/common/Types.d.ts +553 -0
  64. package/src/common/WindowsMode.ts +27 -0
  65. package/src/common/buffer/AttributeData.ts +196 -0
  66. package/src/common/buffer/Buffer.ts +654 -0
  67. package/src/common/buffer/BufferLine.ts +524 -0
  68. package/src/common/buffer/BufferRange.ts +13 -0
  69. package/src/common/buffer/BufferReflow.ts +223 -0
  70. package/src/common/buffer/BufferSet.ts +134 -0
  71. package/src/common/buffer/CellData.ts +94 -0
  72. package/src/common/buffer/Constants.ts +149 -0
  73. package/src/common/buffer/Marker.ts +43 -0
  74. package/src/common/buffer/Types.d.ts +52 -0
  75. package/src/common/data/Charsets.ts +256 -0
  76. package/src/common/data/EscapeSequences.ts +153 -0
  77. package/src/common/input/Keyboard.ts +398 -0
  78. package/src/common/input/TextDecoder.ts +346 -0
  79. package/src/common/input/UnicodeV6.ts +145 -0
  80. package/src/common/input/WriteBuffer.ts +246 -0
  81. package/src/common/input/XParseColor.ts +80 -0
  82. package/src/common/parser/Constants.ts +58 -0
  83. package/src/common/parser/DcsParser.ts +192 -0
  84. package/src/common/parser/EscapeSequenceParser.ts +792 -0
  85. package/src/common/parser/OscParser.ts +238 -0
  86. package/src/common/parser/Params.ts +229 -0
  87. package/src/common/parser/Types.d.ts +275 -0
  88. package/src/common/public/AddonManager.ts +53 -0
  89. package/src/common/public/BufferApiView.ts +35 -0
  90. package/src/common/public/BufferLineApiView.ts +29 -0
  91. package/src/common/public/BufferNamespaceApi.ts +36 -0
  92. package/src/common/public/ParserApi.ts +37 -0
  93. package/src/common/public/UnicodeApi.ts +27 -0
  94. package/src/common/services/BufferService.ts +151 -0
  95. package/src/common/services/CharsetService.ts +34 -0
  96. package/src/common/services/CoreMouseService.ts +318 -0
  97. package/src/common/services/CoreService.ts +87 -0
  98. package/src/common/services/DecorationService.ts +140 -0
  99. package/src/common/services/InstantiationService.ts +85 -0
  100. package/src/common/services/LogService.ts +124 -0
  101. package/src/common/services/OptionsService.ts +202 -0
  102. package/src/common/services/OscLinkService.ts +115 -0
  103. package/src/common/services/ServiceRegistry.ts +49 -0
  104. package/src/common/services/Services.ts +373 -0
  105. package/src/common/services/UnicodeService.ts +111 -0
  106. package/src/headless/Terminal.ts +136 -0
  107. package/src/headless/public/Terminal.ts +195 -0
  108. package/typings/xterm.d.ts +1857 -0
@@ -0,0 +1,416 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { addDisposableDomListener } from 'browser/Lifecycle';
7
+ import { IBufferCellPosition, ILink, ILinkDecorations, ILinkProvider, ILinkWithState, ILinkifier2, ILinkifierEvent } from 'browser/Types';
8
+ import { EventEmitter } from 'common/EventEmitter';
9
+ import { Disposable, disposeArray, getDisposeArrayDisposable, toDisposable } from 'common/Lifecycle';
10
+ import { IDisposable } from 'common/Types';
11
+ import { IBufferService } from 'common/services/Services';
12
+ import { IMouseService, IRenderService } from './services/Services';
13
+
14
+ export class Linkifier2 extends Disposable implements ILinkifier2 {
15
+ private _element: HTMLElement | undefined;
16
+ private _mouseService: IMouseService | undefined;
17
+ private _renderService: IRenderService | undefined;
18
+ private _linkProviders: ILinkProvider[] = [];
19
+ public get currentLink(): ILinkWithState | undefined { return this._currentLink; }
20
+ protected _currentLink: ILinkWithState | undefined;
21
+ private _mouseDownLink: ILinkWithState | undefined;
22
+ private _lastMouseEvent: MouseEvent | undefined;
23
+ private _linkCacheDisposables: IDisposable[] = [];
24
+ private _lastBufferCell: IBufferCellPosition | undefined;
25
+ private _isMouseOut: boolean = true;
26
+ private _wasResized: boolean = false;
27
+ private _activeProviderReplies: Map<Number, ILinkWithState[] | undefined> | undefined;
28
+ private _activeLine: number = -1;
29
+
30
+ private readonly _onShowLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>());
31
+ public readonly onShowLinkUnderline = this._onShowLinkUnderline.event;
32
+ private readonly _onHideLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>());
33
+ public readonly onHideLinkUnderline = this._onHideLinkUnderline.event;
34
+
35
+ constructor(
36
+ @IBufferService private readonly _bufferService: IBufferService
37
+ ) {
38
+ super();
39
+ this.register(getDisposeArrayDisposable(this._linkCacheDisposables));
40
+ this.register(toDisposable(() => {
41
+ this._lastMouseEvent = undefined;
42
+ }));
43
+ // Listen to resize to catch the case where it's resized and the cursor is out of the viewport.
44
+ this.register(this._bufferService.onResize(() => {
45
+ this._clearCurrentLink();
46
+ this._wasResized = true;
47
+ }));
48
+ }
49
+
50
+ public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
51
+ this._linkProviders.push(linkProvider);
52
+ return {
53
+ dispose: () => {
54
+ // Remove the link provider from the list
55
+ const providerIndex = this._linkProviders.indexOf(linkProvider);
56
+
57
+ if (providerIndex !== -1) {
58
+ this._linkProviders.splice(providerIndex, 1);
59
+ }
60
+ }
61
+ };
62
+ }
63
+
64
+ public attachToDom(element: HTMLElement, mouseService: IMouseService, renderService: IRenderService): void {
65
+ this._element = element;
66
+ this._mouseService = mouseService;
67
+ this._renderService = renderService;
68
+
69
+ this.register(addDisposableDomListener(this._element, 'mouseleave', () => {
70
+ this._isMouseOut = true;
71
+ this._clearCurrentLink();
72
+ }));
73
+ this.register(addDisposableDomListener(this._element, 'mousemove', this._handleMouseMove.bind(this)));
74
+ this.register(addDisposableDomListener(this._element, 'mousedown', this._handleMouseDown.bind(this)));
75
+ this.register(addDisposableDomListener(this._element, 'mouseup', this._handleMouseUp.bind(this)));
76
+ }
77
+
78
+ private _handleMouseMove(event: MouseEvent): void {
79
+ this._lastMouseEvent = event;
80
+
81
+ if (!this._element || !this._mouseService) {
82
+ return;
83
+ }
84
+
85
+ const position = this._positionFromMouseEvent(event, this._element, this._mouseService);
86
+ if (!position) {
87
+ return;
88
+ }
89
+ this._isMouseOut = false;
90
+
91
+ // Ignore the event if it's an embedder created hover widget
92
+ const composedPath = event.composedPath() as HTMLElement[];
93
+ for (let i = 0; i < composedPath.length; i++) {
94
+ const target = composedPath[i];
95
+ // Hit Terminal.element, break and continue
96
+ if (target.classList.contains('xterm')) {
97
+ break;
98
+ }
99
+ // It's a hover, don't respect hover event
100
+ if (target.classList.contains('xterm-hover')) {
101
+ return;
102
+ }
103
+ }
104
+
105
+ if (!this._lastBufferCell || (position.x !== this._lastBufferCell.x || position.y !== this._lastBufferCell.y)) {
106
+ this._handleHover(position);
107
+ this._lastBufferCell = position;
108
+ }
109
+ }
110
+
111
+ private _handleHover(position: IBufferCellPosition): void {
112
+ // TODO: This currently does not cache link provider results across wrapped lines, activeLine
113
+ // should be something like `activeRange: {startY, endY}`
114
+ // Check if we need to clear the link
115
+ if (this._activeLine !== position.y || this._wasResized) {
116
+ this._clearCurrentLink();
117
+ this._askForLink(position, false);
118
+ this._wasResized = false;
119
+ return;
120
+ }
121
+
122
+ // Check the if the link is in the mouse position
123
+ const isCurrentLinkInPosition = this._currentLink && this._linkAtPosition(this._currentLink.link, position);
124
+ if (!isCurrentLinkInPosition) {
125
+ this._clearCurrentLink();
126
+ this._askForLink(position, true);
127
+ }
128
+ }
129
+
130
+ private _askForLink(position: IBufferCellPosition, useLineCache: boolean): void {
131
+ if (!this._activeProviderReplies || !useLineCache) {
132
+ this._activeProviderReplies?.forEach(reply => {
133
+ reply?.forEach(linkWithState => {
134
+ if (linkWithState.link.dispose) {
135
+ linkWithState.link.dispose();
136
+ }
137
+ });
138
+ });
139
+ this._activeProviderReplies = new Map();
140
+ this._activeLine = position.y;
141
+ }
142
+ let linkProvided = false;
143
+
144
+ // There is no link cached, so ask for one
145
+ for (const [i, linkProvider] of this._linkProviders.entries()) {
146
+ if (useLineCache) {
147
+ const existingReply = this._activeProviderReplies?.get(i);
148
+ // If there isn't a reply, the provider hasn't responded yet.
149
+
150
+ // TODO: If there isn't a reply yet it means that the provider is still resolving. Ensuring
151
+ // provideLinks isn't triggered again saves ILink.hover firing twice though. This probably
152
+ // needs promises to get fixed
153
+ if (existingReply) {
154
+ linkProvided = this._checkLinkProviderResult(i, position, linkProvided);
155
+ }
156
+ } else {
157
+ linkProvider.provideLinks(position.y, (links: ILink[] | undefined) => {
158
+ if (this._isMouseOut) {
159
+ return;
160
+ }
161
+ const linksWithState: ILinkWithState[] | undefined = links?.map(link => ({ link }));
162
+ this._activeProviderReplies?.set(i, linksWithState);
163
+ linkProvided = this._checkLinkProviderResult(i, position, linkProvided);
164
+
165
+ // If all providers have responded, remove lower priority links that intersect ranges of
166
+ // higher priority links
167
+ if (this._activeProviderReplies?.size === this._linkProviders.length) {
168
+ this._removeIntersectingLinks(position.y, this._activeProviderReplies);
169
+ }
170
+ });
171
+ }
172
+ }
173
+ }
174
+
175
+ private _removeIntersectingLinks(y: number, replies: Map<Number, ILinkWithState[] | undefined>): void {
176
+ const occupiedCells = new Set<number>();
177
+ for (let i = 0; i < replies.size; i++) {
178
+ const providerReply = replies.get(i);
179
+ if (!providerReply) {
180
+ continue;
181
+ }
182
+ for (let i = 0; i < providerReply.length; i++) {
183
+ const linkWithState = providerReply[i];
184
+ const startX = linkWithState.link.range.start.y < y ? 0 : linkWithState.link.range.start.x;
185
+ const endX = linkWithState.link.range.end.y > y ? this._bufferService.cols : linkWithState.link.range.end.x;
186
+ for (let x = startX; x <= endX; x++) {
187
+ if (occupiedCells.has(x)) {
188
+ providerReply.splice(i--, 1);
189
+ break;
190
+ }
191
+ occupiedCells.add(x);
192
+ }
193
+ }
194
+ }
195
+ }
196
+
197
+ private _checkLinkProviderResult(index: number, position: IBufferCellPosition, linkProvided: boolean): boolean {
198
+ if (!this._activeProviderReplies) {
199
+ return linkProvided;
200
+ }
201
+
202
+ const links = this._activeProviderReplies.get(index);
203
+
204
+ // Check if every provider before this one has come back undefined
205
+ let hasLinkBefore = false;
206
+ for (let j = 0; j < index; j++) {
207
+ if (!this._activeProviderReplies.has(j) || this._activeProviderReplies.get(j)) {
208
+ hasLinkBefore = true;
209
+ }
210
+ }
211
+
212
+ // If all providers with higher priority came back undefined, then this provider's link for
213
+ // the position should be used
214
+ if (!hasLinkBefore && links) {
215
+ const linkAtPosition = links.find(link => this._linkAtPosition(link.link, position));
216
+ if (linkAtPosition) {
217
+ linkProvided = true;
218
+ this._handleNewLink(linkAtPosition);
219
+ }
220
+ }
221
+
222
+ // Check if all the providers have responded
223
+ if (this._activeProviderReplies.size === this._linkProviders.length && !linkProvided) {
224
+ // Respect the order of the link providers
225
+ for (let j = 0; j < this._activeProviderReplies.size; j++) {
226
+ const currentLink = this._activeProviderReplies.get(j)?.find(link => this._linkAtPosition(link.link, position));
227
+ if (currentLink) {
228
+ linkProvided = true;
229
+ this._handleNewLink(currentLink);
230
+ break;
231
+ }
232
+ }
233
+ }
234
+
235
+ return linkProvided;
236
+ }
237
+
238
+ private _handleMouseDown(): void {
239
+ this._mouseDownLink = this._currentLink;
240
+ }
241
+
242
+ private _handleMouseUp(event: MouseEvent): void {
243
+ if (!this._element || !this._mouseService || !this._currentLink) {
244
+ return;
245
+ }
246
+
247
+ const position = this._positionFromMouseEvent(event, this._element, this._mouseService);
248
+ if (!position) {
249
+ return;
250
+ }
251
+
252
+ if (this._mouseDownLink === this._currentLink && this._linkAtPosition(this._currentLink.link, position)) {
253
+ this._currentLink.link.activate(event, this._currentLink.link.text);
254
+ }
255
+ }
256
+
257
+ private _clearCurrentLink(startRow?: number, endRow?: number): void {
258
+ if (!this._element || !this._currentLink || !this._lastMouseEvent) {
259
+ return;
260
+ }
261
+
262
+ // If we have a start and end row, check that the link is within it
263
+ if (!startRow || !endRow || (this._currentLink.link.range.start.y >= startRow && this._currentLink.link.range.end.y <= endRow)) {
264
+ this._linkLeave(this._element, this._currentLink.link, this._lastMouseEvent);
265
+ this._currentLink = undefined;
266
+ disposeArray(this._linkCacheDisposables);
267
+ }
268
+ }
269
+
270
+ private _handleNewLink(linkWithState: ILinkWithState): void {
271
+ if (!this._element || !this._lastMouseEvent || !this._mouseService) {
272
+ return;
273
+ }
274
+
275
+ const position = this._positionFromMouseEvent(this._lastMouseEvent, this._element, this._mouseService);
276
+
277
+ if (!position) {
278
+ return;
279
+ }
280
+
281
+ // Trigger hover if the we have a link at the position
282
+ if (this._linkAtPosition(linkWithState.link, position)) {
283
+ this._currentLink = linkWithState;
284
+ this._currentLink.state = {
285
+ decorations: {
286
+ underline: linkWithState.link.decorations === undefined ? true : linkWithState.link.decorations.underline,
287
+ pointerCursor: linkWithState.link.decorations === undefined ? true : linkWithState.link.decorations.pointerCursor
288
+ },
289
+ isHovered: true
290
+ };
291
+ this._linkHover(this._element, linkWithState.link, this._lastMouseEvent);
292
+
293
+ // Add listener for tracking decorations changes
294
+ linkWithState.link.decorations = {} as ILinkDecorations;
295
+ Object.defineProperties(linkWithState.link.decorations, {
296
+ pointerCursor: {
297
+ get: () => this._currentLink?.state?.decorations.pointerCursor,
298
+ set: v => {
299
+ if (this._currentLink?.state && this._currentLink.state.decorations.pointerCursor !== v) {
300
+ this._currentLink.state.decorations.pointerCursor = v;
301
+ if (this._currentLink.state.isHovered) {
302
+ this._element?.classList.toggle('xterm-cursor-pointer', v);
303
+ }
304
+ }
305
+ }
306
+ },
307
+ underline: {
308
+ get: () => this._currentLink?.state?.decorations.underline,
309
+ set: v => {
310
+ if (this._currentLink?.state && this._currentLink?.state?.decorations.underline !== v) {
311
+ this._currentLink.state.decorations.underline = v;
312
+ if (this._currentLink.state.isHovered) {
313
+ this._fireUnderlineEvent(linkWithState.link, v);
314
+ }
315
+ }
316
+ }
317
+ }
318
+ });
319
+
320
+ // Listen to viewport changes to re-render the link under the cursor (only when the line the
321
+ // link is on changes)
322
+ if (this._renderService) {
323
+ this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e => {
324
+ // Sanity check, this shouldn't happen in practice as this listener would be disposed
325
+ if (!this._currentLink) {
326
+ return;
327
+ }
328
+ // When start is 0 a scroll most likely occurred, make sure links above the fold also get
329
+ // cleared.
330
+ const start = e.start === 0 ? 0 : e.start + 1 + this._bufferService.buffer.ydisp;
331
+ const end = this._bufferService.buffer.ydisp + 1 + e.end;
332
+ // Only clear the link if the viewport change happened on this line
333
+ if (this._currentLink.link.range.start.y >= start && this._currentLink.link.range.end.y <= end) {
334
+ this._clearCurrentLink(start, end);
335
+ if (this._lastMouseEvent && this._element) {
336
+ // re-eval previously active link after changes
337
+ const position = this._positionFromMouseEvent(this._lastMouseEvent, this._element, this._mouseService!);
338
+ if (position) {
339
+ this._askForLink(position, false);
340
+ }
341
+ }
342
+ }
343
+ }));
344
+ }
345
+ }
346
+ }
347
+
348
+ protected _linkHover(element: HTMLElement, link: ILink, event: MouseEvent): void {
349
+ if (this._currentLink?.state) {
350
+ this._currentLink.state.isHovered = true;
351
+ if (this._currentLink.state.decorations.underline) {
352
+ this._fireUnderlineEvent(link, true);
353
+ }
354
+ if (this._currentLink.state.decorations.pointerCursor) {
355
+ element.classList.add('xterm-cursor-pointer');
356
+ }
357
+ }
358
+
359
+ if (link.hover) {
360
+ link.hover(event, link.text);
361
+ }
362
+ }
363
+
364
+ private _fireUnderlineEvent(link: ILink, showEvent: boolean): void {
365
+ const range = link.range;
366
+ const scrollOffset = this._bufferService.buffer.ydisp;
367
+ const event = this._createLinkUnderlineEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined);
368
+ const emitter = showEvent ? this._onShowLinkUnderline : this._onHideLinkUnderline;
369
+ emitter.fire(event);
370
+ }
371
+
372
+ protected _linkLeave(element: HTMLElement, link: ILink, event: MouseEvent): void {
373
+ if (this._currentLink?.state) {
374
+ this._currentLink.state.isHovered = false;
375
+ if (this._currentLink.state.decorations.underline) {
376
+ this._fireUnderlineEvent(link, false);
377
+ }
378
+ if (this._currentLink.state.decorations.pointerCursor) {
379
+ element.classList.remove('xterm-cursor-pointer');
380
+ }
381
+ }
382
+
383
+ if (link.leave) {
384
+ link.leave(event, link.text);
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Check if the buffer position is within the link
390
+ * @param link
391
+ * @param position
392
+ */
393
+ private _linkAtPosition(link: ILink, position: IBufferCellPosition): boolean {
394
+ const lower = link.range.start.y * this._bufferService.cols + link.range.start.x;
395
+ const upper = link.range.end.y * this._bufferService.cols + link.range.end.x;
396
+ const current = position.y * this._bufferService.cols + position.x;
397
+ return (lower <= current && current <= upper);
398
+ }
399
+
400
+ /**
401
+ * Get the buffer position from a mouse event
402
+ * @param event
403
+ */
404
+ private _positionFromMouseEvent(event: MouseEvent, element: HTMLElement, mouseService: IMouseService): IBufferCellPosition | undefined {
405
+ const coords = mouseService.getCoords(event, element, this._bufferService.cols, this._bufferService.rows);
406
+ if (!coords) {
407
+ return;
408
+ }
409
+
410
+ return { x: coords[0], y: coords[1] + this._bufferService.buffer.ydisp };
411
+ }
412
+
413
+ private _createLinkUnderlineEvent(x1: number, y1: number, x2: number, y2: number, fg: number | undefined): ILinkifierEvent {
414
+ return { x1, y1, x2, y2, cols: this._bufferService.cols, fg };
415
+ }
416
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ // This file contains strings that get exported in the API so they can be localized
7
+
8
+ // eslint-disable-next-line prefer-const
9
+ export let promptLabel = 'Terminal input';
10
+
11
+ // eslint-disable-next-line prefer-const
12
+ export let tooMuchOutput = 'Too much output to announce, navigate to rows manually to read';
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Copyright (c) 2022 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IBufferRange, ILink, ILinkProvider } from 'browser/Types';
7
+ import { CellData } from 'common/buffer/CellData';
8
+ import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
9
+
10
+ export class OscLinkProvider implements ILinkProvider {
11
+ constructor(
12
+ @IBufferService private readonly _bufferService: IBufferService,
13
+ @IOptionsService private readonly _optionsService: IOptionsService,
14
+ @IOscLinkService private readonly _oscLinkService: IOscLinkService
15
+ ) {
16
+ }
17
+
18
+ public provideLinks(y: number, callback: (links: ILink[] | undefined) => void): void {
19
+ const line = this._bufferService.buffer.lines.get(y - 1);
20
+ if (!line) {
21
+ callback(undefined);
22
+ return;
23
+ }
24
+
25
+ const result: ILink[] = [];
26
+ const linkHandler = this._optionsService.rawOptions.linkHandler;
27
+ const cell = new CellData();
28
+ const lineLength = line.getTrimmedLength();
29
+ let currentLinkId = -1;
30
+ let currentStart = -1;
31
+ let finishLink = false;
32
+ for (let x = 0; x < lineLength; x++) {
33
+ // Minor optimization, only check for content if there isn't a link in case the link ends with
34
+ // a null cell
35
+ if (currentStart === -1 && !line.hasContent(x)) {
36
+ continue;
37
+ }
38
+
39
+ line.loadCell(x, cell);
40
+ if (cell.hasExtendedAttrs() && cell.extended.urlId) {
41
+ if (currentStart === -1) {
42
+ currentStart = x;
43
+ currentLinkId = cell.extended.urlId;
44
+ continue;
45
+ } else {
46
+ finishLink = cell.extended.urlId !== currentLinkId;
47
+ }
48
+ } else {
49
+ if (currentStart !== -1) {
50
+ finishLink = true;
51
+ }
52
+ }
53
+
54
+ if (finishLink || (currentStart !== -1 && x === lineLength - 1)) {
55
+ const text = this._oscLinkService.getLinkData(currentLinkId)?.uri;
56
+ if (text) {
57
+ // These ranges are 1-based
58
+ const range: IBufferRange = {
59
+ start: {
60
+ x: currentStart + 1,
61
+ y
62
+ },
63
+ end: {
64
+ // Offset end x if it's a link that ends on the last cell in the line
65
+ x: x + (!finishLink && x === lineLength - 1 ? 1 : 0),
66
+ y
67
+ }
68
+ };
69
+
70
+ let ignoreLink = false;
71
+ if (!linkHandler?.allowNonHttpProtocols) {
72
+ try {
73
+ const parsed = new URL(text);
74
+ if (!['http:', 'https:'].includes(parsed.protocol)) {
75
+ ignoreLink = true;
76
+ }
77
+ } catch (e) {
78
+ // Ignore invalid URLs to prevent unexpected behaviors
79
+ ignoreLink = true;
80
+ }
81
+ }
82
+
83
+ if (!ignoreLink) {
84
+ // OSC links always use underline and pointer decorations
85
+ result.push({
86
+ text,
87
+ range,
88
+ activate: (e, text) => (linkHandler ? linkHandler.activate(e, text, range) : defaultActivate(e, text)),
89
+ hover: (e, text) => linkHandler?.hover?.(e, text, range),
90
+ leave: (e, text) => linkHandler?.leave?.(e, text, range)
91
+ });
92
+ }
93
+ }
94
+ finishLink = false;
95
+
96
+ // Clear link or start a new link if one starts immediately
97
+ if (cell.hasExtendedAttrs() && cell.extended.urlId) {
98
+ currentStart = x;
99
+ currentLinkId = cell.extended.urlId;
100
+ } else {
101
+ currentStart = -1;
102
+ currentLinkId = -1;
103
+ }
104
+ }
105
+ }
106
+
107
+ // TODO: Handle fetching and returning other link ranges to underline other links with the same
108
+ // id
109
+ callback(result);
110
+ }
111
+ }
112
+
113
+ function defaultActivate(e: MouseEvent, uri: string): void {
114
+ const answer = confirm(`Do you want to navigate to ${uri}?\n\nWARNING: This link could potentially be dangerous`);
115
+ if (answer) {
116
+ const newWindow = window.open();
117
+ if (newWindow) {
118
+ try {
119
+ newWindow.opener = null;
120
+ } catch {
121
+ // no-op, Electron can throw
122
+ }
123
+ newWindow.location.href = uri;
124
+ } else {
125
+ console.warn('Opening link blocked as opener could not be cleared');
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IRenderDebouncerWithCallback } from 'browser/Types';
7
+
8
+ /**
9
+ * Debounces calls to render terminal rows using animation frames.
10
+ */
11
+ export class RenderDebouncer implements IRenderDebouncerWithCallback {
12
+ private _rowStart: number | undefined;
13
+ private _rowEnd: number | undefined;
14
+ private _rowCount: number | undefined;
15
+ private _animationFrame: number | undefined;
16
+ private _refreshCallbacks: FrameRequestCallback[] = [];
17
+
18
+ constructor(
19
+ private _parentWindow: Window,
20
+ private _renderCallback: (start: number, end: number) => void
21
+ ) {
22
+ }
23
+
24
+ public dispose(): void {
25
+ if (this._animationFrame) {
26
+ this._parentWindow.cancelAnimationFrame(this._animationFrame);
27
+ this._animationFrame = undefined;
28
+ }
29
+ }
30
+
31
+ public addRefreshCallback(callback: FrameRequestCallback): number {
32
+ this._refreshCallbacks.push(callback);
33
+ if (!this._animationFrame) {
34
+ this._animationFrame = this._parentWindow.requestAnimationFrame(() => this._innerRefresh());
35
+ }
36
+ return this._animationFrame;
37
+ }
38
+
39
+ public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
40
+ this._rowCount = rowCount;
41
+ // Get the min/max row start/end for the arg values
42
+ rowStart = rowStart !== undefined ? rowStart : 0;
43
+ rowEnd = rowEnd !== undefined ? rowEnd : this._rowCount - 1;
44
+ // Set the properties to the updated values
45
+ this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
46
+ this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
47
+
48
+ if (this._animationFrame) {
49
+ return;
50
+ }
51
+
52
+ this._animationFrame = this._parentWindow.requestAnimationFrame(() => this._innerRefresh());
53
+ }
54
+
55
+ private _innerRefresh(): void {
56
+ this._animationFrame = undefined;
57
+
58
+ // Make sure values are set
59
+ if (this._rowStart === undefined || this._rowEnd === undefined || this._rowCount === undefined) {
60
+ this._runRefreshCallbacks();
61
+ return;
62
+ }
63
+
64
+ // Clamp values
65
+ const start = Math.max(this._rowStart, 0);
66
+ const end = Math.min(this._rowEnd, this._rowCount - 1);
67
+
68
+ // Reset debouncer (this happens before render callback as the render could trigger it again)
69
+ this._rowStart = undefined;
70
+ this._rowEnd = undefined;
71
+
72
+ // Run render callback
73
+ this._renderCallback(start, end);
74
+ this._runRefreshCallbacks();
75
+ }
76
+
77
+ private _runRefreshCallbacks(): void {
78
+ for (const callback of this._refreshCallbacks) {
79
+ callback(0);
80
+ }
81
+ this._refreshCallbacks = [];
82
+ }
83
+ }