groove-dev 0.16.1 → 0.16.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 (203) hide show
  1. package/node_modules/@groove-dev/daemon/src/index.js +25 -7
  2. package/node_modules/@groove-dev/daemon/src/terminal-pty.js +141 -0
  3. package/node_modules/@groove-dev/gui/dist/assets/{index-Gfb8Zxy9.css → index-BhjOFLBc.css} +32 -1
  4. package/node_modules/@groove-dev/gui/dist/assets/index-CFeltwTB.js +153 -0
  5. package/node_modules/@groove-dev/gui/dist/index.html +2 -2
  6. package/node_modules/@groove-dev/gui/package.json +3 -0
  7. package/node_modules/@groove-dev/gui/src/components/EditorTabs.jsx +3 -3
  8. package/node_modules/@groove-dev/gui/src/components/FileTree.jsx +18 -22
  9. package/node_modules/@groove-dev/gui/src/components/Terminal.jsx +154 -0
  10. package/node_modules/@groove-dev/gui/src/views/FileEditor.jsx +100 -39
  11. package/node_modules/@xterm/addon-fit/LICENSE +19 -0
  12. package/node_modules/@xterm/addon-fit/README.md +24 -0
  13. package/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
  14. package/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
  15. package/node_modules/@xterm/addon-fit/lib/addon-fit.mjs +18 -0
  16. package/node_modules/@xterm/addon-fit/lib/addon-fit.mjs.map +7 -0
  17. package/node_modules/@xterm/addon-fit/package.json +26 -0
  18. package/node_modules/@xterm/addon-fit/src/FitAddon.ts +92 -0
  19. package/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
  20. package/node_modules/@xterm/addon-web-links/LICENSE +19 -0
  21. package/node_modules/@xterm/addon-web-links/README.md +21 -0
  22. package/node_modules/@xterm/addon-web-links/lib/addon-web-links.js +2 -0
  23. package/node_modules/@xterm/addon-web-links/lib/addon-web-links.js.map +1 -0
  24. package/node_modules/@xterm/addon-web-links/lib/addon-web-links.mjs +18 -0
  25. package/node_modules/@xterm/addon-web-links/lib/addon-web-links.mjs.map +7 -0
  26. package/node_modules/@xterm/addon-web-links/package.json +26 -0
  27. package/node_modules/@xterm/addon-web-links/src/WebLinkProvider.ts +199 -0
  28. package/node_modules/@xterm/addon-web-links/src/WebLinksAddon.ts +58 -0
  29. package/node_modules/@xterm/addon-web-links/typings/addon-web-links.d.ts +57 -0
  30. package/node_modules/@xterm/xterm/LICENSE +21 -0
  31. package/node_modules/@xterm/xterm/README.md +243 -0
  32. package/node_modules/@xterm/xterm/css/xterm.css +285 -0
  33. package/node_modules/@xterm/xterm/lib/xterm.js +2 -0
  34. package/node_modules/@xterm/xterm/lib/xterm.js.map +1 -0
  35. package/node_modules/@xterm/xterm/lib/xterm.mjs +53 -0
  36. package/node_modules/@xterm/xterm/lib/xterm.mjs.map +7 -0
  37. package/node_modules/@xterm/xterm/package.json +111 -0
  38. package/node_modules/@xterm/xterm/src/browser/AccessibilityManager.ts +435 -0
  39. package/node_modules/@xterm/xterm/src/browser/Clipboard.ts +93 -0
  40. package/node_modules/@xterm/xterm/src/browser/ColorContrastCache.ts +34 -0
  41. package/node_modules/@xterm/xterm/src/browser/CoreBrowserTerminal.ts +1339 -0
  42. package/node_modules/@xterm/xterm/src/browser/Linkifier.ts +403 -0
  43. package/node_modules/@xterm/xterm/src/browser/LocalizableStrings.ts +23 -0
  44. package/node_modules/@xterm/xterm/src/browser/OscLinkProvider.ts +129 -0
  45. package/node_modules/@xterm/xterm/src/browser/RenderDebouncer.ts +84 -0
  46. package/node_modules/@xterm/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
  47. package/node_modules/@xterm/xterm/src/browser/Types.ts +226 -0
  48. package/node_modules/@xterm/xterm/src/browser/Viewport.ts +192 -0
  49. package/node_modules/@xterm/xterm/src/browser/decorations/BufferDecorationRenderer.ts +139 -0
  50. package/node_modules/@xterm/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
  51. package/node_modules/@xterm/xterm/src/browser/decorations/OverviewRulerRenderer.ts +214 -0
  52. package/node_modules/@xterm/xterm/src/browser/input/CompositionHelper.ts +248 -0
  53. package/node_modules/@xterm/xterm/src/browser/input/Mouse.ts +54 -0
  54. package/node_modules/@xterm/xterm/src/browser/input/MoveToCell.ts +251 -0
  55. package/node_modules/@xterm/xterm/src/browser/public/Terminal.ts +275 -0
  56. package/node_modules/@xterm/xterm/src/browser/renderer/dom/DomRenderer.ts +542 -0
  57. package/node_modules/@xterm/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +546 -0
  58. package/node_modules/@xterm/xterm/src/browser/renderer/dom/WidthCache.ts +167 -0
  59. package/node_modules/@xterm/xterm/src/browser/renderer/shared/Constants.ts +6 -0
  60. package/node_modules/@xterm/xterm/src/browser/renderer/shared/RendererUtils.ts +95 -0
  61. package/node_modules/@xterm/xterm/src/browser/renderer/shared/SelectionRenderModel.ts +93 -0
  62. package/node_modules/@xterm/xterm/src/browser/renderer/shared/Types.ts +84 -0
  63. package/node_modules/@xterm/xterm/src/browser/selection/SelectionModel.ts +144 -0
  64. package/node_modules/@xterm/xterm/src/browser/selection/Types.ts +15 -0
  65. package/node_modules/@xterm/xterm/src/browser/services/CharSizeService.ts +127 -0
  66. package/node_modules/@xterm/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
  67. package/node_modules/@xterm/xterm/src/browser/services/CoreBrowserService.ts +137 -0
  68. package/node_modules/@xterm/xterm/src/browser/services/LinkProviderService.ts +28 -0
  69. package/node_modules/@xterm/xterm/src/browser/services/MouseService.ts +46 -0
  70. package/node_modules/@xterm/xterm/src/browser/services/RenderService.ts +376 -0
  71. package/node_modules/@xterm/xterm/src/browser/services/SelectionService.ts +1039 -0
  72. package/node_modules/@xterm/xterm/src/browser/services/Services.ts +158 -0
  73. package/node_modules/@xterm/xterm/src/browser/services/ThemeService.ts +198 -0
  74. package/node_modules/@xterm/xterm/src/browser/shared/Constants.ts +8 -0
  75. package/node_modules/@xterm/xterm/src/common/CircularList.ts +241 -0
  76. package/node_modules/@xterm/xterm/src/common/Clone.ts +23 -0
  77. package/node_modules/@xterm/xterm/src/common/Color.ts +376 -0
  78. package/node_modules/@xterm/xterm/src/common/CoreTerminal.ts +283 -0
  79. package/node_modules/@xterm/xterm/src/common/InputHandler.ts +3495 -0
  80. package/node_modules/@xterm/xterm/src/common/MultiKeyMap.ts +42 -0
  81. package/node_modules/@xterm/xterm/src/common/Platform.ts +44 -0
  82. package/node_modules/@xterm/xterm/src/common/SortedList.ts +194 -0
  83. package/node_modules/@xterm/xterm/src/common/TaskQueue.ts +166 -0
  84. package/node_modules/@xterm/xterm/src/common/TypedArrayUtils.ts +17 -0
  85. package/node_modules/@xterm/xterm/src/common/Types.ts +552 -0
  86. package/node_modules/@xterm/xterm/src/common/WindowsMode.ts +27 -0
  87. package/node_modules/@xterm/xterm/src/common/buffer/AttributeData.ts +211 -0
  88. package/node_modules/@xterm/xterm/src/common/buffer/Buffer.ts +662 -0
  89. package/node_modules/@xterm/xterm/src/common/buffer/BufferLine.ts +551 -0
  90. package/node_modules/@xterm/xterm/src/common/buffer/BufferRange.ts +13 -0
  91. package/node_modules/@xterm/xterm/src/common/buffer/BufferReflow.ts +226 -0
  92. package/node_modules/@xterm/xterm/src/common/buffer/BufferSet.ts +134 -0
  93. package/node_modules/@xterm/xterm/src/common/buffer/CellData.ts +94 -0
  94. package/node_modules/@xterm/xterm/src/common/buffer/Constants.ts +157 -0
  95. package/node_modules/@xterm/xterm/src/common/buffer/Marker.ts +43 -0
  96. package/node_modules/@xterm/xterm/src/common/buffer/Types.ts +52 -0
  97. package/node_modules/@xterm/xterm/src/common/data/Charsets.ts +256 -0
  98. package/node_modules/@xterm/xterm/src/common/data/EscapeSequences.ts +153 -0
  99. package/node_modules/@xterm/xterm/src/common/input/Keyboard.ts +373 -0
  100. package/node_modules/@xterm/xterm/src/common/input/TextDecoder.ts +346 -0
  101. package/node_modules/@xterm/xterm/src/common/input/UnicodeV6.ts +145 -0
  102. package/node_modules/@xterm/xterm/src/common/input/WriteBuffer.ts +247 -0
  103. package/node_modules/@xterm/xterm/src/common/input/XParseColor.ts +80 -0
  104. package/node_modules/@xterm/xterm/src/common/parser/Constants.ts +58 -0
  105. package/node_modules/@xterm/xterm/src/common/parser/DcsParser.ts +192 -0
  106. package/node_modules/@xterm/xterm/src/common/parser/EscapeSequenceParser.ts +792 -0
  107. package/node_modules/@xterm/xterm/src/common/parser/OscParser.ts +238 -0
  108. package/node_modules/@xterm/xterm/src/common/parser/Params.ts +229 -0
  109. package/node_modules/@xterm/xterm/src/common/parser/Types.ts +275 -0
  110. package/node_modules/@xterm/xterm/src/common/public/AddonManager.ts +53 -0
  111. package/node_modules/@xterm/xterm/src/common/public/BufferApiView.ts +35 -0
  112. package/node_modules/@xterm/xterm/src/common/public/BufferLineApiView.ts +29 -0
  113. package/node_modules/@xterm/xterm/src/common/public/BufferNamespaceApi.ts +36 -0
  114. package/node_modules/@xterm/xterm/src/common/public/ParserApi.ts +37 -0
  115. package/node_modules/@xterm/xterm/src/common/public/UnicodeApi.ts +27 -0
  116. package/node_modules/@xterm/xterm/src/common/services/BufferService.ts +154 -0
  117. package/node_modules/@xterm/xterm/src/common/services/CharsetService.ts +34 -0
  118. package/node_modules/@xterm/xterm/src/common/services/CoreMouseService.ts +365 -0
  119. package/node_modules/@xterm/xterm/src/common/services/CoreService.ts +92 -0
  120. package/node_modules/@xterm/xterm/src/common/services/DecorationService.ts +140 -0
  121. package/node_modules/@xterm/xterm/src/common/services/InstantiationService.ts +85 -0
  122. package/node_modules/@xterm/xterm/src/common/services/LogService.ts +124 -0
  123. package/node_modules/@xterm/xterm/src/common/services/OptionsService.ts +212 -0
  124. package/node_modules/@xterm/xterm/src/common/services/OscLinkService.ts +115 -0
  125. package/node_modules/@xterm/xterm/src/common/services/ServiceRegistry.ts +49 -0
  126. package/node_modules/@xterm/xterm/src/common/services/Services.ts +396 -0
  127. package/node_modules/@xterm/xterm/src/common/services/UnicodeService.ts +111 -0
  128. package/node_modules/@xterm/xterm/src/vs/base/browser/browser.ts +141 -0
  129. package/node_modules/@xterm/xterm/src/vs/base/browser/canIUse.ts +49 -0
  130. package/node_modules/@xterm/xterm/src/vs/base/browser/dom.ts +2369 -0
  131. package/node_modules/@xterm/xterm/src/vs/base/browser/fastDomNode.ts +316 -0
  132. package/node_modules/@xterm/xterm/src/vs/base/browser/globalPointerMoveMonitor.ts +112 -0
  133. package/node_modules/@xterm/xterm/src/vs/base/browser/iframe.ts +135 -0
  134. package/node_modules/@xterm/xterm/src/vs/base/browser/keyboardEvent.ts +213 -0
  135. package/node_modules/@xterm/xterm/src/vs/base/browser/mouseEvent.ts +229 -0
  136. package/node_modules/@xterm/xterm/src/vs/base/browser/touch.ts +372 -0
  137. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts +303 -0
  138. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts +114 -0
  139. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +720 -0
  140. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts +165 -0
  141. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/scrollbarArrow.ts +114 -0
  142. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/scrollbarState.ts +243 -0
  143. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts +118 -0
  144. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts +116 -0
  145. package/node_modules/@xterm/xterm/src/vs/base/browser/ui/widget.ts +57 -0
  146. package/node_modules/@xterm/xterm/src/vs/base/browser/window.ts +14 -0
  147. package/node_modules/@xterm/xterm/src/vs/base/common/arrays.ts +887 -0
  148. package/node_modules/@xterm/xterm/src/vs/base/common/arraysFind.ts +202 -0
  149. package/node_modules/@xterm/xterm/src/vs/base/common/assert.ts +71 -0
  150. package/node_modules/@xterm/xterm/src/vs/base/common/async.ts +1992 -0
  151. package/node_modules/@xterm/xterm/src/vs/base/common/cancellation.ts +148 -0
  152. package/node_modules/@xterm/xterm/src/vs/base/common/charCode.ts +450 -0
  153. package/node_modules/@xterm/xterm/src/vs/base/common/collections.ts +140 -0
  154. package/node_modules/@xterm/xterm/src/vs/base/common/decorators.ts +130 -0
  155. package/node_modules/@xterm/xterm/src/vs/base/common/equals.ts +146 -0
  156. package/node_modules/@xterm/xterm/src/vs/base/common/errors.ts +303 -0
  157. package/node_modules/@xterm/xterm/src/vs/base/common/event.ts +1778 -0
  158. package/node_modules/@xterm/xterm/src/vs/base/common/functional.ts +32 -0
  159. package/node_modules/@xterm/xterm/src/vs/base/common/hash.ts +316 -0
  160. package/node_modules/@xterm/xterm/src/vs/base/common/iterator.ts +159 -0
  161. package/node_modules/@xterm/xterm/src/vs/base/common/keyCodes.ts +526 -0
  162. package/node_modules/@xterm/xterm/src/vs/base/common/keybindings.ts +284 -0
  163. package/node_modules/@xterm/xterm/src/vs/base/common/lazy.ts +47 -0
  164. package/node_modules/@xterm/xterm/src/vs/base/common/lifecycle.ts +801 -0
  165. package/node_modules/@xterm/xterm/src/vs/base/common/linkedList.ts +142 -0
  166. package/node_modules/@xterm/xterm/src/vs/base/common/map.ts +202 -0
  167. package/node_modules/@xterm/xterm/src/vs/base/common/numbers.ts +98 -0
  168. package/node_modules/@xterm/xterm/src/vs/base/common/observable.ts +76 -0
  169. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/api.ts +31 -0
  170. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/autorun.ts +281 -0
  171. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/base.ts +489 -0
  172. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/debugName.ts +145 -0
  173. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/derived.ts +428 -0
  174. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/lazyObservableValue.ts +146 -0
  175. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/logging.ts +328 -0
  176. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/promise.ts +209 -0
  177. package/node_modules/@xterm/xterm/src/vs/base/common/observableInternal/utils.ts +610 -0
  178. package/node_modules/@xterm/xterm/src/vs/base/common/platform.ts +281 -0
  179. package/node_modules/@xterm/xterm/src/vs/base/common/scrollable.ts +522 -0
  180. package/node_modules/@xterm/xterm/src/vs/base/common/sequence.ts +34 -0
  181. package/node_modules/@xterm/xterm/src/vs/base/common/stopwatch.ts +43 -0
  182. package/node_modules/@xterm/xterm/src/vs/base/common/strings.ts +557 -0
  183. package/node_modules/@xterm/xterm/src/vs/base/common/symbols.ts +9 -0
  184. package/node_modules/@xterm/xterm/src/vs/base/common/uint.ts +59 -0
  185. package/node_modules/@xterm/xterm/src/vs/patches/nls.ts +90 -0
  186. package/node_modules/@xterm/xterm/src/vs/typings/base-common.d.ts +20 -0
  187. package/node_modules/@xterm/xterm/src/vs/typings/require.d.ts +42 -0
  188. package/node_modules/@xterm/xterm/src/vs/typings/vscode-globals-nls.d.ts +36 -0
  189. package/node_modules/@xterm/xterm/src/vs/typings/vscode-globals-product.d.ts +33 -0
  190. package/node_modules/@xterm/xterm/typings/xterm.d.ts +1957 -0
  191. package/package.json +1 -1
  192. package/packages/daemon/src/index.js +25 -7
  193. package/packages/daemon/src/terminal-pty.js +141 -0
  194. package/packages/gui/dist/assets/{index-Gfb8Zxy9.css → index-BhjOFLBc.css} +32 -1
  195. package/packages/gui/dist/assets/index-CFeltwTB.js +153 -0
  196. package/packages/gui/dist/index.html +2 -2
  197. package/packages/gui/package.json +3 -0
  198. package/packages/gui/src/components/EditorTabs.jsx +3 -3
  199. package/packages/gui/src/components/FileTree.jsx +18 -22
  200. package/packages/gui/src/components/Terminal.jsx +154 -0
  201. package/packages/gui/src/views/FileEditor.jsx +100 -39
  202. package/node_modules/@groove-dev/gui/dist/assets/index-BQSznoq0.js +0 -103
  203. package/packages/gui/dist/assets/index-BQSznoq0.js +0 -103
@@ -0,0 +1,662 @@
1
+ /**
2
+ * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { CircularList, IInsertEvent } from 'common/CircularList';
7
+ import { IdleTaskQueue } from 'common/TaskQueue';
8
+ import { IAttributeData, IBufferLine, ICellData, ICharset } from 'common/Types';
9
+ import { ExtendedAttrs } from 'common/buffer/AttributeData';
10
+ import { BufferLine, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
11
+ import { getWrappedLineTrimmedLength, reflowLargerApplyNewLayout, reflowLargerCreateNewLayout, reflowLargerGetLinesToRemove, reflowSmallerGetNewLineLengths } from 'common/buffer/BufferReflow';
12
+ import { CellData } from 'common/buffer/CellData';
13
+ import { NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE, WHITESPACE_CELL_WIDTH } from 'common/buffer/Constants';
14
+ import { Marker } from 'common/buffer/Marker';
15
+ import { IBuffer } from 'common/buffer/Types';
16
+ import { DEFAULT_CHARSET } from 'common/data/Charsets';
17
+ import { IBufferService, IOptionsService } from 'common/services/Services';
18
+
19
+ export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1
20
+
21
+ /**
22
+ * This class represents a terminal buffer (an internal state of the terminal), where the
23
+ * following information is stored (in high-level):
24
+ * - text content of this particular buffer
25
+ * - cursor position
26
+ * - scroll position
27
+ */
28
+ export class Buffer implements IBuffer {
29
+ public lines: CircularList<IBufferLine>;
30
+ public ydisp: number = 0;
31
+ public ybase: number = 0;
32
+ public y: number = 0;
33
+ public x: number = 0;
34
+ public scrollBottom: number;
35
+ public scrollTop: number;
36
+ public tabs: { [column: number]: boolean | undefined } = {};
37
+ public savedY: number = 0;
38
+ public savedX: number = 0;
39
+ public savedCurAttrData = DEFAULT_ATTR_DATA.clone();
40
+ public savedCharset: ICharset | undefined = DEFAULT_CHARSET;
41
+ public markers: Marker[] = [];
42
+ private _nullCell: ICellData = CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
43
+ private _whitespaceCell: ICellData = CellData.fromCharData([0, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE]);
44
+ private _cols: number;
45
+ private _rows: number;
46
+ private _isClearing: boolean = false;
47
+
48
+ constructor(
49
+ private _hasScrollback: boolean,
50
+ private _optionsService: IOptionsService,
51
+ private _bufferService: IBufferService
52
+ ) {
53
+ this._cols = this._bufferService.cols;
54
+ this._rows = this._bufferService.rows;
55
+ this.lines = new CircularList<IBufferLine>(this._getCorrectBufferLength(this._rows));
56
+ this.scrollTop = 0;
57
+ this.scrollBottom = this._rows - 1;
58
+ this.setupTabStops();
59
+ }
60
+
61
+ public getNullCell(attr?: IAttributeData): ICellData {
62
+ if (attr) {
63
+ this._nullCell.fg = attr.fg;
64
+ this._nullCell.bg = attr.bg;
65
+ this._nullCell.extended = attr.extended;
66
+ } else {
67
+ this._nullCell.fg = 0;
68
+ this._nullCell.bg = 0;
69
+ this._nullCell.extended = new ExtendedAttrs();
70
+ }
71
+ return this._nullCell;
72
+ }
73
+
74
+ public getWhitespaceCell(attr?: IAttributeData): ICellData {
75
+ if (attr) {
76
+ this._whitespaceCell.fg = attr.fg;
77
+ this._whitespaceCell.bg = attr.bg;
78
+ this._whitespaceCell.extended = attr.extended;
79
+ } else {
80
+ this._whitespaceCell.fg = 0;
81
+ this._whitespaceCell.bg = 0;
82
+ this._whitespaceCell.extended = new ExtendedAttrs();
83
+ }
84
+ return this._whitespaceCell;
85
+ }
86
+
87
+ public getBlankLine(attr: IAttributeData, isWrapped?: boolean): IBufferLine {
88
+ return new BufferLine(this._bufferService.cols, this.getNullCell(attr), isWrapped);
89
+ }
90
+
91
+ public get hasScrollback(): boolean {
92
+ return this._hasScrollback && this.lines.maxLength > this._rows;
93
+ }
94
+
95
+ public get isCursorInViewport(): boolean {
96
+ const absoluteY = this.ybase + this.y;
97
+ const relativeY = absoluteY - this.ydisp;
98
+ return (relativeY >= 0 && relativeY < this._rows);
99
+ }
100
+
101
+ /**
102
+ * Gets the correct buffer length based on the rows provided, the terminal's
103
+ * scrollback and whether this buffer is flagged to have scrollback or not.
104
+ * @param rows The terminal rows to use in the calculation.
105
+ */
106
+ private _getCorrectBufferLength(rows: number): number {
107
+ if (!this._hasScrollback) {
108
+ return rows;
109
+ }
110
+
111
+ const correctBufferLength = rows + this._optionsService.rawOptions.scrollback;
112
+
113
+ return correctBufferLength > MAX_BUFFER_SIZE ? MAX_BUFFER_SIZE : correctBufferLength;
114
+ }
115
+
116
+ /**
117
+ * Fills the buffer's viewport with blank lines.
118
+ */
119
+ public fillViewportRows(fillAttr?: IAttributeData): void {
120
+ if (this.lines.length === 0) {
121
+ if (fillAttr === undefined) {
122
+ fillAttr = DEFAULT_ATTR_DATA;
123
+ }
124
+ let i = this._rows;
125
+ while (i--) {
126
+ this.lines.push(this.getBlankLine(fillAttr));
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Clears the buffer to it's initial state, discarding all previous data.
133
+ */
134
+ public clear(): void {
135
+ this.ydisp = 0;
136
+ this.ybase = 0;
137
+ this.y = 0;
138
+ this.x = 0;
139
+ this.lines = new CircularList<IBufferLine>(this._getCorrectBufferLength(this._rows));
140
+ this.scrollTop = 0;
141
+ this.scrollBottom = this._rows - 1;
142
+ this.setupTabStops();
143
+ }
144
+
145
+ /**
146
+ * Resizes the buffer, adjusting its data accordingly.
147
+ * @param newCols The new number of columns.
148
+ * @param newRows The new number of rows.
149
+ */
150
+ public resize(newCols: number, newRows: number): void {
151
+ // store reference to null cell with default attrs
152
+ const nullCell = this.getNullCell(DEFAULT_ATTR_DATA);
153
+
154
+ // count bufferlines with overly big memory to be cleaned afterwards
155
+ let dirtyMemoryLines = 0;
156
+
157
+ // Increase max length if needed before adjustments to allow space to fill
158
+ // as required.
159
+ const newMaxLength = this._getCorrectBufferLength(newRows);
160
+ if (newMaxLength > this.lines.maxLength) {
161
+ this.lines.maxLength = newMaxLength;
162
+ }
163
+
164
+ // if (this._cols > newCols) {
165
+ // console.log('increase!');
166
+ // }
167
+
168
+ // The following adjustments should only happen if the buffer has been
169
+ // initialized/filled.
170
+ if (this.lines.length > 0) {
171
+ // Deal with columns increasing (reducing needs to happen after reflow)
172
+ if (this._cols < newCols) {
173
+ for (let i = 0; i < this.lines.length; i++) {
174
+ // +boolean for fast 0 or 1 conversion
175
+ dirtyMemoryLines += +this.lines.get(i)!.resize(newCols, nullCell);
176
+ }
177
+ }
178
+
179
+ // Resize rows in both directions as needed
180
+ let addToY = 0;
181
+ if (this._rows < newRows) {
182
+ for (let y = this._rows; y < newRows; y++) {
183
+ if (this.lines.length < newRows + this.ybase) {
184
+ if (this._optionsService.rawOptions.windowsMode || this._optionsService.rawOptions.windowsPty.backend !== undefined || this._optionsService.rawOptions.windowsPty.buildNumber !== undefined) {
185
+ // Just add the new missing rows on Windows as conpty reprints the screen with it's
186
+ // view of the world. Once a line enters scrollback for conpty it remains there
187
+ this.lines.push(new BufferLine(newCols, nullCell));
188
+ } else {
189
+ if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
190
+ // There is room above the buffer and there are no empty elements below the line,
191
+ // scroll up
192
+ this.ybase--;
193
+ addToY++;
194
+ if (this.ydisp > 0) {
195
+ // Viewport is at the top of the buffer, must increase downwards
196
+ this.ydisp--;
197
+ }
198
+ } else {
199
+ // Add a blank line if there is no buffer left at the top to scroll to, or if there
200
+ // are blank lines after the cursor
201
+ this.lines.push(new BufferLine(newCols, nullCell));
202
+ }
203
+ }
204
+ }
205
+ }
206
+ } else { // (this._rows >= newRows)
207
+ for (let y = this._rows; y > newRows; y--) {
208
+ if (this.lines.length > newRows + this.ybase) {
209
+ if (this.lines.length > this.ybase + this.y + 1) {
210
+ // The line is a blank line below the cursor, remove it
211
+ this.lines.pop();
212
+ } else {
213
+ // The line is the cursor, scroll down
214
+ this.ybase++;
215
+ this.ydisp++;
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ // Reduce max length if needed after adjustments, this is done after as it
222
+ // would otherwise cut data from the bottom of the buffer.
223
+ if (newMaxLength < this.lines.maxLength) {
224
+ // Trim from the top of the buffer and adjust ybase and ydisp.
225
+ const amountToTrim = this.lines.length - newMaxLength;
226
+ if (amountToTrim > 0) {
227
+ this.lines.trimStart(amountToTrim);
228
+ this.ybase = Math.max(this.ybase - amountToTrim, 0);
229
+ this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
230
+ this.savedY = Math.max(this.savedY - amountToTrim, 0);
231
+ }
232
+ this.lines.maxLength = newMaxLength;
233
+ }
234
+
235
+ // Make sure that the cursor stays on screen
236
+ this.x = Math.min(this.x, newCols - 1);
237
+ this.y = Math.min(this.y, newRows - 1);
238
+ if (addToY) {
239
+ this.y += addToY;
240
+ }
241
+ this.savedX = Math.min(this.savedX, newCols - 1);
242
+
243
+ this.scrollTop = 0;
244
+ }
245
+
246
+ this.scrollBottom = newRows - 1;
247
+
248
+ if (this._isReflowEnabled) {
249
+ this._reflow(newCols, newRows);
250
+
251
+ // Trim the end of the line off if cols shrunk
252
+ if (this._cols > newCols) {
253
+ for (let i = 0; i < this.lines.length; i++) {
254
+ // +boolean for fast 0 or 1 conversion
255
+ dirtyMemoryLines += +this.lines.get(i)!.resize(newCols, nullCell);
256
+ }
257
+ }
258
+ }
259
+
260
+ this._cols = newCols;
261
+ this._rows = newRows;
262
+
263
+ this._memoryCleanupQueue.clear();
264
+ // schedule memory cleanup only, if more than 10% of the lines are affected
265
+ if (dirtyMemoryLines > 0.1 * this.lines.length) {
266
+ this._memoryCleanupPosition = 0;
267
+ this._memoryCleanupQueue.enqueue(() => this._batchedMemoryCleanup());
268
+ }
269
+ }
270
+
271
+ private _memoryCleanupQueue = new IdleTaskQueue();
272
+ private _memoryCleanupPosition = 0;
273
+
274
+ private _batchedMemoryCleanup(): boolean {
275
+ let normalRun = true;
276
+ if (this._memoryCleanupPosition >= this.lines.length) {
277
+ // cleanup made it once through all lines, thus rescan in loop below to also catch shifted
278
+ // lines, which should finish rather quick if there are no more cleanups pending
279
+ this._memoryCleanupPosition = 0;
280
+ normalRun = false;
281
+ }
282
+ let counted = 0;
283
+ while (this._memoryCleanupPosition < this.lines.length) {
284
+ counted += this.lines.get(this._memoryCleanupPosition++)!.cleanupMemory();
285
+ // cleanup max 100 lines per batch
286
+ if (counted > 100) {
287
+ return true;
288
+ }
289
+ }
290
+ // normal runs always need another rescan afterwards
291
+ // if we made it here with normalRun=false, we are in a final run
292
+ // and can end the cleanup task for sure
293
+ return normalRun;
294
+ }
295
+
296
+ private get _isReflowEnabled(): boolean {
297
+ const windowsPty = this._optionsService.rawOptions.windowsPty;
298
+ if (windowsPty && windowsPty.buildNumber) {
299
+ return this._hasScrollback && windowsPty.backend === 'conpty' && windowsPty.buildNumber >= 21376;
300
+ }
301
+ return this._hasScrollback && !this._optionsService.rawOptions.windowsMode;
302
+ }
303
+
304
+ private _reflow(newCols: number, newRows: number): void {
305
+ if (this._cols === newCols) {
306
+ return;
307
+ }
308
+
309
+ // Iterate through rows, ignore the last one as it cannot be wrapped
310
+ if (newCols > this._cols) {
311
+ this._reflowLarger(newCols, newRows);
312
+ } else {
313
+ this._reflowSmaller(newCols, newRows);
314
+ }
315
+ }
316
+
317
+ private _reflowLarger(newCols: number, newRows: number): void {
318
+ const reflowCursorLine = this._optionsService.rawOptions.reflowCursorLine;
319
+ const toRemove: number[] = reflowLargerGetLinesToRemove(this.lines, this._cols, newCols, this.ybase + this.y, this.getNullCell(DEFAULT_ATTR_DATA), reflowCursorLine);
320
+ if (toRemove.length > 0) {
321
+ const newLayoutResult = reflowLargerCreateNewLayout(this.lines, toRemove);
322
+ reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout);
323
+ this._reflowLargerAdjustViewport(newCols, newRows, newLayoutResult.countRemoved);
324
+ }
325
+ }
326
+
327
+ private _reflowLargerAdjustViewport(newCols: number, newRows: number, countRemoved: number): void {
328
+ const nullCell = this.getNullCell(DEFAULT_ATTR_DATA);
329
+ // Adjust viewport based on number of items removed
330
+ let viewportAdjustments = countRemoved;
331
+ while (viewportAdjustments-- > 0) {
332
+ if (this.ybase === 0) {
333
+ if (this.y > 0) {
334
+ this.y--;
335
+ }
336
+ if (this.lines.length < newRows) {
337
+ // Add an extra row at the bottom of the viewport
338
+ this.lines.push(new BufferLine(newCols, nullCell));
339
+ }
340
+ } else {
341
+ if (this.ydisp === this.ybase) {
342
+ this.ydisp--;
343
+ }
344
+ this.ybase--;
345
+ }
346
+ }
347
+ this.savedY = Math.max(this.savedY - countRemoved, 0);
348
+ }
349
+
350
+ private _reflowSmaller(newCols: number, newRows: number): void {
351
+ const reflowCursorLine = this._optionsService.rawOptions.reflowCursorLine;
352
+ const nullCell = this.getNullCell(DEFAULT_ATTR_DATA);
353
+ // Gather all BufferLines that need to be inserted into the Buffer here so that they can be
354
+ // batched up and only committed once
355
+ const toInsert = [];
356
+ let countToInsert = 0;
357
+ // Go backwards as many lines may be trimmed and this will avoid considering them
358
+ for (let y = this.lines.length - 1; y >= 0; y--) {
359
+ // Check whether this line is a problem
360
+ let nextLine = this.lines.get(y) as BufferLine;
361
+ if (!nextLine || !nextLine.isWrapped && nextLine.getTrimmedLength() <= newCols) {
362
+ continue;
363
+ }
364
+
365
+ // Gather wrapped lines and adjust y to be the starting line
366
+ const wrappedLines: BufferLine[] = [nextLine];
367
+ while (nextLine.isWrapped && y > 0) {
368
+ nextLine = this.lines.get(--y) as BufferLine;
369
+ wrappedLines.unshift(nextLine);
370
+ }
371
+
372
+ if (!reflowCursorLine) {
373
+ // If these lines contain the cursor don't touch them, the program will handle fixing up
374
+ // wrapped lines with the cursor
375
+ const absoluteY = this.ybase + this.y;
376
+ if (absoluteY >= y && absoluteY < y + wrappedLines.length) {
377
+ continue;
378
+ }
379
+ }
380
+
381
+ const lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
382
+ const destLineLengths = reflowSmallerGetNewLineLengths(wrappedLines, this._cols, newCols);
383
+ const linesToAdd = destLineLengths.length - wrappedLines.length;
384
+ let trimmedLines: number;
385
+ if (this.ybase === 0 && this.y !== this.lines.length - 1) {
386
+ // If the top section of the buffer is not yet filled
387
+ trimmedLines = Math.max(0, this.y - this.lines.maxLength + linesToAdd);
388
+ } else {
389
+ trimmedLines = Math.max(0, this.lines.length - this.lines.maxLength + linesToAdd);
390
+ }
391
+
392
+ // Add the new lines
393
+ const newLines: BufferLine[] = [];
394
+ for (let i = 0; i < linesToAdd; i++) {
395
+ const newLine = this.getBlankLine(DEFAULT_ATTR_DATA, true) as BufferLine;
396
+ newLines.push(newLine);
397
+ }
398
+ if (newLines.length > 0) {
399
+ toInsert.push({
400
+ // countToInsert here gets the actual index, taking into account other inserted items.
401
+ // using this we can iterate through the list forwards
402
+ start: y + wrappedLines.length + countToInsert,
403
+ newLines
404
+ });
405
+ countToInsert += newLines.length;
406
+ }
407
+ wrappedLines.push(...newLines);
408
+
409
+ // Copy buffer data to new locations, this needs to happen backwards to do in-place
410
+ let destLineIndex = destLineLengths.length - 1; // Math.floor(cellsNeeded / newCols);
411
+ let destCol = destLineLengths[destLineIndex]; // cellsNeeded % newCols;
412
+ if (destCol === 0) {
413
+ destLineIndex--;
414
+ destCol = destLineLengths[destLineIndex];
415
+ }
416
+ let srcLineIndex = wrappedLines.length - linesToAdd - 1;
417
+ let srcCol = lastLineLength;
418
+ while (srcLineIndex >= 0) {
419
+ const cellsToCopy = Math.min(srcCol, destCol);
420
+ if (wrappedLines[destLineIndex] === undefined) {
421
+ // Sanity check that the line exists, this has been known to fail for an unknown reason
422
+ // which would stop the reflow from happening if an exception would throw.
423
+ break;
424
+ }
425
+ wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[srcLineIndex], srcCol - cellsToCopy, destCol - cellsToCopy, cellsToCopy, true);
426
+ destCol -= cellsToCopy;
427
+ if (destCol === 0) {
428
+ destLineIndex--;
429
+ destCol = destLineLengths[destLineIndex];
430
+ }
431
+ srcCol -= cellsToCopy;
432
+ if (srcCol === 0) {
433
+ srcLineIndex--;
434
+ const wrappedLinesIndex = Math.max(srcLineIndex, 0);
435
+ srcCol = getWrappedLineTrimmedLength(wrappedLines, wrappedLinesIndex, this._cols);
436
+ }
437
+ }
438
+
439
+ // Null out the end of the line ends if a wide character wrapped to the following line
440
+ for (let i = 0; i < wrappedLines.length; i++) {
441
+ if (destLineLengths[i] < newCols) {
442
+ wrappedLines[i].setCell(destLineLengths[i], nullCell);
443
+ }
444
+ }
445
+
446
+ // Adjust viewport as needed
447
+ let viewportAdjustments = linesToAdd - trimmedLines;
448
+ while (viewportAdjustments-- > 0) {
449
+ if (this.ybase === 0) {
450
+ if (this.y < newRows - 1) {
451
+ this.y++;
452
+ this.lines.pop();
453
+ } else {
454
+ this.ybase++;
455
+ this.ydisp++;
456
+ }
457
+ } else {
458
+ // Ensure ybase does not exceed its maximum value
459
+ if (this.ybase < Math.min(this.lines.maxLength, this.lines.length + countToInsert) - newRows) {
460
+ if (this.ybase === this.ydisp) {
461
+ this.ydisp++;
462
+ }
463
+ this.ybase++;
464
+ }
465
+ }
466
+ }
467
+ this.savedY = Math.min(this.savedY + linesToAdd, this.ybase + newRows - 1);
468
+ }
469
+
470
+ // Rearrange lines in the buffer if there are any insertions, this is done at the end rather
471
+ // than earlier so that it's a single O(n) pass through the buffer, instead of O(n^2) from many
472
+ // costly calls to CircularList.splice.
473
+ if (toInsert.length > 0) {
474
+ // Record buffer insert events and then play them back backwards so that the indexes are
475
+ // correct
476
+ const insertEvents: IInsertEvent[] = [];
477
+
478
+ // Record original lines so they don't get overridden when we rearrange the list
479
+ const originalLines: BufferLine[] = [];
480
+ for (let i = 0; i < this.lines.length; i++) {
481
+ originalLines.push(this.lines.get(i) as BufferLine);
482
+ }
483
+ const originalLinesLength = this.lines.length;
484
+
485
+ let originalLineIndex = originalLinesLength - 1;
486
+ let nextToInsertIndex = 0;
487
+ let nextToInsert = toInsert[nextToInsertIndex];
488
+ this.lines.length = Math.min(this.lines.maxLength, this.lines.length + countToInsert);
489
+ let countInsertedSoFar = 0;
490
+ for (let i = Math.min(this.lines.maxLength - 1, originalLinesLength + countToInsert - 1); i >= 0; i--) {
491
+ if (nextToInsert && nextToInsert.start > originalLineIndex + countInsertedSoFar) {
492
+ // Insert extra lines here, adjusting i as needed
493
+ for (let nextI = nextToInsert.newLines.length - 1; nextI >= 0; nextI--) {
494
+ this.lines.set(i--, nextToInsert.newLines[nextI]);
495
+ }
496
+ i++;
497
+
498
+ // Create insert events for later
499
+ insertEvents.push({
500
+ index: originalLineIndex + 1,
501
+ amount: nextToInsert.newLines.length
502
+ });
503
+
504
+ countInsertedSoFar += nextToInsert.newLines.length;
505
+ nextToInsert = toInsert[++nextToInsertIndex];
506
+ } else {
507
+ this.lines.set(i, originalLines[originalLineIndex--]);
508
+ }
509
+ }
510
+
511
+ // Update markers
512
+ let insertCountEmitted = 0;
513
+ for (let i = insertEvents.length - 1; i >= 0; i--) {
514
+ insertEvents[i].index += insertCountEmitted;
515
+ this.lines.onInsertEmitter.fire(insertEvents[i]);
516
+ insertCountEmitted += insertEvents[i].amount;
517
+ }
518
+ const amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength);
519
+ if (amountToTrim > 0) {
520
+ this.lines.onTrimEmitter.fire(amountToTrim);
521
+ }
522
+ }
523
+ }
524
+
525
+ /**
526
+ * Translates a buffer line to a string, with optional start and end columns.
527
+ * Wide characters will count as two columns in the resulting string. This
528
+ * function is useful for getting the actual text underneath the raw selection
529
+ * position.
530
+ * @param lineIndex The absolute index of the line being translated.
531
+ * @param trimRight Whether to trim whitespace to the right.
532
+ * @param startCol The column to start at.
533
+ * @param endCol The column to end at.
534
+ */
535
+ public translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol: number = 0, endCol?: number): string {
536
+ const line = this.lines.get(lineIndex);
537
+ if (!line) {
538
+ return '';
539
+ }
540
+ return line.translateToString(trimRight, startCol, endCol);
541
+ }
542
+
543
+ public getWrappedRangeForLine(y: number): { first: number, last: number } {
544
+ let first = y;
545
+ let last = y;
546
+ // Scan upwards for wrapped lines
547
+ while (first > 0 && this.lines.get(first)!.isWrapped) {
548
+ first--;
549
+ }
550
+ // Scan downwards for wrapped lines
551
+ while (last + 1 < this.lines.length && this.lines.get(last + 1)!.isWrapped) {
552
+ last++;
553
+ }
554
+ return { first, last };
555
+ }
556
+
557
+ /**
558
+ * Setup the tab stops.
559
+ * @param i The index to start setting up tab stops from.
560
+ */
561
+ public setupTabStops(i?: number): void {
562
+ if (i !== null && i !== undefined) {
563
+ if (!this.tabs[i]) {
564
+ i = this.prevStop(i);
565
+ }
566
+ } else {
567
+ this.tabs = {};
568
+ i = 0;
569
+ }
570
+
571
+ for (; i < this._cols; i += this._optionsService.rawOptions.tabStopWidth) {
572
+ this.tabs[i] = true;
573
+ }
574
+ }
575
+
576
+ /**
577
+ * Move the cursor to the previous tab stop from the given position (default is current).
578
+ * @param x The position to move the cursor to the previous tab stop.
579
+ */
580
+ public prevStop(x?: number): number {
581
+ if (x === null || x === undefined) {
582
+ x = this.x;
583
+ }
584
+ while (!this.tabs[--x] && x > 0);
585
+ return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
586
+ }
587
+
588
+ /**
589
+ * Move the cursor one tab stop forward from the given position (default is current).
590
+ * @param x The position to move the cursor one tab stop forward.
591
+ */
592
+ public nextStop(x?: number): number {
593
+ if (x === null || x === undefined) {
594
+ x = this.x;
595
+ }
596
+ while (!this.tabs[++x] && x < this._cols);
597
+ return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
598
+ }
599
+
600
+ /**
601
+ * Clears markers on single line.
602
+ * @param y The line to clear.
603
+ */
604
+ public clearMarkers(y: number): void {
605
+ this._isClearing = true;
606
+ for (let i = 0; i < this.markers.length; i++) {
607
+ if (this.markers[i].line === y) {
608
+ this.markers[i].dispose();
609
+ this.markers.splice(i--, 1);
610
+ }
611
+ }
612
+ this._isClearing = false;
613
+ }
614
+
615
+ /**
616
+ * Clears markers on all lines
617
+ */
618
+ public clearAllMarkers(): void {
619
+ this._isClearing = true;
620
+ for (let i = 0; i < this.markers.length; i++) {
621
+ this.markers[i].dispose();
622
+ }
623
+ this.markers.length = 0;
624
+ this._isClearing = false;
625
+ }
626
+
627
+ public addMarker(y: number): Marker {
628
+ const marker = new Marker(y);
629
+ this.markers.push(marker);
630
+ marker.register(this.lines.onTrim(amount => {
631
+ marker.line -= amount;
632
+ // The marker should be disposed when the line is trimmed from the buffer
633
+ if (marker.line < 0) {
634
+ marker.dispose();
635
+ }
636
+ }));
637
+ marker.register(this.lines.onInsert(event => {
638
+ if (marker.line >= event.index) {
639
+ marker.line += event.amount;
640
+ }
641
+ }));
642
+ marker.register(this.lines.onDelete(event => {
643
+ // Delete the marker if it's within the range
644
+ if (marker.line >= event.index && marker.line < event.index + event.amount) {
645
+ marker.dispose();
646
+ }
647
+
648
+ // Shift the marker if it's after the deleted range
649
+ if (marker.line > event.index) {
650
+ marker.line -= event.amount;
651
+ }
652
+ }));
653
+ marker.register(marker.onDispose(() => this._removeMarker(marker)));
654
+ return marker;
655
+ }
656
+
657
+ private _removeMarker(marker: Marker): void {
658
+ if (!this._isClearing) {
659
+ this.markers.splice(this.markers.indexOf(marker), 1);
660
+ }
661
+ }
662
+ }