@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,346 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ /**
7
+ * Polyfill - Convert UTF32 codepoint into JS string.
8
+ * Note: The built-in String.fromCodePoint happens to be much slower
9
+ * due to additional sanity checks. We can avoid them since
10
+ * we always operate on legal UTF32 (granted by the input decoders)
11
+ * and use this faster version instead.
12
+ */
13
+ export function stringFromCodePoint(codePoint: number): string {
14
+ if (codePoint > 0xFFFF) {
15
+ codePoint -= 0x10000;
16
+ return String.fromCharCode((codePoint >> 10) + 0xD800) + String.fromCharCode((codePoint % 0x400) + 0xDC00);
17
+ }
18
+ return String.fromCharCode(codePoint);
19
+ }
20
+
21
+ /**
22
+ * Convert UTF32 char codes into JS string.
23
+ * Basically the same as `stringFromCodePoint` but for multiple codepoints
24
+ * in a loop (which is a lot faster).
25
+ */
26
+ export function utf32ToString(data: Uint32Array, start: number = 0, end: number = data.length): string {
27
+ let result = '';
28
+ for (let i = start; i < end; ++i) {
29
+ let codepoint = data[i];
30
+ if (codepoint > 0xFFFF) {
31
+ // JS strings are encoded as UTF16, thus a non BMP codepoint gets converted into a surrogate pair
32
+ // conversion rules:
33
+ // - subtract 0x10000 from code point, leaving a 20 bit number
34
+ // - add high 10 bits to 0xD800 --> first surrogate
35
+ // - add low 10 bits to 0xDC00 --> second surrogate
36
+ codepoint -= 0x10000;
37
+ result += String.fromCharCode((codepoint >> 10) + 0xD800) + String.fromCharCode((codepoint % 0x400) + 0xDC00);
38
+ } else {
39
+ result += String.fromCharCode(codepoint);
40
+ }
41
+ }
42
+ return result;
43
+ }
44
+
45
+ /**
46
+ * StringToUtf32 - decodes UTF16 sequences into UTF32 codepoints.
47
+ * To keep the decoder in line with JS strings it handles single surrogates as UCS2.
48
+ */
49
+ export class StringToUtf32 {
50
+ private _interim: number = 0;
51
+
52
+ /**
53
+ * Clears interim and resets decoder to clean state.
54
+ */
55
+ public clear(): void {
56
+ this._interim = 0;
57
+ }
58
+
59
+ /**
60
+ * Decode JS string to UTF32 codepoints.
61
+ * The methods assumes stream input and will store partly transmitted
62
+ * surrogate pairs and decode them with the next data chunk.
63
+ * Note: The method does no bound checks for target, therefore make sure
64
+ * the provided input data does not exceed the size of `target`.
65
+ * Returns the number of written codepoints in `target`.
66
+ */
67
+ public decode(input: string, target: Uint32Array): number {
68
+ const length = input.length;
69
+
70
+ if (!length) {
71
+ return 0;
72
+ }
73
+
74
+ let size = 0;
75
+ let startPos = 0;
76
+
77
+ // handle leftover surrogate high
78
+ if (this._interim) {
79
+ const second = input.charCodeAt(startPos++);
80
+ if (0xDC00 <= second && second <= 0xDFFF) {
81
+ target[size++] = (this._interim - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
82
+ } else {
83
+ // illegal codepoint (USC2 handling)
84
+ target[size++] = this._interim;
85
+ target[size++] = second;
86
+ }
87
+ this._interim = 0;
88
+ }
89
+
90
+ for (let i = startPos; i < length; ++i) {
91
+ const code = input.charCodeAt(i);
92
+ // surrogate pair first
93
+ if (0xD800 <= code && code <= 0xDBFF) {
94
+ if (++i >= length) {
95
+ this._interim = code;
96
+ return size;
97
+ }
98
+ const second = input.charCodeAt(i);
99
+ if (0xDC00 <= second && second <= 0xDFFF) {
100
+ target[size++] = (code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
101
+ } else {
102
+ // illegal codepoint (USC2 handling)
103
+ target[size++] = code;
104
+ target[size++] = second;
105
+ }
106
+ continue;
107
+ }
108
+ if (code === 0xFEFF) {
109
+ // BOM
110
+ continue;
111
+ }
112
+ target[size++] = code;
113
+ }
114
+ return size;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Utf8Decoder - decodes UTF8 byte sequences into UTF32 codepoints.
120
+ */
121
+ export class Utf8ToUtf32 {
122
+ public interim: Uint8Array = new Uint8Array(3);
123
+
124
+ /**
125
+ * Clears interim bytes and resets decoder to clean state.
126
+ */
127
+ public clear(): void {
128
+ this.interim.fill(0);
129
+ }
130
+
131
+ /**
132
+ * Decodes UTF8 byte sequences in `input` to UTF32 codepoints in `target`.
133
+ * The methods assumes stream input and will store partly transmitted bytes
134
+ * and decode them with the next data chunk.
135
+ * Note: The method does no bound checks for target, therefore make sure
136
+ * the provided data chunk does not exceed the size of `target`.
137
+ * Returns the number of written codepoints in `target`.
138
+ */
139
+ public decode(input: Uint8Array, target: Uint32Array): number {
140
+ const length = input.length;
141
+
142
+ if (!length) {
143
+ return 0;
144
+ }
145
+
146
+ let size = 0;
147
+ let byte1: number;
148
+ let byte2: number;
149
+ let byte3: number;
150
+ let byte4: number;
151
+ let codepoint = 0;
152
+ let startPos = 0;
153
+
154
+ // handle leftover bytes
155
+ if (this.interim[0]) {
156
+ let discardInterim = false;
157
+ let cp = this.interim[0];
158
+ cp &= ((((cp & 0xE0) === 0xC0)) ? 0x1F : (((cp & 0xF0) === 0xE0)) ? 0x0F : 0x07);
159
+ let pos = 0;
160
+ let tmp: number;
161
+ while ((tmp = this.interim[++pos] & 0x3F) && pos < 4) {
162
+ cp <<= 6;
163
+ cp |= tmp;
164
+ }
165
+ // missing bytes - read ahead from input
166
+ const type = (((this.interim[0] & 0xE0) === 0xC0)) ? 2 : (((this.interim[0] & 0xF0) === 0xE0)) ? 3 : 4;
167
+ const missing = type - pos;
168
+ while (startPos < missing) {
169
+ if (startPos >= length) {
170
+ return 0;
171
+ }
172
+ tmp = input[startPos++];
173
+ if ((tmp & 0xC0) !== 0x80) {
174
+ // wrong continuation, discard interim bytes completely
175
+ startPos--;
176
+ discardInterim = true;
177
+ break;
178
+ } else {
179
+ // need to save so we can continue short inputs in next call
180
+ this.interim[pos++] = tmp;
181
+ cp <<= 6;
182
+ cp |= tmp & 0x3F;
183
+ }
184
+ }
185
+ if (!discardInterim) {
186
+ // final test is type dependent
187
+ if (type === 2) {
188
+ if (cp < 0x80) {
189
+ // wrong starter byte
190
+ startPos--;
191
+ } else {
192
+ target[size++] = cp;
193
+ }
194
+ } else if (type === 3) {
195
+ if (cp < 0x0800 || (cp >= 0xD800 && cp <= 0xDFFF) || cp === 0xFEFF) {
196
+ // illegal codepoint or BOM
197
+ } else {
198
+ target[size++] = cp;
199
+ }
200
+ } else {
201
+ if (cp < 0x010000 || cp > 0x10FFFF) {
202
+ // illegal codepoint
203
+ } else {
204
+ target[size++] = cp;
205
+ }
206
+ }
207
+ }
208
+ this.interim.fill(0);
209
+ }
210
+
211
+ // loop through input
212
+ const fourStop = length - 4;
213
+ let i = startPos;
214
+ while (i < length) {
215
+ /**
216
+ * ASCII shortcut with loop unrolled to 4 consecutive ASCII chars.
217
+ * This is a compromise between speed gain for ASCII
218
+ * and penalty for non ASCII:
219
+ * For best ASCII performance the char should be stored directly into target,
220
+ * but even a single attempt to write to target and compare afterwards
221
+ * penalizes non ASCII really bad (-50%), thus we load the char into byteX first,
222
+ * which reduces ASCII performance by ~15%.
223
+ * This trial for ASCII reduces non ASCII performance by ~10% which seems acceptible
224
+ * compared to the gains.
225
+ * Note that this optimization only takes place for 4 consecutive ASCII chars,
226
+ * for any shorter it bails out. Worst case - all 4 bytes being read but
227
+ * thrown away due to the last being a non ASCII char (-10% performance).
228
+ */
229
+ while (i < fourStop
230
+ && !((byte1 = input[i]) & 0x80)
231
+ && !((byte2 = input[i + 1]) & 0x80)
232
+ && !((byte3 = input[i + 2]) & 0x80)
233
+ && !((byte4 = input[i + 3]) & 0x80))
234
+ {
235
+ target[size++] = byte1;
236
+ target[size++] = byte2;
237
+ target[size++] = byte3;
238
+ target[size++] = byte4;
239
+ i += 4;
240
+ }
241
+
242
+ // reread byte1
243
+ byte1 = input[i++];
244
+
245
+ // 1 byte
246
+ if (byte1 < 0x80) {
247
+ target[size++] = byte1;
248
+
249
+ // 2 bytes
250
+ } else if ((byte1 & 0xE0) === 0xC0) {
251
+ if (i >= length) {
252
+ this.interim[0] = byte1;
253
+ return size;
254
+ }
255
+ byte2 = input[i++];
256
+ if ((byte2 & 0xC0) !== 0x80) {
257
+ // wrong continuation
258
+ i--;
259
+ continue;
260
+ }
261
+ codepoint = (byte1 & 0x1F) << 6 | (byte2 & 0x3F);
262
+ if (codepoint < 0x80) {
263
+ // wrong starter byte
264
+ i--;
265
+ continue;
266
+ }
267
+ target[size++] = codepoint;
268
+
269
+ // 3 bytes
270
+ } else if ((byte1 & 0xF0) === 0xE0) {
271
+ if (i >= length) {
272
+ this.interim[0] = byte1;
273
+ return size;
274
+ }
275
+ byte2 = input[i++];
276
+ if ((byte2 & 0xC0) !== 0x80) {
277
+ // wrong continuation
278
+ i--;
279
+ continue;
280
+ }
281
+ if (i >= length) {
282
+ this.interim[0] = byte1;
283
+ this.interim[1] = byte2;
284
+ return size;
285
+ }
286
+ byte3 = input[i++];
287
+ if ((byte3 & 0xC0) !== 0x80) {
288
+ // wrong continuation
289
+ i--;
290
+ continue;
291
+ }
292
+ codepoint = (byte1 & 0x0F) << 12 | (byte2 & 0x3F) << 6 | (byte3 & 0x3F);
293
+ if (codepoint < 0x0800 || (codepoint >= 0xD800 && codepoint <= 0xDFFF) || codepoint === 0xFEFF) {
294
+ // illegal codepoint or BOM, no i-- here
295
+ continue;
296
+ }
297
+ target[size++] = codepoint;
298
+
299
+ // 4 bytes
300
+ } else if ((byte1 & 0xF8) === 0xF0) {
301
+ if (i >= length) {
302
+ this.interim[0] = byte1;
303
+ return size;
304
+ }
305
+ byte2 = input[i++];
306
+ if ((byte2 & 0xC0) !== 0x80) {
307
+ // wrong continuation
308
+ i--;
309
+ continue;
310
+ }
311
+ if (i >= length) {
312
+ this.interim[0] = byte1;
313
+ this.interim[1] = byte2;
314
+ return size;
315
+ }
316
+ byte3 = input[i++];
317
+ if ((byte3 & 0xC0) !== 0x80) {
318
+ // wrong continuation
319
+ i--;
320
+ continue;
321
+ }
322
+ if (i >= length) {
323
+ this.interim[0] = byte1;
324
+ this.interim[1] = byte2;
325
+ this.interim[2] = byte3;
326
+ return size;
327
+ }
328
+ byte4 = input[i++];
329
+ if ((byte4 & 0xC0) !== 0x80) {
330
+ // wrong continuation
331
+ i--;
332
+ continue;
333
+ }
334
+ codepoint = (byte1 & 0x07) << 18 | (byte2 & 0x3F) << 12 | (byte3 & 0x3F) << 6 | (byte4 & 0x3F);
335
+ if (codepoint < 0x010000 || codepoint > 0x10FFFF) {
336
+ // illegal codepoint, no i-- here
337
+ continue;
338
+ }
339
+ target[size++] = codepoint;
340
+ } else {
341
+ // illegal byte, just skip
342
+ }
343
+ }
344
+ return size;
345
+ }
346
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+ import { IUnicodeVersionProvider } from 'common/services/Services';
6
+ import { fill } from 'common/TypedArrayUtils';
7
+
8
+ type CharWidth = 0 | 1 | 2;
9
+
10
+ const BMP_COMBINING = [
11
+ [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
12
+ [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
13
+ [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
14
+ [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
15
+ [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
16
+ [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
17
+ [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
18
+ [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
19
+ [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
20
+ [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
21
+ [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
22
+ [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
23
+ [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
24
+ [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
25
+ [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
26
+ [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
27
+ [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
28
+ [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
29
+ [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
30
+ [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
31
+ [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
32
+ [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
33
+ [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
34
+ [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
35
+ [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
36
+ [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
37
+ [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
38
+ [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
39
+ [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
40
+ [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
41
+ [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
42
+ [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
43
+ [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
44
+ [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
45
+ [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
46
+ [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
47
+ [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
48
+ [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
49
+ [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
50
+ [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
51
+ [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
52
+ [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
53
+ [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB]
54
+ ];
55
+ const HIGH_COMBINING = [
56
+ [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
57
+ [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
58
+ [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
59
+ [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
60
+ [0xE0100, 0xE01EF]
61
+ ];
62
+
63
+ // BMP lookup table, lazy initialized during first addon loading
64
+ let table: Uint8Array;
65
+
66
+ function bisearch(ucs: number, data: number[][]): boolean {
67
+ let min = 0;
68
+ let max = data.length - 1;
69
+ let mid;
70
+ if (ucs < data[0][0] || ucs > data[max][1]) {
71
+ return false;
72
+ }
73
+ while (max >= min) {
74
+ mid = (min + max) >> 1;
75
+ if (ucs > data[mid][1]) {
76
+ min = mid + 1;
77
+ } else if (ucs < data[mid][0]) {
78
+ max = mid - 1;
79
+ } else {
80
+ return true;
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+
86
+ export class UnicodeV6 implements IUnicodeVersionProvider {
87
+ public readonly version = '6';
88
+
89
+ constructor() {
90
+ // init lookup table once
91
+ if (!table) {
92
+ table = new Uint8Array(65536);
93
+ fill(table, 1);
94
+ table[0] = 0;
95
+ // control chars
96
+ fill(table, 0, 1, 32);
97
+ fill(table, 0, 0x7f, 0xa0);
98
+
99
+ // apply wide char rules first
100
+ // wide chars
101
+ fill(table, 2, 0x1100, 0x1160);
102
+ table[0x2329] = 2;
103
+ table[0x232a] = 2;
104
+ fill(table, 2, 0x2e80, 0xa4d0);
105
+ table[0x303f] = 1; // wrongly in last line
106
+
107
+ fill(table, 2, 0xac00, 0xd7a4);
108
+ fill(table, 2, 0xf900, 0xfb00);
109
+ fill(table, 2, 0xfe10, 0xfe1a);
110
+ fill(table, 2, 0xfe30, 0xfe70);
111
+ fill(table, 2, 0xff00, 0xff61);
112
+ fill(table, 2, 0xffe0, 0xffe7);
113
+
114
+ // apply combining last to ensure we overwrite
115
+ // wrongly wide set chars:
116
+ // the original algo evals combining first and falls
117
+ // through to wide check so we simply do here the opposite
118
+ // combining 0
119
+ for (let r = 0; r < BMP_COMBINING.length; ++r) {
120
+ fill(table, 0, BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1);
121
+ }
122
+ }
123
+ }
124
+
125
+ public wcwidth(num: number): CharWidth {
126
+ if (num < 32) return 0;
127
+ if (num < 127) return 1;
128
+ if (num < 65536) return table[num] as CharWidth;
129
+ if (bisearch(num, HIGH_COMBINING)) return 0;
130
+ if ((num >= 0x20000 && num <= 0x2fffd) || (num >= 0x30000 && num <= 0x3fffd)) return 2;
131
+ return 1;
132
+ }
133
+ }
@@ -0,0 +1,229 @@
1
+
2
+ /**
3
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
4
+ * @license MIT
5
+ */
6
+
7
+ import { EventEmitter, IEvent } from 'common/EventEmitter';
8
+
9
+ declare const setTimeout: (handler: () => void, timeout?: number) => void;
10
+
11
+ /**
12
+ * Safety watermark to avoid memory exhaustion and browser engine crash on fast data input.
13
+ * Enable flow control to avoid this limit and make sure that your backend correctly
14
+ * propagates this to the underlying pty. (see docs for further instructions)
15
+ * Since this limit is meant as a safety parachute to prevent browser crashs,
16
+ * it is set to a very high number. Typically xterm.js gets unresponsive with
17
+ * a 100 times lower number (>500 kB).
18
+ */
19
+ const DISCARD_WATERMARK = 50000000; // ~50 MB
20
+
21
+ /**
22
+ * The max number of ms to spend on writes before allowing the renderer to
23
+ * catch up with a 0ms setTimeout. A value of < 33 to keep us close to
24
+ * 30fps, and a value of < 16 to try to run at 60fps. Of course, the real FPS
25
+ * depends on the time it takes for the renderer to draw the frame.
26
+ */
27
+ const WRITE_TIMEOUT_MS = 12;
28
+
29
+ /**
30
+ * Threshold of max held chunks in the write buffer, that were already processed.
31
+ * This is a tradeoff between extensive write buffer shifts (bad runtime) and high
32
+ * memory consumption by data thats not used anymore.
33
+ */
34
+ const WRITE_BUFFER_LENGTH_THRESHOLD = 50;
35
+
36
+ // queueMicrotask polyfill for nodejs < v11
37
+ const qmt: (cb: () => void) => void = (typeof queueMicrotask === 'undefined')
38
+ ? (cb: () => void) => { Promise.resolve().then(cb); }
39
+ : queueMicrotask;
40
+
41
+
42
+ export class WriteBuffer {
43
+ private _writeBuffer: (string | Uint8Array)[] = [];
44
+ private _callbacks: ((() => void) | undefined)[] = [];
45
+ private _pendingData = 0;
46
+ private _bufferOffset = 0;
47
+ private _isSyncWriting = false;
48
+ private _syncCalls = 0;
49
+ public get onWriteParsed(): IEvent<void> { return this._onWriteParsed.event; }
50
+ private _onWriteParsed = new EventEmitter<void>();
51
+
52
+ constructor(private _action: (data: string | Uint8Array, promiseResult?: boolean) => void | Promise<boolean>) { }
53
+
54
+ /**
55
+ * @deprecated Unreliable, to be removed soon.
56
+ */
57
+ public writeSync(data: string | Uint8Array, maxSubsequentCalls?: number): void {
58
+ // stop writeSync recursions with maxSubsequentCalls argument
59
+ // This is dangerous to use as it will lose the current data chunk
60
+ // and return immediately.
61
+ if (maxSubsequentCalls !== undefined && this._syncCalls > maxSubsequentCalls) {
62
+ // comment next line if a whole loop block should only contain x `writeSync` calls
63
+ // (total flat vs. deep nested limit)
64
+ this._syncCalls = 0;
65
+ return;
66
+ }
67
+ // append chunk to buffer
68
+ this._pendingData += data.length;
69
+ this._writeBuffer.push(data);
70
+ this._callbacks.push(undefined);
71
+
72
+ // increase recursion counter
73
+ this._syncCalls++;
74
+ // exit early if another writeSync loop is active
75
+ if (this._isSyncWriting) {
76
+ return;
77
+ }
78
+ this._isSyncWriting = true;
79
+
80
+ // force sync processing on pending data chunks to avoid in-band data scrambling
81
+ // does the same as innerWrite but without event loop
82
+ // we have to do it here as single loop steps to not corrupt loop subject
83
+ // by another writeSync call triggered from _action
84
+ let chunk: string | Uint8Array | undefined;
85
+ while (chunk = this._writeBuffer.shift()) {
86
+ this._action(chunk);
87
+ const cb = this._callbacks.shift();
88
+ if (cb) cb();
89
+ }
90
+ // reset to avoid reprocessing of chunks with scheduled innerWrite call
91
+ // stopping scheduled innerWrite by offset > length condition
92
+ this._pendingData = 0;
93
+ this._bufferOffset = 0x7FFFFFFF;
94
+
95
+ // allow another writeSync to loop
96
+ this._isSyncWriting = false;
97
+ this._syncCalls = 0;
98
+ }
99
+
100
+ public write(data: string | Uint8Array, callback?: () => void): void {
101
+ if (this._pendingData > DISCARD_WATERMARK) {
102
+ throw new Error('write data discarded, use flow control to avoid losing data');
103
+ }
104
+
105
+ // schedule chunk processing for next event loop run
106
+ if (!this._writeBuffer.length) {
107
+ this._bufferOffset = 0;
108
+ setTimeout(() => this._innerWrite());
109
+ }
110
+
111
+ this._pendingData += data.length;
112
+ this._writeBuffer.push(data);
113
+ this._callbacks.push(callback);
114
+ }
115
+
116
+ /**
117
+ * Inner write call, that enters the sliced chunk processing by timing.
118
+ *
119
+ * `lastTime` indicates, when the last _innerWrite call had started.
120
+ * It is used to aggregate async handler execution under a timeout constraint
121
+ * effectively lowering the redrawing needs, schematically:
122
+ *
123
+ * macroTask _innerWrite:
124
+ * if (Date.now() - (lastTime | 0) < WRITE_TIMEOUT_MS):
125
+ * schedule microTask _innerWrite(lastTime)
126
+ * else:
127
+ * schedule macroTask _innerWrite(0)
128
+ *
129
+ * overall execution order on task queues:
130
+ *
131
+ * macrotasks: [...] --> _innerWrite(0) --> [...] --> screenUpdate --> [...]
132
+ * m t: |
133
+ * i a: [...]
134
+ * c s: |
135
+ * r k: while < timeout:
136
+ * o s: _innerWrite(timeout)
137
+ *
138
+ * `promiseResult` depicts the promise resolve value of an async handler.
139
+ * This value gets carried forward through all saved stack states of the
140
+ * paused parser for proper continuation.
141
+ *
142
+ * Note, for pure sync code `lastTime` and `promiseResult` have no meaning.
143
+ */
144
+ protected _innerWrite(lastTime: number = 0, promiseResult: boolean = true): void {
145
+ const startTime = lastTime || Date.now();
146
+ while (this._writeBuffer.length > this._bufferOffset) {
147
+ const data = this._writeBuffer[this._bufferOffset];
148
+ const result = this._action(data, promiseResult);
149
+ if (result) {
150
+ /**
151
+ * If we get a promise as return value, we re-schedule the continuation
152
+ * as thenable on the promise and exit right away.
153
+ *
154
+ * The exit here means, that we block input processing at the current active chunk,
155
+ * the exact execution position within the chunk is preserved by the saved
156
+ * stack content in InputHandler and EscapeSequenceParser.
157
+ *
158
+ * Resuming happens automatically from that saved stack state.
159
+ * Also the resolved promise value is passed along the callstack to
160
+ * `EscapeSequenceParser.parse` to correctly resume the stopped handler loop.
161
+ *
162
+ * Exceptions on async handlers will be logged to console async, but do not interrupt
163
+ * the input processing (continues with next handler at the current input position).
164
+ */
165
+
166
+ /**
167
+ * If a promise takes long to resolve, we should schedule continuation behind setTimeout.
168
+ * This might already be too late, if our .then enters really late (executor + prev thens took very long).
169
+ * This cannot be solved here for the handler itself (it is the handlers responsibility to slice hard work),
170
+ * but we can at least schedule a screen update as we gain control.
171
+ */
172
+ const continuation: (r: boolean) => void = (r: boolean) => Date.now() - startTime >= WRITE_TIMEOUT_MS
173
+ ? setTimeout(() => this._innerWrite(0, r))
174
+ : this._innerWrite(startTime, r);
175
+
176
+ /**
177
+ * Optimization considerations:
178
+ * The continuation above favors FPS over throughput by eval'ing `startTime` on resolve.
179
+ * This might schedule too many screen updates with bad throughput drops (in case a slow
180
+ * resolving handler sliced its work properly behind setTimeout calls). We cannot spot
181
+ * this condition here, also the renderer has no way to spot nonsense updates either.
182
+ * FIXME: A proper fix for this would track the FPS at the renderer entry level separately.
183
+ *
184
+ * If favoring of FPS shows bad throughtput impact, use the following instead. It favors
185
+ * throughput by eval'ing `startTime` upfront pulling at least one more chunk into the
186
+ * current microtask queue (executed before setTimeout).
187
+ */
188
+ // const continuation: (r: boolean) => void = Date.now() - startTime >= WRITE_TIMEOUT_MS
189
+ // ? r => setTimeout(() => this._innerWrite(0, r))
190
+ // : r => this._innerWrite(startTime, r);
191
+
192
+ // Handle exceptions synchronously to current band position, idea:
193
+ // 1. spawn a single microtask which we allow to throw hard
194
+ // 2. spawn a promise immediately resolving to `true`
195
+ // (executed on the same queue, thus properly aligned before continuation happens)
196
+ result.catch(err => {
197
+ qmt(() => {throw err;});
198
+ return Promise.resolve(false);
199
+ }).then(continuation);
200
+ return;
201
+ }
202
+
203
+ const cb = this._callbacks[this._bufferOffset];
204
+ if (cb) cb();
205
+ this._bufferOffset++;
206
+ this._pendingData -= data.length;
207
+
208
+ if (Date.now() - startTime >= WRITE_TIMEOUT_MS) {
209
+ break;
210
+ }
211
+ }
212
+ if (this._writeBuffer.length > this._bufferOffset) {
213
+ // Allow renderer to catch up before processing the next batch
214
+ // trim already processed chunks if we are above threshold
215
+ if (this._bufferOffset > WRITE_BUFFER_LENGTH_THRESHOLD) {
216
+ this._writeBuffer = this._writeBuffer.slice(this._bufferOffset);
217
+ this._callbacks = this._callbacks.slice(this._bufferOffset);
218
+ this._bufferOffset = 0;
219
+ }
220
+ setTimeout(() => this._innerWrite());
221
+ } else {
222
+ this._writeBuffer.length = 0;
223
+ this._callbacks.length = 0;
224
+ this._pendingData = 0;
225
+ this._bufferOffset = 0;
226
+ }
227
+ this._onWriteParsed.fire();
228
+ }
229
+ }