@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,344 @@
1
+ /**
2
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IBufferLine, ICellData, IColor } from 'common/Types';
7
+ import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants';
8
+ import { NULL_CELL_CODE, WHITESPACE_CELL_CHAR, Attributes } from 'common/buffer/Constants';
9
+ import { CellData } from 'common/buffer/CellData';
10
+ import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
11
+ import { color, rgba } from 'common/Color';
12
+ import { IColorSet } from 'browser/Types';
13
+ import { ICharacterJoinerService, ISelectionService } from 'browser/services/Services';
14
+ import { JoinedCellData } from 'browser/services/CharacterJoinerService';
15
+ import { excludeFromContrastRatioDemands } from 'browser/renderer/RendererUtils';
16
+
17
+ export const BOLD_CLASS = 'xterm-bold';
18
+ export const DIM_CLASS = 'xterm-dim';
19
+ export const ITALIC_CLASS = 'xterm-italic';
20
+ export const UNDERLINE_CLASS = 'xterm-underline';
21
+ export const STRIKETHROUGH_CLASS = 'xterm-strikethrough';
22
+ export const CURSOR_CLASS = 'xterm-cursor';
23
+ export const CURSOR_BLINK_CLASS = 'xterm-cursor-blink';
24
+ export const CURSOR_STYLE_BLOCK_CLASS = 'xterm-cursor-block';
25
+ export const CURSOR_STYLE_BAR_CLASS = 'xterm-cursor-bar';
26
+ export const CURSOR_STYLE_UNDERLINE_CLASS = 'xterm-cursor-underline';
27
+
28
+ export class DomRendererRowFactory {
29
+ private _workCell: CellData = new CellData();
30
+
31
+ private _selectionStart: [number, number] | undefined;
32
+ private _selectionEnd: [number, number] | undefined;
33
+ private _columnSelectMode: boolean = false;
34
+
35
+ constructor(
36
+ private readonly _document: Document,
37
+ private _colors: IColorSet,
38
+ @ICharacterJoinerService private readonly _characterJoinerService: ICharacterJoinerService,
39
+ @IOptionsService private readonly _optionsService: IOptionsService,
40
+ @ICoreService private readonly _coreService: ICoreService,
41
+ @IDecorationService private readonly _decorationService: IDecorationService
42
+ ) {
43
+ }
44
+
45
+ public setColors(colors: IColorSet): void {
46
+ this._colors = colors;
47
+ }
48
+
49
+ public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void {
50
+ this._selectionStart = start;
51
+ this._selectionEnd = end;
52
+ this._columnSelectMode = columnSelectMode;
53
+ }
54
+
55
+ public createRow(lineData: IBufferLine, row: number, isCursorRow: boolean, cursorStyle: string | undefined, cursorX: number, cursorBlink: boolean, cellWidth: number, cols: number): DocumentFragment {
56
+ const fragment = this._document.createDocumentFragment();
57
+
58
+ const joinedRanges = this._characterJoinerService.getJoinedCharacters(row);
59
+ // Find the line length first, this prevents the need to output a bunch of
60
+ // empty cells at the end. This cannot easily be integrated into the main
61
+ // loop below because of the colCount feature (which can be removed after we
62
+ // properly support reflow and disallow data to go beyond the right-side of
63
+ // the viewport).
64
+ let lineLength = 0;
65
+ for (let x = Math.min(lineData.length, cols) - 1; x >= 0; x--) {
66
+ if (lineData.loadCell(x, this._workCell).getCode() !== NULL_CELL_CODE || (isCursorRow && x === cursorX)) {
67
+ lineLength = x + 1;
68
+ break;
69
+ }
70
+ }
71
+
72
+ for (let x = 0; x < lineLength; x++) {
73
+ lineData.loadCell(x, this._workCell);
74
+ let width = this._workCell.getWidth();
75
+
76
+ // The character to the left is a wide character, drawing is owned by the char at x-1
77
+ if (width === 0) {
78
+ continue;
79
+ }
80
+
81
+ // If true, indicates that the current character(s) to draw were joined.
82
+ let isJoined = false;
83
+ let lastCharX = x;
84
+
85
+ // Process any joined character ranges as needed. Because of how the
86
+ // ranges are produced, we know that they are valid for the characters
87
+ // and attributes of our input.
88
+ let cell = this._workCell;
89
+ if (joinedRanges.length > 0 && x === joinedRanges[0][0]) {
90
+ isJoined = true;
91
+ const range = joinedRanges.shift()!;
92
+
93
+ // We already know the exact start and end column of the joined range,
94
+ // so we get the string and width representing it directly
95
+ cell = new JoinedCellData(
96
+ this._workCell,
97
+ lineData.translateToString(true, range[0], range[1]),
98
+ range[1] - range[0]
99
+ );
100
+
101
+ // Skip over the cells occupied by this range in the loop
102
+ lastCharX = range[1] - 1;
103
+
104
+ // Recalculate width
105
+ width = cell.getWidth();
106
+ }
107
+
108
+ const charElement = this._document.createElement('span');
109
+ if (width > 1) {
110
+ charElement.style.width = `${cellWidth * width}px`;
111
+ }
112
+
113
+ if (isJoined) {
114
+ // Ligatures in the DOM renderer must use display inline, as they may not show with
115
+ // inline-block if they are outside the bounds of the element
116
+ charElement.style.display = 'inline';
117
+
118
+ // The DOM renderer colors the background of the cursor but for ligatures all cells are
119
+ // joined. The workaround here is to show a cursor around the whole ligature so it shows up,
120
+ // the cursor looks the same when on any character of the ligature though
121
+ if (cursorX >= x && cursorX <= lastCharX) {
122
+ cursorX = x;
123
+ }
124
+ }
125
+
126
+ if (!this._coreService.isCursorHidden && isCursorRow && x === cursorX) {
127
+ charElement.classList.add(CURSOR_CLASS);
128
+
129
+ if (cursorBlink) {
130
+ charElement.classList.add(CURSOR_BLINK_CLASS);
131
+ }
132
+
133
+ switch (cursorStyle) {
134
+ case 'bar':
135
+ charElement.classList.add(CURSOR_STYLE_BAR_CLASS);
136
+ break;
137
+ case 'underline':
138
+ charElement.classList.add(CURSOR_STYLE_UNDERLINE_CLASS);
139
+ break;
140
+ default:
141
+ charElement.classList.add(CURSOR_STYLE_BLOCK_CLASS);
142
+ break;
143
+ }
144
+ }
145
+
146
+ if (cell.isBold()) {
147
+ charElement.classList.add(BOLD_CLASS);
148
+ }
149
+
150
+ if (cell.isItalic()) {
151
+ charElement.classList.add(ITALIC_CLASS);
152
+ }
153
+
154
+ if (cell.isDim()) {
155
+ charElement.classList.add(DIM_CLASS);
156
+ }
157
+
158
+ if (cell.isUnderline()) {
159
+ charElement.classList.add(UNDERLINE_CLASS);
160
+ }
161
+
162
+ if (cell.isInvisible()) {
163
+ charElement.textContent = WHITESPACE_CELL_CHAR;
164
+ } else {
165
+ charElement.textContent = cell.getChars() || WHITESPACE_CELL_CHAR;
166
+ }
167
+
168
+ if (cell.isStrikethrough()) {
169
+ charElement.classList.add(STRIKETHROUGH_CLASS);
170
+ }
171
+
172
+ let fg = cell.getFgColor();
173
+ let fgColorMode = cell.getFgColorMode();
174
+ let bg = cell.getBgColor();
175
+ let bgColorMode = cell.getBgColorMode();
176
+ const isInverse = !!cell.isInverse();
177
+ if (isInverse) {
178
+ const temp = fg;
179
+ fg = bg;
180
+ bg = temp;
181
+ const temp2 = fgColorMode;
182
+ fgColorMode = bgColorMode;
183
+ bgColorMode = temp2;
184
+ }
185
+
186
+ // Apply any decoration foreground/background overrides, this must happen after inverse has
187
+ // been applied
188
+ let bgOverride: IColor | undefined;
189
+ let fgOverride: IColor | undefined;
190
+ let isTop = false;
191
+ for (const d of this._decorationService.getDecorationsAtCell(x, row)) {
192
+ if (d.options.layer !== 'top' && isTop) {
193
+ continue;
194
+ }
195
+ if (d.backgroundColorRGB) {
196
+ bgColorMode = Attributes.CM_RGB;
197
+ bg = d.backgroundColorRGB.rgba >> 8 & 0xFFFFFF;
198
+ bgOverride = d.backgroundColorRGB;
199
+ }
200
+ if (d.foregroundColorRGB) {
201
+ fgColorMode = Attributes.CM_RGB;
202
+ fg = d.foregroundColorRGB.rgba >> 8 & 0xFFFFFF;
203
+ fgOverride = d.foregroundColorRGB;
204
+ }
205
+ isTop = d.options.layer === 'top';
206
+ }
207
+
208
+ // Apply selection foreground if applicable
209
+ const isInSelection = this._isCellInSelection(x, row);
210
+ if (!isTop) {
211
+ if (this._colors.selectionForeground && isInSelection) {
212
+ fgColorMode = Attributes.CM_RGB;
213
+ fg = this._colors.selectionForeground.rgba >> 8 & 0xFFFFFF;
214
+ fgOverride = this._colors.selectionForeground;
215
+ }
216
+ }
217
+
218
+ // If in the selection, force the element to be above the selection to improve contrast and
219
+ // support opaque selections
220
+ if (isInSelection) {
221
+ bgOverride = this._colors.selectionOpaque;
222
+ isTop = true;
223
+ }
224
+
225
+ // If it's a top decoration, render above the selection
226
+ if (isTop) {
227
+ charElement.classList.add(`xterm-decoration-top`);
228
+ }
229
+
230
+ // Background
231
+ let resolvedBg: IColor;
232
+ switch (bgColorMode) {
233
+ case Attributes.CM_P16:
234
+ case Attributes.CM_P256:
235
+ resolvedBg = this._colors.ansi[bg];
236
+ charElement.classList.add(`xterm-bg-${bg}`);
237
+ break;
238
+ case Attributes.CM_RGB:
239
+ resolvedBg = rgba.toColor(bg >> 16, bg >> 8 & 0xFF, bg & 0xFF);
240
+ this._addStyle(charElement, `background-color:#${padStart((bg >>> 0).toString(16), '0', 6)}`);
241
+ break;
242
+ case Attributes.CM_DEFAULT:
243
+ default:
244
+ if (isInverse) {
245
+ resolvedBg = this._colors.foreground;
246
+ charElement.classList.add(`xterm-bg-${INVERTED_DEFAULT_COLOR}`);
247
+ } else {
248
+ resolvedBg = this._colors.background;
249
+ }
250
+ }
251
+
252
+ // Foreground
253
+ switch (fgColorMode) {
254
+ case Attributes.CM_P16:
255
+ case Attributes.CM_P256:
256
+ if (cell.isBold() && fg < 8 && this._optionsService.rawOptions.drawBoldTextInBrightColors) {
257
+ fg += 8;
258
+ }
259
+ if (!this._applyMinimumContrast(charElement, resolvedBg, this._colors.ansi[fg], cell, bgOverride, undefined)) {
260
+ charElement.classList.add(`xterm-fg-${fg}`);
261
+ }
262
+ break;
263
+ case Attributes.CM_RGB:
264
+ const color = rgba.toColor(
265
+ (fg >> 16) & 0xFF,
266
+ (fg >> 8) & 0xFF,
267
+ (fg ) & 0xFF
268
+ );
269
+ if (!this._applyMinimumContrast(charElement, resolvedBg, color, cell, bgOverride, fgOverride)) {
270
+ this._addStyle(charElement, `color:#${padStart(fg.toString(16), '0', 6)}`);
271
+ }
272
+ break;
273
+ case Attributes.CM_DEFAULT:
274
+ default:
275
+ if (!this._applyMinimumContrast(charElement, resolvedBg, this._colors.foreground, cell, bgOverride, undefined)) {
276
+ if (isInverse) {
277
+ charElement.classList.add(`xterm-fg-${INVERTED_DEFAULT_COLOR}`);
278
+ }
279
+ }
280
+ }
281
+
282
+ fragment.appendChild(charElement);
283
+
284
+ x = lastCharX;
285
+ }
286
+ return fragment;
287
+ }
288
+
289
+ private _applyMinimumContrast(element: HTMLElement, bg: IColor, fg: IColor, cell: ICellData, bgOverride: IColor | undefined, fgOverride: IColor | undefined): boolean {
290
+ if (this._optionsService.rawOptions.minimumContrastRatio === 1 || excludeFromContrastRatioDemands(cell.getCode())) {
291
+ return false;
292
+ }
293
+
294
+ // Try get from cache first, only use the cache when there are no decoration overrides
295
+ let adjustedColor: IColor | undefined | null = undefined;
296
+ if (!bgOverride && !fgOverride) {
297
+ adjustedColor = this._colors.contrastCache.getColor(bg.rgba, fg.rgba);
298
+ }
299
+
300
+ // Calculate and store in cache
301
+ if (adjustedColor === undefined) {
302
+ adjustedColor = color.ensureContrastRatio(bgOverride || bg, fgOverride || fg, this._optionsService.rawOptions.minimumContrastRatio);
303
+ this._colors.contrastCache.setColor((bgOverride || bg).rgba, (fgOverride || fg).rgba, adjustedColor ?? null);
304
+ }
305
+
306
+ if (adjustedColor) {
307
+ this._addStyle(element, `color:${adjustedColor.css}`);
308
+ return true;
309
+ }
310
+
311
+ return false;
312
+ }
313
+
314
+ private _addStyle(element: HTMLElement, style: string): void {
315
+ element.setAttribute('style', `${element.getAttribute('style') || ''}${style};`);
316
+ }
317
+
318
+ private _isCellInSelection(x: number, y: number): boolean {
319
+ const start = this._selectionStart;
320
+ const end = this._selectionEnd;
321
+ if (!start || !end) {
322
+ return false;
323
+ }
324
+ if (this._columnSelectMode) {
325
+ if (start[0] <= end[0]) {
326
+ return x >= start[0] && y >= start[1] &&
327
+ x < end[0] && y <= end[1];
328
+ }
329
+ return x < start[0] && y >= start[1] &&
330
+ x >= end[0] && y <= end[1];
331
+ }
332
+ return (y > start[1] && y < end[1]) ||
333
+ (start[1] === end[1] && y === start[1] && x >= start[0] && x < end[0]) ||
334
+ (start[1] < end[1] && y === end[1] && x < end[0]) ||
335
+ (start[1] < end[1] && y === start[1] && x >= start[0]);
336
+ }
337
+ }
338
+
339
+ function padStart(text: string, padChar: string, length: number): string {
340
+ while (text.length < length) {
341
+ text = padChar + text;
342
+ }
343
+ return text;
344
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IBufferService } from 'common/services/Services';
7
+
8
+ /**
9
+ * Represents a selection within the buffer. This model only cares about column
10
+ * and row coordinates, not wide characters.
11
+ */
12
+ export class SelectionModel {
13
+ /**
14
+ * Whether select all is currently active.
15
+ */
16
+ public isSelectAllActive: boolean = false;
17
+
18
+ /**
19
+ * The minimal length of the selection from the start position. When double
20
+ * clicking on a word, the word will be selected which makes the selection
21
+ * start at the start of the word and makes this variable the length.
22
+ */
23
+ public selectionStartLength: number = 0;
24
+
25
+ /**
26
+ * The [x, y] position the selection starts at.
27
+ */
28
+ public selectionStart: [number, number] | undefined;
29
+
30
+ /**
31
+ * The [x, y] position the selection ends at.
32
+ */
33
+ public selectionEnd: [number, number] | undefined;
34
+
35
+ constructor(
36
+ private _bufferService: IBufferService
37
+ ) {
38
+ }
39
+
40
+ /**
41
+ * Clears the current selection.
42
+ */
43
+ public clearSelection(): void {
44
+ this.selectionStart = undefined;
45
+ this.selectionEnd = undefined;
46
+ this.isSelectAllActive = false;
47
+ this.selectionStartLength = 0;
48
+ }
49
+
50
+ /**
51
+ * The final selection start, taking into consideration select all.
52
+ */
53
+ public get finalSelectionStart(): [number, number] | undefined {
54
+ if (this.isSelectAllActive) {
55
+ return [0, 0];
56
+ }
57
+
58
+ if (!this.selectionEnd || !this.selectionStart) {
59
+ return this.selectionStart;
60
+ }
61
+
62
+ return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
63
+ }
64
+
65
+ /**
66
+ * The final selection end, taking into consideration select all, double click
67
+ * word selection and triple click line selection.
68
+ */
69
+ public get finalSelectionEnd(): [number, number] | undefined {
70
+ if (this.isSelectAllActive) {
71
+ return [this._bufferService.cols, this._bufferService.buffer.ybase + this._bufferService.rows - 1];
72
+ }
73
+
74
+ if (!this.selectionStart) {
75
+ return undefined;
76
+ }
77
+
78
+ // Use the selection start + length if the end doesn't exist or they're reversed
79
+ if (!this.selectionEnd || this.areSelectionValuesReversed()) {
80
+ const startPlusLength = this.selectionStart[0] + this.selectionStartLength;
81
+ if (startPlusLength > this._bufferService.cols) {
82
+ // Ensure the trailing EOL isn't included when the selection ends on the right edge
83
+ if (startPlusLength % this._bufferService.cols === 0) {
84
+ return [this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols) - 1];
85
+ }
86
+ return [startPlusLength % this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols)];
87
+ }
88
+ return [startPlusLength, this.selectionStart[1]];
89
+ }
90
+
91
+ // Ensure the the word/line is selected after a double/triple click
92
+ if (this.selectionStartLength) {
93
+ // Select the larger of the two when start and end are on the same line
94
+ if (this.selectionEnd[1] === this.selectionStart[1]) {
95
+ // Keep the whole wrapped word/line selected if the content wraps multiple lines
96
+ const startPlusLength = this.selectionStart[0] + this.selectionStartLength;
97
+ if (startPlusLength > this._bufferService.cols) {
98
+ return [startPlusLength % this._bufferService.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._bufferService.cols)];
99
+ }
100
+ return [Math.max(startPlusLength, this.selectionEnd[0]), this.selectionEnd[1]];
101
+ }
102
+ }
103
+ return this.selectionEnd;
104
+ }
105
+
106
+ /**
107
+ * Returns whether the selection start and end are reversed.
108
+ */
109
+ public areSelectionValuesReversed(): boolean {
110
+ const start = this.selectionStart;
111
+ const end = this.selectionEnd;
112
+ if (!start || !end) {
113
+ return false;
114
+ }
115
+ return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
116
+ }
117
+
118
+ /**
119
+ * Handle the buffer being trimmed, adjust the selection position.
120
+ * @param amount The amount the buffer is being trimmed.
121
+ * @return Whether a refresh is necessary.
122
+ */
123
+ public onTrim(amount: number): boolean {
124
+ // Adjust the selection position based on the trimmed amount.
125
+ if (this.selectionStart) {
126
+ this.selectionStart[1] -= amount;
127
+ }
128
+ if (this.selectionEnd) {
129
+ this.selectionEnd[1] -= amount;
130
+ }
131
+
132
+ // The selection has moved off the buffer, clear it.
133
+ if (this.selectionEnd && this.selectionEnd[1] < 0) {
134
+ this.clearSelection();
135
+ return true;
136
+ }
137
+
138
+ // If the selection start is trimmed, ensure the start column is 0.
139
+ if (this.selectionStart && this.selectionStart[1] < 0) {
140
+ this.selectionStart[1] = 0;
141
+ }
142
+ return false;
143
+ }
144
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ export interface ISelectionRedrawRequestEvent {
7
+ start: [number, number] | undefined;
8
+ end: [number, number] | undefined;
9
+ columnSelectMode: boolean;
10
+ }
11
+
12
+ export interface ISelectionRequestScrollLinesEvent {
13
+ amount: number;
14
+ suppressScrollEvent: boolean;
15
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Copyright (c) 2016 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { IOptionsService } from 'common/services/Services';
7
+ import { IEvent, EventEmitter } from 'common/EventEmitter';
8
+ import { ICharSizeService } from 'browser/services/Services';
9
+
10
+ export class CharSizeService implements ICharSizeService {
11
+ public serviceBrand: undefined;
12
+
13
+ public width: number = 0;
14
+ public height: number = 0;
15
+ private _measureStrategy: IMeasureStrategy;
16
+
17
+ public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
18
+
19
+ private _onCharSizeChange = new EventEmitter<void>();
20
+ public get onCharSizeChange(): IEvent<void> { return this._onCharSizeChange.event; }
21
+
22
+ constructor(
23
+ document: Document,
24
+ parentElement: HTMLElement,
25
+ @IOptionsService private readonly _optionsService: IOptionsService
26
+ ) {
27
+ this._measureStrategy = new DomMeasureStrategy(document, parentElement, this._optionsService);
28
+ }
29
+
30
+ public measure(): void {
31
+ const result = this._measureStrategy.measure();
32
+ if (result.width !== this.width || result.height !== this.height) {
33
+ this.width = result.width;
34
+ this.height = result.height;
35
+ this._onCharSizeChange.fire();
36
+ }
37
+ }
38
+ }
39
+
40
+ interface IMeasureStrategy {
41
+ measure(): IReadonlyMeasureResult;
42
+ }
43
+
44
+ interface IReadonlyMeasureResult {
45
+ readonly width: number;
46
+ readonly height: number;
47
+ }
48
+
49
+ interface IMeasureResult {
50
+ width: number;
51
+ height: number;
52
+ }
53
+
54
+ // TODO: For supporting browsers we should also provide a CanvasCharDimensionsProvider that uses ctx.measureText
55
+ class DomMeasureStrategy implements IMeasureStrategy {
56
+ private _result: IMeasureResult = { width: 0, height: 0 };
57
+ private _measureElement: HTMLElement;
58
+
59
+ constructor(
60
+ private _document: Document,
61
+ private _parentElement: HTMLElement,
62
+ private _optionsService: IOptionsService
63
+ ) {
64
+ this._measureElement = this._document.createElement('span');
65
+ this._measureElement.classList.add('xterm-char-measure-element');
66
+ this._measureElement.textContent = 'W';
67
+ this._measureElement.setAttribute('aria-hidden', 'true');
68
+ this._parentElement.appendChild(this._measureElement);
69
+ }
70
+
71
+ public measure(): IReadonlyMeasureResult {
72
+ this._measureElement.style.fontFamily = this._optionsService.rawOptions.fontFamily;
73
+ this._measureElement.style.fontSize = `${this._optionsService.rawOptions.fontSize}px`;
74
+
75
+ // Note that this triggers a synchronous layout
76
+ const geometry = this._measureElement.getBoundingClientRect();
77
+
78
+ // If values are 0 then the element is likely currently display:none, in which case we should
79
+ // retain the previous value.
80
+ if (geometry.width !== 0 && geometry.height !== 0) {
81
+ this._result.width = geometry.width;
82
+ this._result.height = Math.ceil(geometry.height);
83
+ }
84
+
85
+ return this._result;
86
+ }
87
+ }