@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.
Files changed (135) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/lib/xterm/LICENSE +21 -0
  3. package/dist/lib/xterm/README.md +225 -0
  4. package/dist/lib/xterm/css/xterm.css +190 -0
  5. package/dist/lib/xterm/lib/xterm.js +2 -0
  6. package/dist/lib/xterm/lib/xterm.js.map +1 -0
  7. package/dist/lib/xterm/package.json +90 -0
  8. package/dist/lib/xterm/src/browser/AccessibilityManager.ts +301 -0
  9. package/dist/lib/xterm/src/browser/Clipboard.ts +99 -0
  10. package/dist/lib/xterm/src/browser/ColorContrastCache.ts +39 -0
  11. package/dist/lib/xterm/src/browser/ColorManager.ts +268 -0
  12. package/dist/lib/xterm/src/browser/Dom.ts +10 -0
  13. package/dist/lib/xterm/src/browser/Lifecycle.ts +30 -0
  14. package/dist/lib/xterm/src/browser/Linkifier.ts +356 -0
  15. package/dist/lib/xterm/src/browser/Linkifier2.ts +397 -0
  16. package/dist/lib/xterm/src/browser/LocalizableStrings.ts +10 -0
  17. package/dist/lib/xterm/src/browser/MouseZoneManager.ts +236 -0
  18. package/dist/lib/xterm/src/browser/RenderDebouncer.ts +82 -0
  19. package/dist/lib/xterm/src/browser/ScreenDprMonitor.ts +69 -0
  20. package/dist/lib/xterm/src/browser/Terminal.ts +1447 -0
  21. package/dist/lib/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
  22. package/dist/lib/xterm/src/browser/Types.d.ts +317 -0
  23. package/dist/lib/xterm/src/browser/Viewport.ts +276 -0
  24. package/dist/lib/xterm/src/browser/decorations/BufferDecorationRenderer.ts +131 -0
  25. package/dist/lib/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
  26. package/dist/lib/xterm/src/browser/decorations/OverviewRulerRenderer.ts +228 -0
  27. package/dist/lib/xterm/src/browser/input/CompositionHelper.ts +237 -0
  28. package/dist/lib/xterm/src/browser/input/Mouse.ts +64 -0
  29. package/dist/lib/xterm/src/browser/input/MoveToCell.ts +249 -0
  30. package/dist/lib/xterm/src/browser/public/Terminal.ts +298 -0
  31. package/dist/lib/xterm/src/browser/renderer/BaseRenderLayer.ts +582 -0
  32. package/dist/lib/xterm/src/browser/renderer/CursorRenderLayer.ts +378 -0
  33. package/dist/lib/xterm/src/browser/renderer/CustomGlyphs.ts +632 -0
  34. package/dist/lib/xterm/src/browser/renderer/GridCache.ts +33 -0
  35. package/dist/lib/xterm/src/browser/renderer/LinkRenderLayer.ts +84 -0
  36. package/dist/lib/xterm/src/browser/renderer/Renderer.ts +219 -0
  37. package/dist/lib/xterm/src/browser/renderer/RendererUtils.ts +26 -0
  38. package/dist/lib/xterm/src/browser/renderer/SelectionRenderLayer.ts +131 -0
  39. package/dist/lib/xterm/src/browser/renderer/TextRenderLayer.ts +344 -0
  40. package/dist/lib/xterm/src/browser/renderer/Types.d.ts +109 -0
  41. package/dist/lib/xterm/src/browser/renderer/atlas/BaseCharAtlas.ts +58 -0
  42. package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasCache.ts +95 -0
  43. package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasUtils.ts +54 -0
  44. package/dist/lib/xterm/src/browser/renderer/atlas/Constants.ts +15 -0
  45. package/dist/lib/xterm/src/browser/renderer/atlas/DynamicCharAtlas.ts +404 -0
  46. package/dist/lib/xterm/src/browser/renderer/atlas/LRUMap.ts +136 -0
  47. package/dist/lib/xterm/src/browser/renderer/atlas/Types.d.ts +29 -0
  48. package/dist/lib/xterm/src/browser/renderer/dom/DomRenderer.ts +403 -0
  49. package/dist/lib/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +344 -0
  50. package/dist/lib/xterm/src/browser/selection/SelectionModel.ts +144 -0
  51. package/dist/lib/xterm/src/browser/selection/Types.d.ts +15 -0
  52. package/dist/lib/xterm/src/browser/services/CharSizeService.ts +87 -0
  53. package/dist/lib/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
  54. package/dist/lib/xterm/src/browser/services/CoreBrowserService.ts +20 -0
  55. package/dist/lib/xterm/src/browser/services/MouseService.ts +36 -0
  56. package/dist/lib/xterm/src/browser/services/RenderService.ts +237 -0
  57. package/dist/lib/xterm/src/browser/services/SelectionService.ts +1027 -0
  58. package/dist/lib/xterm/src/browser/services/Services.ts +123 -0
  59. package/dist/lib/xterm/src/browser/services/SoundService.ts +63 -0
  60. package/dist/lib/xterm/src/common/CircularList.ts +239 -0
  61. package/dist/lib/xterm/src/common/Clone.ts +23 -0
  62. package/dist/lib/xterm/src/common/Color.ts +285 -0
  63. package/dist/lib/xterm/src/common/CoreTerminal.ts +300 -0
  64. package/dist/lib/xterm/src/common/EventEmitter.ts +69 -0
  65. package/dist/lib/xterm/src/common/InputHandler.ts +3230 -0
  66. package/dist/lib/xterm/src/common/Lifecycle.ts +68 -0
  67. package/dist/lib/xterm/src/common/Platform.ts +31 -0
  68. package/dist/lib/xterm/src/common/SortedList.ts +88 -0
  69. package/dist/lib/xterm/src/common/TypedArrayUtils.ts +50 -0
  70. package/dist/lib/xterm/src/common/Types.d.ts +489 -0
  71. package/dist/lib/xterm/src/common/WindowsMode.ts +27 -0
  72. package/dist/lib/xterm/src/common/buffer/AttributeData.ts +148 -0
  73. package/dist/lib/xterm/src/common/buffer/Buffer.ts +711 -0
  74. package/dist/lib/xterm/src/common/buffer/BufferLine.ts +441 -0
  75. package/dist/lib/xterm/src/common/buffer/BufferRange.ts +13 -0
  76. package/dist/lib/xterm/src/common/buffer/BufferReflow.ts +220 -0
  77. package/dist/lib/xterm/src/common/buffer/BufferSet.ts +131 -0
  78. package/dist/lib/xterm/src/common/buffer/CellData.ts +94 -0
  79. package/dist/lib/xterm/src/common/buffer/Constants.ts +139 -0
  80. package/dist/lib/xterm/src/common/buffer/Marker.ts +37 -0
  81. package/dist/lib/xterm/src/common/buffer/Types.d.ts +64 -0
  82. package/dist/lib/xterm/src/common/data/Charsets.ts +256 -0
  83. package/dist/lib/xterm/src/common/data/EscapeSequences.ts +153 -0
  84. package/dist/lib/xterm/src/common/input/Keyboard.ts +398 -0
  85. package/dist/lib/xterm/src/common/input/TextDecoder.ts +346 -0
  86. package/dist/lib/xterm/src/common/input/UnicodeV6.ts +133 -0
  87. package/dist/lib/xterm/src/common/input/WriteBuffer.ts +229 -0
  88. package/dist/lib/xterm/src/common/input/XParseColor.ts +80 -0
  89. package/dist/lib/xterm/src/common/parser/Constants.ts +58 -0
  90. package/dist/lib/xterm/src/common/parser/DcsParser.ts +192 -0
  91. package/dist/lib/xterm/src/common/parser/EscapeSequenceParser.ts +796 -0
  92. package/dist/lib/xterm/src/common/parser/OscParser.ts +238 -0
  93. package/dist/lib/xterm/src/common/parser/Params.ts +229 -0
  94. package/dist/lib/xterm/src/common/parser/Types.d.ts +274 -0
  95. package/dist/lib/xterm/src/common/public/AddonManager.ts +56 -0
  96. package/dist/lib/xterm/src/common/public/BufferApiView.ts +35 -0
  97. package/dist/lib/xterm/src/common/public/BufferLineApiView.ts +29 -0
  98. package/dist/lib/xterm/src/common/public/BufferNamespaceApi.ts +33 -0
  99. package/dist/lib/xterm/src/common/public/ParserApi.ts +37 -0
  100. package/dist/lib/xterm/src/common/public/UnicodeApi.ts +27 -0
  101. package/dist/lib/xterm/src/common/services/BufferService.ts +185 -0
  102. package/dist/lib/xterm/src/common/services/CharsetService.ts +34 -0
  103. package/dist/lib/xterm/src/common/services/CoreMouseService.ts +309 -0
  104. package/dist/lib/xterm/src/common/services/CoreService.ts +92 -0
  105. package/dist/lib/xterm/src/common/services/DecorationService.ts +139 -0
  106. package/dist/lib/xterm/src/common/services/DirtyRowService.ts +53 -0
  107. package/dist/lib/xterm/src/common/services/InstantiationService.ts +83 -0
  108. package/dist/lib/xterm/src/common/services/LogService.ts +88 -0
  109. package/dist/lib/xterm/src/common/services/OptionsService.ts +178 -0
  110. package/dist/lib/xterm/src/common/services/ServiceRegistry.ts +49 -0
  111. package/dist/lib/xterm/src/common/services/Services.ts +323 -0
  112. package/dist/lib/xterm/src/common/services/UnicodeService.ts +82 -0
  113. package/dist/lib/xterm/src/headless/Terminal.ts +170 -0
  114. package/dist/lib/xterm/src/headless/Types.d.ts +31 -0
  115. package/dist/lib/xterm/src/headless/public/Terminal.ts +216 -0
  116. package/dist/lib/xterm/typings/xterm.d.ts +1872 -0
  117. package/dist/lib/xterm-fit/LICENSE +19 -0
  118. package/dist/lib/xterm-fit/README.md +24 -0
  119. package/dist/lib/xterm-fit/lib/xterm-addon-fit.js +2 -0
  120. package/dist/lib/xterm-fit/lib/xterm-addon-fit.js.map +1 -0
  121. package/dist/lib/xterm-fit/out/FitAddon.js +58 -0
  122. package/dist/lib/xterm-fit/out/FitAddon.js.map +1 -0
  123. package/dist/lib/xterm-fit/out-test/FitAddon.api.js.map +1 -0
  124. package/dist/lib/xterm-fit/package.json +21 -0
  125. package/dist/lib/xterm-fit/src/FitAddon.ts +86 -0
  126. package/dist/lib/xterm-fit/typings/xterm-addon-fit.d.ts +55 -0
  127. package/dist/lib/xterm-links/LICENSE +19 -0
  128. package/dist/lib/xterm-links/README.md +21 -0
  129. package/dist/lib/xterm-links/lib/xterm-addon-web-links.js +2 -0
  130. package/dist/lib/xterm-links/lib/xterm-addon-web-links.js.map +1 -0
  131. package/dist/lib/xterm-links/package.json +26 -0
  132. package/dist/lib/xterm-links/src/WebLinkProvider.ts +145 -0
  133. package/dist/lib/xterm-links/src/WebLinksAddon.ts +77 -0
  134. package/dist/lib/xterm-links/typings/xterm-addon-web-links.d.ts +58 -0
  135. package/package.json +1 -1
@@ -0,0 +1,1447 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * @license MIT
5
+ *
6
+ * Originally forked from (with the author's permission):
7
+ * Fabrice Bellard's javascript vt100 for jslinux:
8
+ * http://bellard.org/jslinux/
9
+ * Copyright (c) 2011 Fabrice Bellard
10
+ * The original design remains. The terminal itself
11
+ * has been extended to include xterm CSI codes, among
12
+ * other features.
13
+ *
14
+ * Terminal Emulation References:
15
+ * http://vt100.net/
16
+ * http://invisible-island.net/xterm/ctlseqs/ctlseqs.txt
17
+ * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
18
+ * http://invisible-island.net/vttest/
19
+ * http://www.inwap.com/pdp10/ansicode.txt
20
+ * http://linux.die.net/man/4/console_codes
21
+ * http://linux.die.net/man/7/urxvt
22
+ */
23
+
24
+ import { ICompositionHelper, ITerminal, IBrowser, CustomKeyEventHandler, ILinkifier, IMouseZoneManager, LinkMatcherHandler, ILinkMatcherOptions, IViewport, ILinkifier2, CharacterJoinerHandler } from 'browser/Types';
25
+ import { IRenderer } from 'browser/renderer/Types';
26
+ import { CompositionHelper } from 'browser/input/CompositionHelper';
27
+ import { Viewport } from 'browser/Viewport';
28
+ import { rightClickHandler, moveTextAreaUnderMouseCursor, handlePasteEvent, copyHandler, paste } from 'browser/Clipboard';
29
+ import { C0, C1_ESCAPED } from 'common/data/EscapeSequences';
30
+ import { WindowsOptionsReportType } from '../common/InputHandler';
31
+ import { Renderer } from 'browser/renderer/Renderer';
32
+ import { Linkifier } from 'browser/Linkifier';
33
+ import { SelectionService } from 'browser/services/SelectionService';
34
+ import * as Browser from 'common/Platform';
35
+ import { addDisposableDomListener } from 'browser/Lifecycle';
36
+ import * as Strings from 'browser/LocalizableStrings';
37
+ import { SoundService } from 'browser/services/SoundService';
38
+ import { MouseZoneManager } from 'browser/MouseZoneManager';
39
+ import { AccessibilityManager } from './AccessibilityManager';
40
+ import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm';
41
+ import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
42
+ import { KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IColorEvent, ColorIndex, ColorRequestType } from 'common/Types';
43
+ import { evaluateKeyboardEvent } from 'common/input/Keyboard';
44
+ import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
45
+ import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
46
+ import { ColorManager } from 'browser/ColorManager';
47
+ import { RenderService } from 'browser/services/RenderService';
48
+ import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService, ICoreBrowserService, ICharacterJoinerService } from 'browser/services/Services';
49
+ import { CharSizeService } from 'browser/services/CharSizeService';
50
+ import { IBuffer } from 'common/buffer/Types';
51
+ import { MouseService } from 'browser/services/MouseService';
52
+ import { Linkifier2 } from 'browser/Linkifier2';
53
+ import { CoreBrowserService } from 'browser/services/CoreBrowserService';
54
+ import { CoreTerminal } from 'common/CoreTerminal';
55
+ import { color, rgba } from 'common/Color';
56
+ import { CharacterJoinerService } from 'browser/services/CharacterJoinerService';
57
+ import { toRgbString } from 'common/input/XParseColor';
58
+ import { BufferDecorationRenderer } from 'browser/decorations/BufferDecorationRenderer';
59
+ import { OverviewRulerRenderer } from 'browser/decorations/OverviewRulerRenderer';
60
+ import { DecorationService } from 'common/services/DecorationService';
61
+ import { IDecorationService } from 'common/services/Services';
62
+
63
+ // Let it work inside Node.js for automated testing purposes.
64
+ const document: Document = (typeof window !== 'undefined') ? window.document : null as any;
65
+
66
+ export class Terminal extends CoreTerminal implements ITerminal {
67
+ public textarea: HTMLTextAreaElement | undefined;
68
+ public element: HTMLElement | undefined;
69
+ public screenElement: HTMLElement | undefined;
70
+
71
+ private _document: Document | undefined;
72
+ private _viewportScrollArea: HTMLElement | undefined;
73
+ private _viewportElement: HTMLElement | undefined;
74
+ private _helperContainer: HTMLElement | undefined;
75
+ private _compositionView: HTMLElement | undefined;
76
+
77
+ private _overviewRulerRenderer: OverviewRulerRenderer | undefined;
78
+
79
+ // private _visualBellTimer: number;
80
+
81
+ public browser: IBrowser = Browser as any;
82
+
83
+ private _customKeyEventHandler: CustomKeyEventHandler | undefined;
84
+
85
+ // browser services
86
+ private _decorationService: DecorationService;
87
+ private _charSizeService: ICharSizeService | undefined;
88
+ private _mouseService: IMouseService | undefined;
89
+ private _renderService: IRenderService | undefined;
90
+ private _characterJoinerService: ICharacterJoinerService | undefined;
91
+ private _selectionService: ISelectionService | undefined;
92
+ private _soundService: ISoundService | undefined;
93
+
94
+ /**
95
+ * Records whether the keydown event has already been handled and triggered a data event, if so
96
+ * the keypress event should not trigger a data event but should still print to the textarea so
97
+ * screen readers will announce it.
98
+ */
99
+ private _keyDownHandled: boolean = false;
100
+
101
+ /**
102
+ * Records whether a keydown event has occured since the last keyup event, i.e. whether a key
103
+ * is currently "pressed".
104
+ */
105
+ private _keyDownSeen: boolean = false;
106
+
107
+ /**
108
+ * Records whether the keypress event has already been handled and triggered a data event, if so
109
+ * the input event should not trigger a data event but should still print to the textarea so
110
+ * screen readers will announce it.
111
+ */
112
+ private _keyPressHandled: boolean = false;
113
+
114
+ /**
115
+ * Records whether there has been a keydown event for a dead key without a corresponding keydown
116
+ * event for the composed/alternative character. If we cancel the keydown event for the dead key,
117
+ * no events will be emitted for the final character.
118
+ */
119
+ private _unprocessedDeadKey: boolean = false;
120
+
121
+ public linkifier: ILinkifier;
122
+ public linkifier2: ILinkifier2;
123
+ public viewport: IViewport | undefined;
124
+ private _compositionHelper: ICompositionHelper | undefined;
125
+ private _mouseZoneManager: IMouseZoneManager | undefined;
126
+ private _accessibilityManager: AccessibilityManager | undefined;
127
+ private _colorManager: ColorManager | undefined;
128
+ private _theme: ITheme | undefined;
129
+
130
+ private _onCursorMove = new EventEmitter<void>();
131
+ public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
132
+ private _onKey = new EventEmitter<{ key: string, domEvent: KeyboardEvent }>();
133
+ public get onKey(): IEvent<{ key: string, domEvent: KeyboardEvent }> { return this._onKey.event; }
134
+ private _onRender = new EventEmitter<{ start: number, end: number }>();
135
+ public get onRender(): IEvent<{ start: number, end: number }> { return this._onRender.event; }
136
+ private _onSelectionChange = new EventEmitter<void>();
137
+ public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
138
+ private _onTitleChange = new EventEmitter<string>();
139
+ public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
140
+ private _onBell = new EventEmitter<void>();
141
+ public get onBell(): IEvent<void> { return this._onBell.event; }
142
+
143
+ private _onFocus = new EventEmitter<void>();
144
+ public get onFocus(): IEvent<void> { return this._onFocus.event; }
145
+ private _onBlur = new EventEmitter<void>();
146
+ public get onBlur(): IEvent<void> { return this._onBlur.event; }
147
+ private _onA11yCharEmitter = new EventEmitter<string>();
148
+ public get onA11yChar(): IEvent<string> { return this._onA11yCharEmitter.event; }
149
+ private _onA11yTabEmitter = new EventEmitter<number>();
150
+ public get onA11yTab(): IEvent<number> { return this._onA11yTabEmitter.event; }
151
+
152
+ /**
153
+ * Creates a new `Terminal` object.
154
+ *
155
+ * @param options An object containing a set of options, the available options are:
156
+ * - `cursorBlink` (boolean): Whether the terminal cursor blinks
157
+ * - `cols` (number): The number of columns of the terminal (horizontal size)
158
+ * - `rows` (number): The number of rows of the terminal (vertical size)
159
+ *
160
+ * @public
161
+ * @class Xterm Xterm
162
+ * @alias module:xterm/src/xterm
163
+ */
164
+ constructor(
165
+ options: Partial<ITerminalOptions> = {}
166
+ ) {
167
+ super(options);
168
+
169
+ this._setup();
170
+
171
+ this.linkifier = this._instantiationService.createInstance(Linkifier);
172
+ this.linkifier2 = this.register(this._instantiationService.createInstance(Linkifier2));
173
+ this._decorationService = this._instantiationService.createInstance(DecorationService);
174
+ this._instantiationService.setService(IDecorationService, this._decorationService);
175
+
176
+ // Setup InputHandler listeners
177
+ this.register(this._inputHandler.onRequestBell(() => this.bell()));
178
+ this.register(this._inputHandler.onRequestRefreshRows((start, end) => this.refresh(start, end)));
179
+ this.register(this._inputHandler.onRequestSendFocus(() => this._reportFocus()));
180
+ this.register(this._inputHandler.onRequestReset(() => this.reset()));
181
+ this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
182
+ this.register(this._inputHandler.onColor((event) => this._handleColorEvent(event)));
183
+ this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
184
+ this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
185
+ this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
186
+ this.register(forwardEvent(this._inputHandler.onA11yTab, this._onA11yTabEmitter));
187
+
188
+ // Setup listeners
189
+ this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
190
+ }
191
+
192
+ /**
193
+ * Handle color event from inputhandler for OSC 4|104 | 10|110 | 11|111 | 12|112.
194
+ * An event from OSC 4|104 may contain multiple set or report requests, and multiple
195
+ * or none restore requests (resetting all),
196
+ * while an event from OSC 10|110 | 11|111 | 12|112 always contains a single request.
197
+ */
198
+ private _handleColorEvent(event: IColorEvent): void {
199
+ if (!this._colorManager) return;
200
+ for (const req of event) {
201
+ let acc: 'foreground' | 'background' | 'cursor' | 'ansi' | undefined = undefined;
202
+ let ident = '';
203
+ switch (req.index) {
204
+ case ColorIndex.FOREGROUND: // OSC 10 | 110
205
+ acc = 'foreground';
206
+ ident = '10';
207
+ break;
208
+ case ColorIndex.BACKGROUND: // OSC 11 | 111
209
+ acc = 'background';
210
+ ident = '11';
211
+ break;
212
+ case ColorIndex.CURSOR: // OSC 12 | 112
213
+ acc = 'cursor';
214
+ ident = '12';
215
+ break;
216
+ default: // OSC 4 | 104
217
+ // we can skip the [0..255] range check here (already done in inputhandler)
218
+ acc = 'ansi';
219
+ ident = '4;' + req.index;
220
+ }
221
+ if (acc) {
222
+ switch (req.type) {
223
+ case ColorRequestType.REPORT:
224
+ const channels = color.toColorRGB(acc === 'ansi'
225
+ ? this._colorManager.colors.ansi[req.index]
226
+ : this._colorManager.colors[acc]);
227
+ this.coreService.triggerDataEvent(`${C0.ESC}]${ident};${toRgbString(channels)}${C1_ESCAPED.ST}`);
228
+ break;
229
+ case ColorRequestType.SET:
230
+ if (acc === 'ansi') this._colorManager.colors.ansi[req.index] = rgba.toColor(...req.color);
231
+ else this._colorManager.colors[acc] = rgba.toColor(...req.color);
232
+ break;
233
+ case ColorRequestType.RESTORE:
234
+ this._colorManager.restoreColor(req.index);
235
+ break;
236
+ }
237
+ }
238
+ }
239
+ this._renderService?.setColors(this._colorManager.colors);
240
+ this.viewport?.onThemeChange(this._colorManager.colors);
241
+ }
242
+
243
+ public dispose(): void {
244
+ if (this._isDisposed) {
245
+ return;
246
+ }
247
+ super.dispose();
248
+ this._renderService?.dispose();
249
+ this._customKeyEventHandler = undefined;
250
+ this.write = () => { };
251
+ this.element?.parentNode?.removeChild(this.element);
252
+ }
253
+
254
+ protected _setup(): void {
255
+ super._setup();
256
+
257
+ this._customKeyEventHandler = undefined;
258
+ }
259
+
260
+ /**
261
+ * Convenience property to active buffer.
262
+ */
263
+ public get buffer(): IBuffer {
264
+ return this.buffers.active;
265
+ }
266
+
267
+ /**
268
+ * Focus the terminal. Delegates focus handling to the terminal's DOM element.
269
+ */
270
+ public focus(): void {
271
+ if (this.textarea) {
272
+ this.textarea.focus({ preventScroll: true });
273
+ }
274
+ }
275
+
276
+ protected _updateOptions(key: string): void {
277
+ super._updateOptions(key);
278
+
279
+ // TODO: These listeners should be owned by individual components
280
+ switch (key) {
281
+ case 'fontFamily':
282
+ case 'fontSize':
283
+ // When the font changes the size of the cells may change which requires a renderer clear
284
+ this._renderService?.clear();
285
+ this._charSizeService?.measure();
286
+ break;
287
+ case 'cursorBlink':
288
+ case 'cursorStyle':
289
+ // The DOM renderer needs a row refresh to update the cursor styles
290
+ this.refresh(this.buffer.y, this.buffer.y);
291
+ break;
292
+ case 'customGlyphs':
293
+ case 'drawBoldTextInBrightColors':
294
+ case 'letterSpacing':
295
+ case 'lineHeight':
296
+ case 'fontWeight':
297
+ case 'fontWeightBold':
298
+ case 'minimumContrastRatio':
299
+ // When the font changes the size of the cells may change which requires a renderer clear
300
+ if (this._renderService) {
301
+ this._renderService.clear();
302
+ this._renderService.onResize(this.cols, this.rows);
303
+ this.refresh(0, this.rows - 1);
304
+ }
305
+ break;
306
+ case 'rendererType':
307
+ if (this._renderService) {
308
+ this._renderService.setRenderer(this._createRenderer());
309
+ this._renderService.onResize(this.cols, this.rows);
310
+ }
311
+ break;
312
+ case 'scrollback':
313
+ this.viewport?.syncScrollArea();
314
+ break;
315
+ case 'screenReaderMode':
316
+ if (this.optionsService.rawOptions.screenReaderMode) {
317
+ if (!this._accessibilityManager && this._renderService) {
318
+ this._accessibilityManager = new AccessibilityManager(this, this._renderService);
319
+ }
320
+ } else {
321
+ this._accessibilityManager?.dispose();
322
+ this._accessibilityManager = undefined;
323
+ }
324
+ break;
325
+ case 'tabStopWidth': this.buffers.setupTabStops(); break;
326
+ case 'theme':
327
+ this._setTheme(this.optionsService.rawOptions.theme);
328
+ break;
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Binds the desired focus behavior on a given terminal object.
334
+ */
335
+ private _onTextAreaFocus(ev: KeyboardEvent): void {
336
+ if (this.coreService.decPrivateModes.sendFocus) {
337
+ this.coreService.triggerDataEvent(C0.ESC + '[I');
338
+ }
339
+ this.updateCursorStyle(ev);
340
+ this.element!.classList.add('focus');
341
+ this._showCursor();
342
+ this._onFocus.fire();
343
+ }
344
+
345
+ /**
346
+ * Blur the terminal, calling the blur function on the terminal's underlying
347
+ * textarea.
348
+ */
349
+ public blur(): void {
350
+ return this.textarea?.blur();
351
+ }
352
+
353
+ /**
354
+ * Binds the desired blur behavior on a given terminal object.
355
+ */
356
+ private _onTextAreaBlur(): void {
357
+ // Text can safely be removed on blur. Doing it earlier could interfere with
358
+ // screen readers reading it out.
359
+ this.textarea!.value = '';
360
+ this.refresh(this.buffer.y, this.buffer.y);
361
+ if (this.coreService.decPrivateModes.sendFocus) {
362
+ this.coreService.triggerDataEvent(C0.ESC + '[O');
363
+ }
364
+ this.element!.classList.remove('focus');
365
+ this._onBlur.fire();
366
+ }
367
+
368
+ private _syncTextArea(): void {
369
+ if (!this.textarea || !this.buffer.isCursorInViewport || this._compositionHelper!.isComposing || !this._renderService) {
370
+ return;
371
+ }
372
+ const cursorY = this.buffer.ybase + this.buffer.y;
373
+ const bufferLine = this.buffer.lines.get(cursorY);
374
+ if (!bufferLine) {
375
+ return;
376
+ }
377
+ const cursorX = Math.min(this.buffer.x, this.cols - 1);
378
+ const cellHeight = this._renderService.dimensions.actualCellHeight;
379
+ const width = bufferLine.getWidth(cursorX);
380
+ const cellWidth = this._renderService.dimensions.actualCellWidth * width;
381
+ const cursorTop = this.buffer.y * this._renderService.dimensions.actualCellHeight;
382
+ const cursorLeft = cursorX * this._renderService.dimensions.actualCellWidth;
383
+
384
+ // Sync the textarea to the exact position of the composition view so the IME knows where the
385
+ // text is.
386
+ this.textarea.style.left = cursorLeft + 'px';
387
+ this.textarea.style.top = cursorTop + 'px';
388
+ this.textarea.style.width = cellWidth + 'px';
389
+ this.textarea.style.height = cellHeight + 'px';
390
+ this.textarea.style.lineHeight = cellHeight + 'px';
391
+ this.textarea.style.zIndex = '-5';
392
+ }
393
+
394
+ /**
395
+ * Initialize default behavior
396
+ */
397
+ private _initGlobal(): void {
398
+ this._bindKeys();
399
+
400
+ // Bind clipboard functionality
401
+ this.register(addDisposableDomListener(this.element!, 'copy', (event: ClipboardEvent) => {
402
+ // If mouse events are active it means the selection manager is disabled and
403
+ // copy should be handled by the host program.
404
+ if (!this.hasSelection()) {
405
+ return;
406
+ }
407
+ copyHandler(event, this._selectionService!);
408
+ }));
409
+ const pasteHandlerWrapper = (event: ClipboardEvent): void => handlePasteEvent(event, this.textarea!, this.coreService);
410
+ this.register(addDisposableDomListener(this.textarea!, 'paste', pasteHandlerWrapper));
411
+ this.register(addDisposableDomListener(this.element!, 'paste', pasteHandlerWrapper));
412
+
413
+ // Handle right click context menus
414
+ if (Browser.isFirefox) {
415
+ // Firefox doesn't appear to fire the contextmenu event on right click
416
+ this.register(addDisposableDomListener(this.element!, 'mousedown', (event: MouseEvent) => {
417
+ if (event.button === 2) {
418
+ rightClickHandler(event, this.textarea!, this.screenElement!, this._selectionService!, this.options.rightClickSelectsWord);
419
+ }
420
+ }));
421
+ } else {
422
+ this.register(addDisposableDomListener(this.element!, 'contextmenu', (event: MouseEvent) => {
423
+ rightClickHandler(event, this.textarea!, this.screenElement!, this._selectionService!, this.options.rightClickSelectsWord);
424
+ }));
425
+ }
426
+
427
+ // Move the textarea under the cursor when middle clicking on Linux to ensure
428
+ // middle click to paste selection works. This only appears to work in Chrome
429
+ // at the time is writing.
430
+ if (Browser.isLinux) {
431
+ // Use auxclick event over mousedown the latter doesn't seem to work. Note
432
+ // that the regular click event doesn't fire for the middle mouse button.
433
+ this.register(addDisposableDomListener(this.element!, 'auxclick', (event: MouseEvent) => {
434
+ if (event.button === 1) {
435
+ moveTextAreaUnderMouseCursor(event, this.textarea!, this.screenElement!);
436
+ }
437
+ }));
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Apply key handling to the terminal
443
+ */
444
+ private _bindKeys(): void {
445
+ this.register(addDisposableDomListener(this.textarea!, 'keyup', (ev: KeyboardEvent) => this._keyUp(ev), true));
446
+ this.register(addDisposableDomListener(this.textarea!, 'keydown', (ev: KeyboardEvent) => this._keyDown(ev), true));
447
+ this.register(addDisposableDomListener(this.textarea!, 'keypress', (ev: KeyboardEvent) => this._keyPress(ev), true));
448
+ this.register(addDisposableDomListener(this.textarea!, 'compositionstart', () => this._compositionHelper!.compositionstart()));
449
+ this.register(addDisposableDomListener(this.textarea!, 'compositionupdate', (e: CompositionEvent) => this._compositionHelper!.compositionupdate(e)));
450
+ this.register(addDisposableDomListener(this.textarea!, 'compositionend', () => this._compositionHelper!.compositionend()));
451
+ this.register(addDisposableDomListener(this.textarea!, 'input', (ev: InputEvent) => this._inputEvent(ev), true));
452
+ this.register(this.onRender(() => this._compositionHelper!.updateCompositionElements()));
453
+ this.register(this.onRender(e => this._queueLinkification(e.start, e.end)));
454
+ }
455
+
456
+ /**
457
+ * Opens the terminal within an element.
458
+ *
459
+ * @param parent The element to create the terminal within.
460
+ */
461
+ public open(parent: HTMLElement): void {
462
+ if (!parent) {
463
+ throw new Error('Terminal requires a parent element.');
464
+ }
465
+
466
+ if (!parent.isConnected) {
467
+ this._logService.debug('Terminal.open was called on an element that was not attached to the DOM');
468
+ }
469
+
470
+ this._document = parent.ownerDocument!;
471
+
472
+ // Create main element container
473
+ this.element = this._document.createElement('div');
474
+ this.element.dir = 'ltr'; // xterm.css assumes LTR
475
+ this.element.classList.add('terminal');
476
+ this.element.classList.add('xterm');
477
+ this.element.setAttribute('tabindex', '0');
478
+ parent.appendChild(this.element);
479
+
480
+ // Performance: Use a document fragment to build the terminal
481
+ // viewport and helper elements detached from the DOM
482
+ const fragment = document.createDocumentFragment();
483
+ this._viewportElement = document.createElement('div');
484
+ this._viewportElement.classList.add('xterm-viewport');
485
+ fragment.appendChild(this._viewportElement);
486
+
487
+ this._viewportScrollArea = document.createElement('div');
488
+ this._viewportScrollArea.classList.add('xterm-scroll-area');
489
+ this._viewportElement.appendChild(this._viewportScrollArea);
490
+
491
+ this.screenElement = document.createElement('div');
492
+ this.screenElement.classList.add('xterm-screen');
493
+ // Create the container that will hold helpers like the textarea for
494
+ // capturing DOM Events. Then produce the helpers.
495
+ this._helperContainer = document.createElement('div');
496
+ this._helperContainer.classList.add('xterm-helpers');
497
+ this.screenElement.appendChild(this._helperContainer);
498
+ fragment.appendChild(this.screenElement);
499
+
500
+ this.textarea = document.createElement('textarea');
501
+ this.textarea.classList.add('xterm-helper-textarea');
502
+ this.textarea.setAttribute('aria-label', Strings.promptLabel);
503
+ this.textarea.setAttribute('aria-multiline', 'false');
504
+ this.textarea.setAttribute('autocorrect', 'off');
505
+ this.textarea.setAttribute('autocapitalize', 'off');
506
+ this.textarea.setAttribute('spellcheck', 'false');
507
+ this.textarea.tabIndex = 0;
508
+ this.register(addDisposableDomListener(this.textarea, 'focus', (ev: KeyboardEvent) => this._onTextAreaFocus(ev)));
509
+ this.register(addDisposableDomListener(this.textarea, 'blur', () => this._onTextAreaBlur()));
510
+ this._helperContainer.appendChild(this.textarea);
511
+
512
+ const coreBrowserService = this._instantiationService.createInstance(CoreBrowserService, this.textarea);
513
+ this._instantiationService.setService(ICoreBrowserService, coreBrowserService);
514
+
515
+ this._charSizeService = this._instantiationService.createInstance(CharSizeService, this._document, this._helperContainer);
516
+ this._instantiationService.setService(ICharSizeService, this._charSizeService);
517
+
518
+ this._theme = this.options.theme || this._theme;
519
+ this._colorManager = new ColorManager(document, this.options.allowTransparency);
520
+ this.register(this.optionsService.onOptionChange(e => this._colorManager!.onOptionsChange(e)));
521
+ this._colorManager.setTheme(this._theme);
522
+
523
+ this._characterJoinerService = this._instantiationService.createInstance(CharacterJoinerService);
524
+ this._instantiationService.setService(ICharacterJoinerService, this._characterJoinerService);
525
+
526
+ const renderer = this._createRenderer();
527
+ this._renderService = this.register(this._instantiationService.createInstance(RenderService, renderer, this.rows, this.screenElement));
528
+ this._instantiationService.setService(IRenderService, this._renderService);
529
+ this.register(this._renderService.onRenderedViewportChange(e => this._onRender.fire(e)));
530
+ this.onResize(e => this._renderService!.resize(e.cols, e.rows));
531
+
532
+ this._compositionView = document.createElement('div');
533
+ this._compositionView.classList.add('composition-view');
534
+ this._compositionHelper = this._instantiationService.createInstance(CompositionHelper, this.textarea, this._compositionView);
535
+ this._helperContainer.appendChild(this._compositionView);
536
+
537
+ // Performance: Add viewport and helper elements from the fragment
538
+ this.element.appendChild(fragment);
539
+
540
+ this._soundService = this._instantiationService.createInstance(SoundService);
541
+ this._instantiationService.setService(ISoundService, this._soundService);
542
+ this._mouseService = this._instantiationService.createInstance(MouseService);
543
+ this._instantiationService.setService(IMouseService, this._mouseService);
544
+
545
+ this.viewport = this._instantiationService.createInstance(Viewport,
546
+ (amount: number) => this.scrollLines(amount, true, ScrollSource.VIEWPORT),
547
+ this._viewportElement,
548
+ this._viewportScrollArea,
549
+ this.element
550
+ );
551
+ this.viewport.onThemeChange(this._colorManager.colors);
552
+ this.register(this._inputHandler.onRequestSyncScrollBar(() => this.viewport!.syncScrollArea()));
553
+ this.register(this.viewport);
554
+
555
+ this.register(this.onCursorMove(() => {
556
+ this._renderService!.onCursorMove();
557
+ this._syncTextArea();
558
+ }));
559
+ this.register(this.onResize(() => this._renderService!.onResize(this.cols, this.rows)));
560
+ this.register(this.onBlur(() => this._renderService!.onBlur()));
561
+ this.register(this.onFocus(() => this._renderService!.onFocus()));
562
+ this.register(this._renderService.onDimensionsChange(() => this.viewport!.syncScrollArea()));
563
+
564
+ this._selectionService = this.register(this._instantiationService.createInstance(SelectionService,
565
+ this.element,
566
+ this.screenElement,
567
+ this.linkifier2
568
+ ));
569
+ this._instantiationService.setService(ISelectionService, this._selectionService);
570
+ this.register(this._selectionService.onRequestScrollLines(e => this.scrollLines(e.amount, e.suppressScrollEvent)));
571
+ this.register(this._selectionService.onSelectionChange(() => this._onSelectionChange.fire()));
572
+ this.register(this._selectionService.onRequestRedraw(e => this._renderService!.onSelectionChanged(e.start, e.end, e.columnSelectMode)));
573
+ this.register(this._selectionService.onLinuxMouseSelection(text => {
574
+ // If there's a new selection, put it into the textarea, focus and select it
575
+ // in order to register it as a selection on the OS. This event is fired
576
+ // only on Linux to enable middle click to paste selection.
577
+ this.textarea!.value = text;
578
+ this.textarea!.focus();
579
+ this.textarea!.select();
580
+ }));
581
+ this.register(this._onScroll.event(ev => {
582
+ this.viewport!.syncScrollArea();
583
+ this._selectionService!.refresh();
584
+ }));
585
+ this.register(addDisposableDomListener(this._viewportElement, 'scroll', () => this._selectionService!.refresh()));
586
+
587
+ this._mouseZoneManager = this._instantiationService.createInstance(MouseZoneManager, this.element, this.screenElement);
588
+ this.register(this._mouseZoneManager);
589
+ this.register(this.onScroll(() => this._mouseZoneManager!.clearAll()));
590
+ this.linkifier.attachToDom(this.element, this._mouseZoneManager);
591
+ this.linkifier2.attachToDom(this.screenElement, this._mouseService, this._renderService);
592
+ this.register(this._instantiationService.createInstance(BufferDecorationRenderer, this.screenElement));
593
+ // This event listener must be registered aftre MouseZoneManager is created
594
+ this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService!.onMouseDown(e)));
595
+
596
+ // apply mouse event classes set by escape codes before terminal was attached
597
+ if (this.coreMouseService.areMouseEventsActive) {
598
+ this._selectionService.disable();
599
+ this.element.classList.add('enable-mouse-events');
600
+ } else {
601
+ this._selectionService.enable();
602
+ }
603
+
604
+ if (this.options.screenReaderMode) {
605
+ // Note that this must be done *after* the renderer is created in order to
606
+ // ensure the correct order of the dprchange event
607
+ this._accessibilityManager = new AccessibilityManager(this, this._renderService);
608
+ }
609
+
610
+ if (this.options.overviewRulerWidth) {
611
+ this._overviewRulerRenderer = this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement);
612
+ }
613
+ this.optionsService.onOptionChange(() => {
614
+ if (!this._overviewRulerRenderer && this.options.overviewRulerWidth && this._viewportElement && this.screenElement) {
615
+ this._overviewRulerRenderer = this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement);
616
+ }
617
+ });
618
+ // Measure the character size
619
+ this._charSizeService.measure();
620
+
621
+ // Setup loop that draws to screen
622
+ this.refresh(0, this.rows - 1);
623
+
624
+ // Initialize global actions that need to be taken on the document.
625
+ this._initGlobal();
626
+
627
+ // Listen for mouse events and translate
628
+ // them into terminal mouse protocols.
629
+ this.bindMouse();
630
+ }
631
+
632
+ private _createRenderer(): IRenderer {
633
+ switch (this.options.rendererType) {
634
+ case 'canvas': return this._instantiationService.createInstance(Renderer, this._colorManager!.colors, this.screenElement!, this.linkifier, this.linkifier2);
635
+ case 'dom': return this._instantiationService.createInstance(DomRenderer, this._colorManager!.colors, this.element!, this.screenElement!, this._viewportElement!, this.linkifier, this.linkifier2);
636
+ default: throw new Error(`Unrecognized rendererType "${this.options.rendererType}"`);
637
+ }
638
+ }
639
+
640
+ /**
641
+ * Sets the theme on the renderer. The renderer must have been initialized.
642
+ * @param theme The theme to set.
643
+ */
644
+ private _setTheme(theme: ITheme): void {
645
+ this._theme = theme;
646
+ this._colorManager?.setTheme(theme);
647
+ this._renderService?.setColors(this._colorManager!.colors);
648
+ this.viewport?.onThemeChange(this._colorManager!.colors);
649
+ }
650
+
651
+ /**
652
+ * Bind certain mouse events to the terminal.
653
+ * By default only 3 button + wheel up/down is ativated. For higher buttons
654
+ * no mouse report will be created. Typically the standard actions will be active.
655
+ *
656
+ * There are several reasons not to enable support for higher buttons/wheel:
657
+ * - Button 4 and 5 are typically used for history back and forward navigation,
658
+ * there is no straight forward way to supress/intercept those standard actions.
659
+ * - Support for higher buttons does not work in some platform/browser combinations.
660
+ * - Left/right wheel was not tested.
661
+ * - Emulators vary in mouse button support, typically only 3 buttons and
662
+ * wheel up/down work reliable.
663
+ *
664
+ * TODO: Move mouse event code into its own file.
665
+ */
666
+ public bindMouse(): void {
667
+ const self = this;
668
+ const el = this.element!;
669
+
670
+ // send event to CoreMouseService
671
+ function sendEvent(ev: MouseEvent | WheelEvent): boolean {
672
+ // get mouse coordinates
673
+ const pos = self._mouseService!.getRawByteCoords(ev, self.screenElement!, self.cols, self.rows);
674
+ if (!pos) {
675
+ return false;
676
+ }
677
+
678
+ let but: CoreMouseButton;
679
+ let action: CoreMouseAction | undefined;
680
+ switch ((ev as any).overrideType || ev.type) {
681
+ case 'mousemove':
682
+ action = CoreMouseAction.MOVE;
683
+ if (ev.buttons === undefined) {
684
+ // buttons is not supported on macOS, try to get a value from button instead
685
+ but = CoreMouseButton.NONE;
686
+ if (ev.button !== undefined) {
687
+ but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
688
+ }
689
+ } else {
690
+ // according to MDN buttons only reports up to button 5 (AUX2)
691
+ but = ev.buttons & 1 ? CoreMouseButton.LEFT :
692
+ ev.buttons & 4 ? CoreMouseButton.MIDDLE :
693
+ ev.buttons & 2 ? CoreMouseButton.RIGHT :
694
+ CoreMouseButton.NONE; // fallback to NONE
695
+ }
696
+ break;
697
+ case 'mouseup':
698
+ action = CoreMouseAction.UP;
699
+ but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
700
+ break;
701
+ case 'mousedown':
702
+ action = CoreMouseAction.DOWN;
703
+ but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
704
+ break;
705
+ case 'wheel':
706
+ const amount = self.viewport!.getLinesScrolled(ev as WheelEvent);
707
+
708
+ if (amount === 0) {
709
+ return false;
710
+ }
711
+
712
+ action = (ev as WheelEvent).deltaY < 0 ? CoreMouseAction.UP : CoreMouseAction.DOWN;
713
+ but = CoreMouseButton.WHEEL;
714
+ break;
715
+ default:
716
+ // dont handle other event types by accident
717
+ return false;
718
+ }
719
+
720
+ // exit if we cannot determine valid button/action values
721
+ // do nothing for higher buttons than wheel
722
+ if (action === undefined || but === undefined || but > CoreMouseButton.WHEEL) {
723
+ return false;
724
+ }
725
+
726
+ return self.coreMouseService.triggerMouseEvent({
727
+ col: pos.x - 33, // FIXME: why -33 here?
728
+ row: pos.y - 33,
729
+ button: but,
730
+ action,
731
+ ctrl: ev.ctrlKey,
732
+ alt: ev.altKey,
733
+ shift: ev.shiftKey
734
+ });
735
+ }
736
+
737
+ /**
738
+ * Event listener state handling.
739
+ * We listen to the onProtocolChange event of CoreMouseService and put
740
+ * requested listeners in `requestedEvents`. With this the listeners
741
+ * have all bits to do the event listener juggling.
742
+ * Note: 'mousedown' currently is "always on" and not managed
743
+ * by onProtocolChange.
744
+ */
745
+ const requestedEvents: { [key: string]: ((ev: Event) => void) | null } = {
746
+ mouseup: null,
747
+ wheel: null,
748
+ mousedrag: null,
749
+ mousemove: null
750
+ };
751
+ const eventListeners: { [key: string]: (ev: any) => void | boolean } = {
752
+ mouseup: (ev: MouseEvent) => {
753
+ sendEvent(ev);
754
+ if (!ev.buttons) {
755
+ // if no other button is held remove global handlers
756
+ this._document!.removeEventListener('mouseup', requestedEvents.mouseup!);
757
+ if (requestedEvents.mousedrag) {
758
+ this._document!.removeEventListener('mousemove', requestedEvents.mousedrag);
759
+ }
760
+ }
761
+ return this.cancel(ev);
762
+ },
763
+ wheel: (ev: WheelEvent) => {
764
+ sendEvent(ev);
765
+ return this.cancel(ev, true);
766
+ },
767
+ mousedrag: (ev: MouseEvent) => {
768
+ // deal only with move while a button is held
769
+ if (ev.buttons) {
770
+ sendEvent(ev);
771
+ }
772
+ },
773
+ mousemove: (ev: MouseEvent) => {
774
+ // deal only with move without any button
775
+ if (!ev.buttons) {
776
+ sendEvent(ev);
777
+ }
778
+ }
779
+ };
780
+ this.register(this.coreMouseService.onProtocolChange(events => {
781
+ // apply global changes on events
782
+ if (events) {
783
+ if (this.optionsService.rawOptions.logLevel === 'debug') {
784
+ this._logService.debug('Binding to mouse events:', this.coreMouseService.explainEvents(events));
785
+ }
786
+ this.element!.classList.add('enable-mouse-events');
787
+ this._selectionService!.disable();
788
+ } else {
789
+ this._logService.debug('Unbinding from mouse events.');
790
+ this.element!.classList.remove('enable-mouse-events');
791
+ this._selectionService!.enable();
792
+ }
793
+
794
+ // add/remove handlers from requestedEvents
795
+
796
+ if (!(events & CoreMouseEventType.MOVE)) {
797
+ el.removeEventListener('mousemove', requestedEvents.mousemove!);
798
+ requestedEvents.mousemove = null;
799
+ } else if (!requestedEvents.mousemove) {
800
+ el.addEventListener('mousemove', eventListeners.mousemove);
801
+ requestedEvents.mousemove = eventListeners.mousemove;
802
+ }
803
+
804
+ if (!(events & CoreMouseEventType.WHEEL)) {
805
+ el.removeEventListener('wheel', requestedEvents.wheel!);
806
+ requestedEvents.wheel = null;
807
+ } else if (!requestedEvents.wheel) {
808
+ el.addEventListener('wheel', eventListeners.wheel, { passive: false });
809
+ requestedEvents.wheel = eventListeners.wheel;
810
+ }
811
+
812
+ if (!(events & CoreMouseEventType.UP)) {
813
+ this._document!.removeEventListener('mouseup', requestedEvents.mouseup!);
814
+ requestedEvents.mouseup = null;
815
+ } else if (!requestedEvents.mouseup) {
816
+ requestedEvents.mouseup = eventListeners.mouseup;
817
+ }
818
+
819
+ if (!(events & CoreMouseEventType.DRAG)) {
820
+ this._document!.removeEventListener('mousemove', requestedEvents.mousedrag!);
821
+ requestedEvents.mousedrag = null;
822
+ } else if (!requestedEvents.mousedrag) {
823
+ requestedEvents.mousedrag = eventListeners.mousedrag;
824
+ }
825
+ }));
826
+ // force initial onProtocolChange so we dont miss early mouse requests
827
+ this.coreMouseService.activeProtocol = this.coreMouseService.activeProtocol;
828
+
829
+ /**
830
+ * "Always on" event listeners.
831
+ */
832
+ this.register(addDisposableDomListener(el, 'mousedown', (ev: MouseEvent) => {
833
+ ev.preventDefault();
834
+ this.focus();
835
+
836
+ // Don't send the mouse button to the pty if mouse events are disabled or
837
+ // if the selection manager is having selection forced (ie. a modifier is
838
+ // held).
839
+ if (!this.coreMouseService.areMouseEventsActive || this._selectionService!.shouldForceSelection(ev)) {
840
+ return;
841
+ }
842
+
843
+ sendEvent(ev);
844
+
845
+ // Register additional global handlers which should keep reporting outside
846
+ // of the terminal element.
847
+ // Note: Other emulators also do this for 'mousedown' while a button
848
+ // is held, we currently limit 'mousedown' to the terminal only.
849
+ if (requestedEvents.mouseup) {
850
+ this._document!.addEventListener('mouseup', requestedEvents.mouseup);
851
+ }
852
+ if (requestedEvents.mousedrag) {
853
+ this._document!.addEventListener('mousemove', requestedEvents.mousedrag);
854
+ }
855
+
856
+ return this.cancel(ev);
857
+ }));
858
+
859
+ this.register(addDisposableDomListener(el, 'wheel', (ev: WheelEvent) => {
860
+ // do nothing, if app side handles wheel itself
861
+ if (requestedEvents.wheel) return;
862
+
863
+ if (!this.buffer.hasScrollback) {
864
+ // Convert wheel events into up/down events when the buffer does not have scrollback, this
865
+ // enables scrolling in apps hosted in the alt buffer such as vim or tmux.
866
+ const amount = this.viewport!.getLinesScrolled(ev);
867
+
868
+ // Do nothing if there's no vertical scroll
869
+ if (amount === 0) {
870
+ return;
871
+ }
872
+
873
+ // Construct and send sequences
874
+ const sequence = C0.ESC + (this.coreService.decPrivateModes.applicationCursorKeys ? 'O' : '[') + (ev.deltaY < 0 ? 'A' : 'B');
875
+ let data = '';
876
+ for (let i = 0; i < Math.abs(amount); i++) {
877
+ data += sequence;
878
+ }
879
+ this.coreService.triggerDataEvent(data, true);
880
+ return this.cancel(ev, true);
881
+ }
882
+
883
+ // normal viewport scrolling
884
+ // conditionally stop event, if the viewport still had rows to scroll within
885
+ if (this.viewport!.onWheel(ev)) {
886
+ return this.cancel(ev);
887
+ }
888
+ }, { passive: false }));
889
+
890
+ this.register(addDisposableDomListener(el, 'touchstart', (ev: TouchEvent) => {
891
+ if (this.coreMouseService.areMouseEventsActive) return;
892
+ this.viewport!.onTouchStart(ev);
893
+ return this.cancel(ev);
894
+ }, { passive: true }));
895
+
896
+ this.register(addDisposableDomListener(el, 'touchmove', (ev: TouchEvent) => {
897
+ if (this.coreMouseService.areMouseEventsActive) return;
898
+ if (!this.viewport!.onTouchMove(ev)) {
899
+ return this.cancel(ev);
900
+ }
901
+ }, { passive: false }));
902
+ }
903
+
904
+
905
+ /**
906
+ * Tells the renderer to refresh terminal content between two rows (inclusive) at the next
907
+ * opportunity.
908
+ * @param start The row to start from (between 0 and this.rows - 1).
909
+ * @param end The row to end at (between start and this.rows - 1).
910
+ */
911
+ public refresh(start: number, end: number): void {
912
+ this._renderService?.refreshRows(start, end);
913
+ }
914
+
915
+ /**
916
+ * Queues linkification for the specified rows.
917
+ * @param start The row to start from (between 0 and this.rows - 1).
918
+ * @param end The row to end at (between start and this.rows - 1).
919
+ */
920
+ private _queueLinkification(start: number, end: number): void {
921
+ this.linkifier?.linkifyRows(start, end);
922
+ }
923
+
924
+ /**
925
+ * Change the cursor style for different selection modes
926
+ */
927
+ public updateCursorStyle(ev: KeyboardEvent): void {
928
+ if (this._selectionService?.shouldColumnSelect(ev)) {
929
+ this.element!.classList.add('column-select');
930
+ } else {
931
+ this.element!.classList.remove('column-select');
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Display the cursor element
937
+ */
938
+ private _showCursor(): void {
939
+ if (!this.coreService.isCursorInitialized) {
940
+ this.coreService.isCursorInitialized = true;
941
+ this.refresh(this.buffer.y, this.buffer.y);
942
+ }
943
+ }
944
+
945
+ public scrollLines(disp: number, suppressScrollEvent?: boolean, source = ScrollSource.TERMINAL): void {
946
+ super.scrollLines(disp, suppressScrollEvent, source);
947
+ this.refresh(0, this.rows - 1);
948
+ }
949
+
950
+ public paste(data: string): void {
951
+ paste(data, this.textarea!, this.coreService);
952
+ }
953
+
954
+ /**
955
+ * Attaches a custom key event handler which is run before keys are processed,
956
+ * giving consumers of xterm.js ultimate control as to what keys should be
957
+ * processed by the terminal and what keys should not.
958
+ * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
959
+ * This is a function that takes a KeyboardEvent, allowing consumers to stop
960
+ * propagation and/or prevent the default action. The function returns whether
961
+ * the event should be processed by xterm.js.
962
+ */
963
+ public attachCustomKeyEventHandler(customKeyEventHandler: CustomKeyEventHandler): void {
964
+ this._customKeyEventHandler = customKeyEventHandler;
965
+ }
966
+
967
+ /**
968
+ * Registers a link matcher, allowing custom link patterns to be matched and
969
+ * handled.
970
+ * @param regex The regular expression to search for, specifically
971
+ * this searches the textContent of the rows. You will want to use \s to match
972
+ * a space ' ' character for example.
973
+ * @param handler The callback when the link is called.
974
+ * @param options Options for the link matcher.
975
+ * @return The ID of the new matcher, this can be used to deregister.
976
+ */
977
+ public registerLinkMatcher(regex: RegExp, handler: LinkMatcherHandler, options?: ILinkMatcherOptions): number {
978
+ const matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
979
+ this.refresh(0, this.rows - 1);
980
+ return matcherId;
981
+ }
982
+
983
+ /**
984
+ * Deregisters a link matcher if it has been registered.
985
+ * @param matcherId The link matcher's ID (returned after register)
986
+ */
987
+ public deregisterLinkMatcher(matcherId: number): void {
988
+ if (this.linkifier.deregisterLinkMatcher(matcherId)) {
989
+ this.refresh(0, this.rows - 1);
990
+ }
991
+ }
992
+
993
+ public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
994
+ return this.linkifier2.registerLinkProvider(linkProvider);
995
+ }
996
+
997
+ public registerCharacterJoiner(handler: CharacterJoinerHandler): number {
998
+ if (!this._characterJoinerService) {
999
+ throw new Error('Terminal must be opened first');
1000
+ }
1001
+ const joinerId = this._characterJoinerService.register(handler);
1002
+ this.refresh(0, this.rows - 1);
1003
+ return joinerId;
1004
+ }
1005
+
1006
+ public deregisterCharacterJoiner(joinerId: number): void {
1007
+ if (!this._characterJoinerService) {
1008
+ throw new Error('Terminal must be opened first');
1009
+ }
1010
+ if (this._characterJoinerService.deregister(joinerId)) {
1011
+ this.refresh(0, this.rows - 1);
1012
+ }
1013
+ }
1014
+
1015
+ public get markers(): IMarker[] {
1016
+ return this.buffer.markers;
1017
+ }
1018
+
1019
+ public addMarker(cursorYOffset: number): IMarker | undefined {
1020
+ // Disallow markers on the alt buffer
1021
+ if (this.buffer !== this.buffers.normal) {
1022
+ return;
1023
+ }
1024
+
1025
+ return this.buffer.addMarker(this.buffer.ybase + this.buffer.y + cursorYOffset);
1026
+ }
1027
+
1028
+ public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined {
1029
+ return this._decorationService.registerDecoration(decorationOptions);
1030
+ }
1031
+
1032
+ /**
1033
+ * Gets whether the terminal has an active selection.
1034
+ */
1035
+ public hasSelection(): boolean {
1036
+ return this._selectionService ? this._selectionService.hasSelection : false;
1037
+ }
1038
+
1039
+ /**
1040
+ * Selects text within the terminal.
1041
+ * @param column The column the selection starts at..
1042
+ * @param row The row the selection starts at.
1043
+ * @param length The length of the selection.
1044
+ */
1045
+ public select(column: number, row: number, length: number): void {
1046
+ this._selectionService!.setSelection(column, row, length);
1047
+ }
1048
+
1049
+ /**
1050
+ * Gets the terminal's current selection, this is useful for implementing copy
1051
+ * behavior outside of xterm.js.
1052
+ */
1053
+ public getSelection(): string {
1054
+ return this._selectionService ? this._selectionService.selectionText : '';
1055
+ }
1056
+
1057
+ public getSelectionPosition(): ISelectionPosition | undefined {
1058
+ if (!this._selectionService || !this._selectionService.hasSelection) {
1059
+ return undefined;
1060
+ }
1061
+
1062
+ return {
1063
+ startColumn: this._selectionService.selectionStart![0],
1064
+ startRow: this._selectionService.selectionStart![1],
1065
+ endColumn: this._selectionService.selectionEnd![0],
1066
+ endRow: this._selectionService.selectionEnd![1]
1067
+ };
1068
+ }
1069
+
1070
+ /**
1071
+ * Clears the current terminal selection.
1072
+ */
1073
+ public clearSelection(): void {
1074
+ this._selectionService?.clearSelection();
1075
+ }
1076
+
1077
+ /**
1078
+ * Selects all text within the terminal.
1079
+ */
1080
+ public selectAll(): void {
1081
+ this._selectionService?.selectAll();
1082
+ }
1083
+
1084
+ public selectLines(start: number, end: number): void {
1085
+ this._selectionService?.selectLines(start, end);
1086
+ }
1087
+
1088
+ /**
1089
+ * Handle a keydown event
1090
+ * Key Resources:
1091
+ * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1092
+ * @param ev The keydown event to be handled.
1093
+ */
1094
+ protected _keyDown(event: KeyboardEvent): boolean | undefined {
1095
+ this._keyDownHandled = false;
1096
+ this._keyDownSeen = true;
1097
+
1098
+ if (this._customKeyEventHandler && this._customKeyEventHandler(event) === false) {
1099
+ return false;
1100
+ }
1101
+
1102
+ // Ignore composing with Alt key on Mac when macOptionIsMeta is enabled
1103
+ const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey;
1104
+
1105
+ if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) {
1106
+ if (this.buffer.ybase !== this.buffer.ydisp) {
1107
+ this._bufferService.scrollToBottom();
1108
+ }
1109
+ return false;
1110
+ }
1111
+
1112
+ if (!shouldIgnoreComposition && (event.key === 'Dead' || event.key === 'AltGraph')) {
1113
+ this._unprocessedDeadKey = true;
1114
+ }
1115
+
1116
+ const result = evaluateKeyboardEvent(event, this.coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta);
1117
+
1118
+ this.updateCursorStyle(event);
1119
+
1120
+ if (result.type === KeyboardResultType.PAGE_DOWN || result.type === KeyboardResultType.PAGE_UP) {
1121
+ const scrollCount = this.rows - 1;
1122
+ this.scrollLines(result.type === KeyboardResultType.PAGE_UP ? -scrollCount : scrollCount);
1123
+ return this.cancel(event, true);
1124
+ }
1125
+
1126
+ if (result.type === KeyboardResultType.SELECT_ALL) {
1127
+ this.selectAll();
1128
+ }
1129
+
1130
+ if (this._isThirdLevelShift(this.browser, event)) {
1131
+ return true;
1132
+ }
1133
+
1134
+ if (result.cancel) {
1135
+ // The event is canceled at the end already, is this necessary?
1136
+ this.cancel(event, true);
1137
+ }
1138
+
1139
+ if (!result.key) {
1140
+ return true;
1141
+ }
1142
+
1143
+ // HACK: Process A-Z in the keypress event to fix an issue with macOS IMEs where lower case
1144
+ // letters cannot be input while caps lock is on.
1145
+ if (event.key && !event.ctrlKey && !event.altKey && !event.metaKey && event.key.length === 1) {
1146
+ if (event.key.charCodeAt(0) >= 65 && event.key.charCodeAt(0) <= 90) {
1147
+ return true;
1148
+ }
1149
+ }
1150
+
1151
+ if (this._unprocessedDeadKey) {
1152
+ this._unprocessedDeadKey = false;
1153
+ return true;
1154
+ }
1155
+
1156
+ // If ctrl+c or enter is being sent, clear out the textarea. This is done so that screen readers
1157
+ // will announce deleted characters. This will not work 100% of the time but it should cover
1158
+ // most scenarios.
1159
+ if (result.key === C0.ETX || result.key === C0.CR) {
1160
+ this.textarea!.value = '';
1161
+ }
1162
+
1163
+ this._onKey.fire({ key: result.key, domEvent: event });
1164
+ this._showCursor();
1165
+ this.coreService.triggerDataEvent(result.key, true);
1166
+
1167
+ // Cancel events when not in screen reader mode so events don't get bubbled up and handled by
1168
+ // other listeners. When screen reader mode is enabled, this could cause issues if the event
1169
+ // is handled at a higher level, this is a compromise in order to echo keys to the screen
1170
+ // reader.
1171
+ if (!this.optionsService.rawOptions.screenReaderMode) {
1172
+ return this.cancel(event, true);
1173
+ }
1174
+
1175
+ this._keyDownHandled = true;
1176
+ }
1177
+
1178
+ private _isThirdLevelShift(browser: IBrowser, ev: KeyboardEvent): boolean {
1179
+ const thirdLevelKey =
1180
+ (browser.isMac && !this.options.macOptionIsMeta && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
1181
+ (browser.isWindows && ev.altKey && ev.ctrlKey && !ev.metaKey) ||
1182
+ (browser.isWindows && ev.getModifierState('AltGraph'));
1183
+
1184
+ if (ev.type === 'keypress') {
1185
+ return thirdLevelKey;
1186
+ }
1187
+
1188
+ // Don't invoke for arrows, pageDown, home, backspace, etc. (on non-keypress events)
1189
+ return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
1190
+ }
1191
+
1192
+ protected _keyUp(ev: KeyboardEvent): void {
1193
+ this._keyDownSeen = false;
1194
+
1195
+ if (this._customKeyEventHandler && this._customKeyEventHandler(ev) === false) {
1196
+ return;
1197
+ }
1198
+
1199
+ if (!wasModifierKeyOnlyEvent(ev)) {
1200
+ this.focus();
1201
+ }
1202
+
1203
+ this.updateCursorStyle(ev);
1204
+ this._keyPressHandled = false;
1205
+ }
1206
+
1207
+ /**
1208
+ * Handle a keypress event.
1209
+ * Key Resources:
1210
+ * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
1211
+ * @param ev The keypress event to be handled.
1212
+ */
1213
+ protected _keyPress(ev: KeyboardEvent): boolean {
1214
+ let key;
1215
+
1216
+ this._keyPressHandled = false;
1217
+
1218
+ if (this._keyDownHandled) {
1219
+ return false;
1220
+ }
1221
+
1222
+ if (this._customKeyEventHandler && this._customKeyEventHandler(ev) === false) {
1223
+ return false;
1224
+ }
1225
+
1226
+ this.cancel(ev);
1227
+
1228
+ if (ev.charCode) {
1229
+ key = ev.charCode;
1230
+ } else if (ev.which === null || ev.which === undefined) {
1231
+ key = ev.keyCode;
1232
+ } else if (ev.which !== 0 && ev.charCode !== 0) {
1233
+ key = ev.which;
1234
+ } else {
1235
+ return false;
1236
+ }
1237
+
1238
+ if (!key || (
1239
+ (ev.altKey || ev.ctrlKey || ev.metaKey) && !this._isThirdLevelShift(this.browser, ev)
1240
+ )) {
1241
+ return false;
1242
+ }
1243
+
1244
+ key = String.fromCharCode(key);
1245
+
1246
+ this._onKey.fire({ key, domEvent: ev });
1247
+ this._showCursor();
1248
+ this.coreService.triggerDataEvent(key, true);
1249
+
1250
+ this._keyPressHandled = true;
1251
+
1252
+ // The key was handled so clear the dead key state, otherwise certain keystrokes like arrow
1253
+ // keys could be ignored
1254
+ this._unprocessedDeadKey = false;
1255
+
1256
+ return true;
1257
+ }
1258
+
1259
+ /**
1260
+ * Handle an input event.
1261
+ * Key Resources:
1262
+ * - https://developer.mozilla.org/en-US/docs/Web/API/InputEvent
1263
+ * @param ev The input event to be handled.
1264
+ */
1265
+ protected _inputEvent(ev: InputEvent): boolean {
1266
+ // Only support emoji IMEs when screen reader mode is disabled as the event must bubble up to
1267
+ // support reading out character input which can doubling up input characters
1268
+ // Based on these event traces: https://github.com/xtermjs/xterm.js/issues/3679
1269
+ if (ev.data && ev.inputType === 'insertText' && (!ev.composed || !this._keyDownSeen) && !this.optionsService.rawOptions.screenReaderMode) {
1270
+ if (this._keyPressHandled) {
1271
+ return false;
1272
+ }
1273
+
1274
+ // The key was handled so clear the dead key state, otherwise certain keystrokes like arrow
1275
+ // keys could be ignored
1276
+ this._unprocessedDeadKey = false;
1277
+
1278
+ const text = ev.data;
1279
+ this.coreService.triggerDataEvent(text, true);
1280
+
1281
+ this.cancel(ev);
1282
+ return true;
1283
+ }
1284
+
1285
+ return false;
1286
+ }
1287
+
1288
+ /**
1289
+ * Ring the bell.
1290
+ * Note: We could do sweet things with webaudio here
1291
+ */
1292
+ public bell(): void {
1293
+ if (this._soundBell()) {
1294
+ this._soundService?.playBellSound();
1295
+ }
1296
+
1297
+ this._onBell.fire();
1298
+
1299
+ // if (this._visualBell()) {
1300
+ // this.element.classList.add('visual-bell-active');
1301
+ // clearTimeout(this._visualBellTimer);
1302
+ // this._visualBellTimer = window.setTimeout(() => {
1303
+ // this.element.classList.remove('visual-bell-active');
1304
+ // }, 200);
1305
+ // }
1306
+ }
1307
+
1308
+ /**
1309
+ * Resizes the terminal.
1310
+ *
1311
+ * @param x The number of columns to resize to.
1312
+ * @param y The number of rows to resize to.
1313
+ */
1314
+ public resize(x: number, y: number): void {
1315
+ if (x === this.cols && y === this.rows) {
1316
+ // Check if we still need to measure the char size (fixes #785).
1317
+ if (this._charSizeService && !this._charSizeService.hasValidSize) {
1318
+ this._charSizeService.measure();
1319
+ }
1320
+ return;
1321
+ }
1322
+
1323
+ super.resize(x, y);
1324
+ }
1325
+
1326
+ private _afterResize(x: number, y: number): void {
1327
+ this._charSizeService?.measure();
1328
+
1329
+ // Sync the scroll area to make sure scroll events don't fire and scroll the viewport to an
1330
+ // invalid location
1331
+ this.viewport?.syncScrollArea(true);
1332
+ }
1333
+
1334
+ /**
1335
+ * Clear the entire buffer, making the prompt line the new first line.
1336
+ */
1337
+ public clear(): void {
1338
+ if (this.buffer.ybase === 0 && this.buffer.y === 0) {
1339
+ // Don't clear if it's already clear
1340
+ return;
1341
+ }
1342
+ this.buffer.clearAllMarkers();
1343
+ this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y)!);
1344
+ this.buffer.lines.length = 1;
1345
+ this.buffer.ydisp = 0;
1346
+ this.buffer.ybase = 0;
1347
+ this.buffer.y = 0;
1348
+ for (let i = 1; i < this.rows; i++) {
1349
+ this.buffer.lines.push(this.buffer.getBlankLine(DEFAULT_ATTR_DATA));
1350
+ }
1351
+ this.refresh(0, this.rows - 1);
1352
+ this._onScroll.fire({ position: this.buffer.ydisp, source: ScrollSource.TERMINAL });
1353
+ }
1354
+
1355
+ /**
1356
+ * Reset terminal.
1357
+ * Note: Calling this directly from JS is synchronous but does not clear
1358
+ * input buffers and does not reset the parser, thus the terminal will
1359
+ * continue to apply pending input data.
1360
+ * If you need in band reset (synchronous with input data) consider
1361
+ * using DECSTR (soft reset, CSI ! p) or RIS instead (hard reset, ESC c).
1362
+ */
1363
+ public reset(): void {
1364
+ /**
1365
+ * Since _setup handles a full terminal creation, we have to carry forward
1366
+ * a few things that should not reset.
1367
+ */
1368
+ this.options.rows = this.rows;
1369
+ this.options.cols = this.cols;
1370
+ const customKeyEventHandler = this._customKeyEventHandler;
1371
+
1372
+ this._setup();
1373
+ super.reset();
1374
+ this._selectionService?.reset();
1375
+ this._decorationService.reset();
1376
+
1377
+ // reattach
1378
+ this._customKeyEventHandler = customKeyEventHandler;
1379
+
1380
+ // do a full screen refresh
1381
+ this.refresh(0, this.rows - 1);
1382
+ this.viewport?.syncScrollArea();
1383
+ }
1384
+
1385
+ public clearTextureAtlas(): void {
1386
+ this._renderService?.clearTextureAtlas();
1387
+ }
1388
+
1389
+ private _reportFocus(): void {
1390
+ if (this.element?.classList.contains('focus')) {
1391
+ this.coreService.triggerDataEvent(C0.ESC + '[I');
1392
+ } else {
1393
+ this.coreService.triggerDataEvent(C0.ESC + '[O');
1394
+ }
1395
+ }
1396
+
1397
+ private _reportWindowsOptions(type: WindowsOptionsReportType): void {
1398
+ if (!this._renderService) {
1399
+ return;
1400
+ }
1401
+
1402
+ switch (type) {
1403
+ case WindowsOptionsReportType.GET_WIN_SIZE_PIXELS:
1404
+ const canvasWidth = this._renderService.dimensions.scaledCanvasWidth.toFixed(0);
1405
+ const canvasHeight = this._renderService.dimensions.scaledCanvasHeight.toFixed(0);
1406
+ this.coreService.triggerDataEvent(`${C0.ESC}[4;${canvasHeight};${canvasWidth}t`);
1407
+ break;
1408
+ case WindowsOptionsReportType.GET_CELL_SIZE_PIXELS:
1409
+ const cellWidth = this._renderService.dimensions.scaledCellWidth.toFixed(0);
1410
+ const cellHeight = this._renderService.dimensions.scaledCellHeight.toFixed(0);
1411
+ this.coreService.triggerDataEvent(`${C0.ESC}[6;${cellHeight};${cellWidth}t`);
1412
+ break;
1413
+ }
1414
+ }
1415
+
1416
+ // TODO: Remove cancel function and cancelEvents option
1417
+ public cancel(ev: Event, force?: boolean): boolean | undefined {
1418
+ if (!this.options.cancelEvents && !force) {
1419
+ return;
1420
+ }
1421
+ ev.preventDefault();
1422
+ ev.stopPropagation();
1423
+ return false;
1424
+ }
1425
+
1426
+ private _visualBell(): boolean {
1427
+ return false;
1428
+ // return this.options.bellStyle === 'visual' ||
1429
+ // this.options.bellStyle === 'both';
1430
+ }
1431
+
1432
+ private _soundBell(): boolean {
1433
+ return this.options.bellStyle === 'sound';
1434
+ // return this.options.bellStyle === 'sound' ||
1435
+ // this.options.bellStyle === 'both';
1436
+ }
1437
+ }
1438
+
1439
+ /**
1440
+ * Helpers
1441
+ */
1442
+
1443
+ function wasModifierKeyOnlyEvent(ev: KeyboardEvent): boolean {
1444
+ return ev.keyCode === 16 || // Shift
1445
+ ev.keyCode === 17 || // Ctrl
1446
+ ev.keyCode === 18; // Alt
1447
+ }