@wendongfly/myhi 1.0.2 → 1.0.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.
- package/dist/index.js +1 -1
- package/dist/lib/xterm/LICENSE +21 -0
- package/dist/lib/xterm/README.md +225 -0
- package/dist/lib/xterm/css/xterm.css +190 -0
- package/dist/lib/xterm/lib/xterm.js +2 -0
- package/dist/lib/xterm/lib/xterm.js.map +1 -0
- package/dist/lib/xterm/package.json +90 -0
- package/dist/lib/xterm/src/browser/AccessibilityManager.ts +301 -0
- package/dist/lib/xterm/src/browser/Clipboard.ts +99 -0
- package/dist/lib/xterm/src/browser/ColorContrastCache.ts +39 -0
- package/dist/lib/xterm/src/browser/ColorManager.ts +268 -0
- package/dist/lib/xterm/src/browser/Dom.ts +10 -0
- package/dist/lib/xterm/src/browser/Lifecycle.ts +30 -0
- package/dist/lib/xterm/src/browser/Linkifier.ts +356 -0
- package/dist/lib/xterm/src/browser/Linkifier2.ts +397 -0
- package/dist/lib/xterm/src/browser/LocalizableStrings.ts +10 -0
- package/dist/lib/xterm/src/browser/MouseZoneManager.ts +236 -0
- package/dist/lib/xterm/src/browser/RenderDebouncer.ts +82 -0
- package/dist/lib/xterm/src/browser/ScreenDprMonitor.ts +69 -0
- package/dist/lib/xterm/src/browser/Terminal.ts +1447 -0
- package/dist/lib/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
- package/dist/lib/xterm/src/browser/Types.d.ts +317 -0
- package/dist/lib/xterm/src/browser/Viewport.ts +276 -0
- package/dist/lib/xterm/src/browser/decorations/BufferDecorationRenderer.ts +131 -0
- package/dist/lib/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
- package/dist/lib/xterm/src/browser/decorations/OverviewRulerRenderer.ts +228 -0
- package/dist/lib/xterm/src/browser/input/CompositionHelper.ts +237 -0
- package/dist/lib/xterm/src/browser/input/Mouse.ts +64 -0
- package/dist/lib/xterm/src/browser/input/MoveToCell.ts +249 -0
- package/dist/lib/xterm/src/browser/public/Terminal.ts +298 -0
- package/dist/lib/xterm/src/browser/renderer/BaseRenderLayer.ts +582 -0
- package/dist/lib/xterm/src/browser/renderer/CursorRenderLayer.ts +378 -0
- package/dist/lib/xterm/src/browser/renderer/CustomGlyphs.ts +632 -0
- package/dist/lib/xterm/src/browser/renderer/GridCache.ts +33 -0
- package/dist/lib/xterm/src/browser/renderer/LinkRenderLayer.ts +84 -0
- package/dist/lib/xterm/src/browser/renderer/Renderer.ts +219 -0
- package/dist/lib/xterm/src/browser/renderer/RendererUtils.ts +26 -0
- package/dist/lib/xterm/src/browser/renderer/SelectionRenderLayer.ts +131 -0
- package/dist/lib/xterm/src/browser/renderer/TextRenderLayer.ts +344 -0
- package/dist/lib/xterm/src/browser/renderer/Types.d.ts +109 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/BaseCharAtlas.ts +58 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasCache.ts +95 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasUtils.ts +54 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Constants.ts +15 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/DynamicCharAtlas.ts +404 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/LRUMap.ts +136 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Types.d.ts +29 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRenderer.ts +403 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +344 -0
- package/dist/lib/xterm/src/browser/selection/SelectionModel.ts +144 -0
- package/dist/lib/xterm/src/browser/selection/Types.d.ts +15 -0
- package/dist/lib/xterm/src/browser/services/CharSizeService.ts +87 -0
- package/dist/lib/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
- package/dist/lib/xterm/src/browser/services/CoreBrowserService.ts +20 -0
- package/dist/lib/xterm/src/browser/services/MouseService.ts +36 -0
- package/dist/lib/xterm/src/browser/services/RenderService.ts +237 -0
- package/dist/lib/xterm/src/browser/services/SelectionService.ts +1027 -0
- package/dist/lib/xterm/src/browser/services/Services.ts +123 -0
- package/dist/lib/xterm/src/browser/services/SoundService.ts +63 -0
- package/dist/lib/xterm/src/common/CircularList.ts +239 -0
- package/dist/lib/xterm/src/common/Clone.ts +23 -0
- package/dist/lib/xterm/src/common/Color.ts +285 -0
- package/dist/lib/xterm/src/common/CoreTerminal.ts +300 -0
- package/dist/lib/xterm/src/common/EventEmitter.ts +69 -0
- package/dist/lib/xterm/src/common/InputHandler.ts +3230 -0
- package/dist/lib/xterm/src/common/Lifecycle.ts +68 -0
- package/dist/lib/xterm/src/common/Platform.ts +31 -0
- package/dist/lib/xterm/src/common/SortedList.ts +88 -0
- package/dist/lib/xterm/src/common/TypedArrayUtils.ts +50 -0
- package/dist/lib/xterm/src/common/Types.d.ts +489 -0
- package/dist/lib/xterm/src/common/WindowsMode.ts +27 -0
- package/dist/lib/xterm/src/common/buffer/AttributeData.ts +148 -0
- package/dist/lib/xterm/src/common/buffer/Buffer.ts +711 -0
- package/dist/lib/xterm/src/common/buffer/BufferLine.ts +441 -0
- package/dist/lib/xterm/src/common/buffer/BufferRange.ts +13 -0
- package/dist/lib/xterm/src/common/buffer/BufferReflow.ts +220 -0
- package/dist/lib/xterm/src/common/buffer/BufferSet.ts +131 -0
- package/dist/lib/xterm/src/common/buffer/CellData.ts +94 -0
- package/dist/lib/xterm/src/common/buffer/Constants.ts +139 -0
- package/dist/lib/xterm/src/common/buffer/Marker.ts +37 -0
- package/dist/lib/xterm/src/common/buffer/Types.d.ts +64 -0
- package/dist/lib/xterm/src/common/data/Charsets.ts +256 -0
- package/dist/lib/xterm/src/common/data/EscapeSequences.ts +153 -0
- package/dist/lib/xterm/src/common/input/Keyboard.ts +398 -0
- package/dist/lib/xterm/src/common/input/TextDecoder.ts +346 -0
- package/dist/lib/xterm/src/common/input/UnicodeV6.ts +133 -0
- package/dist/lib/xterm/src/common/input/WriteBuffer.ts +229 -0
- package/dist/lib/xterm/src/common/input/XParseColor.ts +80 -0
- package/dist/lib/xterm/src/common/parser/Constants.ts +58 -0
- package/dist/lib/xterm/src/common/parser/DcsParser.ts +192 -0
- package/dist/lib/xterm/src/common/parser/EscapeSequenceParser.ts +796 -0
- package/dist/lib/xterm/src/common/parser/OscParser.ts +238 -0
- package/dist/lib/xterm/src/common/parser/Params.ts +229 -0
- package/dist/lib/xterm/src/common/parser/Types.d.ts +274 -0
- package/dist/lib/xterm/src/common/public/AddonManager.ts +56 -0
- package/dist/lib/xterm/src/common/public/BufferApiView.ts +35 -0
- package/dist/lib/xterm/src/common/public/BufferLineApiView.ts +29 -0
- package/dist/lib/xterm/src/common/public/BufferNamespaceApi.ts +33 -0
- package/dist/lib/xterm/src/common/public/ParserApi.ts +37 -0
- package/dist/lib/xterm/src/common/public/UnicodeApi.ts +27 -0
- package/dist/lib/xterm/src/common/services/BufferService.ts +185 -0
- package/dist/lib/xterm/src/common/services/CharsetService.ts +34 -0
- package/dist/lib/xterm/src/common/services/CoreMouseService.ts +309 -0
- package/dist/lib/xterm/src/common/services/CoreService.ts +92 -0
- package/dist/lib/xterm/src/common/services/DecorationService.ts +139 -0
- package/dist/lib/xterm/src/common/services/DirtyRowService.ts +53 -0
- package/dist/lib/xterm/src/common/services/InstantiationService.ts +83 -0
- package/dist/lib/xterm/src/common/services/LogService.ts +88 -0
- package/dist/lib/xterm/src/common/services/OptionsService.ts +178 -0
- package/dist/lib/xterm/src/common/services/ServiceRegistry.ts +49 -0
- package/dist/lib/xterm/src/common/services/Services.ts +323 -0
- package/dist/lib/xterm/src/common/services/UnicodeService.ts +82 -0
- package/dist/lib/xterm/src/headless/Terminal.ts +170 -0
- package/dist/lib/xterm/src/headless/Types.d.ts +31 -0
- package/dist/lib/xterm/src/headless/public/Terminal.ts +216 -0
- package/dist/lib/xterm/typings/xterm.d.ts +1872 -0
- package/dist/lib/xterm-fit/LICENSE +19 -0
- package/dist/lib/xterm-fit/README.md +24 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js +2 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js.map +1 -0
- package/dist/lib/xterm-fit/out/FitAddon.js +58 -0
- package/dist/lib/xterm-fit/out/FitAddon.js.map +1 -0
- package/dist/lib/xterm-fit/out-test/FitAddon.api.js.map +1 -0
- package/dist/lib/xterm-fit/package.json +21 -0
- package/dist/lib/xterm-fit/src/FitAddon.ts +86 -0
- package/dist/lib/xterm-fit/typings/xterm-addon-fit.d.ts +55 -0
- package/dist/lib/xterm-links/LICENSE +19 -0
- package/dist/lib/xterm-links/README.md +21 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js +2 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js.map +1 -0
- package/dist/lib/xterm-links/package.json +26 -0
- package/dist/lib/xterm-links/src/WebLinkProvider.ts +145 -0
- package/dist/lib/xterm-links/src/WebLinksAddon.ts +77 -0
- package/dist/lib/xterm-links/typings/xterm-addon-web-links.d.ts +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ILinkifier2, ILinkProvider, IBufferCellPosition, ILink, ILinkifierEvent, ILinkDecorations, ILinkWithState } from 'browser/Types';
|
|
7
|
+
import { IDisposable } from 'common/Types';
|
|
8
|
+
import { IMouseService, IRenderService } from './services/Services';
|
|
9
|
+
import { IBufferService } from 'common/services/Services';
|
|
10
|
+
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
|
11
|
+
import { Disposable, getDisposeArrayDisposable, disposeArray } from 'common/Lifecycle';
|
|
12
|
+
import { addDisposableDomListener } from 'browser/Lifecycle';
|
|
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 _activeProviderReplies: Map<Number, ILinkWithState[] | undefined> | undefined;
|
|
27
|
+
private _activeLine: number = -1;
|
|
28
|
+
|
|
29
|
+
private _onShowLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>());
|
|
30
|
+
public get onShowLinkUnderline(): IEvent<ILinkifierEvent> { return this._onShowLinkUnderline.event; }
|
|
31
|
+
private _onHideLinkUnderline = this.register(new EventEmitter<ILinkifierEvent>());
|
|
32
|
+
public get onHideLinkUnderline(): IEvent<ILinkifierEvent> { return this._onHideLinkUnderline.event; }
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
@IBufferService private readonly _bufferService: IBufferService
|
|
36
|
+
) {
|
|
37
|
+
super();
|
|
38
|
+
this.register(getDisposeArrayDisposable(this._linkCacheDisposables));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
|
|
42
|
+
this._linkProviders.push(linkProvider);
|
|
43
|
+
return {
|
|
44
|
+
dispose: () => {
|
|
45
|
+
// Remove the link provider from the list
|
|
46
|
+
const providerIndex = this._linkProviders.indexOf(linkProvider);
|
|
47
|
+
|
|
48
|
+
if (providerIndex !== -1) {
|
|
49
|
+
this._linkProviders.splice(providerIndex, 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public attachToDom(element: HTMLElement, mouseService: IMouseService, renderService: IRenderService): void {
|
|
56
|
+
this._element = element;
|
|
57
|
+
this._mouseService = mouseService;
|
|
58
|
+
this._renderService = renderService;
|
|
59
|
+
|
|
60
|
+
this.register(addDisposableDomListener(this._element, 'mouseleave', () => {
|
|
61
|
+
this._isMouseOut = true;
|
|
62
|
+
this._clearCurrentLink();
|
|
63
|
+
}));
|
|
64
|
+
this.register(addDisposableDomListener(this._element, 'mousemove', this._onMouseMove.bind(this)));
|
|
65
|
+
this.register(addDisposableDomListener(this._element, 'mousedown', this._handleMouseDown.bind(this)));
|
|
66
|
+
this.register(addDisposableDomListener(this._element, 'mouseup', this._handleMouseUp.bind(this)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private _onMouseMove(event: MouseEvent): void {
|
|
70
|
+
this._lastMouseEvent = event;
|
|
71
|
+
|
|
72
|
+
if (!this._element || !this._mouseService) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const position = this._positionFromMouseEvent(event, this._element, this._mouseService);
|
|
77
|
+
if (!position) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._isMouseOut = false;
|
|
81
|
+
|
|
82
|
+
// Ignore the event if it's an embedder created hover widget
|
|
83
|
+
const composedPath = event.composedPath() as HTMLElement[];
|
|
84
|
+
for (let i = 0; i < composedPath.length; i++) {
|
|
85
|
+
const target = composedPath[i];
|
|
86
|
+
// Hit Terminal.element, break and continue
|
|
87
|
+
if (target.classList.contains('xterm')) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
// It's a hover, don't respect hover event
|
|
91
|
+
if (target.classList.contains('xterm-hover')) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!this._lastBufferCell || (position.x !== this._lastBufferCell.x || position.y !== this._lastBufferCell.y)) {
|
|
97
|
+
this._onHover(position);
|
|
98
|
+
this._lastBufferCell = position;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private _onHover(position: IBufferCellPosition): void {
|
|
103
|
+
// TODO: This currently does not cache link provider results across wrapped lines, activeLine should be something like `activeRange: {startY, endY}`
|
|
104
|
+
// Check if we need to clear the link
|
|
105
|
+
if (this._activeLine !== position.y) {
|
|
106
|
+
this._clearCurrentLink();
|
|
107
|
+
this._askForLink(position, false);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Check the if the link is in the mouse position
|
|
112
|
+
const isCurrentLinkInPosition = this._currentLink && this._linkAtPosition(this._currentLink.link, position);
|
|
113
|
+
if (!isCurrentLinkInPosition) {
|
|
114
|
+
this._clearCurrentLink();
|
|
115
|
+
this._askForLink(position, true);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private _askForLink(position: IBufferCellPosition, useLineCache: boolean): void {
|
|
120
|
+
if (!this._activeProviderReplies || !useLineCache) {
|
|
121
|
+
this._activeProviderReplies?.forEach(reply => {
|
|
122
|
+
reply?.forEach(linkWithState => {
|
|
123
|
+
if (linkWithState.link.dispose) {
|
|
124
|
+
linkWithState.link.dispose();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
this._activeProviderReplies = new Map();
|
|
129
|
+
this._activeLine = position.y;
|
|
130
|
+
}
|
|
131
|
+
let linkProvided = false;
|
|
132
|
+
|
|
133
|
+
// There is no link cached, so ask for one
|
|
134
|
+
for (const [i, linkProvider] of this._linkProviders.entries()) {
|
|
135
|
+
if (useLineCache) {
|
|
136
|
+
const existingReply = this._activeProviderReplies?.get(i);
|
|
137
|
+
// If there isn't a reply, the provider hasn't responded yet.
|
|
138
|
+
|
|
139
|
+
// TODO: If there isn't a reply yet it means that the provider is still resolving. Ensuring
|
|
140
|
+
// provideLinks isn't triggered again saves ILink.hover firing twice though. This probably
|
|
141
|
+
// needs promises to get fixed
|
|
142
|
+
if (existingReply) {
|
|
143
|
+
linkProvided = this._checkLinkProviderResult(i, position, linkProvided);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
linkProvider.provideLinks(position.y, (links: ILink[] | undefined) => {
|
|
147
|
+
if (this._isMouseOut) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const linksWithState: ILinkWithState[] | undefined = links?.map(link => ({ link }));
|
|
151
|
+
this._activeProviderReplies?.set(i, linksWithState);
|
|
152
|
+
linkProvided = this._checkLinkProviderResult(i, position, linkProvided);
|
|
153
|
+
|
|
154
|
+
// If all providers have responded, remove lower priority links that intersect ranges of
|
|
155
|
+
// higher priority links
|
|
156
|
+
if (this._activeProviderReplies?.size === this._linkProviders.length) {
|
|
157
|
+
this._removeIntersectingLinks(position.y, this._activeProviderReplies);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private _removeIntersectingLinks(y: number, replies: Map<Number, ILinkWithState[] | undefined>): void {
|
|
165
|
+
const occupiedCells = new Set<number>();
|
|
166
|
+
for (let i = 0; i < replies.size; i++) {
|
|
167
|
+
const providerReply = replies.get(i);
|
|
168
|
+
if (!providerReply) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < providerReply.length; i++) {
|
|
172
|
+
const linkWithState = providerReply[i];
|
|
173
|
+
const startX = linkWithState.link.range.start.y < y ? 0 : linkWithState.link.range.start.x;
|
|
174
|
+
const endX = linkWithState.link.range.end.y > y ? this._bufferService.cols : linkWithState.link.range.end.x;
|
|
175
|
+
for (let x = startX; x <= endX; x++) {
|
|
176
|
+
if (occupiedCells.has(x)) {
|
|
177
|
+
providerReply.splice(i--, 1);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
occupiedCells.add(x);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private _checkLinkProviderResult(index: number, position: IBufferCellPosition, linkProvided: boolean): boolean {
|
|
187
|
+
if (!this._activeProviderReplies) {
|
|
188
|
+
return linkProvided;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const links = this._activeProviderReplies.get(index);
|
|
192
|
+
|
|
193
|
+
// Check if every provider before this one has come back undefined
|
|
194
|
+
let hasLinkBefore = false;
|
|
195
|
+
for (let j = 0; j < index; j++) {
|
|
196
|
+
if (!this._activeProviderReplies.has(j) || this._activeProviderReplies.get(j)) {
|
|
197
|
+
hasLinkBefore = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// If all providers with higher priority came back undefined, then this provider's link for
|
|
202
|
+
// the position should be used
|
|
203
|
+
if (!hasLinkBefore && links) {
|
|
204
|
+
const linkAtPosition = links.find(link => this._linkAtPosition(link.link, position));
|
|
205
|
+
if (linkAtPosition) {
|
|
206
|
+
linkProvided = true;
|
|
207
|
+
this._handleNewLink(linkAtPosition);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Check if all the providers have responded
|
|
212
|
+
if (this._activeProviderReplies.size === this._linkProviders.length && !linkProvided) {
|
|
213
|
+
// Respect the order of the link providers
|
|
214
|
+
for (let j = 0; j < this._activeProviderReplies.size; j++) {
|
|
215
|
+
const currentLink = this._activeProviderReplies.get(j)?.find(link => this._linkAtPosition(link.link, position));
|
|
216
|
+
if (currentLink) {
|
|
217
|
+
linkProvided = true;
|
|
218
|
+
this._handleNewLink(currentLink);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return linkProvided;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private _handleMouseDown(): void {
|
|
228
|
+
this._mouseDownLink = this._currentLink;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private _handleMouseUp(event: MouseEvent): void {
|
|
232
|
+
if (!this._element || !this._mouseService || !this._currentLink) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const position = this._positionFromMouseEvent(event, this._element, this._mouseService);
|
|
237
|
+
if (!position) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (this._mouseDownLink === this._currentLink && this._linkAtPosition(this._currentLink.link, position)) {
|
|
242
|
+
this._currentLink.link.activate(event, this._currentLink.link.text);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private _clearCurrentLink(startRow?: number, endRow?: number): void {
|
|
247
|
+
if (!this._element || !this._currentLink || !this._lastMouseEvent) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// If we have a start and end row, check that the link is within it
|
|
252
|
+
if (!startRow || !endRow || (this._currentLink.link.range.start.y >= startRow && this._currentLink.link.range.end.y <= endRow)) {
|
|
253
|
+
this._linkLeave(this._element, this._currentLink.link, this._lastMouseEvent);
|
|
254
|
+
this._currentLink = undefined;
|
|
255
|
+
disposeArray(this._linkCacheDisposables);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private _handleNewLink(linkWithState: ILinkWithState): void {
|
|
260
|
+
if (!this._element || !this._lastMouseEvent || !this._mouseService) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const position = this._positionFromMouseEvent(this._lastMouseEvent, this._element, this._mouseService);
|
|
265
|
+
|
|
266
|
+
if (!position) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Trigger hover if the we have a link at the position
|
|
271
|
+
if (this._linkAtPosition(linkWithState.link, position)) {
|
|
272
|
+
this._currentLink = linkWithState;
|
|
273
|
+
this._currentLink.state = {
|
|
274
|
+
decorations: {
|
|
275
|
+
underline: linkWithState.link.decorations === undefined ? true : linkWithState.link.decorations.underline,
|
|
276
|
+
pointerCursor: linkWithState.link.decorations === undefined ? true : linkWithState.link.decorations.pointerCursor
|
|
277
|
+
},
|
|
278
|
+
isHovered: true
|
|
279
|
+
};
|
|
280
|
+
this._linkHover(this._element, linkWithState.link, this._lastMouseEvent);
|
|
281
|
+
|
|
282
|
+
// Add listener for tracking decorations changes
|
|
283
|
+
linkWithState.link.decorations = {} as ILinkDecorations;
|
|
284
|
+
Object.defineProperties(linkWithState.link.decorations, {
|
|
285
|
+
pointerCursor: {
|
|
286
|
+
get: () => this._currentLink?.state?.decorations.pointerCursor,
|
|
287
|
+
set: v => {
|
|
288
|
+
if (this._currentLink?.state && this._currentLink.state.decorations.pointerCursor !== v) {
|
|
289
|
+
this._currentLink.state.decorations.pointerCursor = v;
|
|
290
|
+
if (this._currentLink.state.isHovered) {
|
|
291
|
+
this._element?.classList.toggle('xterm-cursor-pointer', v);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
underline: {
|
|
297
|
+
get: () => this._currentLink?.state?.decorations.underline,
|
|
298
|
+
set: v => {
|
|
299
|
+
if (this._currentLink?.state && this._currentLink?.state?.decorations.underline !== v) {
|
|
300
|
+
this._currentLink.state.decorations.underline = v;
|
|
301
|
+
if (this._currentLink.state.isHovered) {
|
|
302
|
+
this._fireUnderlineEvent(linkWithState.link, v);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Add listener for rerendering
|
|
310
|
+
if (this._renderService) {
|
|
311
|
+
this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e => {
|
|
312
|
+
// When start is 0 a scroll most likely occurred, make sure links above the fold also get
|
|
313
|
+
// cleared.
|
|
314
|
+
const start = e.start === 0 ? 0 : e.start + 1 + this._bufferService.buffer.ydisp;
|
|
315
|
+
this._clearCurrentLink(start, e.end + 1 + this._bufferService.buffer.ydisp);
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
protected _linkHover(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
|
322
|
+
if (this._currentLink?.state) {
|
|
323
|
+
this._currentLink.state.isHovered = true;
|
|
324
|
+
if (this._currentLink.state.decorations.underline) {
|
|
325
|
+
this._fireUnderlineEvent(link, true);
|
|
326
|
+
}
|
|
327
|
+
if (this._currentLink.state.decorations.pointerCursor) {
|
|
328
|
+
element.classList.add('xterm-cursor-pointer');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (link.hover) {
|
|
333
|
+
link.hover(event, link.text);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private _fireUnderlineEvent(link: ILink, showEvent: boolean): void {
|
|
338
|
+
const range = link.range;
|
|
339
|
+
const scrollOffset = this._bufferService.buffer.ydisp;
|
|
340
|
+
const event = this._createLinkUnderlineEvent(range.start.x - 1, range.start.y - scrollOffset - 1, range.end.x, range.end.y - scrollOffset - 1, undefined);
|
|
341
|
+
const emitter = showEvent ? this._onShowLinkUnderline : this._onHideLinkUnderline;
|
|
342
|
+
emitter.fire(event);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
protected _linkLeave(element: HTMLElement, link: ILink, event: MouseEvent): void {
|
|
346
|
+
if (this._currentLink?.state) {
|
|
347
|
+
this._currentLink.state.isHovered = false;
|
|
348
|
+
if (this._currentLink.state.decorations.underline) {
|
|
349
|
+
this._fireUnderlineEvent(link, false);
|
|
350
|
+
}
|
|
351
|
+
if (this._currentLink.state.decorations.pointerCursor) {
|
|
352
|
+
element.classList.remove('xterm-cursor-pointer');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (link.leave) {
|
|
357
|
+
link.leave(event, link.text);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Check if the buffer position is within the link
|
|
363
|
+
* @param link
|
|
364
|
+
* @param position
|
|
365
|
+
*/
|
|
366
|
+
private _linkAtPosition(link: ILink, position: IBufferCellPosition): boolean {
|
|
367
|
+
const sameLine = link.range.start.y === link.range.end.y;
|
|
368
|
+
const wrappedFromLeft = link.range.start.y < position.y;
|
|
369
|
+
const wrappedToRight = link.range.end.y > position.y;
|
|
370
|
+
|
|
371
|
+
// If the start and end have the same y, then the position must be between start and end x
|
|
372
|
+
// If not, then handle each case seperately, depending on which way it wraps
|
|
373
|
+
return ((sameLine && link.range.start.x <= position.x && link.range.end.x >= position.x) ||
|
|
374
|
+
(wrappedFromLeft && link.range.end.x >= position.x) ||
|
|
375
|
+
(wrappedToRight && link.range.start.x <= position.x) ||
|
|
376
|
+
(wrappedFromLeft && wrappedToRight)) &&
|
|
377
|
+
link.range.start.y <= position.y &&
|
|
378
|
+
link.range.end.y >= position.y;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Get the buffer position from a mouse event
|
|
383
|
+
* @param event
|
|
384
|
+
*/
|
|
385
|
+
private _positionFromMouseEvent(event: MouseEvent, element: HTMLElement, mouseService: IMouseService): IBufferCellPosition | undefined {
|
|
386
|
+
const coords = mouseService.getCoords(event, element, this._bufferService.cols, this._bufferService.rows);
|
|
387
|
+
if (!coords) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return { x: coords[0], y: coords[1] + this._bufferService.buffer.ydisp };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private _createLinkUnderlineEvent(x1: number, y1: number, x2: number, y2: number, fg: number | undefined): ILinkifierEvent {
|
|
395
|
+
return { x1, y1, x2, y2, cols: this._bufferService.cols, fg };
|
|
396
|
+
}
|
|
397
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line prefer-const
|
|
7
|
+
export let promptLabel = 'Terminal input';
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line prefer-const
|
|
10
|
+
export let tooMuchOutput = 'Too much output to announce, navigate to rows manually to read';
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Disposable } from 'common/Lifecycle';
|
|
7
|
+
import { addDisposableDomListener } from 'browser/Lifecycle';
|
|
8
|
+
import { IMouseService, ISelectionService } from 'browser/services/Services';
|
|
9
|
+
import { IMouseZoneManager, IMouseZone } from 'browser/Types';
|
|
10
|
+
import { IBufferService, IOptionsService } from 'common/services/Services';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The MouseZoneManager allows components to register zones within the terminal
|
|
14
|
+
* that trigger hover and click callbacks.
|
|
15
|
+
*
|
|
16
|
+
* This class was intentionally made not so robust initially as the only case it
|
|
17
|
+
* needed to support was single-line links which never overlap. Improvements can
|
|
18
|
+
* be made in the future.
|
|
19
|
+
*/
|
|
20
|
+
export class MouseZoneManager extends Disposable implements IMouseZoneManager {
|
|
21
|
+
private _zones: IMouseZone[] = [];
|
|
22
|
+
|
|
23
|
+
private _areZonesActive: boolean = false;
|
|
24
|
+
private _mouseMoveListener: (e: MouseEvent) => any;
|
|
25
|
+
private _mouseLeaveListener: (e: MouseEvent) => any;
|
|
26
|
+
private _clickListener: (e: MouseEvent) => any;
|
|
27
|
+
|
|
28
|
+
private _tooltipTimeout: number | undefined;
|
|
29
|
+
private _currentZone: IMouseZone | undefined;
|
|
30
|
+
private _lastHoverCoords: [number | undefined, number | undefined] = [undefined, undefined];
|
|
31
|
+
private _initialSelectionLength: number = 0;
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
private readonly _element: HTMLElement,
|
|
35
|
+
private readonly _screenElement: HTMLElement,
|
|
36
|
+
@IBufferService private readonly _bufferService: IBufferService,
|
|
37
|
+
@IMouseService private readonly _mouseService: IMouseService,
|
|
38
|
+
@ISelectionService private readonly _selectionService: ISelectionService,
|
|
39
|
+
@IOptionsService private readonly _optionsService: IOptionsService
|
|
40
|
+
) {
|
|
41
|
+
super();
|
|
42
|
+
|
|
43
|
+
this.register(addDisposableDomListener(this._element, 'mousedown', e => this._onMouseDown(e)));
|
|
44
|
+
|
|
45
|
+
// These events are expensive, only listen to it when mouse zones are active
|
|
46
|
+
this._mouseMoveListener = e => this._onMouseMove(e);
|
|
47
|
+
this._mouseLeaveListener = e => this._onMouseLeave(e);
|
|
48
|
+
this._clickListener = e => this._onClick(e);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public dispose(): void {
|
|
52
|
+
super.dispose();
|
|
53
|
+
this._deactivate();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public add(zone: IMouseZone): void {
|
|
57
|
+
this._zones.push(zone);
|
|
58
|
+
if (this._zones.length === 1) {
|
|
59
|
+
this._activate();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public clearAll(start?: number, end?: number): void {
|
|
64
|
+
// Exit if there's nothing to clear
|
|
65
|
+
if (this._zones.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Clear all if start/end weren't set
|
|
70
|
+
if (!start || !end) {
|
|
71
|
+
start = 0;
|
|
72
|
+
end = this._bufferService.rows - 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Iterate through zones and clear them out if they're within the range
|
|
76
|
+
for (let i = 0; i < this._zones.length; i++) {
|
|
77
|
+
const zone = this._zones[i];
|
|
78
|
+
if ((zone.y1 > start && zone.y1 <= end + 1) ||
|
|
79
|
+
(zone.y2 > start && zone.y2 <= end + 1) ||
|
|
80
|
+
(zone.y1 < start && zone.y2 > end + 1)) {
|
|
81
|
+
if (this._currentZone && this._currentZone === zone) {
|
|
82
|
+
this._currentZone.leaveCallback();
|
|
83
|
+
this._currentZone = undefined;
|
|
84
|
+
}
|
|
85
|
+
this._zones.splice(i--, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Deactivate the mouse zone manager if all the zones have been removed
|
|
90
|
+
if (this._zones.length === 0) {
|
|
91
|
+
this._deactivate();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private _activate(): void {
|
|
96
|
+
if (!this._areZonesActive) {
|
|
97
|
+
this._areZonesActive = true;
|
|
98
|
+
this._element.addEventListener('mousemove', this._mouseMoveListener);
|
|
99
|
+
this._element.addEventListener('mouseleave', this._mouseLeaveListener);
|
|
100
|
+
this._element.addEventListener('click', this._clickListener);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private _deactivate(): void {
|
|
105
|
+
if (this._areZonesActive) {
|
|
106
|
+
this._areZonesActive = false;
|
|
107
|
+
this._element.removeEventListener('mousemove', this._mouseMoveListener);
|
|
108
|
+
this._element.removeEventListener('mouseleave', this._mouseLeaveListener);
|
|
109
|
+
this._element.removeEventListener('click', this._clickListener);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private _onMouseMove(e: MouseEvent): void {
|
|
114
|
+
// TODO: Ideally this would only clear the hover state when the mouse moves
|
|
115
|
+
// outside of the mouse zone
|
|
116
|
+
if (this._lastHoverCoords[0] !== e.pageX || this._lastHoverCoords[1] !== e.pageY) {
|
|
117
|
+
this._onHover(e);
|
|
118
|
+
// Record the current coordinates
|
|
119
|
+
this._lastHoverCoords = [e.pageX, e.pageY];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private _onHover(e: MouseEvent): void {
|
|
124
|
+
const zone = this._findZoneEventAt(e);
|
|
125
|
+
|
|
126
|
+
// Do nothing if the zone is the same
|
|
127
|
+
if (zone === this._currentZone) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Fire the hover end callback and cancel any existing timer if a new zone
|
|
132
|
+
// is being hovered
|
|
133
|
+
if (this._currentZone) {
|
|
134
|
+
this._currentZone.leaveCallback();
|
|
135
|
+
this._currentZone = undefined;
|
|
136
|
+
if (this._tooltipTimeout) {
|
|
137
|
+
clearTimeout(this._tooltipTimeout);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Exit if there is not zone
|
|
142
|
+
if (!zone) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this._currentZone = zone;
|
|
146
|
+
|
|
147
|
+
// Trigger the hover callback
|
|
148
|
+
if (zone.hoverCallback) {
|
|
149
|
+
zone.hoverCallback(e);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Restart the tooltip timeout
|
|
153
|
+
this._tooltipTimeout = window.setTimeout(() => this._onTooltip(e), this._optionsService.rawOptions.linkTooltipHoverDuration);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private _onTooltip(e: MouseEvent): void {
|
|
157
|
+
this._tooltipTimeout = undefined;
|
|
158
|
+
const zone = this._findZoneEventAt(e);
|
|
159
|
+
zone?.tooltipCallback(e);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private _onMouseDown(e: MouseEvent): void {
|
|
163
|
+
// Store current terminal selection length, to check if we're performing
|
|
164
|
+
// a selection operation
|
|
165
|
+
this._initialSelectionLength = this._getSelectionLength();
|
|
166
|
+
|
|
167
|
+
// Ignore the event if there are no zones active
|
|
168
|
+
if (!this._areZonesActive) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Find the active zone, prevent event propagation if found to prevent other
|
|
173
|
+
// components from handling the mouse event.
|
|
174
|
+
const zone = this._findZoneEventAt(e);
|
|
175
|
+
if (zone?.willLinkActivate(e)) {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
e.stopImmediatePropagation();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private _onMouseLeave(e: MouseEvent): void {
|
|
182
|
+
// Fire the hover end callback and cancel any existing timer if the mouse
|
|
183
|
+
// leaves the terminal element
|
|
184
|
+
if (this._currentZone) {
|
|
185
|
+
this._currentZone.leaveCallback();
|
|
186
|
+
this._currentZone = undefined;
|
|
187
|
+
if (this._tooltipTimeout) {
|
|
188
|
+
clearTimeout(this._tooltipTimeout);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private _onClick(e: MouseEvent): void {
|
|
194
|
+
// Find the active zone and click it if found and no selection was
|
|
195
|
+
// being performed
|
|
196
|
+
const zone = this._findZoneEventAt(e);
|
|
197
|
+
const currentSelectionLength = this._getSelectionLength();
|
|
198
|
+
|
|
199
|
+
if (zone && currentSelectionLength === this._initialSelectionLength) {
|
|
200
|
+
zone.clickCallback(e);
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
e.stopImmediatePropagation();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private _getSelectionLength(): number {
|
|
207
|
+
const selectionText = this._selectionService.selectionText;
|
|
208
|
+
return selectionText ? selectionText.length : 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private _findZoneEventAt(e: MouseEvent): IMouseZone | undefined {
|
|
212
|
+
const coords = this._mouseService.getCoords(e, this._screenElement, this._bufferService.cols, this._bufferService.rows);
|
|
213
|
+
if (!coords) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const x = coords[0];
|
|
217
|
+
const y = coords[1];
|
|
218
|
+
for (let i = 0; i < this._zones.length; i++) {
|
|
219
|
+
const zone = this._zones[i];
|
|
220
|
+
if (zone.y1 === zone.y2) {
|
|
221
|
+
// Single line link
|
|
222
|
+
if (y === zone.y1 && x >= zone.x1 && x < zone.x2) {
|
|
223
|
+
return zone;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
// Multi-line link
|
|
227
|
+
if ((y === zone.y1 && x >= zone.x1) ||
|
|
228
|
+
(y === zone.y2 && x < zone.x2) ||
|
|
229
|
+
(y > zone.y1 && y < zone.y2)) {
|
|
230
|
+
return zone;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|