@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.
- package/dist/index.js +1 -1
- package/dist/lib/xterm/LICENSE +21 -0
- package/dist/lib/xterm/README.md +225 -0
- package/dist/lib/xterm/css/xterm.css +190 -0
- package/dist/lib/xterm/lib/xterm.js +2 -0
- package/dist/lib/xterm/lib/xterm.js.map +1 -0
- package/dist/lib/xterm/package.json +90 -0
- package/dist/lib/xterm/src/browser/AccessibilityManager.ts +301 -0
- package/dist/lib/xterm/src/browser/Clipboard.ts +99 -0
- package/dist/lib/xterm/src/browser/ColorContrastCache.ts +39 -0
- package/dist/lib/xterm/src/browser/ColorManager.ts +268 -0
- package/dist/lib/xterm/src/browser/Dom.ts +10 -0
- package/dist/lib/xterm/src/browser/Lifecycle.ts +30 -0
- package/dist/lib/xterm/src/browser/Linkifier.ts +356 -0
- package/dist/lib/xterm/src/browser/Linkifier2.ts +397 -0
- package/dist/lib/xterm/src/browser/LocalizableStrings.ts +10 -0
- package/dist/lib/xterm/src/browser/MouseZoneManager.ts +236 -0
- package/dist/lib/xterm/src/browser/RenderDebouncer.ts +82 -0
- package/dist/lib/xterm/src/browser/ScreenDprMonitor.ts +69 -0
- package/dist/lib/xterm/src/browser/Terminal.ts +1447 -0
- package/dist/lib/xterm/src/browser/TimeBasedDebouncer.ts +86 -0
- package/dist/lib/xterm/src/browser/Types.d.ts +317 -0
- package/dist/lib/xterm/src/browser/Viewport.ts +276 -0
- package/dist/lib/xterm/src/browser/decorations/BufferDecorationRenderer.ts +131 -0
- package/dist/lib/xterm/src/browser/decorations/ColorZoneStore.ts +117 -0
- package/dist/lib/xterm/src/browser/decorations/OverviewRulerRenderer.ts +228 -0
- package/dist/lib/xterm/src/browser/input/CompositionHelper.ts +237 -0
- package/dist/lib/xterm/src/browser/input/Mouse.ts +64 -0
- package/dist/lib/xterm/src/browser/input/MoveToCell.ts +249 -0
- package/dist/lib/xterm/src/browser/public/Terminal.ts +298 -0
- package/dist/lib/xterm/src/browser/renderer/BaseRenderLayer.ts +582 -0
- package/dist/lib/xterm/src/browser/renderer/CursorRenderLayer.ts +378 -0
- package/dist/lib/xterm/src/browser/renderer/CustomGlyphs.ts +632 -0
- package/dist/lib/xterm/src/browser/renderer/GridCache.ts +33 -0
- package/dist/lib/xterm/src/browser/renderer/LinkRenderLayer.ts +84 -0
- package/dist/lib/xterm/src/browser/renderer/Renderer.ts +219 -0
- package/dist/lib/xterm/src/browser/renderer/RendererUtils.ts +26 -0
- package/dist/lib/xterm/src/browser/renderer/SelectionRenderLayer.ts +131 -0
- package/dist/lib/xterm/src/browser/renderer/TextRenderLayer.ts +344 -0
- package/dist/lib/xterm/src/browser/renderer/Types.d.ts +109 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/BaseCharAtlas.ts +58 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasCache.ts +95 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/CharAtlasUtils.ts +54 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Constants.ts +15 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/DynamicCharAtlas.ts +404 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/LRUMap.ts +136 -0
- package/dist/lib/xterm/src/browser/renderer/atlas/Types.d.ts +29 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRenderer.ts +403 -0
- package/dist/lib/xterm/src/browser/renderer/dom/DomRendererRowFactory.ts +344 -0
- package/dist/lib/xterm/src/browser/selection/SelectionModel.ts +144 -0
- package/dist/lib/xterm/src/browser/selection/Types.d.ts +15 -0
- package/dist/lib/xterm/src/browser/services/CharSizeService.ts +87 -0
- package/dist/lib/xterm/src/browser/services/CharacterJoinerService.ts +339 -0
- package/dist/lib/xterm/src/browser/services/CoreBrowserService.ts +20 -0
- package/dist/lib/xterm/src/browser/services/MouseService.ts +36 -0
- package/dist/lib/xterm/src/browser/services/RenderService.ts +237 -0
- package/dist/lib/xterm/src/browser/services/SelectionService.ts +1027 -0
- package/dist/lib/xterm/src/browser/services/Services.ts +123 -0
- package/dist/lib/xterm/src/browser/services/SoundService.ts +63 -0
- package/dist/lib/xterm/src/common/CircularList.ts +239 -0
- package/dist/lib/xterm/src/common/Clone.ts +23 -0
- package/dist/lib/xterm/src/common/Color.ts +285 -0
- package/dist/lib/xterm/src/common/CoreTerminal.ts +300 -0
- package/dist/lib/xterm/src/common/EventEmitter.ts +69 -0
- package/dist/lib/xterm/src/common/InputHandler.ts +3230 -0
- package/dist/lib/xterm/src/common/Lifecycle.ts +68 -0
- package/dist/lib/xterm/src/common/Platform.ts +31 -0
- package/dist/lib/xterm/src/common/SortedList.ts +88 -0
- package/dist/lib/xterm/src/common/TypedArrayUtils.ts +50 -0
- package/dist/lib/xterm/src/common/Types.d.ts +489 -0
- package/dist/lib/xterm/src/common/WindowsMode.ts +27 -0
- package/dist/lib/xterm/src/common/buffer/AttributeData.ts +148 -0
- package/dist/lib/xterm/src/common/buffer/Buffer.ts +711 -0
- package/dist/lib/xterm/src/common/buffer/BufferLine.ts +441 -0
- package/dist/lib/xterm/src/common/buffer/BufferRange.ts +13 -0
- package/dist/lib/xterm/src/common/buffer/BufferReflow.ts +220 -0
- package/dist/lib/xterm/src/common/buffer/BufferSet.ts +131 -0
- package/dist/lib/xterm/src/common/buffer/CellData.ts +94 -0
- package/dist/lib/xterm/src/common/buffer/Constants.ts +139 -0
- package/dist/lib/xterm/src/common/buffer/Marker.ts +37 -0
- package/dist/lib/xterm/src/common/buffer/Types.d.ts +64 -0
- package/dist/lib/xterm/src/common/data/Charsets.ts +256 -0
- package/dist/lib/xterm/src/common/data/EscapeSequences.ts +153 -0
- package/dist/lib/xterm/src/common/input/Keyboard.ts +398 -0
- package/dist/lib/xterm/src/common/input/TextDecoder.ts +346 -0
- package/dist/lib/xterm/src/common/input/UnicodeV6.ts +133 -0
- package/dist/lib/xterm/src/common/input/WriteBuffer.ts +229 -0
- package/dist/lib/xterm/src/common/input/XParseColor.ts +80 -0
- package/dist/lib/xterm/src/common/parser/Constants.ts +58 -0
- package/dist/lib/xterm/src/common/parser/DcsParser.ts +192 -0
- package/dist/lib/xterm/src/common/parser/EscapeSequenceParser.ts +796 -0
- package/dist/lib/xterm/src/common/parser/OscParser.ts +238 -0
- package/dist/lib/xterm/src/common/parser/Params.ts +229 -0
- package/dist/lib/xterm/src/common/parser/Types.d.ts +274 -0
- package/dist/lib/xterm/src/common/public/AddonManager.ts +56 -0
- package/dist/lib/xterm/src/common/public/BufferApiView.ts +35 -0
- package/dist/lib/xterm/src/common/public/BufferLineApiView.ts +29 -0
- package/dist/lib/xterm/src/common/public/BufferNamespaceApi.ts +33 -0
- package/dist/lib/xterm/src/common/public/ParserApi.ts +37 -0
- package/dist/lib/xterm/src/common/public/UnicodeApi.ts +27 -0
- package/dist/lib/xterm/src/common/services/BufferService.ts +185 -0
- package/dist/lib/xterm/src/common/services/CharsetService.ts +34 -0
- package/dist/lib/xterm/src/common/services/CoreMouseService.ts +309 -0
- package/dist/lib/xterm/src/common/services/CoreService.ts +92 -0
- package/dist/lib/xterm/src/common/services/DecorationService.ts +139 -0
- package/dist/lib/xterm/src/common/services/DirtyRowService.ts +53 -0
- package/dist/lib/xterm/src/common/services/InstantiationService.ts +83 -0
- package/dist/lib/xterm/src/common/services/LogService.ts +88 -0
- package/dist/lib/xterm/src/common/services/OptionsService.ts +178 -0
- package/dist/lib/xterm/src/common/services/ServiceRegistry.ts +49 -0
- package/dist/lib/xterm/src/common/services/Services.ts +323 -0
- package/dist/lib/xterm/src/common/services/UnicodeService.ts +82 -0
- package/dist/lib/xterm/src/headless/Terminal.ts +170 -0
- package/dist/lib/xterm/src/headless/Types.d.ts +31 -0
- package/dist/lib/xterm/src/headless/public/Terminal.ts +216 -0
- package/dist/lib/xterm/typings/xterm.d.ts +1872 -0
- package/dist/lib/xterm-fit/LICENSE +19 -0
- package/dist/lib/xterm-fit/README.md +24 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js +2 -0
- package/dist/lib/xterm-fit/lib/xterm-addon-fit.js.map +1 -0
- package/dist/lib/xterm-fit/out/FitAddon.js +58 -0
- package/dist/lib/xterm-fit/out/FitAddon.js.map +1 -0
- package/dist/lib/xterm-fit/out-test/FitAddon.api.js.map +1 -0
- package/dist/lib/xterm-fit/package.json +21 -0
- package/dist/lib/xterm-fit/src/FitAddon.ts +86 -0
- package/dist/lib/xterm-fit/typings/xterm-addon-fit.d.ts +55 -0
- package/dist/lib/xterm-links/LICENSE +19 -0
- package/dist/lib/xterm-links/README.md +21 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js +2 -0
- package/dist/lib/xterm-links/lib/xterm-addon-web-links.js.map +1 -0
- package/dist/lib/xterm-links/package.json +26 -0
- package/dist/lib/xterm-links/src/WebLinkProvider.ts +145 -0
- package/dist/lib/xterm-links/src/WebLinksAddon.ts +77 -0
- package/dist/lib/xterm-links/typings/xterm-addon-web-links.d.ts +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,711 @@
|
|
|
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 { IBuffer, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult } from 'common/buffer/Types';
|
|
8
|
+
import { IBufferLine, ICellData, IAttributeData, ICharset } from 'common/Types';
|
|
9
|
+
import { BufferLine, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
|
|
10
|
+
import { CellData } from 'common/buffer/CellData';
|
|
11
|
+
import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from 'common/buffer/Constants';
|
|
12
|
+
import { reflowLargerApplyNewLayout, reflowLargerCreateNewLayout, reflowLargerGetLinesToRemove, reflowSmallerGetNewLineLengths, getWrappedLineTrimmedLength } from 'common/buffer/BufferReflow';
|
|
13
|
+
import { Marker } from 'common/buffer/Marker';
|
|
14
|
+
import { IOptionsService, IBufferService } from 'common/services/Services';
|
|
15
|
+
import { DEFAULT_CHARSET } from 'common/data/Charsets';
|
|
16
|
+
import { ExtendedAttrs } from 'common/buffer/AttributeData';
|
|
17
|
+
|
|
18
|
+
export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This class represents a terminal buffer (an internal state of the terminal), where the
|
|
22
|
+
* following information is stored (in high-level):
|
|
23
|
+
* - text content of this particular buffer
|
|
24
|
+
* - cursor position
|
|
25
|
+
* - scroll position
|
|
26
|
+
*/
|
|
27
|
+
export class Buffer implements IBuffer {
|
|
28
|
+
public lines: CircularList<IBufferLine>;
|
|
29
|
+
public ydisp: number = 0;
|
|
30
|
+
public ybase: number = 0;
|
|
31
|
+
public y: number = 0;
|
|
32
|
+
public x: number = 0;
|
|
33
|
+
public scrollBottom: number;
|
|
34
|
+
public scrollTop: number;
|
|
35
|
+
// TODO: Type me
|
|
36
|
+
public tabs: any;
|
|
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
|
+
// Increase max length if needed before adjustments to allow space to fill
|
|
155
|
+
// as required.
|
|
156
|
+
const newMaxLength = this._getCorrectBufferLength(newRows);
|
|
157
|
+
if (newMaxLength > this.lines.maxLength) {
|
|
158
|
+
this.lines.maxLength = newMaxLength;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The following adjustments should only happen if the buffer has been
|
|
162
|
+
// initialized/filled.
|
|
163
|
+
if (this.lines.length > 0) {
|
|
164
|
+
// Deal with columns increasing (reducing needs to happen after reflow)
|
|
165
|
+
if (this._cols < newCols) {
|
|
166
|
+
for (let i = 0; i < this.lines.length; i++) {
|
|
167
|
+
this.lines.get(i)!.resize(newCols, nullCell);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Resize rows in both directions as needed
|
|
172
|
+
let addToY = 0;
|
|
173
|
+
if (this._rows < newRows) {
|
|
174
|
+
for (let y = this._rows; y < newRows; y++) {
|
|
175
|
+
if (this.lines.length < newRows + this.ybase) {
|
|
176
|
+
if (this._optionsService.rawOptions.windowsMode) {
|
|
177
|
+
// Just add the new missing rows on Windows as conpty reprints the screen with it's
|
|
178
|
+
// view of the world. Once a line enters scrollback for conpty it remains there
|
|
179
|
+
this.lines.push(new BufferLine(newCols, nullCell));
|
|
180
|
+
} else {
|
|
181
|
+
if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
|
|
182
|
+
// There is room above the buffer and there are no empty elements below the line,
|
|
183
|
+
// scroll up
|
|
184
|
+
this.ybase--;
|
|
185
|
+
addToY++;
|
|
186
|
+
if (this.ydisp > 0) {
|
|
187
|
+
// Viewport is at the top of the buffer, must increase downwards
|
|
188
|
+
this.ydisp--;
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
// Add a blank line if there is no buffer left at the top to scroll to, or if there
|
|
192
|
+
// are blank lines after the cursor
|
|
193
|
+
this.lines.push(new BufferLine(newCols, nullCell));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} else { // (this._rows >= newRows)
|
|
199
|
+
for (let y = this._rows; y > newRows; y--) {
|
|
200
|
+
if (this.lines.length > newRows + this.ybase) {
|
|
201
|
+
if (this.lines.length > this.ybase + this.y + 1) {
|
|
202
|
+
// The line is a blank line below the cursor, remove it
|
|
203
|
+
this.lines.pop();
|
|
204
|
+
} else {
|
|
205
|
+
// The line is the cursor, scroll down
|
|
206
|
+
this.ybase++;
|
|
207
|
+
this.ydisp++;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Reduce max length if needed after adjustments, this is done after as it
|
|
214
|
+
// would otherwise cut data from the bottom of the buffer.
|
|
215
|
+
if (newMaxLength < this.lines.maxLength) {
|
|
216
|
+
// Trim from the top of the buffer and adjust ybase and ydisp.
|
|
217
|
+
const amountToTrim = this.lines.length - newMaxLength;
|
|
218
|
+
if (amountToTrim > 0) {
|
|
219
|
+
this.lines.trimStart(amountToTrim);
|
|
220
|
+
this.ybase = Math.max(this.ybase - amountToTrim, 0);
|
|
221
|
+
this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
|
|
222
|
+
this.savedY = Math.max(this.savedY - amountToTrim, 0);
|
|
223
|
+
}
|
|
224
|
+
this.lines.maxLength = newMaxLength;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Make sure that the cursor stays on screen
|
|
228
|
+
this.x = Math.min(this.x, newCols - 1);
|
|
229
|
+
this.y = Math.min(this.y, newRows - 1);
|
|
230
|
+
if (addToY) {
|
|
231
|
+
this.y += addToY;
|
|
232
|
+
}
|
|
233
|
+
this.savedX = Math.min(this.savedX, newCols - 1);
|
|
234
|
+
|
|
235
|
+
this.scrollTop = 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
this.scrollBottom = newRows - 1;
|
|
239
|
+
|
|
240
|
+
if (this._isReflowEnabled) {
|
|
241
|
+
this._reflow(newCols, newRows);
|
|
242
|
+
|
|
243
|
+
// Trim the end of the line off if cols shrunk
|
|
244
|
+
if (this._cols > newCols) {
|
|
245
|
+
for (let i = 0; i < this.lines.length; i++) {
|
|
246
|
+
this.lines.get(i)!.resize(newCols, nullCell);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
this._cols = newCols;
|
|
252
|
+
this._rows = newRows;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private get _isReflowEnabled(): boolean {
|
|
256
|
+
return this._hasScrollback && !this._optionsService.rawOptions.windowsMode;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private _reflow(newCols: number, newRows: number): void {
|
|
260
|
+
if (this._cols === newCols) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Iterate through rows, ignore the last one as it cannot be wrapped
|
|
265
|
+
if (newCols > this._cols) {
|
|
266
|
+
this._reflowLarger(newCols, newRows);
|
|
267
|
+
} else {
|
|
268
|
+
this._reflowSmaller(newCols, newRows);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private _reflowLarger(newCols: number, newRows: number): void {
|
|
273
|
+
const toRemove: number[] = reflowLargerGetLinesToRemove(this.lines, this._cols, newCols, this.ybase + this.y, this.getNullCell(DEFAULT_ATTR_DATA));
|
|
274
|
+
if (toRemove.length > 0) {
|
|
275
|
+
const newLayoutResult = reflowLargerCreateNewLayout(this.lines, toRemove);
|
|
276
|
+
reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout);
|
|
277
|
+
this._reflowLargerAdjustViewport(newCols, newRows, newLayoutResult.countRemoved);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private _reflowLargerAdjustViewport(newCols: number, newRows: number, countRemoved: number): void {
|
|
282
|
+
const nullCell = this.getNullCell(DEFAULT_ATTR_DATA);
|
|
283
|
+
// Adjust viewport based on number of items removed
|
|
284
|
+
let viewportAdjustments = countRemoved;
|
|
285
|
+
while (viewportAdjustments-- > 0) {
|
|
286
|
+
if (this.ybase === 0) {
|
|
287
|
+
if (this.y > 0) {
|
|
288
|
+
this.y--;
|
|
289
|
+
}
|
|
290
|
+
if (this.lines.length < newRows) {
|
|
291
|
+
// Add an extra row at the bottom of the viewport
|
|
292
|
+
this.lines.push(new BufferLine(newCols, nullCell));
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
if (this.ydisp === this.ybase) {
|
|
296
|
+
this.ydisp--;
|
|
297
|
+
}
|
|
298
|
+
this.ybase--;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
this.savedY = Math.max(this.savedY - countRemoved, 0);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private _reflowSmaller(newCols: number, newRows: number): void {
|
|
305
|
+
const nullCell = this.getNullCell(DEFAULT_ATTR_DATA);
|
|
306
|
+
// Gather all BufferLines that need to be inserted into the Buffer here so that they can be
|
|
307
|
+
// batched up and only committed once
|
|
308
|
+
const toInsert = [];
|
|
309
|
+
let countToInsert = 0;
|
|
310
|
+
// Go backwards as many lines may be trimmed and this will avoid considering them
|
|
311
|
+
for (let y = this.lines.length - 1; y >= 0; y--) {
|
|
312
|
+
// Check whether this line is a problem
|
|
313
|
+
let nextLine = this.lines.get(y) as BufferLine;
|
|
314
|
+
if (!nextLine || !nextLine.isWrapped && nextLine.getTrimmedLength() <= newCols) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Gather wrapped lines and adjust y to be the starting line
|
|
319
|
+
const wrappedLines: BufferLine[] = [nextLine];
|
|
320
|
+
while (nextLine.isWrapped && y > 0) {
|
|
321
|
+
nextLine = this.lines.get(--y) as BufferLine;
|
|
322
|
+
wrappedLines.unshift(nextLine);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// If these lines contain the cursor don't touch them, the program will handle fixing up
|
|
326
|
+
// wrapped lines with the cursor
|
|
327
|
+
const absoluteY = this.ybase + this.y;
|
|
328
|
+
if (absoluteY >= y && absoluteY < y + wrappedLines.length) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
|
|
333
|
+
const destLineLengths = reflowSmallerGetNewLineLengths(wrappedLines, this._cols, newCols);
|
|
334
|
+
const linesToAdd = destLineLengths.length - wrappedLines.length;
|
|
335
|
+
let trimmedLines: number;
|
|
336
|
+
if (this.ybase === 0 && this.y !== this.lines.length - 1) {
|
|
337
|
+
// If the top section of the buffer is not yet filled
|
|
338
|
+
trimmedLines = Math.max(0, this.y - this.lines.maxLength + linesToAdd);
|
|
339
|
+
} else {
|
|
340
|
+
trimmedLines = Math.max(0, this.lines.length - this.lines.maxLength + linesToAdd);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Add the new lines
|
|
344
|
+
const newLines: BufferLine[] = [];
|
|
345
|
+
for (let i = 0; i < linesToAdd; i++) {
|
|
346
|
+
const newLine = this.getBlankLine(DEFAULT_ATTR_DATA, true) as BufferLine;
|
|
347
|
+
newLines.push(newLine);
|
|
348
|
+
}
|
|
349
|
+
if (newLines.length > 0) {
|
|
350
|
+
toInsert.push({
|
|
351
|
+
// countToInsert here gets the actual index, taking into account other inserted items.
|
|
352
|
+
// using this we can iterate through the list forwards
|
|
353
|
+
start: y + wrappedLines.length + countToInsert,
|
|
354
|
+
newLines
|
|
355
|
+
});
|
|
356
|
+
countToInsert += newLines.length;
|
|
357
|
+
}
|
|
358
|
+
wrappedLines.push(...newLines);
|
|
359
|
+
|
|
360
|
+
// Copy buffer data to new locations, this needs to happen backwards to do in-place
|
|
361
|
+
let destLineIndex = destLineLengths.length - 1; // Math.floor(cellsNeeded / newCols);
|
|
362
|
+
let destCol = destLineLengths[destLineIndex]; // cellsNeeded % newCols;
|
|
363
|
+
if (destCol === 0) {
|
|
364
|
+
destLineIndex--;
|
|
365
|
+
destCol = destLineLengths[destLineIndex];
|
|
366
|
+
}
|
|
367
|
+
let srcLineIndex = wrappedLines.length - linesToAdd - 1;
|
|
368
|
+
let srcCol = lastLineLength;
|
|
369
|
+
while (srcLineIndex >= 0) {
|
|
370
|
+
const cellsToCopy = Math.min(srcCol, destCol);
|
|
371
|
+
if (wrappedLines[destLineIndex] === undefined) {
|
|
372
|
+
// Sanity check that the line exists, this has been known to fail for an unknown reason
|
|
373
|
+
// which would stop the reflow from happening if an exception would throw.
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[srcLineIndex], srcCol - cellsToCopy, destCol - cellsToCopy, cellsToCopy, true);
|
|
377
|
+
destCol -= cellsToCopy;
|
|
378
|
+
if (destCol === 0) {
|
|
379
|
+
destLineIndex--;
|
|
380
|
+
destCol = destLineLengths[destLineIndex];
|
|
381
|
+
}
|
|
382
|
+
srcCol -= cellsToCopy;
|
|
383
|
+
if (srcCol === 0) {
|
|
384
|
+
srcLineIndex--;
|
|
385
|
+
const wrappedLinesIndex = Math.max(srcLineIndex, 0);
|
|
386
|
+
srcCol = getWrappedLineTrimmedLength(wrappedLines, wrappedLinesIndex, this._cols);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Null out the end of the line ends if a wide character wrapped to the following line
|
|
391
|
+
for (let i = 0; i < wrappedLines.length; i++) {
|
|
392
|
+
if (destLineLengths[i] < newCols) {
|
|
393
|
+
wrappedLines[i].setCell(destLineLengths[i], nullCell);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Adjust viewport as needed
|
|
398
|
+
let viewportAdjustments = linesToAdd - trimmedLines;
|
|
399
|
+
while (viewportAdjustments-- > 0) {
|
|
400
|
+
if (this.ybase === 0) {
|
|
401
|
+
if (this.y < newRows - 1) {
|
|
402
|
+
this.y++;
|
|
403
|
+
this.lines.pop();
|
|
404
|
+
} else {
|
|
405
|
+
this.ybase++;
|
|
406
|
+
this.ydisp++;
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
// Ensure ybase does not exceed its maximum value
|
|
410
|
+
if (this.ybase < Math.min(this.lines.maxLength, this.lines.length + countToInsert) - newRows) {
|
|
411
|
+
if (this.ybase === this.ydisp) {
|
|
412
|
+
this.ydisp++;
|
|
413
|
+
}
|
|
414
|
+
this.ybase++;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
this.savedY = Math.min(this.savedY + linesToAdd, this.ybase + newRows - 1);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Rearrange lines in the buffer if there are any insertions, this is done at the end rather
|
|
422
|
+
// than earlier so that it's a single O(n) pass through the buffer, instead of O(n^2) from many
|
|
423
|
+
// costly calls to CircularList.splice.
|
|
424
|
+
if (toInsert.length > 0) {
|
|
425
|
+
// Record buffer insert events and then play them back backwards so that the indexes are
|
|
426
|
+
// correct
|
|
427
|
+
const insertEvents: IInsertEvent[] = [];
|
|
428
|
+
|
|
429
|
+
// Record original lines so they don't get overridden when we rearrange the list
|
|
430
|
+
const originalLines: BufferLine[] = [];
|
|
431
|
+
for (let i = 0; i < this.lines.length; i++) {
|
|
432
|
+
originalLines.push(this.lines.get(i) as BufferLine);
|
|
433
|
+
}
|
|
434
|
+
const originalLinesLength = this.lines.length;
|
|
435
|
+
|
|
436
|
+
let originalLineIndex = originalLinesLength - 1;
|
|
437
|
+
let nextToInsertIndex = 0;
|
|
438
|
+
let nextToInsert = toInsert[nextToInsertIndex];
|
|
439
|
+
this.lines.length = Math.min(this.lines.maxLength, this.lines.length + countToInsert);
|
|
440
|
+
let countInsertedSoFar = 0;
|
|
441
|
+
for (let i = Math.min(this.lines.maxLength - 1, originalLinesLength + countToInsert - 1); i >= 0; i--) {
|
|
442
|
+
if (nextToInsert && nextToInsert.start > originalLineIndex + countInsertedSoFar) {
|
|
443
|
+
// Insert extra lines here, adjusting i as needed
|
|
444
|
+
for (let nextI = nextToInsert.newLines.length - 1; nextI >= 0; nextI--) {
|
|
445
|
+
this.lines.set(i--, nextToInsert.newLines[nextI]);
|
|
446
|
+
}
|
|
447
|
+
i++;
|
|
448
|
+
|
|
449
|
+
// Create insert events for later
|
|
450
|
+
insertEvents.push({
|
|
451
|
+
index: originalLineIndex + 1,
|
|
452
|
+
amount: nextToInsert.newLines.length
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
countInsertedSoFar += nextToInsert.newLines.length;
|
|
456
|
+
nextToInsert = toInsert[++nextToInsertIndex];
|
|
457
|
+
} else {
|
|
458
|
+
this.lines.set(i, originalLines[originalLineIndex--]);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Update markers
|
|
463
|
+
let insertCountEmitted = 0;
|
|
464
|
+
for (let i = insertEvents.length - 1; i >= 0; i--) {
|
|
465
|
+
insertEvents[i].index += insertCountEmitted;
|
|
466
|
+
this.lines.onInsertEmitter.fire(insertEvents[i]);
|
|
467
|
+
insertCountEmitted += insertEvents[i].amount;
|
|
468
|
+
}
|
|
469
|
+
const amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength);
|
|
470
|
+
if (amountToTrim > 0) {
|
|
471
|
+
this.lines.onTrimEmitter.fire(amountToTrim);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// private _reflowSmallerGetLinesNeeded()
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Translates a string index back to a BufferIndex.
|
|
480
|
+
* To get the correct buffer position the string must start at `startCol` 0
|
|
481
|
+
* (default in translateBufferLineToString).
|
|
482
|
+
* The method also works on wrapped line strings given rows were not trimmed.
|
|
483
|
+
* The method operates on the CharData string length, there are no
|
|
484
|
+
* additional content or boundary checks. Therefore the string and the buffer
|
|
485
|
+
* should not be altered in between.
|
|
486
|
+
* TODO: respect trim flag after fixing #1685
|
|
487
|
+
* @param lineIndex line index the string was retrieved from
|
|
488
|
+
* @param stringIndex index within the string
|
|
489
|
+
* @param startCol column offset the string was retrieved from
|
|
490
|
+
*/
|
|
491
|
+
public stringIndexToBufferIndex(lineIndex: number, stringIndex: number, trimRight: boolean = false): BufferIndex {
|
|
492
|
+
while (stringIndex) {
|
|
493
|
+
const line = this.lines.get(lineIndex);
|
|
494
|
+
if (!line) {
|
|
495
|
+
return [-1, -1];
|
|
496
|
+
}
|
|
497
|
+
const length = (trimRight) ? line.getTrimmedLength() : line.length;
|
|
498
|
+
for (let i = 0; i < length; ++i) {
|
|
499
|
+
if (line.get(i)[CHAR_DATA_WIDTH_INDEX]) {
|
|
500
|
+
// empty cells report a string length of 0, but get replaced
|
|
501
|
+
// with a whitespace in translateToString, thus replace with 1
|
|
502
|
+
stringIndex -= line.get(i)[CHAR_DATA_CHAR_INDEX].length || 1;
|
|
503
|
+
}
|
|
504
|
+
if (stringIndex < 0) {
|
|
505
|
+
return [lineIndex, i];
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
lineIndex++;
|
|
509
|
+
}
|
|
510
|
+
return [lineIndex, 0];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Translates a buffer line to a string, with optional start and end columns.
|
|
515
|
+
* Wide characters will count as two columns in the resulting string. This
|
|
516
|
+
* function is useful for getting the actual text underneath the raw selection
|
|
517
|
+
* position.
|
|
518
|
+
* @param line The line being translated.
|
|
519
|
+
* @param trimRight Whether to trim whitespace to the right.
|
|
520
|
+
* @param startCol The column to start at.
|
|
521
|
+
* @param endCol The column to end at.
|
|
522
|
+
*/
|
|
523
|
+
public translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol: number = 0, endCol?: number): string {
|
|
524
|
+
const line = this.lines.get(lineIndex);
|
|
525
|
+
if (!line) {
|
|
526
|
+
return '';
|
|
527
|
+
}
|
|
528
|
+
return line.translateToString(trimRight, startCol, endCol);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
public getWrappedRangeForLine(y: number): { first: number, last: number } {
|
|
532
|
+
let first = y;
|
|
533
|
+
let last = y;
|
|
534
|
+
// Scan upwards for wrapped lines
|
|
535
|
+
while (first > 0 && this.lines.get(first)!.isWrapped) {
|
|
536
|
+
first--;
|
|
537
|
+
}
|
|
538
|
+
// Scan downwards for wrapped lines
|
|
539
|
+
while (last + 1 < this.lines.length && this.lines.get(last + 1)!.isWrapped) {
|
|
540
|
+
last++;
|
|
541
|
+
}
|
|
542
|
+
return { first, last };
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Setup the tab stops.
|
|
547
|
+
* @param i The index to start setting up tab stops from.
|
|
548
|
+
*/
|
|
549
|
+
public setupTabStops(i?: number): void {
|
|
550
|
+
if (i !== null && i !== undefined) {
|
|
551
|
+
if (!this.tabs[i]) {
|
|
552
|
+
i = this.prevStop(i);
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
this.tabs = {};
|
|
556
|
+
i = 0;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
for (; i < this._cols; i += this._optionsService.rawOptions.tabStopWidth) {
|
|
560
|
+
this.tabs[i] = true;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Move the cursor to the previous tab stop from the given position (default is current).
|
|
566
|
+
* @param x The position to move the cursor to the previous tab stop.
|
|
567
|
+
*/
|
|
568
|
+
public prevStop(x?: number): number {
|
|
569
|
+
if (x === null || x === undefined) {
|
|
570
|
+
x = this.x;
|
|
571
|
+
}
|
|
572
|
+
while (!this.tabs[--x] && x > 0);
|
|
573
|
+
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Move the cursor one tab stop forward from the given position (default is current).
|
|
578
|
+
* @param x The position to move the cursor one tab stop forward.
|
|
579
|
+
*/
|
|
580
|
+
public nextStop(x?: number): number {
|
|
581
|
+
if (x === null || x === undefined) {
|
|
582
|
+
x = this.x;
|
|
583
|
+
}
|
|
584
|
+
while (!this.tabs[++x] && x < this._cols);
|
|
585
|
+
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Clears markers on single line.
|
|
590
|
+
* @param y The line to clear.
|
|
591
|
+
*/
|
|
592
|
+
public clearMarkers(y: number): void {
|
|
593
|
+
this._isClearing = true;
|
|
594
|
+
for (let i = 0; i < this.markers.length; i++) {
|
|
595
|
+
if (this.markers[i].line === y) {
|
|
596
|
+
this.markers[i].dispose();
|
|
597
|
+
this.markers.splice(i--, 1);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
this._isClearing = false;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Clears markers on all lines
|
|
605
|
+
*/
|
|
606
|
+
public clearAllMarkers(): void {
|
|
607
|
+
this._isClearing = true;
|
|
608
|
+
for (let i = 0; i < this.markers.length; i++) {
|
|
609
|
+
this.markers[i].dispose();
|
|
610
|
+
this.markers.splice(i--, 1);
|
|
611
|
+
}
|
|
612
|
+
this._isClearing = false;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
public addMarker(y: number): Marker {
|
|
616
|
+
const marker = new Marker(y);
|
|
617
|
+
this.markers.push(marker);
|
|
618
|
+
marker.register(this.lines.onTrim(amount => {
|
|
619
|
+
marker.line -= amount;
|
|
620
|
+
// The marker should be disposed when the line is trimmed from the buffer
|
|
621
|
+
if (marker.line < 0) {
|
|
622
|
+
marker.dispose();
|
|
623
|
+
}
|
|
624
|
+
}));
|
|
625
|
+
marker.register(this.lines.onInsert(event => {
|
|
626
|
+
if (marker.line >= event.index) {
|
|
627
|
+
marker.line += event.amount;
|
|
628
|
+
}
|
|
629
|
+
}));
|
|
630
|
+
marker.register(this.lines.onDelete(event => {
|
|
631
|
+
// Delete the marker if it's within the range
|
|
632
|
+
if (marker.line >= event.index && marker.line < event.index + event.amount) {
|
|
633
|
+
marker.dispose();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Shift the marker if it's after the deleted range
|
|
637
|
+
if (marker.line > event.index) {
|
|
638
|
+
marker.line -= event.amount;
|
|
639
|
+
}
|
|
640
|
+
}));
|
|
641
|
+
marker.register(marker.onDispose(() => this._removeMarker(marker)));
|
|
642
|
+
return marker;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
private _removeMarker(marker: Marker): void {
|
|
646
|
+
if (!this._isClearing) {
|
|
647
|
+
this.markers.splice(this.markers.indexOf(marker), 1);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
public iterator(trimRight: boolean, startIndex?: number, endIndex?: number, startOverscan?: number, endOverscan?: number): IBufferStringIterator {
|
|
652
|
+
return new BufferStringIterator(this, trimRight, startIndex, endIndex, startOverscan, endOverscan);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Iterator to get unwrapped content strings from the buffer.
|
|
658
|
+
* The iterator returns at least the string data between the borders
|
|
659
|
+
* `startIndex` and `endIndex` (exclusive) and will expand the lines
|
|
660
|
+
* by `startOverscan` to the top and by `endOverscan` to the bottom,
|
|
661
|
+
* if no new line was found in between.
|
|
662
|
+
* It will never read/return string data beyond `startIndex - startOverscan`
|
|
663
|
+
* or `endIndex + endOverscan`. Therefore the first and last line might be truncated.
|
|
664
|
+
* It is possible to always get the full string for the first and last line as well
|
|
665
|
+
* by setting the overscan values to the actual buffer length. This not recommended
|
|
666
|
+
* since it might return the whole buffer within a single string in a worst case scenario.
|
|
667
|
+
*/
|
|
668
|
+
export class BufferStringIterator implements IBufferStringIterator {
|
|
669
|
+
private _current: number;
|
|
670
|
+
|
|
671
|
+
constructor(
|
|
672
|
+
private _buffer: IBuffer,
|
|
673
|
+
private _trimRight: boolean,
|
|
674
|
+
private _startIndex: number = 0,
|
|
675
|
+
private _endIndex: number = _buffer.lines.length,
|
|
676
|
+
private _startOverscan: number = 0,
|
|
677
|
+
private _endOverscan: number = 0
|
|
678
|
+
) {
|
|
679
|
+
if (this._startIndex < 0) {
|
|
680
|
+
this._startIndex = 0;
|
|
681
|
+
}
|
|
682
|
+
if (this._endIndex > this._buffer.lines.length) {
|
|
683
|
+
this._endIndex = this._buffer.lines.length;
|
|
684
|
+
}
|
|
685
|
+
this._current = this._startIndex;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
public hasNext(): boolean {
|
|
689
|
+
return this._current < this._endIndex;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
public next(): IBufferStringIteratorResult {
|
|
693
|
+
const range = this._buffer.getWrappedRangeForLine(this._current);
|
|
694
|
+
// limit search window to overscan value at both borders
|
|
695
|
+
if (range.first < this._startIndex - this._startOverscan) {
|
|
696
|
+
range.first = this._startIndex - this._startOverscan;
|
|
697
|
+
}
|
|
698
|
+
if (range.last > this._endIndex + this._endOverscan) {
|
|
699
|
+
range.last = this._endIndex + this._endOverscan;
|
|
700
|
+
}
|
|
701
|
+
// limit to current buffer length
|
|
702
|
+
range.first = Math.max(range.first, 0);
|
|
703
|
+
range.last = Math.min(range.last, this._buffer.lines.length);
|
|
704
|
+
let content = '';
|
|
705
|
+
for (let i = range.first; i <= range.last; ++i) {
|
|
706
|
+
content += this._buffer.translateBufferLineToString(i, this._trimRight);
|
|
707
|
+
}
|
|
708
|
+
this._current = range.last + 1;
|
|
709
|
+
return { range, content };
|
|
710
|
+
}
|
|
711
|
+
}
|