@xterm/xterm 5.6.0-beta.1 → 5.6.0-beta.100

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 (129) hide show
  1. package/README.md +10 -3
  2. package/css/xterm.css +71 -4
  3. package/lib/xterm.js +1 -1
  4. package/lib/xterm.js.map +1 -1
  5. package/lib/xterm.mjs +53 -0
  6. package/lib/xterm.mjs.map +7 -0
  7. package/package.json +43 -33
  8. package/src/browser/AccessibilityManager.ts +53 -25
  9. package/src/browser/{Terminal.ts → CoreBrowserTerminal.ts} +138 -147
  10. package/src/browser/Linkifier.ts +26 -14
  11. package/src/browser/LocalizableStrings.ts +15 -4
  12. package/src/browser/{Types.d.ts → Types.ts} +67 -15
  13. package/src/browser/Viewport.ts +143 -357
  14. package/src/browser/decorations/BufferDecorationRenderer.ts +14 -9
  15. package/src/browser/decorations/OverviewRulerRenderer.ts +40 -44
  16. package/src/browser/input/CompositionHelper.ts +2 -1
  17. package/src/browser/public/Terminal.ts +31 -23
  18. package/src/browser/renderer/dom/DomRenderer.ts +22 -19
  19. package/src/browser/renderer/dom/DomRendererRowFactory.ts +35 -15
  20. package/src/browser/renderer/shared/Constants.ts +0 -8
  21. package/src/browser/renderer/shared/Types.ts +84 -0
  22. package/src/browser/services/CharSizeService.ts +6 -6
  23. package/src/browser/services/CoreBrowserService.ts +15 -15
  24. package/src/browser/services/LinkProviderService.ts +2 -2
  25. package/src/browser/services/RenderService.ts +20 -20
  26. package/src/browser/services/SelectionService.ts +8 -8
  27. package/src/browser/services/Services.ts +13 -13
  28. package/src/browser/services/ThemeService.ts +19 -58
  29. package/src/browser/shared/Constants.ts +8 -0
  30. package/src/common/CircularList.ts +5 -5
  31. package/src/common/CoreTerminal.ts +35 -41
  32. package/src/common/InputHandler.ts +83 -56
  33. package/src/common/SortedList.ts +86 -10
  34. package/src/common/{Types.d.ts → Types.ts} +13 -17
  35. package/src/common/buffer/Buffer.ts +89 -8
  36. package/src/common/buffer/BufferReflow.ts +9 -6
  37. package/src/common/buffer/BufferSet.ts +5 -5
  38. package/src/common/buffer/Marker.ts +4 -4
  39. package/src/common/buffer/{Types.d.ts → Types.ts} +2 -2
  40. package/src/common/input/WriteBuffer.ts +3 -3
  41. package/src/common/parser/EscapeSequenceParser.ts +4 -4
  42. package/src/common/public/BufferNamespaceApi.ts +3 -3
  43. package/src/common/services/BufferService.ts +7 -7
  44. package/src/common/services/CoreMouseService.ts +5 -3
  45. package/src/common/services/CoreService.ts +8 -6
  46. package/src/common/services/DecorationService.ts +10 -10
  47. package/src/common/services/InstantiationService.ts +1 -1
  48. package/src/common/services/LogService.ts +2 -2
  49. package/src/common/services/OptionsService.ts +8 -6
  50. package/src/common/services/ServiceRegistry.ts +1 -1
  51. package/src/common/services/Services.ts +27 -17
  52. package/src/common/services/UnicodeService.ts +2 -2
  53. package/src/vs/base/browser/browser.ts +141 -0
  54. package/src/vs/base/browser/canIUse.ts +49 -0
  55. package/src/vs/base/browser/dom.ts +2369 -0
  56. package/src/vs/base/browser/fastDomNode.ts +316 -0
  57. package/src/vs/base/browser/globalPointerMoveMonitor.ts +112 -0
  58. package/src/vs/base/browser/iframe.ts +135 -0
  59. package/src/vs/base/browser/keyboardEvent.ts +213 -0
  60. package/src/vs/base/browser/mouseEvent.ts +229 -0
  61. package/src/vs/base/browser/touch.ts +372 -0
  62. package/src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts +303 -0
  63. package/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts +114 -0
  64. package/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +720 -0
  65. package/src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts +165 -0
  66. package/src/vs/base/browser/ui/scrollbar/scrollbarArrow.ts +114 -0
  67. package/src/vs/base/browser/ui/scrollbar/scrollbarState.ts +243 -0
  68. package/src/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts +118 -0
  69. package/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts +116 -0
  70. package/src/vs/base/browser/ui/widget.ts +57 -0
  71. package/src/vs/base/browser/window.ts +14 -0
  72. package/src/vs/base/common/arrays.ts +887 -0
  73. package/src/vs/base/common/arraysFind.ts +202 -0
  74. package/src/vs/base/common/assert.ts +71 -0
  75. package/src/vs/base/common/async.ts +1992 -0
  76. package/src/vs/base/common/cancellation.ts +148 -0
  77. package/src/vs/base/common/charCode.ts +450 -0
  78. package/src/vs/base/common/collections.ts +140 -0
  79. package/src/vs/base/common/decorators.ts +130 -0
  80. package/src/vs/base/common/equals.ts +146 -0
  81. package/src/vs/base/common/errors.ts +303 -0
  82. package/src/vs/base/common/event.ts +1778 -0
  83. package/src/vs/base/common/functional.ts +32 -0
  84. package/src/vs/base/common/hash.ts +316 -0
  85. package/src/vs/base/common/iterator.ts +159 -0
  86. package/src/vs/base/common/keyCodes.ts +526 -0
  87. package/src/vs/base/common/keybindings.ts +284 -0
  88. package/src/vs/base/common/lazy.ts +47 -0
  89. package/src/vs/base/common/lifecycle.ts +801 -0
  90. package/src/vs/base/common/linkedList.ts +142 -0
  91. package/src/vs/base/common/map.ts +202 -0
  92. package/src/vs/base/common/numbers.ts +98 -0
  93. package/src/vs/base/common/observable.ts +76 -0
  94. package/src/vs/base/common/observableInternal/api.ts +31 -0
  95. package/src/vs/base/common/observableInternal/autorun.ts +281 -0
  96. package/src/vs/base/common/observableInternal/base.ts +489 -0
  97. package/src/vs/base/common/observableInternal/debugName.ts +145 -0
  98. package/src/vs/base/common/observableInternal/derived.ts +428 -0
  99. package/src/vs/base/common/observableInternal/lazyObservableValue.ts +146 -0
  100. package/src/vs/base/common/observableInternal/logging.ts +328 -0
  101. package/src/vs/base/common/observableInternal/promise.ts +209 -0
  102. package/src/vs/base/common/observableInternal/utils.ts +610 -0
  103. package/src/vs/base/common/platform.ts +281 -0
  104. package/src/vs/base/common/scrollable.ts +522 -0
  105. package/src/vs/base/common/sequence.ts +34 -0
  106. package/src/vs/base/common/stopwatch.ts +43 -0
  107. package/src/vs/base/common/strings.ts +557 -0
  108. package/src/vs/base/common/symbols.ts +9 -0
  109. package/src/vs/base/common/uint.ts +59 -0
  110. package/src/vs/patches/nls.ts +90 -0
  111. package/src/vs/typings/base-common.d.ts +20 -0
  112. package/src/vs/typings/require.d.ts +42 -0
  113. package/src/vs/typings/thenable.d.ts +12 -0
  114. package/src/vs/typings/vscode-globals-nls.d.ts +36 -0
  115. package/src/vs/typings/vscode-globals-product.d.ts +33 -0
  116. package/typings/xterm.d.ts +73 -15
  117. package/src/browser/Lifecycle.ts +0 -33
  118. package/src/browser/renderer/shared/CellColorResolver.ts +0 -236
  119. package/src/browser/renderer/shared/CharAtlasCache.ts +0 -96
  120. package/src/browser/renderer/shared/CharAtlasUtils.ts +0 -75
  121. package/src/browser/renderer/shared/CursorBlinkStateManager.ts +0 -146
  122. package/src/browser/renderer/shared/CustomGlyphs.ts +0 -687
  123. package/src/browser/renderer/shared/DevicePixelObserver.ts +0 -41
  124. package/src/browser/renderer/shared/TextureAtlas.ts +0 -1100
  125. package/src/browser/renderer/shared/Types.d.ts +0 -173
  126. package/src/common/EventEmitter.ts +0 -78
  127. package/src/common/Lifecycle.ts +0 -108
  128. /package/src/browser/selection/{Types.d.ts → Types.ts} +0 -0
  129. /package/src/common/parser/{Types.d.ts → Types.ts} +0 -0
@@ -0,0 +1,20 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ // Declare types that we probe for to implement util and/or polyfill functions
7
+
8
+ declare global {
9
+
10
+ interface IdleDeadline {
11
+ readonly didTimeout: boolean;
12
+ timeRemaining(): number;
13
+ }
14
+
15
+ function requestIdleCallback(callback: (args: IdleDeadline) => void, options?: { timeout: number }): number;
16
+ function cancelIdleCallback(handle: number): void;
17
+
18
+ }
19
+
20
+ export { }
@@ -0,0 +1,42 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ declare class LoaderEvent {
7
+ readonly type: number;
8
+ readonly timestamp: number;
9
+ readonly detail: string;
10
+ }
11
+
12
+ declare const define: {
13
+ (moduleName: string, dependencies: string[], callback: (...args: any[]) => any): any;
14
+ (moduleName: string, dependencies: string[], definition: any): any;
15
+ (moduleName: string, callback: (...args: any[]) => any): any;
16
+ (moduleName: string, definition: any): any;
17
+ (dependencies: string[], callback: (...args: any[]) => any): any;
18
+ (dependencies: string[], definition: any): any;
19
+ };
20
+
21
+ interface NodeRequire {
22
+ /**
23
+ * @deprecated use `FileAccess.asFileUri()` for node.js contexts or `FileAccess.asBrowserUri` for browser contexts.
24
+ */
25
+ toUrl(path: string): string;
26
+
27
+ /**
28
+ * @deprecated MUST not be used anymore
29
+ *
30
+ * With the move from AMD to ESM we cannot use this anymore. There will be NO MORE node require like this.
31
+ */
32
+ __$__nodeRequire<T>(moduleName: string): T;
33
+
34
+ (dependencies: string[], callback: (...args: any[]) => any, errorback?: (err: any) => void): any;
35
+ config(data: any): any;
36
+ onError: Function;
37
+ getStats?(): ReadonlyArray<LoaderEvent>;
38
+ hasDependencyCycle?(): boolean;
39
+ define(amdModuleId: string, dependencies: string[], callback: (...args: any[]) => any): any;
40
+ }
41
+
42
+ declare var require: NodeRequire;
@@ -0,0 +1,12 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ /**
7
+ * Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
8
+ * and others. This API makes no assumption about what promise library is being used which
9
+ * enables reusing existing code without migrating to a specific promise implementation. Still,
10
+ * we recommend the use of native promises which are available in VS Code.
11
+ */
12
+ interface Thenable<T> extends PromiseLike<T> { }
@@ -0,0 +1,36 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ // AMD2ESM mirgation relevant
7
+
8
+ /**
9
+ * NLS Globals: these need to be defined in all contexts that make
10
+ * use of our `nls.localize` and `nls.localize2` functions. This includes:
11
+ * - Electron main process
12
+ * - Electron window (renderer) process
13
+ * - Utility Process
14
+ * - Node.js
15
+ * - Browser
16
+ * - Web worker
17
+ *
18
+ * That is because during build time we strip out all english strings from
19
+ * the resulting JS code and replace it with a <number> that is then looked
20
+ * up from the `_VSCODE_NLS_MESSAGES` array.
21
+ */
22
+ declare global {
23
+ /**
24
+ * All NLS messages produced by `localize` and `localize2` calls
25
+ * under `src/vs` translated to the language as indicated by
26
+ * `_VSCODE_NLS_LANGUAGE`.
27
+ */
28
+ var _VSCODE_NLS_MESSAGES: string[];
29
+ /**
30
+ * The actual language of the NLS messages (e.g. 'en', de' or 'pt-br').
31
+ */
32
+ var _VSCODE_NLS_LANGUAGE: string | undefined;
33
+ }
34
+
35
+ // fake export to make global work
36
+ export { }
@@ -0,0 +1,33 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ // AMD2ESM mirgation relevant
7
+
8
+ declare global {
9
+
10
+ /**
11
+ * Holds the file root for resources.
12
+ */
13
+ var _VSCODE_FILE_ROOT: string;
14
+
15
+ /**
16
+ * CSS loader that's available during development time.
17
+ * DO NOT call directly, instead just import css modules, like `import 'some.css'`
18
+ */
19
+ var _VSCODE_CSS_LOAD: (module: string) => void;
20
+
21
+ /**
22
+ * @deprecated You MUST use `IProductService` whenever possible.
23
+ */
24
+ var _VSCODE_PRODUCT_JSON: Record<string, any>;
25
+ /**
26
+ * @deprecated You MUST use `IProductService` whenever possible.
27
+ */
28
+ var _VSCODE_PACKAGE_JSON: Record<string, any>;
29
+
30
+ }
31
+
32
+ // fake export to make global work
33
+ export { }
@@ -47,11 +47,13 @@ declare module '@xterm/xterm' {
47
47
 
48
48
  /**
49
49
  * When enabled the cursor will be set to the beginning of the next line
50
- * with every new line. This is equivalent to sending '\r\n' for each '\n'.
51
- * Normally the termios settings of the underlying PTY deals with the
52
- * translation of '\n' to '\r\n' and this setting should not be used. If you
50
+ * with every new line. This is equivalent to sending `\r\n` for each `\n`.
51
+ * Normally the settings of the underlying PTY (`termios`) deal with the
52
+ * translation of `\n` to `\r\n` and this setting should not be used. If you
53
53
  * deal with data from a non-PTY related source, this settings might be
54
54
  * useful.
55
+ *
56
+ * @see https://pubs.opengroup.org/onlinepubs/007904975/basedefs/termios.h.html
55
57
  */
56
58
  convertEol?: boolean;
57
59
 
@@ -107,11 +109,13 @@ declare module '@xterm/xterm' {
107
109
 
108
110
  /**
109
111
  * The modifier key hold to multiply scroll speed.
112
+ * @deprecated This option is no longer available and will always use alt.
113
+ * Setting this will be ignored.
110
114
  */
111
115
  fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';
112
116
 
113
117
  /**
114
- * The scroll speed multiplier used for fast scrolling.
118
+ * The scroll speed multiplier used for fast scrolling when `Alt` is held.
115
119
  */
116
120
  fastScrollSensitivity?: number;
117
121
 
@@ -209,6 +213,13 @@ declare module '@xterm/xterm' {
209
213
  */
210
214
  minimumContrastRatio?: number;
211
215
 
216
+ /**
217
+ * Whether to reflow the line containing the cursor when the terminal is
218
+ * resized. Defaults to false, because shells usually handle this
219
+ * themselves.
220
+ */
221
+ reflowCursorLine?: boolean;
222
+
212
223
  /**
213
224
  * Whether to rescale glyphs horizontally that are a single cell wide but
214
225
  * have glyphs that would overlap following cell(s). This typically happens
@@ -246,6 +257,13 @@ declare module '@xterm/xterm' {
246
257
  */
247
258
  scrollback?: number;
248
259
 
260
+ /**
261
+ * If enabled the Erase in Display All (ED2) escape sequence will push
262
+ * erased text to scrollback, instead of clearing only the viewport portion.
263
+ * This emulates PuTTY's default clear screen behavior.
264
+ */
265
+ scrollOnEraseInDisplay?: boolean;
266
+
249
267
  /**
250
268
  * Whether to scroll to the bottom whenever there is some user input. The
251
269
  * default is true.
@@ -323,10 +341,10 @@ declare module '@xterm/xterm' {
323
341
  windowOptions?: IWindowOptions;
324
342
 
325
343
  /**
326
- * The width, in pixels, of the canvas for the overview ruler. The overview
327
- * ruler will be hidden when not set.
344
+ * Controls the visibility and style of the overview ruler which visualizes
345
+ * decorations underneath the scroll bar.
328
346
  */
329
- overviewRulerWidth?: number;
347
+ overviewRuler?: IOverviewRulerOptions;
330
348
  }
331
349
 
332
350
  /**
@@ -366,6 +384,27 @@ declare module '@xterm/xterm' {
366
384
  * be transparent)
367
385
  */
368
386
  selectionInactiveBackground?: string;
387
+ /**
388
+ * The scrollbar slider background color. Defaults to
389
+ * {@link ITerminalOptions.foreground foreground} with 20% opacity.
390
+ */
391
+ scrollbarSliderBackground?: string;
392
+ /**
393
+ * The scrollbar slider background color when hovered. Defaults to
394
+ * {@link ITerminalOptions.foreground foreground} with 40% opacity.
395
+ */
396
+ scrollbarSliderHoverBackground?: string;
397
+ /**
398
+ * The scrollbar slider background color when clicked. Defaults to
399
+ * {@link ITerminalOptions.foreground foreground} with 50% opacity.
400
+ */
401
+ scrollbarSliderActiveBackground?: string;
402
+ /**
403
+ * The border color of the overview ruler. This visually separates the
404
+ * terminal from the scroll bar when {@link IOverviewRulerOptions.width} is
405
+ * set. When this is not set it defaults to black (`#000000`).
406
+ */
407
+ overviewRulerBorder?: string;
369
408
  /** ANSI black (eg. `\x1b[30m`) */
370
409
  black?: string;
371
410
  /** ANSI red (eg. `\x1b[31m`) */
@@ -586,16 +625,13 @@ declare module '@xterm/xterm' {
586
625
  * What layer to render the decoration at when {@link backgroundColor} or
587
626
  * {@link foregroundColor} are used. `'bottom'` will render under the
588
627
  * selection, `'top`' will render above the selection\*.
589
- *
590
- * *\* The selection will render on top regardless of layer on the canvas
591
- * renderer due to how it renders selection separately.*
592
628
  */
593
629
  readonly layer?: 'bottom' | 'top';
594
630
 
595
631
  /**
596
632
  * When defined, renders the decoration in the overview ruler to the right
597
- * of the terminal. {@link ITerminalOptions.overviewRulerWidth} must be set
598
- * in order to see the overview ruler.
633
+ * of the terminal. {@link IOverviewRulerOptions.width} must be set in order
634
+ * to see the overview ruler.
599
635
  * @param color The color of the decoration.
600
636
  * @param position The position of the decoration.
601
637
  */
@@ -618,6 +654,28 @@ declare module '@xterm/xterm' {
618
654
  tooMuchOutput: string;
619
655
  }
620
656
 
657
+ export interface IOverviewRulerOptions {
658
+ /**
659
+ * When defined, renders decorations in the overview ruler to the right of
660
+ * the terminal. This must be set in order to see the overview ruler.
661
+ * @param color The color of the decoration.
662
+ * @param position The position of the decoration.
663
+ */
664
+ width?: number;
665
+
666
+ /**
667
+ * Whether to show the top border of the overview ruler, which uses the
668
+ * {@link ITheme.overviewRulerBorder} color.
669
+ */
670
+ showTopBorder?: boolean;
671
+
672
+ /**
673
+ * Whether to show the bottom border of the overview ruler, which uses the
674
+ * {@link ITheme.overviewRulerBorder} color.
675
+ */
676
+ showBottomBorder?: boolean;
677
+ }
678
+
621
679
  /**
622
680
  * Enable various window manipulation and report features
623
681
  * (`CSI Ps ; Ps ; Ps t`).
@@ -1090,7 +1148,7 @@ declare module '@xterm/xterm' {
1090
1148
  * render together, since they aren't drawn as optimally as individual
1091
1149
  * characters.
1092
1150
  *
1093
- * NOTE: character joiners are only used by the canvas renderer.
1151
+ * NOTE: character joiners are only used by the webgl renderer.
1094
1152
  *
1095
1153
  * @param handler The function that determines character joins. It is called
1096
1154
  * with a string of text that is eligible for joining and returns an array
@@ -1102,7 +1160,7 @@ declare module '@xterm/xterm' {
1102
1160
 
1103
1161
  /**
1104
1162
  * (EXPERIMENTAL) Deregisters the character joiner if one was registered.
1105
- * NOTE: character joiners are only used by the canvas renderer.
1163
+ * NOTE: character joiners are only used by the webgl renderer.
1106
1164
  * @param joinerId The character joiner's ID (returned after register)
1107
1165
  */
1108
1166
  deregisterCharacterJoiner(joinerId: number): void;
@@ -1241,7 +1299,7 @@ declare module '@xterm/xterm' {
1241
1299
  refresh(start: number, end: number): void;
1242
1300
 
1243
1301
  /**
1244
- * Clears the texture atlas of the canvas renderer if it's active. Doing
1302
+ * Clears the texture atlas of the webgl renderer if it's active. Doing
1245
1303
  * this will force a redraw of all glyphs which can workaround issues
1246
1304
  * causing the texture to become corrupt, for example Chromium/Nvidia has an
1247
1305
  * issue where the texture gets messed up when resuming the OS from sleep.
@@ -1,33 +0,0 @@
1
- /**
2
- * Copyright (c) 2018 The xterm.js authors. All rights reserved.
3
- * @license MIT
4
- */
5
-
6
- import { IDisposable } from 'common/Types';
7
-
8
- /**
9
- * Adds a disposable listener to a node in the DOM, returning the disposable.
10
- * @param node The node to add a listener to.
11
- * @param type The event type.
12
- * @param handler The handler for the listener.
13
- * @param options The boolean or options object to pass on to the event
14
- * listener.
15
- */
16
- export function addDisposableDomListener(
17
- node: Element | Window | Document,
18
- type: string,
19
- handler: (e: any) => void,
20
- options?: boolean | AddEventListenerOptions
21
- ): IDisposable {
22
- node.addEventListener(type, handler, options);
23
- let disposed = false;
24
- return {
25
- dispose: () => {
26
- if (disposed) {
27
- return;
28
- }
29
- disposed = true;
30
- node.removeEventListener(type, handler, options);
31
- }
32
- };
33
- }
@@ -1,236 +0,0 @@
1
- import { ISelectionRenderModel } from 'browser/renderer/shared/Types';
2
- import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
3
- import { ReadonlyColorSet } from 'browser/Types';
4
- import { Attributes, BgFlags, ExtFlags, FgFlags, NULL_CELL_CODE, UnderlineStyle } from 'common/buffer/Constants';
5
- import { IDecorationService, IOptionsService } from 'common/services/Services';
6
- import { ICellData } from 'common/Types';
7
- import { Terminal } from '@xterm/xterm';
8
- import { rgba } from 'common/Color';
9
- import { treatGlyphAsBackgroundColor } from 'browser/renderer/shared/RendererUtils';
10
-
11
- // Work variables to avoid garbage collection
12
- let $fg = 0;
13
- let $bg = 0;
14
- let $hasFg = false;
15
- let $hasBg = false;
16
- let $isSelected = false;
17
- let $colors: ReadonlyColorSet | undefined;
18
- let $variantOffset = 0;
19
-
20
- export class CellColorResolver {
21
- /**
22
- * The shared result of the {@link resolve} call. This is only safe to use immediately after as
23
- * any other calls will share object.
24
- */
25
- public readonly result: { fg: number, bg: number, ext: number } = {
26
- fg: 0,
27
- bg: 0,
28
- ext: 0
29
- };
30
-
31
- constructor(
32
- private readonly _terminal: Terminal,
33
- private readonly _optionService: IOptionsService,
34
- private readonly _selectionRenderModel: ISelectionRenderModel,
35
- private readonly _decorationService: IDecorationService,
36
- private readonly _coreBrowserService: ICoreBrowserService,
37
- private readonly _themeService: IThemeService
38
- ) {
39
- }
40
-
41
- /**
42
- * Resolves colors for the cell, putting the result into the shared {@link result}. This resolves
43
- * overrides, inverse and selection for the cell which can then be used to feed into the renderer.
44
- */
45
- public resolve(cell: ICellData, x: number, y: number, deviceCellWidth: number): void {
46
- this.result.bg = cell.bg;
47
- this.result.fg = cell.fg;
48
- this.result.ext = cell.bg & BgFlags.HAS_EXTENDED ? cell.extended.ext : 0;
49
- // Get any foreground/background overrides, this happens on the model to avoid spreading
50
- // override logic throughout the different sub-renderers
51
-
52
- // Reset overrides work variables
53
- $bg = 0;
54
- $fg = 0;
55
- $hasBg = false;
56
- $hasFg = false;
57
- $isSelected = false;
58
- $colors = this._themeService.colors;
59
- $variantOffset = 0;
60
-
61
- const code = cell.getCode();
62
- if (code !== NULL_CELL_CODE && cell.extended.underlineStyle === UnderlineStyle.DOTTED) {
63
- const lineWidth = Math.max(1, Math.floor(this._optionService.rawOptions.fontSize * this._coreBrowserService.dpr / 15));
64
- $variantOffset = x * deviceCellWidth % (Math.round(lineWidth) * 2);
65
- }
66
-
67
- // Apply decorations on the bottom layer
68
- this._decorationService.forEachDecorationAtCell(x, y, 'bottom', d => {
69
- if (d.backgroundColorRGB) {
70
- $bg = d.backgroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
71
- $hasBg = true;
72
- }
73
- if (d.foregroundColorRGB) {
74
- $fg = d.foregroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
75
- $hasFg = true;
76
- }
77
- });
78
-
79
- // Apply the selection color if needed
80
- $isSelected = this._selectionRenderModel.isCellSelected(this._terminal, x, y);
81
- if ($isSelected) {
82
- // If the cell has a bg color, retain the color by blending it with the selection color
83
- if (
84
- (this.result.fg & FgFlags.INVERSE) ||
85
- (this.result.bg & Attributes.CM_MASK) !== Attributes.CM_DEFAULT
86
- ) {
87
- // Resolve the standard bg color
88
- if (this.result.fg & FgFlags.INVERSE) {
89
- switch (this.result.fg & Attributes.CM_MASK) {
90
- case Attributes.CM_P16:
91
- case Attributes.CM_P256:
92
- $bg = this._themeService.colors.ansi[this.result.fg & Attributes.PCOLOR_MASK].rgba;
93
- break;
94
- case Attributes.CM_RGB:
95
- $bg = ((this.result.fg & Attributes.RGB_MASK) << 8) | 0xFF;
96
- break;
97
- case Attributes.CM_DEFAULT:
98
- default:
99
- $bg = this._themeService.colors.foreground.rgba;
100
- }
101
- } else {
102
- switch (this.result.bg & Attributes.CM_MASK) {
103
- case Attributes.CM_P16:
104
- case Attributes.CM_P256:
105
- $bg = this._themeService.colors.ansi[this.result.bg & Attributes.PCOLOR_MASK].rgba;
106
- break;
107
- case Attributes.CM_RGB:
108
- $bg = ((this.result.bg & Attributes.RGB_MASK) << 8) | 0xFF;
109
- break;
110
- // No need to consider default bg color here as it's not possible
111
- }
112
- }
113
- // Blend with selection bg color
114
- $bg = rgba.blend(
115
- $bg,
116
- ((this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba & 0xFFFFFF00) | 0x80
117
- ) >> 8 & Attributes.RGB_MASK;
118
- } else {
119
- $bg = (this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba >> 8 & Attributes.RGB_MASK;
120
- }
121
- $hasBg = true;
122
-
123
- // Apply explicit selection foreground if present
124
- if ($colors.selectionForeground) {
125
- $fg = $colors.selectionForeground.rgba >> 8 & Attributes.RGB_MASK;
126
- $hasFg = true;
127
- }
128
-
129
- // Overwrite fg as bg if it's a special decorative glyph (eg. powerline)
130
- if (treatGlyphAsBackgroundColor(cell.getCode())) {
131
- // Inverse default background should be treated as transparent
132
- if (
133
- (this.result.fg & FgFlags.INVERSE) &&
134
- (this.result.bg & Attributes.CM_MASK) === Attributes.CM_DEFAULT
135
- ) {
136
- $fg = (this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba >> 8 & Attributes.RGB_MASK;
137
- } else {
138
-
139
- if (this.result.fg & FgFlags.INVERSE) {
140
- switch (this.result.bg & Attributes.CM_MASK) {
141
- case Attributes.CM_P16:
142
- case Attributes.CM_P256:
143
- $fg = this._themeService.colors.ansi[this.result.bg & Attributes.PCOLOR_MASK].rgba;
144
- break;
145
- case Attributes.CM_RGB:
146
- $fg = ((this.result.bg & Attributes.RGB_MASK) << 8) | 0xFF;
147
- break;
148
- // No need to consider default bg color here as it's not possible
149
- }
150
- } else {
151
- switch (this.result.fg & Attributes.CM_MASK) {
152
- case Attributes.CM_P16:
153
- case Attributes.CM_P256:
154
- $fg = this._themeService.colors.ansi[this.result.fg & Attributes.PCOLOR_MASK].rgba;
155
- break;
156
- case Attributes.CM_RGB:
157
- $fg = ((this.result.fg & Attributes.RGB_MASK) << 8) | 0xFF;
158
- break;
159
- case Attributes.CM_DEFAULT:
160
- default:
161
- $fg = this._themeService.colors.foreground.rgba;
162
- }
163
- }
164
-
165
- $fg = rgba.blend(
166
- $fg,
167
- ((this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba & 0xFFFFFF00) | 0x80
168
- ) >> 8 & Attributes.RGB_MASK;
169
- }
170
- $hasFg = true;
171
- }
172
- }
173
-
174
- // Apply decorations on the top layer
175
- this._decorationService.forEachDecorationAtCell(x, y, 'top', d => {
176
- if (d.backgroundColorRGB) {
177
- $bg = d.backgroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
178
- $hasBg = true;
179
- }
180
- if (d.foregroundColorRGB) {
181
- $fg = d.foregroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
182
- $hasFg = true;
183
- }
184
- });
185
-
186
- // Convert any overrides from rgba to the fg/bg packed format. This resolves the inverse flag
187
- // ahead of time in order to use the correct cache key
188
- if ($hasBg) {
189
- if ($isSelected) {
190
- // Non-RGB attributes from model + force non-dim + override + force RGB color mode
191
- $bg = (cell.bg & ~Attributes.RGB_MASK & ~BgFlags.DIM) | $bg | Attributes.CM_RGB;
192
- } else {
193
- // Non-RGB attributes from model + override + force RGB color mode
194
- $bg = (cell.bg & ~Attributes.RGB_MASK) | $bg | Attributes.CM_RGB;
195
- }
196
- }
197
- if ($hasFg) {
198
- // Non-RGB attributes from model + force disable inverse + override + force RGB color mode
199
- $fg = (cell.fg & ~Attributes.RGB_MASK & ~FgFlags.INVERSE) | $fg | Attributes.CM_RGB;
200
- }
201
-
202
- // Handle case where inverse was specified by only one of bg override or fg override was set,
203
- // resolving the other inverse color and setting the inverse flag if needed.
204
- if (this.result.fg & FgFlags.INVERSE) {
205
- if ($hasBg && !$hasFg) {
206
- // Resolve bg color type (default color has a different meaning in fg vs bg)
207
- if ((this.result.bg & Attributes.CM_MASK) === Attributes.CM_DEFAULT) {
208
- $fg = (this.result.fg & ~(Attributes.RGB_MASK | FgFlags.INVERSE | Attributes.CM_MASK)) | (($colors.background.rgba >> 8 & Attributes.RGB_MASK) & Attributes.RGB_MASK) | Attributes.CM_RGB;
209
- } else {
210
- $fg = (this.result.fg & ~(Attributes.RGB_MASK | FgFlags.INVERSE | Attributes.CM_MASK)) | this.result.bg & (Attributes.RGB_MASK | Attributes.CM_MASK);
211
- }
212
- $hasFg = true;
213
- }
214
- if (!$hasBg && $hasFg) {
215
- // Resolve bg color type (default color has a different meaning in fg vs bg)
216
- if ((this.result.fg & Attributes.CM_MASK) === Attributes.CM_DEFAULT) {
217
- $bg = (this.result.bg & ~(Attributes.RGB_MASK | Attributes.CM_MASK)) | (($colors.foreground.rgba >> 8 & Attributes.RGB_MASK) & Attributes.RGB_MASK) | Attributes.CM_RGB;
218
- } else {
219
- $bg = (this.result.bg & ~(Attributes.RGB_MASK | Attributes.CM_MASK)) | this.result.fg & (Attributes.RGB_MASK | Attributes.CM_MASK);
220
- }
221
- $hasBg = true;
222
- }
223
- }
224
-
225
- // Release object
226
- $colors = undefined;
227
-
228
- // Use the override if it exists
229
- this.result.bg = $hasBg ? $bg : this.result.bg;
230
- this.result.fg = $hasFg ? $fg : this.result.fg;
231
-
232
- // Reset overrides variantOffset
233
- this.result.ext &= ~ExtFlags.VARIANT_OFFSET;
234
- this.result.ext |= ($variantOffset << 29) & ExtFlags.VARIANT_OFFSET;
235
- }
236
- }