]> git.proxmox.com Git - pve-xtermjs.git/blob - src/www/xterm.js
update xterm.js sources to 3.13.2 and move away from tarballs
[pve-xtermjs.git] / src / www / xterm.js
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Terminal = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 "use strict";
3 var __extends = (this && this.__extends) || (function () {
4 var extendStatics = function (d, b) {
5 extendStatics = Object.setPrototypeOf ||
6 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8 return extendStatics(d, b);
9 };
10 return function (d, b) {
11 extendStatics(d, b);
12 function __() { this.constructor = d; }
13 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14 };
15 })();
16 Object.defineProperty(exports, "__esModule", { value: true });
17 var Strings = require("./Strings");
18 var Platform_1 = require("./common/Platform");
19 var RenderDebouncer_1 = require("./ui/RenderDebouncer");
20 var Lifecycle_1 = require("./ui/Lifecycle");
21 var Lifecycle_2 = require("./common/Lifecycle");
22 var MAX_ROWS_TO_READ = 20;
23 var AccessibilityManager = (function (_super) {
24 __extends(AccessibilityManager, _super);
25 function AccessibilityManager(_terminal) {
26 var _this = _super.call(this) || this;
27 _this._terminal = _terminal;
28 _this._liveRegionLineCount = 0;
29 _this._charsToConsume = [];
30 _this._accessibilityTreeRoot = document.createElement('div');
31 _this._accessibilityTreeRoot.classList.add('xterm-accessibility');
32 _this._rowContainer = document.createElement('div');
33 _this._rowContainer.classList.add('xterm-accessibility-tree');
34 _this._rowElements = [];
35 for (var i = 0; i < _this._terminal.rows; i++) {
36 _this._rowElements[i] = _this._createAccessibilityTreeNode();
37 _this._rowContainer.appendChild(_this._rowElements[i]);
38 }
39 _this._topBoundaryFocusListener = function (e) { return _this._onBoundaryFocus(e, 0); };
40 _this._bottomBoundaryFocusListener = function (e) { return _this._onBoundaryFocus(e, 1); };
41 _this._rowElements[0].addEventListener('focus', _this._topBoundaryFocusListener);
42 _this._rowElements[_this._rowElements.length - 1].addEventListener('focus', _this._bottomBoundaryFocusListener);
43 _this._refreshRowsDimensions();
44 _this._accessibilityTreeRoot.appendChild(_this._rowContainer);
45 _this._renderRowsDebouncer = new RenderDebouncer_1.RenderDebouncer(_this._renderRows.bind(_this));
46 _this._refreshRows();
47 _this._liveRegion = document.createElement('div');
48 _this._liveRegion.classList.add('live-region');
49 _this._liveRegion.setAttribute('aria-live', 'assertive');
50 _this._accessibilityTreeRoot.appendChild(_this._liveRegion);
51 _this._terminal.element.insertAdjacentElement('afterbegin', _this._accessibilityTreeRoot);
52 _this.register(_this._renderRowsDebouncer);
53 _this.register(_this._terminal.onResize(function (e) { return _this._onResize(e.rows); }));
54 _this.register(_this._terminal.onRender(function (e) { return _this._refreshRows(e.start, e.end); }));
55 _this.register(_this._terminal.onScroll(function () { return _this._refreshRows(); }));
56 _this.register(_this._terminal.addDisposableListener('a11y.char', function (char) { return _this._onChar(char); }));
57 _this.register(_this._terminal.onLineFeed(function () { return _this._onChar('\n'); }));
58 _this.register(_this._terminal.addDisposableListener('a11y.tab', function (spaceCount) { return _this._onTab(spaceCount); }));
59 _this.register(_this._terminal.onKey(function (e) { return _this._onKey(e.key); }));
60 _this.register(_this._terminal.addDisposableListener('blur', function () { return _this._clearLiveRegion(); }));
61 _this.register(_this._terminal.addDisposableListener('dprchange', function () { return _this._refreshRowsDimensions(); }));
62 _this.register(_this._terminal.renderer.onCanvasResize(function () { return _this._refreshRowsDimensions(); }));
63 _this.register(Lifecycle_1.addDisposableDomListener(window, 'resize', function () { return _this._refreshRowsDimensions(); }));
64 return _this;
65 }
66 AccessibilityManager.prototype.dispose = function () {
67 _super.prototype.dispose.call(this);
68 this._terminal.element.removeChild(this._accessibilityTreeRoot);
69 this._rowElements.length = 0;
70 };
71 AccessibilityManager.prototype._onBoundaryFocus = function (e, position) {
72 var boundaryElement = e.target;
73 var beforeBoundaryElement = this._rowElements[position === 0 ? 1 : this._rowElements.length - 2];
74 var posInSet = boundaryElement.getAttribute('aria-posinset');
75 var lastRowPos = position === 0 ? '1' : "" + this._terminal.buffer.lines.length;
76 if (posInSet === lastRowPos) {
77 return;
78 }
79 if (e.relatedTarget !== beforeBoundaryElement) {
80 return;
81 }
82 var topBoundaryElement;
83 var bottomBoundaryElement;
84 if (position === 0) {
85 topBoundaryElement = boundaryElement;
86 bottomBoundaryElement = this._rowElements.pop();
87 this._rowContainer.removeChild(bottomBoundaryElement);
88 }
89 else {
90 topBoundaryElement = this._rowElements.shift();
91 bottomBoundaryElement = boundaryElement;
92 this._rowContainer.removeChild(topBoundaryElement);
93 }
94 topBoundaryElement.removeEventListener('focus', this._topBoundaryFocusListener);
95 bottomBoundaryElement.removeEventListener('focus', this._bottomBoundaryFocusListener);
96 if (position === 0) {
97 var newElement = this._createAccessibilityTreeNode();
98 this._rowElements.unshift(newElement);
99 this._rowContainer.insertAdjacentElement('afterbegin', newElement);
100 }
101 else {
102 var newElement = this._createAccessibilityTreeNode();
103 this._rowElements.push(newElement);
104 this._rowContainer.appendChild(newElement);
105 }
106 this._rowElements[0].addEventListener('focus', this._topBoundaryFocusListener);
107 this._rowElements[this._rowElements.length - 1].addEventListener('focus', this._bottomBoundaryFocusListener);
108 this._terminal.scrollLines(position === 0 ? -1 : 1);
109 this._rowElements[position === 0 ? 1 : this._rowElements.length - 2].focus();
110 e.preventDefault();
111 e.stopImmediatePropagation();
112 };
113 AccessibilityManager.prototype._onResize = function (rows) {
114 this._rowElements[this._rowElements.length - 1].removeEventListener('focus', this._bottomBoundaryFocusListener);
115 for (var i = this._rowContainer.children.length; i < this._terminal.rows; i++) {
116 this._rowElements[i] = this._createAccessibilityTreeNode();
117 this._rowContainer.appendChild(this._rowElements[i]);
118 }
119 while (this._rowElements.length > rows) {
120 this._rowContainer.removeChild(this._rowElements.pop());
121 }
122 this._rowElements[this._rowElements.length - 1].addEventListener('focus', this._bottomBoundaryFocusListener);
123 this._refreshRowsDimensions();
124 };
125 AccessibilityManager.prototype._createAccessibilityTreeNode = function () {
126 var element = document.createElement('div');
127 element.setAttribute('role', 'listitem');
128 element.tabIndex = -1;
129 this._refreshRowDimensions(element);
130 return element;
131 };
132 AccessibilityManager.prototype._onTab = function (spaceCount) {
133 for (var i = 0; i < spaceCount; i++) {
134 this._onChar(' ');
135 }
136 };
137 AccessibilityManager.prototype._onChar = function (char) {
138 var _this = this;
139 if (this._liveRegionLineCount < MAX_ROWS_TO_READ + 1) {
140 if (this._charsToConsume.length > 0) {
141 var shiftedChar = this._charsToConsume.shift();
142 if (shiftedChar !== char) {
143 this._announceCharacter(char);
144 }
145 }
146 else {
147 this._announceCharacter(char);
148 }
149 if (char === '\n') {
150 this._liveRegionLineCount++;
151 if (this._liveRegionLineCount === MAX_ROWS_TO_READ + 1) {
152 this._liveRegion.textContent += Strings.tooMuchOutput;
153 }
154 }
155 if (Platform_1.isMac) {
156 if (this._liveRegion.textContent && this._liveRegion.textContent.length > 0 && !this._liveRegion.parentNode) {
157 setTimeout(function () {
158 _this._accessibilityTreeRoot.appendChild(_this._liveRegion);
159 }, 0);
160 }
161 }
162 }
163 };
164 AccessibilityManager.prototype._clearLiveRegion = function () {
165 this._liveRegion.textContent = '';
166 this._liveRegionLineCount = 0;
167 if (Platform_1.isMac) {
168 if (this._liveRegion.parentNode) {
169 this._accessibilityTreeRoot.removeChild(this._liveRegion);
170 }
171 }
172 };
173 AccessibilityManager.prototype._onKey = function (keyChar) {
174 this._clearLiveRegion();
175 this._charsToConsume.push(keyChar);
176 };
177 AccessibilityManager.prototype._refreshRows = function (start, end) {
178 this._renderRowsDebouncer.refresh(start, end, this._terminal.rows);
179 };
180 AccessibilityManager.prototype._renderRows = function (start, end) {
181 var buffer = this._terminal.buffer;
182 var setSize = buffer.lines.length.toString();
183 for (var i = start; i <= end; i++) {
184 var lineData = buffer.translateBufferLineToString(buffer.ydisp + i, true);
185 var posInSet = (buffer.ydisp + i + 1).toString();
186 var element = this._rowElements[i];
187 if (element) {
188 element.textContent = lineData.length === 0 ? Strings.blankLine : lineData;
189 element.setAttribute('aria-posinset', posInSet);
190 element.setAttribute('aria-setsize', setSize);
191 }
192 }
193 };
194 AccessibilityManager.prototype._refreshRowsDimensions = function () {
195 if (!this._terminal.renderer.dimensions.actualCellHeight) {
196 return;
197 }
198 if (this._rowElements.length !== this._terminal.rows) {
199 this._onResize(this._terminal.rows);
200 }
201 for (var i = 0; i < this._terminal.rows; i++) {
202 this._refreshRowDimensions(this._rowElements[i]);
203 }
204 };
205 AccessibilityManager.prototype._refreshRowDimensions = function (element) {
206 element.style.height = this._terminal.renderer.dimensions.actualCellHeight + "px";
207 };
208 AccessibilityManager.prototype._announceCharacter = function (char) {
209 if (char === ' ') {
210 this._liveRegion.innerHTML += '&nbsp;';
211 }
212 else {
213 this._liveRegion.textContent += char;
214 }
215 };
216 return AccessibilityManager;
217 }(Lifecycle_2.Disposable));
218 exports.AccessibilityManager = AccessibilityManager;
219
220 },{"./Strings":18,"./common/Lifecycle":26,"./common/Platform":27,"./ui/Lifecycle":55,"./ui/RenderDebouncer":56}],2:[function(require,module,exports){
221 "use strict";
222 var __extends = (this && this.__extends) || (function () {
223 var extendStatics = function (d, b) {
224 extendStatics = Object.setPrototypeOf ||
225 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
226 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
227 return extendStatics(d, b);
228 };
229 return function (d, b) {
230 extendStatics(d, b);
231 function __() { this.constructor = d; }
232 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
233 };
234 })();
235 Object.defineProperty(exports, "__esModule", { value: true });
236 var CircularList_1 = require("./common/CircularList");
237 var BufferLine_1 = require("./BufferLine");
238 var BufferReflow_1 = require("./BufferReflow");
239 var Types_1 = require("./renderer/atlas/Types");
240 var EventEmitter2_1 = require("./common/EventEmitter2");
241 var Lifecycle_1 = require("../lib/common/Lifecycle");
242 exports.DEFAULT_ATTR = (0 << 18) | (Types_1.DEFAULT_COLOR << 9) | (256 << 0);
243 exports.DEFAULT_ATTR_DATA = new BufferLine_1.AttributeData();
244 exports.CHAR_DATA_ATTR_INDEX = 0;
245 exports.CHAR_DATA_CHAR_INDEX = 1;
246 exports.CHAR_DATA_WIDTH_INDEX = 2;
247 exports.CHAR_DATA_CODE_INDEX = 3;
248 exports.MAX_BUFFER_SIZE = 4294967295;
249 exports.NULL_CELL_CHAR = '';
250 exports.NULL_CELL_WIDTH = 1;
251 exports.NULL_CELL_CODE = 0;
252 exports.WHITESPACE_CELL_CHAR = ' ';
253 exports.WHITESPACE_CELL_WIDTH = 1;
254 exports.WHITESPACE_CELL_CODE = 32;
255 var Buffer = (function () {
256 function Buffer(_terminal, _hasScrollback) {
257 this._terminal = _terminal;
258 this._hasScrollback = _hasScrollback;
259 this.savedCurAttrData = exports.DEFAULT_ATTR_DATA.clone();
260 this.markers = [];
261 this._nullCell = BufferLine_1.CellData.fromCharData([0, exports.NULL_CELL_CHAR, exports.NULL_CELL_WIDTH, exports.NULL_CELL_CODE]);
262 this._whitespaceCell = BufferLine_1.CellData.fromCharData([0, exports.WHITESPACE_CELL_CHAR, exports.WHITESPACE_CELL_WIDTH, exports.WHITESPACE_CELL_CODE]);
263 this._cols = this._terminal.cols;
264 this._rows = this._terminal.rows;
265 this.clear();
266 }
267 Buffer.prototype.getNullCell = function (attr) {
268 if (attr) {
269 this._nullCell.fg = attr.fg;
270 this._nullCell.bg = attr.bg;
271 }
272 else {
273 this._nullCell.fg = 0;
274 this._nullCell.bg = 0;
275 }
276 return this._nullCell;
277 };
278 Buffer.prototype.getWhitespaceCell = function (attr) {
279 if (attr) {
280 this._whitespaceCell.fg = attr.fg;
281 this._whitespaceCell.bg = attr.bg;
282 }
283 else {
284 this._whitespaceCell.fg = 0;
285 this._whitespaceCell.bg = 0;
286 }
287 return this._whitespaceCell;
288 };
289 Buffer.prototype.getBlankLine = function (attr, isWrapped) {
290 return new BufferLine_1.BufferLine(this._terminal.cols, this.getNullCell(attr), isWrapped);
291 };
292 Object.defineProperty(Buffer.prototype, "hasScrollback", {
293 get: function () {
294 return this._hasScrollback && this.lines.maxLength > this._rows;
295 },
296 enumerable: true,
297 configurable: true
298 });
299 Object.defineProperty(Buffer.prototype, "isCursorInViewport", {
300 get: function () {
301 var absoluteY = this.ybase + this.y;
302 var relativeY = absoluteY - this.ydisp;
303 return (relativeY >= 0 && relativeY < this._rows);
304 },
305 enumerable: true,
306 configurable: true
307 });
308 Buffer.prototype._getCorrectBufferLength = function (rows) {
309 if (!this._hasScrollback) {
310 return rows;
311 }
312 var correctBufferLength = rows + this._terminal.options.scrollback;
313 return correctBufferLength > exports.MAX_BUFFER_SIZE ? exports.MAX_BUFFER_SIZE : correctBufferLength;
314 };
315 Buffer.prototype.fillViewportRows = function (fillAttr) {
316 if (this.lines.length === 0) {
317 if (fillAttr === undefined) {
318 fillAttr = exports.DEFAULT_ATTR_DATA;
319 }
320 var i = this._rows;
321 while (i--) {
322 this.lines.push(this.getBlankLine(fillAttr));
323 }
324 }
325 };
326 Buffer.prototype.clear = function () {
327 this.ydisp = 0;
328 this.ybase = 0;
329 this.y = 0;
330 this.x = 0;
331 this.lines = new CircularList_1.CircularList(this._getCorrectBufferLength(this._rows));
332 this.scrollTop = 0;
333 this.scrollBottom = this._rows - 1;
334 this.setupTabStops();
335 };
336 Buffer.prototype.resize = function (newCols, newRows) {
337 var nullCell = this.getNullCell(exports.DEFAULT_ATTR_DATA);
338 var newMaxLength = this._getCorrectBufferLength(newRows);
339 if (newMaxLength > this.lines.maxLength) {
340 this.lines.maxLength = newMaxLength;
341 }
342 if (this.lines.length > 0) {
343 if (this._cols < newCols) {
344 for (var i = 0; i < this.lines.length; i++) {
345 this.lines.get(i).resize(newCols, nullCell);
346 }
347 }
348 var addToY = 0;
349 if (this._rows < newRows) {
350 for (var y = this._rows; y < newRows; y++) {
351 if (this.lines.length < newRows + this.ybase) {
352 if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
353 this.ybase--;
354 addToY++;
355 if (this.ydisp > 0) {
356 this.ydisp--;
357 }
358 }
359 else {
360 this.lines.push(new BufferLine_1.BufferLine(newCols, nullCell));
361 }
362 }
363 }
364 }
365 else {
366 for (var y = this._rows; y > newRows; y--) {
367 if (this.lines.length > newRows + this.ybase) {
368 if (this.lines.length > this.ybase + this.y + 1) {
369 this.lines.pop();
370 }
371 else {
372 this.ybase++;
373 this.ydisp++;
374 }
375 }
376 }
377 }
378 if (newMaxLength < this.lines.maxLength) {
379 var amountToTrim = this.lines.length - newMaxLength;
380 if (amountToTrim > 0) {
381 this.lines.trimStart(amountToTrim);
382 this.ybase = Math.max(this.ybase - amountToTrim, 0);
383 this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
384 }
385 this.lines.maxLength = newMaxLength;
386 }
387 this.x = Math.min(this.x, newCols - 1);
388 this.y = Math.min(this.y, newRows - 1);
389 if (addToY) {
390 this.y += addToY;
391 }
392 this.savedY = Math.min(this.savedY, newRows - 1);
393 this.savedX = Math.min(this.savedX, newCols - 1);
394 this.scrollTop = 0;
395 }
396 this.scrollBottom = newRows - 1;
397 if (this._isReflowEnabled) {
398 this._reflow(newCols, newRows);
399 if (this._cols > newCols) {
400 for (var i = 0; i < this.lines.length; i++) {
401 this.lines.get(i).resize(newCols, nullCell);
402 }
403 }
404 }
405 this._cols = newCols;
406 this._rows = newRows;
407 };
408 Object.defineProperty(Buffer.prototype, "_isReflowEnabled", {
409 get: function () {
410 return this._hasScrollback && !this._terminal.options.windowsMode;
411 },
412 enumerable: true,
413 configurable: true
414 });
415 Buffer.prototype._reflow = function (newCols, newRows) {
416 if (this._cols === newCols) {
417 return;
418 }
419 if (newCols > this._cols) {
420 this._reflowLarger(newCols, newRows);
421 }
422 else {
423 this._reflowSmaller(newCols, newRows);
424 }
425 };
426 Buffer.prototype._reflowLarger = function (newCols, newRows) {
427 var toRemove = BufferReflow_1.reflowLargerGetLinesToRemove(this.lines, this._cols, newCols, this.ybase + this.y, this.getNullCell(exports.DEFAULT_ATTR_DATA));
428 if (toRemove.length > 0) {
429 var newLayoutResult = BufferReflow_1.reflowLargerCreateNewLayout(this.lines, toRemove);
430 BufferReflow_1.reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout);
431 this._reflowLargerAdjustViewport(newCols, newRows, newLayoutResult.countRemoved);
432 }
433 };
434 Buffer.prototype._reflowLargerAdjustViewport = function (newCols, newRows, countRemoved) {
435 var nullCell = this.getNullCell(exports.DEFAULT_ATTR_DATA);
436 var viewportAdjustments = countRemoved;
437 while (viewportAdjustments-- > 0) {
438 if (this.ybase === 0) {
439 if (this.y > 0) {
440 this.y--;
441 }
442 if (this.lines.length < newRows) {
443 this.lines.push(new BufferLine_1.BufferLine(newCols, nullCell));
444 }
445 }
446 else {
447 if (this.ydisp === this.ybase) {
448 this.ydisp--;
449 }
450 this.ybase--;
451 }
452 }
453 };
454 Buffer.prototype._reflowSmaller = function (newCols, newRows) {
455 var nullCell = this.getNullCell(exports.DEFAULT_ATTR_DATA);
456 var toInsert = [];
457 var countToInsert = 0;
458 for (var y = this.lines.length - 1; y >= 0; y--) {
459 var nextLine = this.lines.get(y);
460 if (!nextLine.isWrapped && nextLine.getTrimmedLength() <= newCols) {
461 continue;
462 }
463 var wrappedLines = [nextLine];
464 while (nextLine.isWrapped && y > 0) {
465 nextLine = this.lines.get(--y);
466 wrappedLines.unshift(nextLine);
467 }
468 var absoluteY = this.ybase + this.y;
469 if (absoluteY >= y && absoluteY < y + wrappedLines.length) {
470 continue;
471 }
472 var lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
473 var destLineLengths = BufferReflow_1.reflowSmallerGetNewLineLengths(wrappedLines, this._cols, newCols);
474 var linesToAdd = destLineLengths.length - wrappedLines.length;
475 var trimmedLines = void 0;
476 if (this.ybase === 0 && this.y !== this.lines.length - 1) {
477 trimmedLines = Math.max(0, this.y - this.lines.maxLength + linesToAdd);
478 }
479 else {
480 trimmedLines = Math.max(0, this.lines.length - this.lines.maxLength + linesToAdd);
481 }
482 var newLines = [];
483 for (var i = 0; i < linesToAdd; i++) {
484 var newLine = this.getBlankLine(exports.DEFAULT_ATTR_DATA, true);
485 newLines.push(newLine);
486 }
487 if (newLines.length > 0) {
488 toInsert.push({
489 start: y + wrappedLines.length + countToInsert,
490 newLines: newLines
491 });
492 countToInsert += newLines.length;
493 }
494 wrappedLines.push.apply(wrappedLines, newLines);
495 var destLineIndex = destLineLengths.length - 1;
496 var destCol = destLineLengths[destLineIndex];
497 if (destCol === 0) {
498 destLineIndex--;
499 destCol = destLineLengths[destLineIndex];
500 }
501 var srcLineIndex = wrappedLines.length - linesToAdd - 1;
502 var srcCol = lastLineLength;
503 while (srcLineIndex >= 0) {
504 var cellsToCopy = Math.min(srcCol, destCol);
505 wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[srcLineIndex], srcCol - cellsToCopy, destCol - cellsToCopy, cellsToCopy, true);
506 destCol -= cellsToCopy;
507 if (destCol === 0) {
508 destLineIndex--;
509 destCol = destLineLengths[destLineIndex];
510 }
511 srcCol -= cellsToCopy;
512 if (srcCol === 0) {
513 srcLineIndex--;
514 var wrappedLinesIndex = Math.max(srcLineIndex, 0);
515 srcCol = BufferReflow_1.getWrappedLineTrimmedLength(wrappedLines, wrappedLinesIndex, this._cols);
516 }
517 }
518 for (var i = 0; i < wrappedLines.length; i++) {
519 if (destLineLengths[i] < newCols) {
520 wrappedLines[i].setCell(destLineLengths[i], nullCell);
521 }
522 }
523 var viewportAdjustments = linesToAdd - trimmedLines;
524 while (viewportAdjustments-- > 0) {
525 if (this.ybase === 0) {
526 if (this.y < newRows - 1) {
527 this.y++;
528 this.lines.pop();
529 }
530 else {
531 this.ybase++;
532 this.ydisp++;
533 }
534 }
535 else {
536 if (this.ybase < Math.min(this.lines.maxLength, this.lines.length + countToInsert) - newRows) {
537 if (this.ybase === this.ydisp) {
538 this.ydisp++;
539 }
540 this.ybase++;
541 }
542 }
543 }
544 }
545 if (toInsert.length > 0) {
546 var insertEvents = [];
547 var originalLines = [];
548 for (var i = 0; i < this.lines.length; i++) {
549 originalLines.push(this.lines.get(i));
550 }
551 var originalLinesLength = this.lines.length;
552 var originalLineIndex = originalLinesLength - 1;
553 var nextToInsertIndex = 0;
554 var nextToInsert = toInsert[nextToInsertIndex];
555 this.lines.length = Math.min(this.lines.maxLength, this.lines.length + countToInsert);
556 var countInsertedSoFar = 0;
557 for (var i = Math.min(this.lines.maxLength - 1, originalLinesLength + countToInsert - 1); i >= 0; i--) {
558 if (nextToInsert && nextToInsert.start > originalLineIndex + countInsertedSoFar) {
559 for (var nextI = nextToInsert.newLines.length - 1; nextI >= 0; nextI--) {
560 this.lines.set(i--, nextToInsert.newLines[nextI]);
561 }
562 i++;
563 insertEvents.push({
564 index: originalLineIndex + 1,
565 amount: nextToInsert.newLines.length
566 });
567 countInsertedSoFar += nextToInsert.newLines.length;
568 nextToInsert = toInsert[++nextToInsertIndex];
569 }
570 else {
571 this.lines.set(i, originalLines[originalLineIndex--]);
572 }
573 }
574 var insertCountEmitted = 0;
575 for (var i = insertEvents.length - 1; i >= 0; i--) {
576 insertEvents[i].index += insertCountEmitted;
577 this.lines.onInsertEmitter.fire(insertEvents[i]);
578 insertCountEmitted += insertEvents[i].amount;
579 }
580 var amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength);
581 if (amountToTrim > 0) {
582 this.lines.onTrimEmitter.fire(amountToTrim);
583 }
584 }
585 };
586 Buffer.prototype.stringIndexToBufferIndex = function (lineIndex, stringIndex, trimRight) {
587 if (trimRight === void 0) { trimRight = false; }
588 while (stringIndex) {
589 var line = this.lines.get(lineIndex);
590 if (!line) {
591 return [-1, -1];
592 }
593 var length_1 = (trimRight) ? line.getTrimmedLength() : line.length;
594 for (var i = 0; i < length_1; ++i) {
595 if (line.get(i)[exports.CHAR_DATA_WIDTH_INDEX]) {
596 stringIndex -= line.get(i)[exports.CHAR_DATA_CHAR_INDEX].length || 1;
597 }
598 if (stringIndex < 0) {
599 return [lineIndex, i];
600 }
601 }
602 lineIndex++;
603 }
604 return [lineIndex, 0];
605 };
606 Buffer.prototype.translateBufferLineToString = function (lineIndex, trimRight, startCol, endCol) {
607 if (startCol === void 0) { startCol = 0; }
608 var line = this.lines.get(lineIndex);
609 if (!line) {
610 return '';
611 }
612 return line.translateToString(trimRight, startCol, endCol);
613 };
614 Buffer.prototype.getWrappedRangeForLine = function (y) {
615 var first = y;
616 var last = y;
617 while (first > 0 && this.lines.get(first).isWrapped) {
618 first--;
619 }
620 while (last + 1 < this.lines.length && this.lines.get(last + 1).isWrapped) {
621 last++;
622 }
623 return { first: first, last: last };
624 };
625 Buffer.prototype.setupTabStops = function (i) {
626 if (i !== null && i !== undefined) {
627 if (!this.tabs[i]) {
628 i = this.prevStop(i);
629 }
630 }
631 else {
632 this.tabs = {};
633 i = 0;
634 }
635 for (; i < this._cols; i += this._terminal.options.tabStopWidth) {
636 this.tabs[i] = true;
637 }
638 };
639 Buffer.prototype.prevStop = function (x) {
640 if (x === null || x === undefined) {
641 x = this.x;
642 }
643 while (!this.tabs[--x] && x > 0)
644 ;
645 return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
646 };
647 Buffer.prototype.nextStop = function (x) {
648 if (x === null || x === undefined) {
649 x = this.x;
650 }
651 while (!this.tabs[++x] && x < this._cols)
652 ;
653 return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
654 };
655 Buffer.prototype.addMarker = function (y) {
656 var _this = this;
657 var marker = new Marker(y);
658 this.markers.push(marker);
659 marker.register(this.lines.onTrim(function (amount) {
660 marker.line -= amount;
661 if (marker.line < 0) {
662 marker.dispose();
663 }
664 }));
665 marker.register(this.lines.onInsert(function (event) {
666 if (marker.line >= event.index) {
667 marker.line += event.amount;
668 }
669 }));
670 marker.register(this.lines.onDelete(function (event) {
671 if (marker.line >= event.index && marker.line < event.index + event.amount) {
672 marker.dispose();
673 }
674 if (marker.line > event.index) {
675 marker.line -= event.amount;
676 }
677 }));
678 marker.register(marker.onDispose(function () { return _this._removeMarker(marker); }));
679 return marker;
680 };
681 Buffer.prototype._removeMarker = function (marker) {
682 this.markers.splice(this.markers.indexOf(marker), 1);
683 };
684 Buffer.prototype.iterator = function (trimRight, startIndex, endIndex, startOverscan, endOverscan) {
685 return new BufferStringIterator(this, trimRight, startIndex, endIndex, startOverscan, endOverscan);
686 };
687 return Buffer;
688 }());
689 exports.Buffer = Buffer;
690 var Marker = (function (_super) {
691 __extends(Marker, _super);
692 function Marker(line) {
693 var _this = _super.call(this) || this;
694 _this.line = line;
695 _this._id = Marker._nextId++;
696 _this.isDisposed = false;
697 _this._onDispose = new EventEmitter2_1.EventEmitter2();
698 return _this;
699 }
700 Object.defineProperty(Marker.prototype, "id", {
701 get: function () { return this._id; },
702 enumerable: true,
703 configurable: true
704 });
705 Object.defineProperty(Marker.prototype, "onDispose", {
706 get: function () { return this._onDispose.event; },
707 enumerable: true,
708 configurable: true
709 });
710 Marker.prototype.dispose = function () {
711 if (this.isDisposed) {
712 return;
713 }
714 this.isDisposed = true;
715 this._onDispose.fire();
716 };
717 Marker._nextId = 1;
718 return Marker;
719 }(Lifecycle_1.Disposable));
720 exports.Marker = Marker;
721 var BufferStringIterator = (function () {
722 function BufferStringIterator(_buffer, _trimRight, _startIndex, _endIndex, _startOverscan, _endOverscan) {
723 if (_startIndex === void 0) { _startIndex = 0; }
724 if (_endIndex === void 0) { _endIndex = _buffer.lines.length; }
725 if (_startOverscan === void 0) { _startOverscan = 0; }
726 if (_endOverscan === void 0) { _endOverscan = 0; }
727 this._buffer = _buffer;
728 this._trimRight = _trimRight;
729 this._startIndex = _startIndex;
730 this._endIndex = _endIndex;
731 this._startOverscan = _startOverscan;
732 this._endOverscan = _endOverscan;
733 if (this._startIndex < 0) {
734 this._startIndex = 0;
735 }
736 if (this._endIndex > this._buffer.lines.length) {
737 this._endIndex = this._buffer.lines.length;
738 }
739 this._current = this._startIndex;
740 }
741 BufferStringIterator.prototype.hasNext = function () {
742 return this._current < this._endIndex;
743 };
744 BufferStringIterator.prototype.next = function () {
745 var range = this._buffer.getWrappedRangeForLine(this._current);
746 if (range.first < this._startIndex - this._startOverscan) {
747 range.first = this._startIndex - this._startOverscan;
748 }
749 if (range.last > this._endIndex + this._endOverscan) {
750 range.last = this._endIndex + this._endOverscan;
751 }
752 range.first = Math.max(range.first, 0);
753 range.last = Math.min(range.last, this._buffer.lines.length);
754 var result = '';
755 for (var i = range.first; i <= range.last; ++i) {
756 result += this._buffer.translateBufferLineToString(i, this._trimRight);
757 }
758 this._current = range.last + 1;
759 return { range: range, content: result };
760 };
761 return BufferStringIterator;
762 }());
763 exports.BufferStringIterator = BufferStringIterator;
764
765 },{"../lib/common/Lifecycle":26,"./BufferLine":3,"./BufferReflow":4,"./common/CircularList":22,"./common/EventEmitter2":25,"./renderer/atlas/Types":52}],3:[function(require,module,exports){
766 "use strict";
767 var __extends = (this && this.__extends) || (function () {
768 var extendStatics = function (d, b) {
769 extendStatics = Object.setPrototypeOf ||
770 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
771 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
772 return extendStatics(d, b);
773 };
774 return function (d, b) {
775 extendStatics(d, b);
776 function __() { this.constructor = d; }
777 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
778 };
779 })();
780 Object.defineProperty(exports, "__esModule", { value: true });
781 var Buffer_1 = require("./Buffer");
782 var TextDecoder_1 = require("./core/input/TextDecoder");
783 var CELL_SIZE = 3;
784 var AttributeData = (function () {
785 function AttributeData() {
786 this.fg = 0;
787 this.bg = 0;
788 }
789 AttributeData.toColorRGB = function (value) {
790 return [
791 value >>> 16 & 255,
792 value >>> 8 & 255,
793 value & 255
794 ];
795 };
796 AttributeData.fromColorRGB = function (value) {
797 return (value[0] & 255) << 16 | (value[1] & 255) << 8 | value[2] & 255;
798 };
799 AttributeData.prototype.clone = function () {
800 var newObj = new AttributeData();
801 newObj.fg = this.fg;
802 newObj.bg = this.bg;
803 return newObj;
804 };
805 AttributeData.prototype.isInverse = function () { return this.fg & 67108864; };
806 AttributeData.prototype.isBold = function () { return this.fg & 134217728; };
807 AttributeData.prototype.isUnderline = function () { return this.fg & 268435456; };
808 AttributeData.prototype.isBlink = function () { return this.fg & 536870912; };
809 AttributeData.prototype.isInvisible = function () { return this.fg & 1073741824; };
810 AttributeData.prototype.isItalic = function () { return this.bg & 67108864; };
811 AttributeData.prototype.isDim = function () { return this.bg & 134217728; };
812 AttributeData.prototype.getFgColorMode = function () { return this.fg & 50331648; };
813 AttributeData.prototype.getBgColorMode = function () { return this.bg & 50331648; };
814 AttributeData.prototype.isFgRGB = function () { return (this.fg & 50331648) === 50331648; };
815 AttributeData.prototype.isBgRGB = function () { return (this.bg & 50331648) === 50331648; };
816 AttributeData.prototype.isFgPalette = function () { return (this.fg & 50331648) === 16777216 || (this.fg & 50331648) === 33554432; };
817 AttributeData.prototype.isBgPalette = function () { return (this.bg & 50331648) === 16777216 || (this.bg & 50331648) === 33554432; };
818 AttributeData.prototype.isFgDefault = function () { return (this.fg & 50331648) === 0; };
819 AttributeData.prototype.isBgDefault = function () { return (this.bg & 50331648) === 0; };
820 AttributeData.prototype.getFgColor = function () {
821 switch (this.fg & 50331648) {
822 case 16777216:
823 case 33554432: return this.fg & 255;
824 case 50331648: return this.fg & 16777215;
825 default: return -1;
826 }
827 };
828 AttributeData.prototype.getBgColor = function () {
829 switch (this.bg & 50331648) {
830 case 16777216:
831 case 33554432: return this.bg & 255;
832 case 50331648: return this.bg & 16777215;
833 default: return -1;
834 }
835 };
836 return AttributeData;
837 }());
838 exports.AttributeData = AttributeData;
839 var CellData = (function (_super) {
840 __extends(CellData, _super);
841 function CellData() {
842 var _this = _super !== null && _super.apply(this, arguments) || this;
843 _this.content = 0;
844 _this.fg = 0;
845 _this.bg = 0;
846 _this.combinedData = '';
847 return _this;
848 }
849 CellData.fromCharData = function (value) {
850 var obj = new CellData();
851 obj.setFromCharData(value);
852 return obj;
853 };
854 CellData.prototype.isCombined = function () {
855 return this.content & 2097152;
856 };
857 CellData.prototype.getWidth = function () {
858 return this.content >> 22;
859 };
860 CellData.prototype.getChars = function () {
861 if (this.content & 2097152) {
862 return this.combinedData;
863 }
864 if (this.content & 2097151) {
865 return TextDecoder_1.stringFromCodePoint(this.content & 2097151);
866 }
867 return '';
868 };
869 CellData.prototype.getCode = function () {
870 return (this.isCombined())
871 ? this.combinedData.charCodeAt(this.combinedData.length - 1)
872 : this.content & 2097151;
873 };
874 CellData.prototype.setFromCharData = function (value) {
875 this.fg = value[Buffer_1.CHAR_DATA_ATTR_INDEX];
876 this.bg = 0;
877 var combined = false;
878 if (value[Buffer_1.CHAR_DATA_CHAR_INDEX].length > 2) {
879 combined = true;
880 }
881 else if (value[Buffer_1.CHAR_DATA_CHAR_INDEX].length === 2) {
882 var code = value[Buffer_1.CHAR_DATA_CHAR_INDEX].charCodeAt(0);
883 if (0xD800 <= code && code <= 0xDBFF) {
884 var second = value[Buffer_1.CHAR_DATA_CHAR_INDEX].charCodeAt(1);
885 if (0xDC00 <= second && second <= 0xDFFF) {
886 this.content = ((code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000) | (value[Buffer_1.CHAR_DATA_WIDTH_INDEX] << 22);
887 }
888 else {
889 combined = true;
890 }
891 }
892 else {
893 combined = true;
894 }
895 }
896 else {
897 this.content = value[Buffer_1.CHAR_DATA_CHAR_INDEX].charCodeAt(0) | (value[Buffer_1.CHAR_DATA_WIDTH_INDEX] << 22);
898 }
899 if (combined) {
900 this.combinedData = value[Buffer_1.CHAR_DATA_CHAR_INDEX];
901 this.content = 2097152 | (value[Buffer_1.CHAR_DATA_WIDTH_INDEX] << 22);
902 }
903 };
904 CellData.prototype.getAsCharData = function () {
905 return [this.fg, this.getChars(), this.getWidth(), this.getCode()];
906 };
907 return CellData;
908 }(AttributeData));
909 exports.CellData = CellData;
910 var BufferLine = (function () {
911 function BufferLine(cols, fillCellData, isWrapped) {
912 if (isWrapped === void 0) { isWrapped = false; }
913 this.isWrapped = isWrapped;
914 this._data = null;
915 this._combined = {};
916 if (cols) {
917 this._data = new Uint32Array(cols * CELL_SIZE);
918 var cell = fillCellData || CellData.fromCharData([0, Buffer_1.NULL_CELL_CHAR, Buffer_1.NULL_CELL_WIDTH, Buffer_1.NULL_CELL_CODE]);
919 for (var i = 0; i < cols; ++i) {
920 this.setCell(i, cell);
921 }
922 }
923 this.length = cols;
924 }
925 BufferLine.prototype.get = function (index) {
926 var content = this._data[index * CELL_SIZE + 0];
927 var cp = content & 2097151;
928 return [
929 this._data[index * CELL_SIZE + 1],
930 (content & 2097152)
931 ? this._combined[index]
932 : (cp) ? TextDecoder_1.stringFromCodePoint(cp) : '',
933 content >> 22,
934 (content & 2097152)
935 ? this._combined[index].charCodeAt(this._combined[index].length - 1)
936 : cp
937 ];
938 };
939 BufferLine.prototype.set = function (index, value) {
940 this._data[index * CELL_SIZE + 1] = value[Buffer_1.CHAR_DATA_ATTR_INDEX];
941 if (value[Buffer_1.CHAR_DATA_CHAR_INDEX].length > 1) {
942 this._combined[index] = value[1];
943 this._data[index * CELL_SIZE + 0] = index | 2097152 | (value[Buffer_1.CHAR_DATA_WIDTH_INDEX] << 22);
944 }
945 else {
946 this._data[index * CELL_SIZE + 0] = value[Buffer_1.CHAR_DATA_CHAR_INDEX].charCodeAt(0) | (value[Buffer_1.CHAR_DATA_WIDTH_INDEX] << 22);
947 }
948 };
949 BufferLine.prototype.getWidth = function (index) {
950 return this._data[index * CELL_SIZE + 0] >> 22;
951 };
952 BufferLine.prototype.hasWidth = function (index) {
953 return this._data[index * CELL_SIZE + 0] & 12582912;
954 };
955 BufferLine.prototype.getFg = function (index) {
956 return this._data[index * CELL_SIZE + 1];
957 };
958 BufferLine.prototype.getBg = function (index) {
959 return this._data[index * CELL_SIZE + 2];
960 };
961 BufferLine.prototype.hasContent = function (index) {
962 return this._data[index * CELL_SIZE + 0] & 4194303;
963 };
964 BufferLine.prototype.getCodePoint = function (index) {
965 var content = this._data[index * CELL_SIZE + 0];
966 if (content & 2097152) {
967 return this._combined[index].charCodeAt(this._combined[index].length - 1);
968 }
969 return content & 2097151;
970 };
971 BufferLine.prototype.isCombined = function (index) {
972 return this._data[index * CELL_SIZE + 0] & 2097152;
973 };
974 BufferLine.prototype.getString = function (index) {
975 var content = this._data[index * CELL_SIZE + 0];
976 if (content & 2097152) {
977 return this._combined[index];
978 }
979 if (content & 2097151) {
980 return TextDecoder_1.stringFromCodePoint(content & 2097151);
981 }
982 return '';
983 };
984 BufferLine.prototype.loadCell = function (index, cell) {
985 var startIndex = index * CELL_SIZE;
986 cell.content = this._data[startIndex + 0];
987 cell.fg = this._data[startIndex + 1];
988 cell.bg = this._data[startIndex + 2];
989 if (cell.content & 2097152) {
990 cell.combinedData = this._combined[index];
991 }
992 return cell;
993 };
994 BufferLine.prototype.setCell = function (index, cell) {
995 if (cell.content & 2097152) {
996 this._combined[index] = cell.combinedData;
997 }
998 this._data[index * CELL_SIZE + 0] = cell.content;
999 this._data[index * CELL_SIZE + 1] = cell.fg;
1000 this._data[index * CELL_SIZE + 2] = cell.bg;
1001 };
1002 BufferLine.prototype.setCellFromCodePoint = function (index, codePoint, width, fg, bg) {
1003 this._data[index * CELL_SIZE + 0] = codePoint | (width << 22);
1004 this._data[index * CELL_SIZE + 1] = fg;
1005 this._data[index * CELL_SIZE + 2] = bg;
1006 };
1007 BufferLine.prototype.addCodepointToCell = function (index, codePoint) {
1008 var content = this._data[index * CELL_SIZE + 0];
1009 if (content & 2097152) {
1010 this._combined[index] += TextDecoder_1.stringFromCodePoint(codePoint);
1011 }
1012 else {
1013 if (content & 2097151) {
1014 this._combined[index] = TextDecoder_1.stringFromCodePoint(content & 2097151) + TextDecoder_1.stringFromCodePoint(codePoint);
1015 content &= ~2097151;
1016 content |= 2097152;
1017 }
1018 else {
1019 content = codePoint | (1 << 22);
1020 }
1021 this._data[index * CELL_SIZE + 0] = content;
1022 }
1023 };
1024 BufferLine.prototype.insertCells = function (pos, n, fillCellData) {
1025 pos %= this.length;
1026 if (n < this.length - pos) {
1027 var cell = new CellData();
1028 for (var i = this.length - pos - n - 1; i >= 0; --i) {
1029 this.setCell(pos + n + i, this.loadCell(pos + i, cell));
1030 }
1031 for (var i = 0; i < n; ++i) {
1032 this.setCell(pos + i, fillCellData);
1033 }
1034 }
1035 else {
1036 for (var i = pos; i < this.length; ++i) {
1037 this.setCell(i, fillCellData);
1038 }
1039 }
1040 };
1041 BufferLine.prototype.deleteCells = function (pos, n, fillCellData) {
1042 pos %= this.length;
1043 if (n < this.length - pos) {
1044 var cell = new CellData();
1045 for (var i = 0; i < this.length - pos - n; ++i) {
1046 this.setCell(pos + i, this.loadCell(pos + n + i, cell));
1047 }
1048 for (var i = this.length - n; i < this.length; ++i) {
1049 this.setCell(i, fillCellData);
1050 }
1051 }
1052 else {
1053 for (var i = pos; i < this.length; ++i) {
1054 this.setCell(i, fillCellData);
1055 }
1056 }
1057 };
1058 BufferLine.prototype.replaceCells = function (start, end, fillCellData) {
1059 while (start < end && start < this.length) {
1060 this.setCell(start++, fillCellData);
1061 }
1062 };
1063 BufferLine.prototype.resize = function (cols, fillCellData) {
1064 if (cols === this.length) {
1065 return;
1066 }
1067 if (cols > this.length) {
1068 var data = new Uint32Array(cols * CELL_SIZE);
1069 if (this.length) {
1070 if (cols * CELL_SIZE < this._data.length) {
1071 data.set(this._data.subarray(0, cols * CELL_SIZE));
1072 }
1073 else {
1074 data.set(this._data);
1075 }
1076 }
1077 this._data = data;
1078 for (var i = this.length; i < cols; ++i) {
1079 this.setCell(i, fillCellData);
1080 }
1081 }
1082 else {
1083 if (cols) {
1084 var data = new Uint32Array(cols * CELL_SIZE);
1085 data.set(this._data.subarray(0, cols * CELL_SIZE));
1086 this._data = data;
1087 var keys = Object.keys(this._combined);
1088 for (var i = 0; i < keys.length; i++) {
1089 var key = parseInt(keys[i], 10);
1090 if (key >= cols) {
1091 delete this._combined[key];
1092 }
1093 }
1094 }
1095 else {
1096 this._data = null;
1097 this._combined = {};
1098 }
1099 }
1100 this.length = cols;
1101 };
1102 BufferLine.prototype.fill = function (fillCellData) {
1103 this._combined = {};
1104 for (var i = 0; i < this.length; ++i) {
1105 this.setCell(i, fillCellData);
1106 }
1107 };
1108 BufferLine.prototype.copyFrom = function (line) {
1109 if (this.length !== line.length) {
1110 this._data = new Uint32Array(line._data);
1111 }
1112 else {
1113 this._data.set(line._data);
1114 }
1115 this.length = line.length;
1116 this._combined = {};
1117 for (var el in line._combined) {
1118 this._combined[el] = line._combined[el];
1119 }
1120 this.isWrapped = line.isWrapped;
1121 };
1122 BufferLine.prototype.clone = function () {
1123 var newLine = new BufferLine(0);
1124 newLine._data = new Uint32Array(this._data);
1125 newLine.length = this.length;
1126 for (var el in this._combined) {
1127 newLine._combined[el] = this._combined[el];
1128 }
1129 newLine.isWrapped = this.isWrapped;
1130 return newLine;
1131 };
1132 BufferLine.prototype.getTrimmedLength = function () {
1133 for (var i = this.length - 1; i >= 0; --i) {
1134 if ((this._data[i * CELL_SIZE + 0] & 4194303)) {
1135 return i + (this._data[i * CELL_SIZE + 0] >> 22);
1136 }
1137 }
1138 return 0;
1139 };
1140 BufferLine.prototype.copyCellsFrom = function (src, srcCol, destCol, length, applyInReverse) {
1141 var srcData = src._data;
1142 if (applyInReverse) {
1143 for (var cell = length - 1; cell >= 0; cell--) {
1144 for (var i = 0; i < CELL_SIZE; i++) {
1145 this._data[(destCol + cell) * CELL_SIZE + i] = srcData[(srcCol + cell) * CELL_SIZE + i];
1146 }
1147 }
1148 }
1149 else {
1150 for (var cell = 0; cell < length; cell++) {
1151 for (var i = 0; i < CELL_SIZE; i++) {
1152 this._data[(destCol + cell) * CELL_SIZE + i] = srcData[(srcCol + cell) * CELL_SIZE + i];
1153 }
1154 }
1155 }
1156 var srcCombinedKeys = Object.keys(src._combined);
1157 for (var i = 0; i < srcCombinedKeys.length; i++) {
1158 var key = parseInt(srcCombinedKeys[i], 10);
1159 if (key >= srcCol) {
1160 this._combined[key - srcCol + destCol] = src._combined[key];
1161 }
1162 }
1163 };
1164 BufferLine.prototype.translateToString = function (trimRight, startCol, endCol) {
1165 if (trimRight === void 0) { trimRight = false; }
1166 if (startCol === void 0) { startCol = 0; }
1167 if (endCol === void 0) { endCol = this.length; }
1168 if (trimRight) {
1169 endCol = Math.min(endCol, this.getTrimmedLength());
1170 }
1171 var result = '';
1172 while (startCol < endCol) {
1173 var content = this._data[startCol * CELL_SIZE + 0];
1174 var cp = content & 2097151;
1175 result += (content & 2097152) ? this._combined[startCol] : (cp) ? TextDecoder_1.stringFromCodePoint(cp) : Buffer_1.WHITESPACE_CELL_CHAR;
1176 startCol += (content >> 22) || 1;
1177 }
1178 return result;
1179 };
1180 return BufferLine;
1181 }());
1182 exports.BufferLine = BufferLine;
1183
1184 },{"./Buffer":2,"./core/input/TextDecoder":32}],4:[function(require,module,exports){
1185 "use strict";
1186 Object.defineProperty(exports, "__esModule", { value: true });
1187 function reflowLargerGetLinesToRemove(lines, oldCols, newCols, bufferAbsoluteY, nullCell) {
1188 var toRemove = [];
1189 for (var y = 0; y < lines.length - 1; y++) {
1190 var i = y;
1191 var nextLine = lines.get(++i);
1192 if (!nextLine.isWrapped) {
1193 continue;
1194 }
1195 var wrappedLines = [lines.get(y)];
1196 while (i < lines.length && nextLine.isWrapped) {
1197 wrappedLines.push(nextLine);
1198 nextLine = lines.get(++i);
1199 }
1200 if (bufferAbsoluteY >= y && bufferAbsoluteY < i) {
1201 y += wrappedLines.length - 1;
1202 continue;
1203 }
1204 var destLineIndex = 0;
1205 var destCol = getWrappedLineTrimmedLength(wrappedLines, destLineIndex, oldCols);
1206 var srcLineIndex = 1;
1207 var srcCol = 0;
1208 while (srcLineIndex < wrappedLines.length) {
1209 var srcTrimmedTineLength = getWrappedLineTrimmedLength(wrappedLines, srcLineIndex, oldCols);
1210 var srcRemainingCells = srcTrimmedTineLength - srcCol;
1211 var destRemainingCells = newCols - destCol;
1212 var cellsToCopy = Math.min(srcRemainingCells, destRemainingCells);
1213 wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[srcLineIndex], srcCol, destCol, cellsToCopy, false);
1214 destCol += cellsToCopy;
1215 if (destCol === newCols) {
1216 destLineIndex++;
1217 destCol = 0;
1218 }
1219 srcCol += cellsToCopy;
1220 if (srcCol === srcTrimmedTineLength) {
1221 srcLineIndex++;
1222 srcCol = 0;
1223 }
1224 if (destCol === 0 && destLineIndex !== 0) {
1225 if (wrappedLines[destLineIndex - 1].getWidth(newCols - 1) === 2) {
1226 wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[destLineIndex - 1], newCols - 1, destCol++, 1, false);
1227 wrappedLines[destLineIndex - 1].setCell(newCols - 1, nullCell);
1228 }
1229 }
1230 }
1231 wrappedLines[destLineIndex].replaceCells(destCol, newCols, nullCell);
1232 var countToRemove = 0;
1233 for (var i_1 = wrappedLines.length - 1; i_1 > 0; i_1--) {
1234 if (i_1 > destLineIndex || wrappedLines[i_1].getTrimmedLength() === 0) {
1235 countToRemove++;
1236 }
1237 else {
1238 break;
1239 }
1240 }
1241 if (countToRemove > 0) {
1242 toRemove.push(y + wrappedLines.length - countToRemove);
1243 toRemove.push(countToRemove);
1244 }
1245 y += wrappedLines.length - 1;
1246 }
1247 return toRemove;
1248 }
1249 exports.reflowLargerGetLinesToRemove = reflowLargerGetLinesToRemove;
1250 function reflowLargerCreateNewLayout(lines, toRemove) {
1251 var layout = [];
1252 var nextToRemoveIndex = 0;
1253 var nextToRemoveStart = toRemove[nextToRemoveIndex];
1254 var countRemovedSoFar = 0;
1255 for (var i = 0; i < lines.length; i++) {
1256 if (nextToRemoveStart === i) {
1257 var countToRemove = toRemove[++nextToRemoveIndex];
1258 lines.onDeleteEmitter.fire({
1259 index: i - countRemovedSoFar,
1260 amount: countToRemove
1261 });
1262 i += countToRemove - 1;
1263 countRemovedSoFar += countToRemove;
1264 nextToRemoveStart = toRemove[++nextToRemoveIndex];
1265 }
1266 else {
1267 layout.push(i);
1268 }
1269 }
1270 return {
1271 layout: layout,
1272 countRemoved: countRemovedSoFar
1273 };
1274 }
1275 exports.reflowLargerCreateNewLayout = reflowLargerCreateNewLayout;
1276 function reflowLargerApplyNewLayout(lines, newLayout) {
1277 var newLayoutLines = [];
1278 for (var i = 0; i < newLayout.length; i++) {
1279 newLayoutLines.push(lines.get(newLayout[i]));
1280 }
1281 for (var i = 0; i < newLayoutLines.length; i++) {
1282 lines.set(i, newLayoutLines[i]);
1283 }
1284 lines.length = newLayout.length;
1285 }
1286 exports.reflowLargerApplyNewLayout = reflowLargerApplyNewLayout;
1287 function reflowSmallerGetNewLineLengths(wrappedLines, oldCols, newCols) {
1288 var newLineLengths = [];
1289 var cellsNeeded = wrappedLines.map(function (l, i) { return getWrappedLineTrimmedLength(wrappedLines, i, oldCols); }).reduce(function (p, c) { return p + c; });
1290 var srcCol = 0;
1291 var srcLine = 0;
1292 var cellsAvailable = 0;
1293 while (cellsAvailable < cellsNeeded) {
1294 if (cellsNeeded - cellsAvailable < newCols) {
1295 newLineLengths.push(cellsNeeded - cellsAvailable);
1296 break;
1297 }
1298 srcCol += newCols;
1299 var oldTrimmedLength = getWrappedLineTrimmedLength(wrappedLines, srcLine, oldCols);
1300 if (srcCol > oldTrimmedLength) {
1301 srcCol -= oldTrimmedLength;
1302 srcLine++;
1303 }
1304 var endsWithWide = wrappedLines[srcLine].getWidth(srcCol - 1) === 2;
1305 if (endsWithWide) {
1306 srcCol--;
1307 }
1308 var lineLength = endsWithWide ? newCols - 1 : newCols;
1309 newLineLengths.push(lineLength);
1310 cellsAvailable += lineLength;
1311 }
1312 return newLineLengths;
1313 }
1314 exports.reflowSmallerGetNewLineLengths = reflowSmallerGetNewLineLengths;
1315 function getWrappedLineTrimmedLength(lines, i, cols) {
1316 if (i === lines.length - 1) {
1317 return lines[i].getTrimmedLength();
1318 }
1319 var endsInNull = !(lines[i].hasContent(cols - 1)) && lines[i].getWidth(cols - 1) === 1;
1320 var followingLineStartsWithWide = lines[i + 1].getWidth(0) === 2;
1321 if (endsInNull && followingLineStartsWithWide) {
1322 return cols - 1;
1323 }
1324 return cols;
1325 }
1326 exports.getWrappedLineTrimmedLength = getWrappedLineTrimmedLength;
1327
1328 },{}],5:[function(require,module,exports){
1329 "use strict";
1330 Object.defineProperty(exports, "__esModule", { value: true });
1331 var Buffer_1 = require("./Buffer");
1332 var EventEmitter2_1 = require("./common/EventEmitter2");
1333 var BufferSet = (function () {
1334 function BufferSet(_terminal) {
1335 this._terminal = _terminal;
1336 this._onBufferActivate = new EventEmitter2_1.EventEmitter2();
1337 this._normal = new Buffer_1.Buffer(this._terminal, true);
1338 this._normal.fillViewportRows();
1339 this._alt = new Buffer_1.Buffer(this._terminal, false);
1340 this._activeBuffer = this._normal;
1341 this.setupTabStops();
1342 }
1343 Object.defineProperty(BufferSet.prototype, "onBufferActivate", {
1344 get: function () { return this._onBufferActivate.event; },
1345 enumerable: true,
1346 configurable: true
1347 });
1348 Object.defineProperty(BufferSet.prototype, "alt", {
1349 get: function () {
1350 return this._alt;
1351 },
1352 enumerable: true,
1353 configurable: true
1354 });
1355 Object.defineProperty(BufferSet.prototype, "active", {
1356 get: function () {
1357 return this._activeBuffer;
1358 },
1359 enumerable: true,
1360 configurable: true
1361 });
1362 Object.defineProperty(BufferSet.prototype, "normal", {
1363 get: function () {
1364 return this._normal;
1365 },
1366 enumerable: true,
1367 configurable: true
1368 });
1369 BufferSet.prototype.activateNormalBuffer = function () {
1370 if (this._activeBuffer === this._normal) {
1371 return;
1372 }
1373 this._normal.x = this._alt.x;
1374 this._normal.y = this._alt.y;
1375 this._alt.clear();
1376 this._activeBuffer = this._normal;
1377 this._onBufferActivate.fire({
1378 activeBuffer: this._normal,
1379 inactiveBuffer: this._alt
1380 });
1381 };
1382 BufferSet.prototype.activateAltBuffer = function (fillAttr) {
1383 if (this._activeBuffer === this._alt) {
1384 return;
1385 }
1386 this._alt.fillViewportRows(fillAttr);
1387 this._alt.x = this._normal.x;
1388 this._alt.y = this._normal.y;
1389 this._activeBuffer = this._alt;
1390 this._onBufferActivate.fire({
1391 activeBuffer: this._alt,
1392 inactiveBuffer: this._normal
1393 });
1394 };
1395 BufferSet.prototype.resize = function (newCols, newRows) {
1396 this._normal.resize(newCols, newRows);
1397 this._alt.resize(newCols, newRows);
1398 };
1399 BufferSet.prototype.setupTabStops = function (i) {
1400 this._normal.setupTabStops(i);
1401 this._alt.setupTabStops(i);
1402 };
1403 return BufferSet;
1404 }());
1405 exports.BufferSet = BufferSet;
1406
1407 },{"./Buffer":2,"./common/EventEmitter2":25}],6:[function(require,module,exports){
1408 "use strict";
1409 Object.defineProperty(exports, "__esModule", { value: true });
1410 var EventEmitter2_1 = require("./common/EventEmitter2");
1411 var CharMeasure = (function () {
1412 function CharMeasure(document, parentElement) {
1413 this._onCharSizeChanged = new EventEmitter2_1.EventEmitter2();
1414 this._document = document;
1415 this._parentElement = parentElement;
1416 this._measureElement = this._document.createElement('span');
1417 this._measureElement.classList.add('xterm-char-measure-element');
1418 this._measureElement.textContent = 'W';
1419 this._measureElement.setAttribute('aria-hidden', 'true');
1420 this._parentElement.appendChild(this._measureElement);
1421 }
1422 Object.defineProperty(CharMeasure.prototype, "onCharSizeChanged", {
1423 get: function () { return this._onCharSizeChanged.event; },
1424 enumerable: true,
1425 configurable: true
1426 });
1427 Object.defineProperty(CharMeasure.prototype, "width", {
1428 get: function () {
1429 return this._width;
1430 },
1431 enumerable: true,
1432 configurable: true
1433 });
1434 Object.defineProperty(CharMeasure.prototype, "height", {
1435 get: function () {
1436 return this._height;
1437 },
1438 enumerable: true,
1439 configurable: true
1440 });
1441 CharMeasure.prototype.measure = function (options) {
1442 this._measureElement.style.fontFamily = options.fontFamily;
1443 this._measureElement.style.fontSize = options.fontSize + "px";
1444 var geometry = this._measureElement.getBoundingClientRect();
1445 if (geometry.width === 0 || geometry.height === 0) {
1446 return;
1447 }
1448 var adjustedHeight = Math.ceil(geometry.height);
1449 if (this._width !== geometry.width || this._height !== adjustedHeight) {
1450 this._width = geometry.width;
1451 this._height = adjustedHeight;
1452 this._onCharSizeChanged.fire();
1453 }
1454 };
1455 return CharMeasure;
1456 }());
1457 exports.CharMeasure = CharMeasure;
1458
1459 },{"./common/EventEmitter2":25}],7:[function(require,module,exports){
1460 "use strict";
1461 Object.defineProperty(exports, "__esModule", { value: true });
1462 var TypedArrayUtils_1 = require("./common/TypedArrayUtils");
1463 exports.wcwidth = (function (opts) {
1464 var COMBINING_BMP = [
1465 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1466 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1467 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1468 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1469 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1470 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1471 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1472 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1473 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1474 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1475 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1476 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1477 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1478 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1479 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1480 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1481 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1482 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1483 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1484 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1485 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1486 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1487 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1488 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1489 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1490 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1491 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1492 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1493 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1494 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1495 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1496 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1497 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1498 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1499 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1500 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1501 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1502 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1503 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1504 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1505 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1506 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1507 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB]
1508 ];
1509 var COMBINING_HIGH = [
1510 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1511 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1512 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1513 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1514 [0xE0100, 0xE01EF]
1515 ];
1516 function bisearch(ucs, data) {
1517 var min = 0;
1518 var max = data.length - 1;
1519 var mid;
1520 if (ucs < data[0][0] || ucs > data[max][1]) {
1521 return false;
1522 }
1523 while (max >= min) {
1524 mid = (min + max) >> 1;
1525 if (ucs > data[mid][1]) {
1526 min = mid + 1;
1527 }
1528 else if (ucs < data[mid][0]) {
1529 max = mid - 1;
1530 }
1531 else {
1532 return true;
1533 }
1534 }
1535 return false;
1536 }
1537 function wcwidthHigh(ucs) {
1538 if (bisearch(ucs, COMBINING_HIGH)) {
1539 return 0;
1540 }
1541 if ((ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd)) {
1542 return 2;
1543 }
1544 return 1;
1545 }
1546 var control = opts.control | 0;
1547 var table = new Uint8Array(65536);
1548 TypedArrayUtils_1.fill(table, 1);
1549 table[0] = opts.nul;
1550 TypedArrayUtils_1.fill(table, opts.control, 1, 32);
1551 TypedArrayUtils_1.fill(table, opts.control, 0x7f, 0xa0);
1552 TypedArrayUtils_1.fill(table, 2, 0x1100, 0x1160);
1553 table[0x2329] = 2;
1554 table[0x232a] = 2;
1555 TypedArrayUtils_1.fill(table, 2, 0x2e80, 0xa4d0);
1556 table[0x303f] = 1;
1557 TypedArrayUtils_1.fill(table, 2, 0xac00, 0xd7a4);
1558 TypedArrayUtils_1.fill(table, 2, 0xf900, 0xfb00);
1559 TypedArrayUtils_1.fill(table, 2, 0xfe10, 0xfe1a);
1560 TypedArrayUtils_1.fill(table, 2, 0xfe30, 0xfe70);
1561 TypedArrayUtils_1.fill(table, 2, 0xff00, 0xff61);
1562 TypedArrayUtils_1.fill(table, 2, 0xffe0, 0xffe7);
1563 for (var r = 0; r < COMBINING_BMP.length; ++r) {
1564 TypedArrayUtils_1.fill(table, 0, COMBINING_BMP[r][0], COMBINING_BMP[r][1] + 1);
1565 }
1566 return function (num) {
1567 if (num < 32) {
1568 return control | 0;
1569 }
1570 if (num < 127) {
1571 return 1;
1572 }
1573 if (num < 65536) {
1574 return table[num];
1575 }
1576 return wcwidthHigh(num);
1577 };
1578 })({ nul: 0, control: 0 });
1579 function getStringCellWidth(s) {
1580 var result = 0;
1581 var length = s.length;
1582 for (var i = 0; i < length; ++i) {
1583 var code = s.charCodeAt(i);
1584 if (0xD800 <= code && code <= 0xDBFF) {
1585 if (++i >= length) {
1586 return result + exports.wcwidth(code);
1587 }
1588 var second = s.charCodeAt(i);
1589 if (0xDC00 <= second && second <= 0xDFFF) {
1590 code = (code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
1591 }
1592 else {
1593 result += exports.wcwidth(second);
1594 }
1595 }
1596 result += exports.wcwidth(code);
1597 }
1598 return result;
1599 }
1600 exports.getStringCellWidth = getStringCellWidth;
1601
1602 },{"./common/TypedArrayUtils":28}],8:[function(require,module,exports){
1603 "use strict";
1604 Object.defineProperty(exports, "__esModule", { value: true });
1605 function prepareTextForTerminal(text) {
1606 return text.replace(/\r?\n/g, '\r');
1607 }
1608 exports.prepareTextForTerminal = prepareTextForTerminal;
1609 function bracketTextForPaste(text, bracketedPasteMode) {
1610 if (bracketedPasteMode) {
1611 return '\x1b[200~' + text + '\x1b[201~';
1612 }
1613 return text;
1614 }
1615 exports.bracketTextForPaste = bracketTextForPaste;
1616 function copyHandler(ev, term, selectionManager) {
1617 if (term.browser.isMSIE) {
1618 window.clipboardData.setData('Text', selectionManager.selectionText);
1619 }
1620 else {
1621 ev.clipboardData.setData('text/plain', selectionManager.selectionText);
1622 }
1623 ev.preventDefault();
1624 }
1625 exports.copyHandler = copyHandler;
1626 function pasteHandler(ev, term) {
1627 ev.stopPropagation();
1628 var text;
1629 var dispatchPaste = function (text) {
1630 text = prepareTextForTerminal(text);
1631 text = bracketTextForPaste(text, term.bracketedPasteMode);
1632 term.handler(text);
1633 term.textarea.value = '';
1634 term.emit('paste', text);
1635 term.cancel(ev);
1636 };
1637 if (term.browser.isMSIE) {
1638 if (window.clipboardData) {
1639 text = window.clipboardData.getData('Text');
1640 dispatchPaste(text);
1641 }
1642 }
1643 else {
1644 if (ev.clipboardData) {
1645 text = ev.clipboardData.getData('text/plain');
1646 dispatchPaste(text);
1647 }
1648 }
1649 }
1650 exports.pasteHandler = pasteHandler;
1651 function moveTextAreaUnderMouseCursor(ev, term) {
1652 var pos = term.screenElement.getBoundingClientRect();
1653 var left = ev.clientX - pos.left - 10;
1654 var top = ev.clientY - pos.top - 10;
1655 term.textarea.style.position = 'absolute';
1656 term.textarea.style.width = '20px';
1657 term.textarea.style.height = '20px';
1658 term.textarea.style.left = left + "px";
1659 term.textarea.style.top = top + "px";
1660 term.textarea.style.zIndex = '1000';
1661 term.textarea.focus();
1662 setTimeout(function () {
1663 term.textarea.style.position = null;
1664 term.textarea.style.width = null;
1665 term.textarea.style.height = null;
1666 term.textarea.style.left = null;
1667 term.textarea.style.top = null;
1668 term.textarea.style.zIndex = null;
1669 }, 200);
1670 }
1671 exports.moveTextAreaUnderMouseCursor = moveTextAreaUnderMouseCursor;
1672 function rightClickHandler(ev, term, selectionManager, shouldSelectWord) {
1673 moveTextAreaUnderMouseCursor(ev, term);
1674 if (shouldSelectWord && !selectionManager.isClickInSelection(ev)) {
1675 selectionManager.selectWordAtCursor(ev);
1676 }
1677 term.textarea.value = selectionManager.selectionText;
1678 term.textarea.select();
1679 }
1680 exports.rightClickHandler = rightClickHandler;
1681
1682 },{}],9:[function(require,module,exports){
1683 "use strict";
1684 Object.defineProperty(exports, "__esModule", { value: true });
1685 var CompositionHelper = (function () {
1686 function CompositionHelper(_textarea, _compositionView, _terminal) {
1687 this._textarea = _textarea;
1688 this._compositionView = _compositionView;
1689 this._terminal = _terminal;
1690 this._isComposing = false;
1691 this._isSendingComposition = false;
1692 this._compositionPosition = { start: null, end: null };
1693 }
1694 CompositionHelper.prototype.compositionstart = function () {
1695 this._isComposing = true;
1696 this._compositionPosition.start = this._textarea.value.length;
1697 this._compositionView.textContent = '';
1698 this._compositionView.classList.add('active');
1699 };
1700 CompositionHelper.prototype.compositionupdate = function (ev) {
1701 var _this = this;
1702 this._compositionView.textContent = ev.data;
1703 this.updateCompositionElements();
1704 setTimeout(function () {
1705 _this._compositionPosition.end = _this._textarea.value.length;
1706 }, 0);
1707 };
1708 CompositionHelper.prototype.compositionend = function () {
1709 this._finalizeComposition(true);
1710 };
1711 CompositionHelper.prototype.keydown = function (ev) {
1712 if (this._isComposing || this._isSendingComposition) {
1713 if (ev.keyCode === 229) {
1714 return false;
1715 }
1716 else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
1717 return false;
1718 }
1719 this._finalizeComposition(false);
1720 }
1721 if (ev.keyCode === 229) {
1722 this._handleAnyTextareaChanges();
1723 return false;
1724 }
1725 return true;
1726 };
1727 CompositionHelper.prototype._finalizeComposition = function (waitForPropagation) {
1728 var _this = this;
1729 this._compositionView.classList.remove('active');
1730 this._isComposing = false;
1731 this._clearTextareaPosition();
1732 if (!waitForPropagation) {
1733 this._isSendingComposition = false;
1734 var input = this._textarea.value.substring(this._compositionPosition.start, this._compositionPosition.end);
1735 this._terminal.handler(input);
1736 }
1737 else {
1738 var currentCompositionPosition_1 = {
1739 start: this._compositionPosition.start,
1740 end: this._compositionPosition.end
1741 };
1742 this._isSendingComposition = true;
1743 setTimeout(function () {
1744 if (_this._isSendingComposition) {
1745 _this._isSendingComposition = false;
1746 var input = void 0;
1747 if (_this._isComposing) {
1748 input = _this._textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end);
1749 }
1750 else {
1751 input = _this._textarea.value.substring(currentCompositionPosition_1.start);
1752 }
1753 _this._terminal.handler(input);
1754 }
1755 }, 0);
1756 }
1757 };
1758 CompositionHelper.prototype._handleAnyTextareaChanges = function () {
1759 var _this = this;
1760 var oldValue = this._textarea.value;
1761 setTimeout(function () {
1762 if (!_this._isComposing) {
1763 var newValue = _this._textarea.value;
1764 var diff = newValue.replace(oldValue, '');
1765 if (diff.length > 0) {
1766 _this._terminal.handler(diff);
1767 }
1768 }
1769 }, 0);
1770 };
1771 CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
1772 var _this = this;
1773 if (!this._isComposing) {
1774 return;
1775 }
1776 if (this._terminal.buffer.isCursorInViewport) {
1777 var cellHeight = Math.ceil(this._terminal.charMeasure.height * this._terminal.options.lineHeight);
1778 var cursorTop = this._terminal.buffer.y * cellHeight;
1779 var cursorLeft = this._terminal.buffer.x * this._terminal.charMeasure.width;
1780 this._compositionView.style.left = cursorLeft + 'px';
1781 this._compositionView.style.top = cursorTop + 'px';
1782 this._compositionView.style.height = cellHeight + 'px';
1783 this._compositionView.style.lineHeight = cellHeight + 'px';
1784 this._compositionView.style.fontFamily = this._terminal.options.fontFamily;
1785 this._compositionView.style.fontSize = this._terminal.options.fontSize + 'px';
1786 var compositionViewBounds = this._compositionView.getBoundingClientRect();
1787 this._textarea.style.left = cursorLeft + 'px';
1788 this._textarea.style.top = cursorTop + 'px';
1789 this._textarea.style.width = compositionViewBounds.width + 'px';
1790 this._textarea.style.height = compositionViewBounds.height + 'px';
1791 this._textarea.style.lineHeight = compositionViewBounds.height + 'px';
1792 }
1793 if (!dontRecurse) {
1794 setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
1795 }
1796 };
1797 CompositionHelper.prototype._clearTextareaPosition = function () {
1798 this._textarea.style.left = '';
1799 this._textarea.style.top = '';
1800 };
1801 return CompositionHelper;
1802 }());
1803 exports.CompositionHelper = CompositionHelper;
1804
1805 },{}],10:[function(require,module,exports){
1806 "use strict";
1807 var __extends = (this && this.__extends) || (function () {
1808 var extendStatics = function (d, b) {
1809 extendStatics = Object.setPrototypeOf ||
1810 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1811 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1812 return extendStatics(d, b);
1813 };
1814 return function (d, b) {
1815 extendStatics(d, b);
1816 function __() { this.constructor = d; }
1817 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1818 };
1819 })();
1820 Object.defineProperty(exports, "__esModule", { value: true });
1821 var Lifecycle_1 = require("./common/Lifecycle");
1822 var TextDecoder_1 = require("./core/input/TextDecoder");
1823 function r(low, high) {
1824 var c = high - low;
1825 var arr = new Array(c);
1826 while (c--) {
1827 arr[c] = --high;
1828 }
1829 return arr;
1830 }
1831 var TransitionTable = (function () {
1832 function TransitionTable(length) {
1833 this.table = (typeof Uint8Array === 'undefined')
1834 ? new Array(length)
1835 : new Uint8Array(length);
1836 }
1837 TransitionTable.prototype.add = function (code, state, action, next) {
1838 this.table[state << 8 | code] = ((action | 0) << 4) | ((next === undefined) ? state : next);
1839 };
1840 TransitionTable.prototype.addMany = function (codes, state, action, next) {
1841 for (var i = 0; i < codes.length; i++) {
1842 this.add(codes[i], state, action, next);
1843 }
1844 };
1845 return TransitionTable;
1846 }());
1847 exports.TransitionTable = TransitionTable;
1848 var PRINTABLES = r(0x20, 0x7f);
1849 var EXECUTABLES = r(0x00, 0x18);
1850 EXECUTABLES.push(0x19);
1851 EXECUTABLES.push.apply(EXECUTABLES, r(0x1c, 0x20));
1852 var NON_ASCII_PRINTABLE = 0xA0;
1853 exports.VT500_TRANSITION_TABLE = (function () {
1854 var table = new TransitionTable(4095);
1855 var states = r(0, 13 + 1);
1856 var state;
1857 for (state in states) {
1858 for (var code = 0; code <= NON_ASCII_PRINTABLE; ++code) {
1859 table.add(code, state, 1, 0);
1860 }
1861 }
1862 table.addMany(PRINTABLES, 0, 2, 0);
1863 for (state in states) {
1864 table.addMany([0x18, 0x1a, 0x99, 0x9a], state, 3, 0);
1865 table.addMany(r(0x80, 0x90), state, 3, 0);
1866 table.addMany(r(0x90, 0x98), state, 3, 0);
1867 table.add(0x9c, state, 0, 0);
1868 table.add(0x1b, state, 11, 1);
1869 table.add(0x9d, state, 4, 8);
1870 table.addMany([0x98, 0x9e, 0x9f], state, 0, 7);
1871 table.add(0x9b, state, 11, 3);
1872 table.add(0x90, state, 11, 9);
1873 }
1874 table.addMany(EXECUTABLES, 0, 3, 0);
1875 table.addMany(EXECUTABLES, 1, 3, 1);
1876 table.add(0x7f, 1, 0, 1);
1877 table.addMany(EXECUTABLES, 8, 0, 8);
1878 table.addMany(EXECUTABLES, 3, 3, 3);
1879 table.add(0x7f, 3, 0, 3);
1880 table.addMany(EXECUTABLES, 4, 3, 4);
1881 table.add(0x7f, 4, 0, 4);
1882 table.addMany(EXECUTABLES, 6, 3, 6);
1883 table.addMany(EXECUTABLES, 5, 3, 5);
1884 table.add(0x7f, 5, 0, 5);
1885 table.addMany(EXECUTABLES, 2, 3, 2);
1886 table.add(0x7f, 2, 0, 2);
1887 table.add(0x5d, 1, 4, 8);
1888 table.addMany(PRINTABLES, 8, 5, 8);
1889 table.add(0x7f, 8, 5, 8);
1890 table.addMany([0x9c, 0x1b, 0x18, 0x1a, 0x07], 8, 6, 0);
1891 table.addMany(r(0x1c, 0x20), 8, 0, 8);
1892 table.addMany([0x58, 0x5e, 0x5f], 1, 0, 7);
1893 table.addMany(PRINTABLES, 7, 0, 7);
1894 table.addMany(EXECUTABLES, 7, 0, 7);
1895 table.add(0x9c, 7, 0, 0);
1896 table.add(0x7f, 7, 0, 7);
1897 table.add(0x5b, 1, 11, 3);
1898 table.addMany(r(0x40, 0x7f), 3, 7, 0);
1899 table.addMany(r(0x30, 0x3a), 3, 8, 4);
1900 table.add(0x3b, 3, 8, 4);
1901 table.addMany([0x3c, 0x3d, 0x3e, 0x3f], 3, 9, 4);
1902 table.addMany(r(0x30, 0x3a), 4, 8, 4);
1903 table.add(0x3b, 4, 8, 4);
1904 table.addMany(r(0x40, 0x7f), 4, 7, 0);
1905 table.addMany([0x3a, 0x3c, 0x3d, 0x3e, 0x3f], 4, 0, 6);
1906 table.addMany(r(0x20, 0x40), 6, 0, 6);
1907 table.add(0x7f, 6, 0, 6);
1908 table.addMany(r(0x40, 0x7f), 6, 0, 0);
1909 table.add(0x3a, 3, 0, 6);
1910 table.addMany(r(0x20, 0x30), 3, 9, 5);
1911 table.addMany(r(0x20, 0x30), 5, 9, 5);
1912 table.addMany(r(0x30, 0x40), 5, 0, 6);
1913 table.addMany(r(0x40, 0x7f), 5, 7, 0);
1914 table.addMany(r(0x20, 0x30), 4, 9, 5);
1915 table.addMany(r(0x20, 0x30), 1, 9, 2);
1916 table.addMany(r(0x20, 0x30), 2, 9, 2);
1917 table.addMany(r(0x30, 0x7f), 2, 10, 0);
1918 table.addMany(r(0x30, 0x50), 1, 10, 0);
1919 table.addMany(r(0x51, 0x58), 1, 10, 0);
1920 table.addMany([0x59, 0x5a, 0x5c], 1, 10, 0);
1921 table.addMany(r(0x60, 0x7f), 1, 10, 0);
1922 table.add(0x50, 1, 11, 9);
1923 table.addMany(EXECUTABLES, 9, 0, 9);
1924 table.add(0x7f, 9, 0, 9);
1925 table.addMany(r(0x1c, 0x20), 9, 0, 9);
1926 table.addMany(r(0x20, 0x30), 9, 9, 12);
1927 table.add(0x3a, 9, 0, 11);
1928 table.addMany(r(0x30, 0x3a), 9, 8, 10);
1929 table.add(0x3b, 9, 8, 10);
1930 table.addMany([0x3c, 0x3d, 0x3e, 0x3f], 9, 9, 10);
1931 table.addMany(EXECUTABLES, 11, 0, 11);
1932 table.addMany(r(0x20, 0x80), 11, 0, 11);
1933 table.addMany(r(0x1c, 0x20), 11, 0, 11);
1934 table.addMany(EXECUTABLES, 10, 0, 10);
1935 table.add(0x7f, 10, 0, 10);
1936 table.addMany(r(0x1c, 0x20), 10, 0, 10);
1937 table.addMany(r(0x30, 0x3a), 10, 8, 10);
1938 table.add(0x3b, 10, 8, 10);
1939 table.addMany([0x3a, 0x3c, 0x3d, 0x3e, 0x3f], 10, 0, 11);
1940 table.addMany(r(0x20, 0x30), 10, 9, 12);
1941 table.addMany(EXECUTABLES, 12, 0, 12);
1942 table.add(0x7f, 12, 0, 12);
1943 table.addMany(r(0x1c, 0x20), 12, 0, 12);
1944 table.addMany(r(0x20, 0x30), 12, 9, 12);
1945 table.addMany(r(0x30, 0x40), 12, 0, 11);
1946 table.addMany(r(0x40, 0x7f), 12, 12, 13);
1947 table.addMany(r(0x40, 0x7f), 10, 12, 13);
1948 table.addMany(r(0x40, 0x7f), 9, 12, 13);
1949 table.addMany(EXECUTABLES, 13, 13, 13);
1950 table.addMany(PRINTABLES, 13, 13, 13);
1951 table.add(0x7f, 13, 0, 13);
1952 table.addMany([0x1b, 0x9c], 13, 14, 0);
1953 table.add(NON_ASCII_PRINTABLE, 8, 5, 8);
1954 return table;
1955 })();
1956 var DcsDummy = (function () {
1957 function DcsDummy() {
1958 }
1959 DcsDummy.prototype.hook = function (collect, params, flag) { };
1960 DcsDummy.prototype.put = function (data, start, end) { };
1961 DcsDummy.prototype.unhook = function () { };
1962 return DcsDummy;
1963 }());
1964 var EscapeSequenceParser = (function (_super) {
1965 __extends(EscapeSequenceParser, _super);
1966 function EscapeSequenceParser(TRANSITIONS) {
1967 if (TRANSITIONS === void 0) { TRANSITIONS = exports.VT500_TRANSITION_TABLE; }
1968 var _this = _super.call(this) || this;
1969 _this.TRANSITIONS = TRANSITIONS;
1970 _this.initialState = 0;
1971 _this.currentState = _this.initialState;
1972 _this._osc = '';
1973 _this._params = [0];
1974 _this._collect = '';
1975 _this._printHandlerFb = function (data, start, end) { };
1976 _this._executeHandlerFb = function (code) { };
1977 _this._csiHandlerFb = function (collect, params, flag) { };
1978 _this._escHandlerFb = function (collect, flag) { };
1979 _this._oscHandlerFb = function (identifier, data) { };
1980 _this._dcsHandlerFb = new DcsDummy();
1981 _this._errorHandlerFb = function (state) { return state; };
1982 _this._printHandler = _this._printHandlerFb;
1983 _this._executeHandlers = Object.create(null);
1984 _this._csiHandlers = Object.create(null);
1985 _this._escHandlers = Object.create(null);
1986 _this._oscHandlers = Object.create(null);
1987 _this._dcsHandlers = Object.create(null);
1988 _this._activeDcsHandler = null;
1989 _this._errorHandler = _this._errorHandlerFb;
1990 _this.setEscHandler('\\', function () { });
1991 return _this;
1992 }
1993 EscapeSequenceParser.prototype.dispose = function () {
1994 this._printHandlerFb = null;
1995 this._executeHandlerFb = null;
1996 this._csiHandlerFb = null;
1997 this._escHandlerFb = null;
1998 this._oscHandlerFb = null;
1999 this._dcsHandlerFb = null;
2000 this._errorHandlerFb = null;
2001 this._printHandler = null;
2002 this._executeHandlers = null;
2003 this._escHandlers = null;
2004 this._csiHandlers = null;
2005 this._oscHandlers = null;
2006 this._dcsHandlers = null;
2007 this._activeDcsHandler = null;
2008 this._errorHandler = null;
2009 };
2010 EscapeSequenceParser.prototype.setPrintHandler = function (callback) {
2011 this._printHandler = callback;
2012 };
2013 EscapeSequenceParser.prototype.clearPrintHandler = function () {
2014 this._printHandler = this._printHandlerFb;
2015 };
2016 EscapeSequenceParser.prototype.setExecuteHandler = function (flag, callback) {
2017 this._executeHandlers[flag.charCodeAt(0)] = callback;
2018 };
2019 EscapeSequenceParser.prototype.clearExecuteHandler = function (flag) {
2020 if (this._executeHandlers[flag.charCodeAt(0)])
2021 delete this._executeHandlers[flag.charCodeAt(0)];
2022 };
2023 EscapeSequenceParser.prototype.setExecuteHandlerFallback = function (callback) {
2024 this._executeHandlerFb = callback;
2025 };
2026 EscapeSequenceParser.prototype.addCsiHandler = function (flag, callback) {
2027 var index = flag.charCodeAt(0);
2028 if (this._csiHandlers[index] === undefined) {
2029 this._csiHandlers[index] = [];
2030 }
2031 var handlerList = this._csiHandlers[index];
2032 handlerList.push(callback);
2033 return {
2034 dispose: function () {
2035 var handlerIndex = handlerList.indexOf(callback);
2036 if (handlerIndex !== -1) {
2037 handlerList.splice(handlerIndex, 1);
2038 }
2039 }
2040 };
2041 };
2042 EscapeSequenceParser.prototype.setCsiHandler = function (flag, callback) {
2043 this._csiHandlers[flag.charCodeAt(0)] = [callback];
2044 };
2045 EscapeSequenceParser.prototype.clearCsiHandler = function (flag) {
2046 if (this._csiHandlers[flag.charCodeAt(0)])
2047 delete this._csiHandlers[flag.charCodeAt(0)];
2048 };
2049 EscapeSequenceParser.prototype.setCsiHandlerFallback = function (callback) {
2050 this._csiHandlerFb = callback;
2051 };
2052 EscapeSequenceParser.prototype.setEscHandler = function (collectAndFlag, callback) {
2053 this._escHandlers[collectAndFlag] = callback;
2054 };
2055 EscapeSequenceParser.prototype.clearEscHandler = function (collectAndFlag) {
2056 if (this._escHandlers[collectAndFlag])
2057 delete this._escHandlers[collectAndFlag];
2058 };
2059 EscapeSequenceParser.prototype.setEscHandlerFallback = function (callback) {
2060 this._escHandlerFb = callback;
2061 };
2062 EscapeSequenceParser.prototype.addOscHandler = function (ident, callback) {
2063 if (this._oscHandlers[ident] === undefined) {
2064 this._oscHandlers[ident] = [];
2065 }
2066 var handlerList = this._oscHandlers[ident];
2067 handlerList.push(callback);
2068 return {
2069 dispose: function () {
2070 var handlerIndex = handlerList.indexOf(callback);
2071 if (handlerIndex !== -1) {
2072 handlerList.splice(handlerIndex, 1);
2073 }
2074 }
2075 };
2076 };
2077 EscapeSequenceParser.prototype.setOscHandler = function (ident, callback) {
2078 this._oscHandlers[ident] = [callback];
2079 };
2080 EscapeSequenceParser.prototype.clearOscHandler = function (ident) {
2081 if (this._oscHandlers[ident])
2082 delete this._oscHandlers[ident];
2083 };
2084 EscapeSequenceParser.prototype.setOscHandlerFallback = function (callback) {
2085 this._oscHandlerFb = callback;
2086 };
2087 EscapeSequenceParser.prototype.setDcsHandler = function (collectAndFlag, handler) {
2088 this._dcsHandlers[collectAndFlag] = handler;
2089 };
2090 EscapeSequenceParser.prototype.clearDcsHandler = function (collectAndFlag) {
2091 if (this._dcsHandlers[collectAndFlag])
2092 delete this._dcsHandlers[collectAndFlag];
2093 };
2094 EscapeSequenceParser.prototype.setDcsHandlerFallback = function (handler) {
2095 this._dcsHandlerFb = handler;
2096 };
2097 EscapeSequenceParser.prototype.setErrorHandler = function (callback) {
2098 this._errorHandler = callback;
2099 };
2100 EscapeSequenceParser.prototype.clearErrorHandler = function () {
2101 this._errorHandler = this._errorHandlerFb;
2102 };
2103 EscapeSequenceParser.prototype.reset = function () {
2104 this.currentState = this.initialState;
2105 this._osc = '';
2106 this._params = [0];
2107 this._collect = '';
2108 this._activeDcsHandler = null;
2109 };
2110 EscapeSequenceParser.prototype.parse = function (data, length) {
2111 var code = 0;
2112 var transition = 0;
2113 var error = false;
2114 var currentState = this.currentState;
2115 var print = -1;
2116 var dcs = -1;
2117 var osc = this._osc;
2118 var collect = this._collect;
2119 var params = this._params;
2120 var table = this.TRANSITIONS.table;
2121 var dcsHandler = this._activeDcsHandler;
2122 var callback = null;
2123 for (var i = 0; i < length; ++i) {
2124 code = data[i];
2125 if (currentState === 0 && code > 0x1f && code < 0x80) {
2126 print = (~print) ? print : i;
2127 do
2128 i++;
2129 while (i < length && data[i] > 0x1f && data[i] < 0x80);
2130 i--;
2131 continue;
2132 }
2133 if (currentState === 4 && (code > 0x2f && code < 0x39)) {
2134 params[params.length - 1] = params[params.length - 1] * 10 + code - 48;
2135 continue;
2136 }
2137 transition = table[currentState << 8 | (code < 0xa0 ? code : NON_ASCII_PRINTABLE)];
2138 switch (transition >> 4) {
2139 case 2:
2140 print = (~print) ? print : i;
2141 break;
2142 case 3:
2143 if (~print) {
2144 this._printHandler(data, print, i);
2145 print = -1;
2146 }
2147 callback = this._executeHandlers[code];
2148 if (callback)
2149 callback();
2150 else
2151 this._executeHandlerFb(code);
2152 break;
2153 case 0:
2154 if (~print) {
2155 this._printHandler(data, print, i);
2156 print = -1;
2157 }
2158 else if (~dcs) {
2159 dcsHandler.put(data, dcs, i);
2160 dcs = -1;
2161 }
2162 break;
2163 case 1:
2164 if (code > 0x9f) {
2165 switch (currentState) {
2166 case 0:
2167 print = (~print) ? print : i;
2168 break;
2169 case 6:
2170 transition |= 6;
2171 break;
2172 case 11:
2173 transition |= 11;
2174 break;
2175 case 13:
2176 dcs = (~dcs) ? dcs : i;
2177 transition |= 13;
2178 break;
2179 default:
2180 error = true;
2181 }
2182 }
2183 else {
2184 error = true;
2185 }
2186 if (error) {
2187 var inject = this._errorHandler({
2188 position: i,
2189 code: code,
2190 currentState: currentState,
2191 print: print,
2192 dcs: dcs,
2193 osc: osc,
2194 collect: collect,
2195 params: params,
2196 abort: false
2197 });
2198 if (inject.abort)
2199 return;
2200 error = false;
2201 }
2202 break;
2203 case 7:
2204 var handlers = this._csiHandlers[code];
2205 var j = handlers ? handlers.length - 1 : -1;
2206 for (; j >= 0; j--) {
2207 if (handlers[j](params, collect) !== false) {
2208 break;
2209 }
2210 }
2211 if (j < 0) {
2212 this._csiHandlerFb(collect, params, code);
2213 }
2214 break;
2215 case 8:
2216 if (code === 0x3b)
2217 params.push(0);
2218 else
2219 params[params.length - 1] = params[params.length - 1] * 10 + code - 48;
2220 break;
2221 case 9:
2222 collect += String.fromCharCode(code);
2223 break;
2224 case 10:
2225 callback = this._escHandlers[collect + String.fromCharCode(code)];
2226 if (callback)
2227 callback(collect, code);
2228 else
2229 this._escHandlerFb(collect, code);
2230 break;
2231 case 11:
2232 if (~print) {
2233 this._printHandler(data, print, i);
2234 print = -1;
2235 }
2236 osc = '';
2237 params = [0];
2238 collect = '';
2239 dcs = -1;
2240 break;
2241 case 12:
2242 dcsHandler = this._dcsHandlers[collect + String.fromCharCode(code)];
2243 if (!dcsHandler)
2244 dcsHandler = this._dcsHandlerFb;
2245 dcsHandler.hook(collect, params, code);
2246 break;
2247 case 13:
2248 dcs = (~dcs) ? dcs : i;
2249 break;
2250 case 14:
2251 if (dcsHandler) {
2252 if (~dcs)
2253 dcsHandler.put(data, dcs, i);
2254 dcsHandler.unhook();
2255 dcsHandler = null;
2256 }
2257 if (code === 0x1b)
2258 transition |= 1;
2259 osc = '';
2260 params = [0];
2261 collect = '';
2262 dcs = -1;
2263 break;
2264 case 4:
2265 if (~print) {
2266 this._printHandler(data, print, i);
2267 print = -1;
2268 }
2269 osc = '';
2270 break;
2271 case 5:
2272 for (var j_1 = i + 1;; j_1++) {
2273 if (j_1 >= length
2274 || (code = data[j_1]) < 0x20
2275 || (code > 0x7f && code <= 0x9f)) {
2276 osc += TextDecoder_1.utf32ToString(data, i, j_1);
2277 i = j_1 - 1;
2278 break;
2279 }
2280 }
2281 break;
2282 case 6:
2283 if (osc && code !== 0x18 && code !== 0x1a) {
2284 var idx = osc.indexOf(';');
2285 if (idx === -1) {
2286 this._oscHandlerFb(-1, osc);
2287 }
2288 else {
2289 var identifier = parseInt(osc.substring(0, idx));
2290 var content = osc.substring(idx + 1);
2291 var handlers_1 = this._oscHandlers[identifier];
2292 var j_2 = handlers_1 ? handlers_1.length - 1 : -1;
2293 for (; j_2 >= 0; j_2--) {
2294 if (handlers_1[j_2](content) !== false) {
2295 break;
2296 }
2297 }
2298 if (j_2 < 0) {
2299 this._oscHandlerFb(identifier, content);
2300 }
2301 }
2302 }
2303 if (code === 0x1b)
2304 transition |= 1;
2305 osc = '';
2306 params = [0];
2307 collect = '';
2308 dcs = -1;
2309 break;
2310 }
2311 currentState = transition & 15;
2312 }
2313 if (currentState === 0 && ~print) {
2314 this._printHandler(data, print, length);
2315 }
2316 else if (currentState === 13 && ~dcs && dcsHandler) {
2317 dcsHandler.put(data, dcs, length);
2318 }
2319 this._osc = osc;
2320 this._collect = collect;
2321 this._params = params;
2322 this._activeDcsHandler = dcsHandler;
2323 this.currentState = currentState;
2324 };
2325 return EscapeSequenceParser;
2326 }(Lifecycle_1.Disposable));
2327 exports.EscapeSequenceParser = EscapeSequenceParser;
2328
2329 },{"./common/Lifecycle":26,"./core/input/TextDecoder":32}],11:[function(require,module,exports){
2330 "use strict";
2331 var __extends = (this && this.__extends) || (function () {
2332 var extendStatics = function (d, b) {
2333 extendStatics = Object.setPrototypeOf ||
2334 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2335 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2336 return extendStatics(d, b);
2337 };
2338 return function (d, b) {
2339 extendStatics(d, b);
2340 function __() { this.constructor = d; }
2341 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2342 };
2343 })();
2344 Object.defineProperty(exports, "__esModule", { value: true });
2345 var EscapeSequences_1 = require("./common/data/EscapeSequences");
2346 var Charsets_1 = require("./core/data/Charsets");
2347 var Buffer_1 = require("./Buffer");
2348 var CharWidth_1 = require("./CharWidth");
2349 var EscapeSequenceParser_1 = require("./EscapeSequenceParser");
2350 var Lifecycle_1 = require("./common/Lifecycle");
2351 var TypedArrayUtils_1 = require("./common/TypedArrayUtils");
2352 var TextDecoder_1 = require("./core/input/TextDecoder");
2353 var BufferLine_1 = require("./BufferLine");
2354 var EventEmitter2_1 = require("./common/EventEmitter2");
2355 var GLEVEL = { '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2 };
2356 var DECRQSS = (function () {
2357 function DECRQSS(_terminal) {
2358 this._terminal = _terminal;
2359 this._data = new Uint32Array(0);
2360 }
2361 DECRQSS.prototype.hook = function (collect, params, flag) {
2362 this._data = new Uint32Array(0);
2363 };
2364 DECRQSS.prototype.put = function (data, start, end) {
2365 this._data = TypedArrayUtils_1.concat(this._data, data.subarray(start, end));
2366 };
2367 DECRQSS.prototype.unhook = function () {
2368 var data = TextDecoder_1.utf32ToString(this._data);
2369 this._data = new Uint32Array(0);
2370 switch (data) {
2371 case '"q':
2372 return this._terminal.handler(EscapeSequences_1.C0.ESC + "P1$r0\"q" + EscapeSequences_1.C0.ESC + "\\");
2373 case '"p':
2374 return this._terminal.handler(EscapeSequences_1.C0.ESC + "P1$r61\"p" + EscapeSequences_1.C0.ESC + "\\");
2375 case 'r':
2376 var pt = '' + (this._terminal.buffer.scrollTop + 1) +
2377 ';' + (this._terminal.buffer.scrollBottom + 1) + 'r';
2378 return this._terminal.handler(EscapeSequences_1.C0.ESC + "P1$r" + pt + EscapeSequences_1.C0.ESC + "\\");
2379 case 'm':
2380 return this._terminal.handler(EscapeSequences_1.C0.ESC + "P1$r0m" + EscapeSequences_1.C0.ESC + "\\");
2381 case ' q':
2382 var STYLES = { 'block': 2, 'underline': 4, 'bar': 6 };
2383 var style = STYLES[this._terminal.getOption('cursorStyle')];
2384 style -= this._terminal.getOption('cursorBlink');
2385 return this._terminal.handler(EscapeSequences_1.C0.ESC + "P1$r" + style + " q" + EscapeSequences_1.C0.ESC + "\\");
2386 default:
2387 this._terminal.error('Unknown DCS $q %s', data);
2388 this._terminal.handler(EscapeSequences_1.C0.ESC + "P0$r" + EscapeSequences_1.C0.ESC + "\\");
2389 }
2390 };
2391 return DECRQSS;
2392 }());
2393 var InputHandler = (function (_super) {
2394 __extends(InputHandler, _super);
2395 function InputHandler(_terminal, _parser) {
2396 if (_parser === void 0) { _parser = new EscapeSequenceParser_1.EscapeSequenceParser(); }
2397 var _this = _super.call(this) || this;
2398 _this._terminal = _terminal;
2399 _this._parser = _parser;
2400 _this._parseBuffer = new Uint32Array(4096);
2401 _this._stringDecoder = new TextDecoder_1.StringToUtf32();
2402 _this._workCell = new BufferLine_1.CellData();
2403 _this._onCursorMove = new EventEmitter2_1.EventEmitter2();
2404 _this._onData = new EventEmitter2_1.EventEmitter2();
2405 _this._onLineFeed = new EventEmitter2_1.EventEmitter2();
2406 _this._onScroll = new EventEmitter2_1.EventEmitter2();
2407 _this.register(_this._parser);
2408 _this._parser.setCsiHandlerFallback(function (collect, params, flag) {
2409 _this._terminal.error('Unknown CSI code: ', { collect: collect, params: params, flag: String.fromCharCode(flag) });
2410 });
2411 _this._parser.setEscHandlerFallback(function (collect, flag) {
2412 _this._terminal.error('Unknown ESC code: ', { collect: collect, flag: String.fromCharCode(flag) });
2413 });
2414 _this._parser.setExecuteHandlerFallback(function (code) {
2415 _this._terminal.error('Unknown EXECUTE code: ', { code: code });
2416 });
2417 _this._parser.setOscHandlerFallback(function (identifier, data) {
2418 _this._terminal.error('Unknown OSC code: ', { identifier: identifier, data: data });
2419 });
2420 _this._parser.setPrintHandler(function (data, start, end) { return _this.print(data, start, end); });
2421 _this._parser.setCsiHandler('@', function (params, collect) { return _this.insertChars(params); });
2422 _this._parser.setCsiHandler('A', function (params, collect) { return _this.cursorUp(params); });
2423 _this._parser.setCsiHandler('B', function (params, collect) { return _this.cursorDown(params); });
2424 _this._parser.setCsiHandler('C', function (params, collect) { return _this.cursorForward(params); });
2425 _this._parser.setCsiHandler('D', function (params, collect) { return _this.cursorBackward(params); });
2426 _this._parser.setCsiHandler('E', function (params, collect) { return _this.cursorNextLine(params); });
2427 _this._parser.setCsiHandler('F', function (params, collect) { return _this.cursorPrecedingLine(params); });
2428 _this._parser.setCsiHandler('G', function (params, collect) { return _this.cursorCharAbsolute(params); });
2429 _this._parser.setCsiHandler('H', function (params, collect) { return _this.cursorPosition(params); });
2430 _this._parser.setCsiHandler('I', function (params, collect) { return _this.cursorForwardTab(params); });
2431 _this._parser.setCsiHandler('J', function (params, collect) { return _this.eraseInDisplay(params); });
2432 _this._parser.setCsiHandler('K', function (params, collect) { return _this.eraseInLine(params); });
2433 _this._parser.setCsiHandler('L', function (params, collect) { return _this.insertLines(params); });
2434 _this._parser.setCsiHandler('M', function (params, collect) { return _this.deleteLines(params); });
2435 _this._parser.setCsiHandler('P', function (params, collect) { return _this.deleteChars(params); });
2436 _this._parser.setCsiHandler('S', function (params, collect) { return _this.scrollUp(params); });
2437 _this._parser.setCsiHandler('T', function (params, collect) { return _this.scrollDown(params, collect); });
2438 _this._parser.setCsiHandler('X', function (params, collect) { return _this.eraseChars(params); });
2439 _this._parser.setCsiHandler('Z', function (params, collect) { return _this.cursorBackwardTab(params); });
2440 _this._parser.setCsiHandler('`', function (params, collect) { return _this.charPosAbsolute(params); });
2441 _this._parser.setCsiHandler('a', function (params, collect) { return _this.hPositionRelative(params); });
2442 _this._parser.setCsiHandler('b', function (params, collect) { return _this.repeatPrecedingCharacter(params); });
2443 _this._parser.setCsiHandler('c', function (params, collect) { return _this.sendDeviceAttributes(params, collect); });
2444 _this._parser.setCsiHandler('d', function (params, collect) { return _this.linePosAbsolute(params); });
2445 _this._parser.setCsiHandler('e', function (params, collect) { return _this.vPositionRelative(params); });
2446 _this._parser.setCsiHandler('f', function (params, collect) { return _this.hVPosition(params); });
2447 _this._parser.setCsiHandler('g', function (params, collect) { return _this.tabClear(params); });
2448 _this._parser.setCsiHandler('h', function (params, collect) { return _this.setMode(params, collect); });
2449 _this._parser.setCsiHandler('l', function (params, collect) { return _this.resetMode(params, collect); });
2450 _this._parser.setCsiHandler('m', function (params, collect) { return _this.charAttributes(params); });
2451 _this._parser.setCsiHandler('n', function (params, collect) { return _this.deviceStatus(params, collect); });
2452 _this._parser.setCsiHandler('p', function (params, collect) { return _this.softReset(params, collect); });
2453 _this._parser.setCsiHandler('q', function (params, collect) { return _this.setCursorStyle(params, collect); });
2454 _this._parser.setCsiHandler('r', function (params, collect) { return _this.setScrollRegion(params, collect); });
2455 _this._parser.setCsiHandler('s', function (params, collect) { return _this.saveCursor(params); });
2456 _this._parser.setCsiHandler('u', function (params, collect) { return _this.restoreCursor(params); });
2457 _this._parser.setExecuteHandler(EscapeSequences_1.C0.BEL, function () { return _this.bell(); });
2458 _this._parser.setExecuteHandler(EscapeSequences_1.C0.LF, function () { return _this.lineFeed(); });
2459 _this._parser.setExecuteHandler(EscapeSequences_1.C0.VT, function () { return _this.lineFeed(); });
2460 _this._parser.setExecuteHandler(EscapeSequences_1.C0.FF, function () { return _this.lineFeed(); });
2461 _this._parser.setExecuteHandler(EscapeSequences_1.C0.CR, function () { return _this.carriageReturn(); });
2462 _this._parser.setExecuteHandler(EscapeSequences_1.C0.BS, function () { return _this.backspace(); });
2463 _this._parser.setExecuteHandler(EscapeSequences_1.C0.HT, function () { return _this.tab(); });
2464 _this._parser.setExecuteHandler(EscapeSequences_1.C0.SO, function () { return _this.shiftOut(); });
2465 _this._parser.setExecuteHandler(EscapeSequences_1.C0.SI, function () { return _this.shiftIn(); });
2466 _this._parser.setExecuteHandler(EscapeSequences_1.C1.IND, function () { return _this.index(); });
2467 _this._parser.setExecuteHandler(EscapeSequences_1.C1.NEL, function () { return _this.nextLine(); });
2468 _this._parser.setExecuteHandler(EscapeSequences_1.C1.HTS, function () { return _this.tabSet(); });
2469 _this._parser.setOscHandler(0, function (data) { return _this.setTitle(data); });
2470 _this._parser.setOscHandler(2, function (data) { return _this.setTitle(data); });
2471 _this._parser.setEscHandler('7', function () { return _this.saveCursor([]); });
2472 _this._parser.setEscHandler('8', function () { return _this.restoreCursor([]); });
2473 _this._parser.setEscHandler('D', function () { return _this.index(); });
2474 _this._parser.setEscHandler('E', function () { return _this.nextLine(); });
2475 _this._parser.setEscHandler('H', function () { return _this.tabSet(); });
2476 _this._parser.setEscHandler('M', function () { return _this.reverseIndex(); });
2477 _this._parser.setEscHandler('=', function () { return _this.keypadApplicationMode(); });
2478 _this._parser.setEscHandler('>', function () { return _this.keypadNumericMode(); });
2479 _this._parser.setEscHandler('c', function () { return _this.reset(); });
2480 _this._parser.setEscHandler('n', function () { return _this.setgLevel(2); });
2481 _this._parser.setEscHandler('o', function () { return _this.setgLevel(3); });
2482 _this._parser.setEscHandler('|', function () { return _this.setgLevel(3); });
2483 _this._parser.setEscHandler('}', function () { return _this.setgLevel(2); });
2484 _this._parser.setEscHandler('~', function () { return _this.setgLevel(1); });
2485 _this._parser.setEscHandler('%@', function () { return _this.selectDefaultCharset(); });
2486 _this._parser.setEscHandler('%G', function () { return _this.selectDefaultCharset(); });
2487 var _loop_1 = function (flag) {
2488 this_1._parser.setEscHandler('(' + flag, function () { return _this.selectCharset('(' + flag); });
2489 this_1._parser.setEscHandler(')' + flag, function () { return _this.selectCharset(')' + flag); });
2490 this_1._parser.setEscHandler('*' + flag, function () { return _this.selectCharset('*' + flag); });
2491 this_1._parser.setEscHandler('+' + flag, function () { return _this.selectCharset('+' + flag); });
2492 this_1._parser.setEscHandler('-' + flag, function () { return _this.selectCharset('-' + flag); });
2493 this_1._parser.setEscHandler('.' + flag, function () { return _this.selectCharset('.' + flag); });
2494 this_1._parser.setEscHandler('/' + flag, function () { return _this.selectCharset('/' + flag); });
2495 };
2496 var this_1 = this;
2497 for (var flag in Charsets_1.CHARSETS) {
2498 _loop_1(flag);
2499 }
2500 _this._parser.setErrorHandler(function (state) {
2501 _this._terminal.error('Parsing error: ', state);
2502 return state;
2503 });
2504 _this._parser.setDcsHandler('$q', new DECRQSS(_this._terminal));
2505 return _this;
2506 }
2507 Object.defineProperty(InputHandler.prototype, "onCursorMove", {
2508 get: function () { return this._onCursorMove.event; },
2509 enumerable: true,
2510 configurable: true
2511 });
2512 Object.defineProperty(InputHandler.prototype, "onData", {
2513 get: function () { return this._onData.event; },
2514 enumerable: true,
2515 configurable: true
2516 });
2517 Object.defineProperty(InputHandler.prototype, "onLineFeed", {
2518 get: function () { return this._onLineFeed.event; },
2519 enumerable: true,
2520 configurable: true
2521 });
2522 Object.defineProperty(InputHandler.prototype, "onScroll", {
2523 get: function () { return this._onScroll.event; },
2524 enumerable: true,
2525 configurable: true
2526 });
2527 InputHandler.prototype.dispose = function () {
2528 _super.prototype.dispose.call(this);
2529 this._terminal = null;
2530 };
2531 InputHandler.prototype.parse = function (data) {
2532 if (!this._terminal) {
2533 return;
2534 }
2535 var buffer = this._terminal.buffer;
2536 var cursorStartX = buffer.x;
2537 var cursorStartY = buffer.y;
2538 if (this._terminal.debug) {
2539 this._terminal.log('data: ' + data);
2540 }
2541 if (this._parseBuffer.length < data.length) {
2542 this._parseBuffer = new Uint32Array(data.length);
2543 }
2544 this._parser.parse(this._parseBuffer, this._stringDecoder.decode(data, this._parseBuffer));
2545 buffer = this._terminal.buffer;
2546 if (buffer.x !== cursorStartX || buffer.y !== cursorStartY) {
2547 this._onCursorMove.fire();
2548 }
2549 };
2550 InputHandler.prototype.print = function (data, start, end) {
2551 var code;
2552 var chWidth;
2553 var buffer = this._terminal.buffer;
2554 var charset = this._terminal.charset;
2555 var screenReaderMode = this._terminal.options.screenReaderMode;
2556 var cols = this._terminal.cols;
2557 var wraparoundMode = this._terminal.wraparoundMode;
2558 var insertMode = this._terminal.insertMode;
2559 var curAttr = this._terminal.curAttrData;
2560 var bufferRow = buffer.lines.get(buffer.y + buffer.ybase);
2561 this._terminal.updateRange(buffer.y);
2562 for (var pos = start; pos < end; ++pos) {
2563 code = data[pos];
2564 chWidth = CharWidth_1.wcwidth(code);
2565 if (code < 127 && charset) {
2566 var ch = charset[String.fromCharCode(code)];
2567 if (ch) {
2568 code = ch.charCodeAt(0);
2569 }
2570 }
2571 if (screenReaderMode) {
2572 this._terminal.emit('a11y.char', TextDecoder_1.stringFromCodePoint(code));
2573 }
2574 if (!chWidth && buffer.x) {
2575 if (!bufferRow.getWidth(buffer.x - 1)) {
2576 bufferRow.addCodepointToCell(buffer.x - 2, code);
2577 }
2578 else {
2579 bufferRow.addCodepointToCell(buffer.x - 1, code);
2580 }
2581 continue;
2582 }
2583 if (buffer.x + chWidth - 1 >= cols) {
2584 if (wraparoundMode) {
2585 buffer.x = 0;
2586 buffer.y++;
2587 if (buffer.y > buffer.scrollBottom) {
2588 buffer.y--;
2589 this._terminal.scroll(true);
2590 }
2591 else {
2592 buffer.lines.get(buffer.y).isWrapped = true;
2593 }
2594 bufferRow = buffer.lines.get(buffer.y + buffer.ybase);
2595 }
2596 else {
2597 if (chWidth === 2) {
2598 continue;
2599 }
2600 }
2601 }
2602 if (insertMode) {
2603 bufferRow.insertCells(buffer.x, chWidth, buffer.getNullCell(curAttr));
2604 if (bufferRow.getWidth(cols - 1) === 2) {
2605 bufferRow.setCellFromCodePoint(cols - 1, Buffer_1.NULL_CELL_CODE, Buffer_1.NULL_CELL_WIDTH, curAttr.fg, curAttr.bg);
2606 }
2607 }
2608 bufferRow.setCellFromCodePoint(buffer.x++, code, chWidth, curAttr.fg, curAttr.bg);
2609 if (chWidth > 0) {
2610 while (--chWidth) {
2611 bufferRow.setCellFromCodePoint(buffer.x++, 0, 0, curAttr.fg, curAttr.bg);
2612 }
2613 }
2614 }
2615 this._terminal.updateRange(buffer.y);
2616 };
2617 InputHandler.prototype.addCsiHandler = function (flag, callback) {
2618 return this._parser.addCsiHandler(flag, callback);
2619 };
2620 InputHandler.prototype.addOscHandler = function (ident, callback) {
2621 return this._parser.addOscHandler(ident, callback);
2622 };
2623 InputHandler.prototype.bell = function () {
2624 this._terminal.bell();
2625 };
2626 InputHandler.prototype.lineFeed = function () {
2627 var buffer = this._terminal.buffer;
2628 if (this._terminal.options.convertEol) {
2629 buffer.x = 0;
2630 }
2631 buffer.y++;
2632 if (buffer.y > buffer.scrollBottom) {
2633 buffer.y--;
2634 this._terminal.scroll();
2635 }
2636 if (buffer.x >= this._terminal.cols) {
2637 buffer.x--;
2638 }
2639 this._onLineFeed.fire();
2640 };
2641 InputHandler.prototype.carriageReturn = function () {
2642 this._terminal.buffer.x = 0;
2643 };
2644 InputHandler.prototype.backspace = function () {
2645 if (this._terminal.buffer.x > 0) {
2646 this._terminal.buffer.x--;
2647 }
2648 };
2649 InputHandler.prototype.tab = function () {
2650 var originalX = this._terminal.buffer.x;
2651 this._terminal.buffer.x = this._terminal.buffer.nextStop();
2652 if (this._terminal.options.screenReaderMode) {
2653 this._terminal.emit('a11y.tab', this._terminal.buffer.x - originalX);
2654 }
2655 };
2656 InputHandler.prototype.shiftOut = function () {
2657 this._terminal.setgLevel(1);
2658 };
2659 InputHandler.prototype.shiftIn = function () {
2660 this._terminal.setgLevel(0);
2661 };
2662 InputHandler.prototype.insertChars = function (params) {
2663 this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).insertCells(this._terminal.buffer.x, params[0] || 1, this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()));
2664 this._terminal.updateRange(this._terminal.buffer.y);
2665 };
2666 InputHandler.prototype.cursorUp = function (params) {
2667 var param = params[0];
2668 if (param < 1) {
2669 param = 1;
2670 }
2671 this._terminal.buffer.y -= param;
2672 if (this._terminal.buffer.y < 0) {
2673 this._terminal.buffer.y = 0;
2674 }
2675 };
2676 InputHandler.prototype.cursorDown = function (params) {
2677 var param = params[0];
2678 if (param < 1) {
2679 param = 1;
2680 }
2681 this._terminal.buffer.y += param;
2682 if (this._terminal.buffer.y >= this._terminal.rows) {
2683 this._terminal.buffer.y = this._terminal.rows - 1;
2684 }
2685 if (this._terminal.buffer.x >= this._terminal.cols) {
2686 this._terminal.buffer.x--;
2687 }
2688 };
2689 InputHandler.prototype.cursorForward = function (params) {
2690 var param = params[0];
2691 if (param < 1) {
2692 param = 1;
2693 }
2694 this._terminal.buffer.x += param;
2695 if (this._terminal.buffer.x >= this._terminal.cols) {
2696 this._terminal.buffer.x = this._terminal.cols - 1;
2697 }
2698 };
2699 InputHandler.prototype.cursorBackward = function (params) {
2700 var param = params[0];
2701 if (param < 1) {
2702 param = 1;
2703 }
2704 if (this._terminal.buffer.x >= this._terminal.cols) {
2705 this._terminal.buffer.x--;
2706 }
2707 this._terminal.buffer.x -= param;
2708 if (this._terminal.buffer.x < 0) {
2709 this._terminal.buffer.x = 0;
2710 }
2711 };
2712 InputHandler.prototype.cursorNextLine = function (params) {
2713 var param = params[0];
2714 if (param < 1) {
2715 param = 1;
2716 }
2717 this._terminal.buffer.y += param;
2718 if (this._terminal.buffer.y >= this._terminal.rows) {
2719 this._terminal.buffer.y = this._terminal.rows - 1;
2720 }
2721 this._terminal.buffer.x = 0;
2722 };
2723 InputHandler.prototype.cursorPrecedingLine = function (params) {
2724 var param = params[0];
2725 if (param < 1) {
2726 param = 1;
2727 }
2728 this._terminal.buffer.y -= param;
2729 if (this._terminal.buffer.y < 0) {
2730 this._terminal.buffer.y = 0;
2731 }
2732 this._terminal.buffer.x = 0;
2733 };
2734 InputHandler.prototype.cursorCharAbsolute = function (params) {
2735 var param = params[0];
2736 if (param < 1) {
2737 param = 1;
2738 }
2739 this._terminal.buffer.x = param - 1;
2740 };
2741 InputHandler.prototype.cursorPosition = function (params) {
2742 var col;
2743 var row = params[0] - 1;
2744 if (params.length >= 2) {
2745 col = params[1] - 1;
2746 }
2747 else {
2748 col = 0;
2749 }
2750 if (row < 0) {
2751 row = 0;
2752 }
2753 else if (row >= this._terminal.rows) {
2754 row = this._terminal.rows - 1;
2755 }
2756 if (col < 0) {
2757 col = 0;
2758 }
2759 else if (col >= this._terminal.cols) {
2760 col = this._terminal.cols - 1;
2761 }
2762 this._terminal.buffer.x = col;
2763 this._terminal.buffer.y = row;
2764 };
2765 InputHandler.prototype.cursorForwardTab = function (params) {
2766 var param = params[0] || 1;
2767 while (param--) {
2768 this._terminal.buffer.x = this._terminal.buffer.nextStop();
2769 }
2770 };
2771 InputHandler.prototype._eraseInBufferLine = function (y, start, end, clearWrap) {
2772 if (clearWrap === void 0) { clearWrap = false; }
2773 var line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + y);
2774 line.replaceCells(start, end, this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()));
2775 if (clearWrap) {
2776 line.isWrapped = false;
2777 }
2778 };
2779 InputHandler.prototype._resetBufferLine = function (y) {
2780 this._eraseInBufferLine(y, 0, this._terminal.cols, true);
2781 };
2782 InputHandler.prototype.eraseInDisplay = function (params) {
2783 var j;
2784 switch (params[0]) {
2785 case 0:
2786 j = this._terminal.buffer.y;
2787 this._terminal.updateRange(j);
2788 this._eraseInBufferLine(j++, this._terminal.buffer.x, this._terminal.cols, this._terminal.buffer.x === 0);
2789 for (; j < this._terminal.rows; j++) {
2790 this._resetBufferLine(j);
2791 }
2792 this._terminal.updateRange(j);
2793 break;
2794 case 1:
2795 j = this._terminal.buffer.y;
2796 this._terminal.updateRange(j);
2797 this._eraseInBufferLine(j, 0, this._terminal.buffer.x + 1, true);
2798 if (this._terminal.buffer.x + 1 >= this._terminal.cols) {
2799 this._terminal.buffer.lines.get(j + 1).isWrapped = false;
2800 }
2801 while (j--) {
2802 this._resetBufferLine(j);
2803 }
2804 this._terminal.updateRange(0);
2805 break;
2806 case 2:
2807 j = this._terminal.rows;
2808 this._terminal.updateRange(j - 1);
2809 while (j--) {
2810 this._resetBufferLine(j);
2811 }
2812 this._terminal.updateRange(0);
2813 break;
2814 case 3:
2815 var scrollBackSize = this._terminal.buffer.lines.length - this._terminal.rows;
2816 if (scrollBackSize > 0) {
2817 this._terminal.buffer.lines.trimStart(scrollBackSize);
2818 this._terminal.buffer.ybase = Math.max(this._terminal.buffer.ybase - scrollBackSize, 0);
2819 this._terminal.buffer.ydisp = Math.max(this._terminal.buffer.ydisp - scrollBackSize, 0);
2820 this._onScroll.fire(0);
2821 }
2822 break;
2823 }
2824 };
2825 InputHandler.prototype.eraseInLine = function (params) {
2826 switch (params[0]) {
2827 case 0:
2828 this._eraseInBufferLine(this._terminal.buffer.y, this._terminal.buffer.x, this._terminal.cols);
2829 break;
2830 case 1:
2831 this._eraseInBufferLine(this._terminal.buffer.y, 0, this._terminal.buffer.x + 1);
2832 break;
2833 case 2:
2834 this._eraseInBufferLine(this._terminal.buffer.y, 0, this._terminal.cols);
2835 break;
2836 }
2837 this._terminal.updateRange(this._terminal.buffer.y);
2838 };
2839 InputHandler.prototype.insertLines = function (params) {
2840 var param = params[0];
2841 if (param < 1) {
2842 param = 1;
2843 }
2844 var buffer = this._terminal.buffer;
2845 var row = buffer.y + buffer.ybase;
2846 var scrollBottomRowsOffset = this._terminal.rows - 1 - buffer.scrollBottom;
2847 var scrollBottomAbsolute = this._terminal.rows - 1 + buffer.ybase - scrollBottomRowsOffset + 1;
2848 while (param--) {
2849 buffer.lines.splice(scrollBottomAbsolute - 1, 1);
2850 buffer.lines.splice(row, 0, buffer.getBlankLine(this._terminal.eraseAttrData()));
2851 }
2852 this._terminal.updateRange(buffer.y);
2853 this._terminal.updateRange(buffer.scrollBottom);
2854 };
2855 InputHandler.prototype.deleteLines = function (params) {
2856 var param = params[0];
2857 if (param < 1) {
2858 param = 1;
2859 }
2860 var buffer = this._terminal.buffer;
2861 var row = buffer.y + buffer.ybase;
2862 var j;
2863 j = this._terminal.rows - 1 - buffer.scrollBottom;
2864 j = this._terminal.rows - 1 + buffer.ybase - j;
2865 while (param--) {
2866 buffer.lines.splice(row, 1);
2867 buffer.lines.splice(j, 0, buffer.getBlankLine(this._terminal.eraseAttrData()));
2868 }
2869 this._terminal.updateRange(buffer.y);
2870 this._terminal.updateRange(buffer.scrollBottom);
2871 };
2872 InputHandler.prototype.deleteChars = function (params) {
2873 this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).deleteCells(this._terminal.buffer.x, params[0] || 1, this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()));
2874 this._terminal.updateRange(this._terminal.buffer.y);
2875 };
2876 InputHandler.prototype.scrollUp = function (params) {
2877 var param = params[0] || 1;
2878 var buffer = this._terminal.buffer;
2879 while (param--) {
2880 buffer.lines.splice(buffer.ybase + buffer.scrollTop, 1);
2881 buffer.lines.splice(buffer.ybase + buffer.scrollBottom, 0, buffer.getBlankLine(Buffer_1.DEFAULT_ATTR_DATA));
2882 }
2883 this._terminal.updateRange(buffer.scrollTop);
2884 this._terminal.updateRange(buffer.scrollBottom);
2885 };
2886 InputHandler.prototype.scrollDown = function (params, collect) {
2887 if (params.length < 2 && !collect) {
2888 var param = params[0] || 1;
2889 var buffer = this._terminal.buffer;
2890 while (param--) {
2891 buffer.lines.splice(buffer.ybase + buffer.scrollBottom, 1);
2892 buffer.lines.splice(buffer.ybase + buffer.scrollTop, 0, buffer.getBlankLine(Buffer_1.DEFAULT_ATTR_DATA));
2893 }
2894 this._terminal.updateRange(buffer.scrollTop);
2895 this._terminal.updateRange(buffer.scrollBottom);
2896 }
2897 };
2898 InputHandler.prototype.eraseChars = function (params) {
2899 this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).replaceCells(this._terminal.buffer.x, this._terminal.buffer.x + (params[0] || 1), this._terminal.buffer.getNullCell(this._terminal.eraseAttrData()));
2900 };
2901 InputHandler.prototype.cursorBackwardTab = function (params) {
2902 var param = params[0] || 1;
2903 var buffer = this._terminal.buffer;
2904 while (param--) {
2905 buffer.x = buffer.prevStop();
2906 }
2907 };
2908 InputHandler.prototype.charPosAbsolute = function (params) {
2909 var param = params[0];
2910 if (param < 1) {
2911 param = 1;
2912 }
2913 this._terminal.buffer.x = param - 1;
2914 if (this._terminal.buffer.x >= this._terminal.cols) {
2915 this._terminal.buffer.x = this._terminal.cols - 1;
2916 }
2917 };
2918 InputHandler.prototype.hPositionRelative = function (params) {
2919 var param = params[0];
2920 if (param < 1) {
2921 param = 1;
2922 }
2923 this._terminal.buffer.x += param;
2924 if (this._terminal.buffer.x >= this._terminal.cols) {
2925 this._terminal.buffer.x = this._terminal.cols - 1;
2926 }
2927 };
2928 InputHandler.prototype.repeatPrecedingCharacter = function (params) {
2929 var buffer = this._terminal.buffer;
2930 var line = buffer.lines.get(buffer.ybase + buffer.y);
2931 line.loadCell(buffer.x - 1, this._workCell);
2932 line.replaceCells(buffer.x, buffer.x + (params[0] || 1), (this._workCell.content !== undefined) ? this._workCell : buffer.getNullCell(Buffer_1.DEFAULT_ATTR_DATA));
2933 };
2934 InputHandler.prototype.sendDeviceAttributes = function (params, collect) {
2935 if (params[0] > 0) {
2936 return;
2937 }
2938 if (!collect) {
2939 if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
2940 this._terminal.handler(EscapeSequences_1.C0.ESC + '[?1;2c');
2941 }
2942 else if (this._terminal.is('linux')) {
2943 this._terminal.handler(EscapeSequences_1.C0.ESC + '[?6c');
2944 }
2945 }
2946 else if (collect === '>') {
2947 if (this._terminal.is('xterm')) {
2948 this._terminal.handler(EscapeSequences_1.C0.ESC + '[>0;276;0c');
2949 }
2950 else if (this._terminal.is('rxvt-unicode')) {
2951 this._terminal.handler(EscapeSequences_1.C0.ESC + '[>85;95;0c');
2952 }
2953 else if (this._terminal.is('linux')) {
2954 this._terminal.handler(params[0] + 'c');
2955 }
2956 else if (this._terminal.is('screen')) {
2957 this._terminal.handler(EscapeSequences_1.C0.ESC + '[>83;40003;0c');
2958 }
2959 }
2960 };
2961 InputHandler.prototype.linePosAbsolute = function (params) {
2962 var param = params[0];
2963 if (param < 1) {
2964 param = 1;
2965 }
2966 this._terminal.buffer.y = param - 1;
2967 if (this._terminal.buffer.y >= this._terminal.rows) {
2968 this._terminal.buffer.y = this._terminal.rows - 1;
2969 }
2970 };
2971 InputHandler.prototype.vPositionRelative = function (params) {
2972 var param = params[0];
2973 if (param < 1) {
2974 param = 1;
2975 }
2976 this._terminal.buffer.y += param;
2977 if (this._terminal.buffer.y >= this._terminal.rows) {
2978 this._terminal.buffer.y = this._terminal.rows - 1;
2979 }
2980 if (this._terminal.buffer.x >= this._terminal.cols) {
2981 this._terminal.buffer.x--;
2982 }
2983 };
2984 InputHandler.prototype.hVPosition = function (params) {
2985 if (params[0] < 1)
2986 params[0] = 1;
2987 if (params[1] < 1)
2988 params[1] = 1;
2989 this._terminal.buffer.y = params[0] - 1;
2990 if (this._terminal.buffer.y >= this._terminal.rows) {
2991 this._terminal.buffer.y = this._terminal.rows - 1;
2992 }
2993 this._terminal.buffer.x = params[1] - 1;
2994 if (this._terminal.buffer.x >= this._terminal.cols) {
2995 this._terminal.buffer.x = this._terminal.cols - 1;
2996 }
2997 };
2998 InputHandler.prototype.tabClear = function (params) {
2999 var param = params[0];
3000 if (param <= 0) {
3001 delete this._terminal.buffer.tabs[this._terminal.buffer.x];
3002 }
3003 else if (param === 3) {
3004 this._terminal.buffer.tabs = {};
3005 }
3006 };
3007 InputHandler.prototype.setMode = function (params, collect) {
3008 if (params.length > 1) {
3009 for (var i = 0; i < params.length; i++) {
3010 this.setMode([params[i]]);
3011 }
3012 return;
3013 }
3014 if (!collect) {
3015 switch (params[0]) {
3016 case 4:
3017 this._terminal.insertMode = true;
3018 break;
3019 case 20:
3020 break;
3021 }
3022 }
3023 else if (collect === '?') {
3024 switch (params[0]) {
3025 case 1:
3026 this._terminal.applicationCursor = true;
3027 break;
3028 case 2:
3029 this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
3030 this._terminal.setgCharset(1, Charsets_1.DEFAULT_CHARSET);
3031 this._terminal.setgCharset(2, Charsets_1.DEFAULT_CHARSET);
3032 this._terminal.setgCharset(3, Charsets_1.DEFAULT_CHARSET);
3033 break;
3034 case 3:
3035 this._terminal.savedCols = this._terminal.cols;
3036 this._terminal.resize(132, this._terminal.rows);
3037 break;
3038 case 6:
3039 this._terminal.originMode = true;
3040 break;
3041 case 7:
3042 this._terminal.wraparoundMode = true;
3043 break;
3044 case 12:
3045 break;
3046 case 66:
3047 this._terminal.log('Serial port requested application keypad.');
3048 this._terminal.applicationKeypad = true;
3049 if (this._terminal.viewport) {
3050 this._terminal.viewport.syncScrollArea();
3051 }
3052 break;
3053 case 9:
3054 case 1000:
3055 case 1002:
3056 case 1003:
3057 this._terminal.x10Mouse = params[0] === 9;
3058 this._terminal.vt200Mouse = params[0] === 1000;
3059 this._terminal.normalMouse = params[0] > 1000;
3060 this._terminal.mouseEvents = true;
3061 if (this._terminal.element) {
3062 this._terminal.element.classList.add('enable-mouse-events');
3063 }
3064 if (this._terminal.selectionManager) {
3065 this._terminal.selectionManager.disable();
3066 }
3067 this._terminal.log('Binding to mouse events.');
3068 break;
3069 case 1004:
3070 this._terminal.sendFocus = true;
3071 break;
3072 case 1005:
3073 this._terminal.utfMouse = true;
3074 break;
3075 case 1006:
3076 this._terminal.sgrMouse = true;
3077 break;
3078 case 1015:
3079 this._terminal.urxvtMouse = true;
3080 break;
3081 case 25:
3082 this._terminal.cursorHidden = false;
3083 break;
3084 case 1048:
3085 this.saveCursor(params);
3086 break;
3087 case 1049:
3088 this.saveCursor(params);
3089 case 47:
3090 case 1047:
3091 this._terminal.buffers.activateAltBuffer(this._terminal.eraseAttrData());
3092 this._terminal.refresh(0, this._terminal.rows - 1);
3093 if (this._terminal.viewport) {
3094 this._terminal.viewport.syncScrollArea();
3095 }
3096 this._terminal.showCursor();
3097 break;
3098 case 2004:
3099 this._terminal.bracketedPasteMode = true;
3100 break;
3101 }
3102 }
3103 };
3104 InputHandler.prototype.resetMode = function (params, collect) {
3105 if (params.length > 1) {
3106 for (var i = 0; i < params.length; i++) {
3107 this.resetMode([params[i]]);
3108 }
3109 return;
3110 }
3111 if (!collect) {
3112 switch (params[0]) {
3113 case 4:
3114 this._terminal.insertMode = false;
3115 break;
3116 case 20:
3117 break;
3118 }
3119 }
3120 else if (collect === '?') {
3121 switch (params[0]) {
3122 case 1:
3123 this._terminal.applicationCursor = false;
3124 break;
3125 case 3:
3126 if (this._terminal.cols === 132 && this._terminal.savedCols) {
3127 this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
3128 }
3129 delete this._terminal.savedCols;
3130 break;
3131 case 6:
3132 this._terminal.originMode = false;
3133 break;
3134 case 7:
3135 this._terminal.wraparoundMode = false;
3136 break;
3137 case 12:
3138 break;
3139 case 66:
3140 this._terminal.log('Switching back to normal keypad.');
3141 this._terminal.applicationKeypad = false;
3142 if (this._terminal.viewport) {
3143 this._terminal.viewport.syncScrollArea();
3144 }
3145 break;
3146 case 9:
3147 case 1000:
3148 case 1002:
3149 case 1003:
3150 this._terminal.x10Mouse = false;
3151 this._terminal.vt200Mouse = false;
3152 this._terminal.normalMouse = false;
3153 this._terminal.mouseEvents = false;
3154 if (this._terminal.element) {
3155 this._terminal.element.classList.remove('enable-mouse-events');
3156 }
3157 if (this._terminal.selectionManager) {
3158 this._terminal.selectionManager.enable();
3159 }
3160 break;
3161 case 1004:
3162 this._terminal.sendFocus = false;
3163 break;
3164 case 1005:
3165 this._terminal.utfMouse = false;
3166 break;
3167 case 1006:
3168 this._terminal.sgrMouse = false;
3169 break;
3170 case 1015:
3171 this._terminal.urxvtMouse = false;
3172 break;
3173 case 25:
3174 this._terminal.cursorHidden = true;
3175 break;
3176 case 1048:
3177 this.restoreCursor(params);
3178 break;
3179 case 1049:
3180 case 47:
3181 case 1047:
3182 this._terminal.buffers.activateNormalBuffer();
3183 if (params[0] === 1049) {
3184 this.restoreCursor(params);
3185 }
3186 this._terminal.refresh(0, this._terminal.rows - 1);
3187 if (this._terminal.viewport) {
3188 this._terminal.viewport.syncScrollArea();
3189 }
3190 this._terminal.showCursor();
3191 break;
3192 case 2004:
3193 this._terminal.bracketedPasteMode = false;
3194 break;
3195 }
3196 }
3197 };
3198 InputHandler.prototype.charAttributes = function (params) {
3199 if (params.length === 1 && params[0] === 0) {
3200 this._terminal.curAttrData.fg = Buffer_1.DEFAULT_ATTR_DATA.fg;
3201 this._terminal.curAttrData.bg = Buffer_1.DEFAULT_ATTR_DATA.bg;
3202 return;
3203 }
3204 var l = params.length;
3205 var p;
3206 var attr = this._terminal.curAttrData;
3207 for (var i = 0; i < l; i++) {
3208 p = params[i];
3209 if (p >= 30 && p <= 37) {
3210 attr.fg &= ~(50331648 | 255);
3211 attr.fg |= 16777216 | (p - 30);
3212 }
3213 else if (p >= 40 && p <= 47) {
3214 attr.bg &= ~(50331648 | 255);
3215 attr.bg |= 16777216 | (p - 40);
3216 }
3217 else if (p >= 90 && p <= 97) {
3218 attr.fg &= ~(50331648 | 255);
3219 attr.fg |= 16777216 | (p - 90) | 8;
3220 }
3221 else if (p >= 100 && p <= 107) {
3222 attr.bg &= ~(50331648 | 255);
3223 attr.bg |= 16777216 | (p - 100) | 8;
3224 }
3225 else if (p === 0) {
3226 attr.fg = Buffer_1.DEFAULT_ATTR_DATA.fg;
3227 attr.bg = Buffer_1.DEFAULT_ATTR_DATA.bg;
3228 }
3229 else if (p === 1) {
3230 attr.fg |= 134217728;
3231 }
3232 else if (p === 3) {
3233 attr.bg |= 67108864;
3234 }
3235 else if (p === 4) {
3236 attr.fg |= 268435456;
3237 }
3238 else if (p === 5) {
3239 attr.fg |= 536870912;
3240 }
3241 else if (p === 7) {
3242 attr.fg |= 67108864;
3243 }
3244 else if (p === 8) {
3245 attr.fg |= 1073741824;
3246 }
3247 else if (p === 2) {
3248 attr.bg |= 134217728;
3249 }
3250 else if (p === 22) {
3251 attr.fg &= ~134217728;
3252 attr.bg &= ~134217728;
3253 }
3254 else if (p === 23) {
3255 attr.bg &= ~67108864;
3256 }
3257 else if (p === 24) {
3258 attr.fg &= ~268435456;
3259 }
3260 else if (p === 25) {
3261 attr.fg &= ~536870912;
3262 }
3263 else if (p === 27) {
3264 attr.fg &= ~67108864;
3265 }
3266 else if (p === 28) {
3267 attr.fg &= ~1073741824;
3268 }
3269 else if (p === 39) {
3270 attr.fg &= ~(50331648 | 16777215);
3271 attr.fg |= Buffer_1.DEFAULT_ATTR_DATA.fg & (255 | 16777215);
3272 }
3273 else if (p === 49) {
3274 attr.bg &= ~(50331648 | 16777215);
3275 attr.bg |= Buffer_1.DEFAULT_ATTR_DATA.bg & (255 | 16777215);
3276 }
3277 else if (p === 38) {
3278 if (params[i + 1] === 2) {
3279 i += 2;
3280 attr.fg |= 50331648;
3281 attr.fg &= ~16777215;
3282 attr.fg |= BufferLine_1.AttributeData.fromColorRGB([params[i], params[i + 1], params[i + 2]]);
3283 i += 2;
3284 }
3285 else if (params[i + 1] === 5) {
3286 i += 2;
3287 p = params[i] & 0xff;
3288 attr.fg &= ~255;
3289 attr.fg |= 33554432 | p;
3290 }
3291 }
3292 else if (p === 48) {
3293 if (params[i + 1] === 2) {
3294 i += 2;
3295 attr.bg |= 50331648;
3296 attr.bg &= ~16777215;
3297 attr.bg |= BufferLine_1.AttributeData.fromColorRGB([params[i], params[i + 1], params[i + 2]]);
3298 i += 2;
3299 }
3300 else if (params[i + 1] === 5) {
3301 i += 2;
3302 p = params[i] & 0xff;
3303 attr.bg &= ~255;
3304 attr.bg |= 33554432 | p;
3305 }
3306 }
3307 else if (p === 100) {
3308 attr.fg &= ~(50331648 | 16777215);
3309 attr.fg |= Buffer_1.DEFAULT_ATTR_DATA.fg & (255 | 16777215);
3310 attr.bg &= ~(50331648 | 16777215);
3311 attr.bg |= Buffer_1.DEFAULT_ATTR_DATA.bg & (255 | 16777215);
3312 }
3313 else {
3314 this._terminal.error('Unknown SGR attribute: %d.', p);
3315 }
3316 }
3317 };
3318 InputHandler.prototype.deviceStatus = function (params, collect) {
3319 if (!collect) {
3320 switch (params[0]) {
3321 case 5:
3322 this._onData.fire(EscapeSequences_1.C0.ESC + "[0n");
3323 break;
3324 case 6:
3325 var y = this._terminal.buffer.y + 1;
3326 var x = this._terminal.buffer.x + 1;
3327 this._onData.fire(EscapeSequences_1.C0.ESC + "[" + y + ";" + x + "R");
3328 break;
3329 }
3330 }
3331 else if (collect === '?') {
3332 switch (params[0]) {
3333 case 6:
3334 var y = this._terminal.buffer.y + 1;
3335 var x = this._terminal.buffer.x + 1;
3336 this._onData.fire(EscapeSequences_1.C0.ESC + "[?" + y + ";" + x + "R");
3337 break;
3338 case 15:
3339 break;
3340 case 25:
3341 break;
3342 case 26:
3343 break;
3344 case 53:
3345 break;
3346 }
3347 }
3348 };
3349 InputHandler.prototype.softReset = function (params, collect) {
3350 if (collect === '!') {
3351 this._terminal.cursorHidden = false;
3352 this._terminal.insertMode = false;
3353 this._terminal.originMode = false;
3354 this._terminal.wraparoundMode = true;
3355 this._terminal.applicationKeypad = false;
3356 if (this._terminal.viewport) {
3357 this._terminal.viewport.syncScrollArea();
3358 }
3359 this._terminal.applicationCursor = false;
3360 this._terminal.buffer.scrollTop = 0;
3361 this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
3362 this._terminal.curAttrData = Buffer_1.DEFAULT_ATTR_DATA;
3363 this._terminal.buffer.x = this._terminal.buffer.y = 0;
3364 this._terminal.charset = null;
3365 this._terminal.glevel = 0;
3366 this._terminal.charsets = [null];
3367 }
3368 };
3369 InputHandler.prototype.setCursorStyle = function (params, collect) {
3370 if (collect === ' ') {
3371 var param = params[0] < 1 ? 1 : params[0];
3372 switch (param) {
3373 case 1:
3374 case 2:
3375 this._terminal.setOption('cursorStyle', 'block');
3376 break;
3377 case 3:
3378 case 4:
3379 this._terminal.setOption('cursorStyle', 'underline');
3380 break;
3381 case 5:
3382 case 6:
3383 this._terminal.setOption('cursorStyle', 'bar');
3384 break;
3385 }
3386 var isBlinking = param % 2 === 1;
3387 this._terminal.setOption('cursorBlink', isBlinking);
3388 }
3389 };
3390 InputHandler.prototype.setScrollRegion = function (params, collect) {
3391 if (collect) {
3392 return;
3393 }
3394 this._terminal.buffer.scrollTop = (params[0] || 1) - 1;
3395 this._terminal.buffer.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
3396 this._terminal.buffer.x = 0;
3397 this._terminal.buffer.y = 0;
3398 };
3399 InputHandler.prototype.saveCursor = function (params) {
3400 this._terminal.buffer.savedX = this._terminal.buffer.x;
3401 this._terminal.buffer.savedY = this._terminal.buffer.y;
3402 this._terminal.buffer.savedCurAttrData.fg = this._terminal.curAttrData.fg;
3403 this._terminal.buffer.savedCurAttrData.bg = this._terminal.curAttrData.bg;
3404 };
3405 InputHandler.prototype.restoreCursor = function (params) {
3406 this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
3407 this._terminal.buffer.y = this._terminal.buffer.savedY || 0;
3408 this._terminal.curAttrData.fg = this._terminal.buffer.savedCurAttrData.fg;
3409 this._terminal.curAttrData.bg = this._terminal.buffer.savedCurAttrData.bg;
3410 };
3411 InputHandler.prototype.setTitle = function (data) {
3412 this._terminal.handleTitle(data);
3413 };
3414 InputHandler.prototype.nextLine = function () {
3415 this._terminal.buffer.x = 0;
3416 this.index();
3417 };
3418 InputHandler.prototype.keypadApplicationMode = function () {
3419 this._terminal.log('Serial port requested application keypad.');
3420 this._terminal.applicationKeypad = true;
3421 if (this._terminal.viewport) {
3422 this._terminal.viewport.syncScrollArea();
3423 }
3424 };
3425 InputHandler.prototype.keypadNumericMode = function () {
3426 this._terminal.log('Switching back to normal keypad.');
3427 this._terminal.applicationKeypad = false;
3428 if (this._terminal.viewport) {
3429 this._terminal.viewport.syncScrollArea();
3430 }
3431 };
3432 InputHandler.prototype.selectDefaultCharset = function () {
3433 this._terminal.setgLevel(0);
3434 this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
3435 };
3436 InputHandler.prototype.selectCharset = function (collectAndFlag) {
3437 if (collectAndFlag.length !== 2) {
3438 this.selectDefaultCharset();
3439 return;
3440 }
3441 if (collectAndFlag[0] === '/') {
3442 return;
3443 }
3444 this._terminal.setgCharset(GLEVEL[collectAndFlag[0]], Charsets_1.CHARSETS[collectAndFlag[1]] || Charsets_1.DEFAULT_CHARSET);
3445 return;
3446 };
3447 InputHandler.prototype.index = function () {
3448 this._terminal.index();
3449 };
3450 InputHandler.prototype.tabSet = function () {
3451 this._terminal.tabSet();
3452 };
3453 InputHandler.prototype.reverseIndex = function () {
3454 this._terminal.reverseIndex();
3455 };
3456 InputHandler.prototype.reset = function () {
3457 this._parser.reset();
3458 this._terminal.reset();
3459 };
3460 InputHandler.prototype.setgLevel = function (level) {
3461 this._terminal.setgLevel(level);
3462 };
3463 return InputHandler;
3464 }(Lifecycle_1.Disposable));
3465 exports.InputHandler = InputHandler;
3466
3467 },{"./Buffer":2,"./BufferLine":3,"./CharWidth":7,"./EscapeSequenceParser":10,"./common/EventEmitter2":25,"./common/Lifecycle":26,"./common/TypedArrayUtils":28,"./common/data/EscapeSequences":29,"./core/data/Charsets":30,"./core/input/TextDecoder":32}],12:[function(require,module,exports){
3468 "use strict";
3469 Object.defineProperty(exports, "__esModule", { value: true });
3470 var MouseZoneManager_1 = require("./MouseZoneManager");
3471 var CharWidth_1 = require("./CharWidth");
3472 var EventEmitter2_1 = require("./common/EventEmitter2");
3473 var Linkifier = (function () {
3474 function Linkifier(_terminal) {
3475 this._terminal = _terminal;
3476 this._linkMatchers = [];
3477 this._nextLinkMatcherId = 0;
3478 this._onLinkHover = new EventEmitter2_1.EventEmitter2();
3479 this._onLinkLeave = new EventEmitter2_1.EventEmitter2();
3480 this._onLinkTooltip = new EventEmitter2_1.EventEmitter2();
3481 this._rowsToLinkify = {
3482 start: null,
3483 end: null
3484 };
3485 }
3486 Object.defineProperty(Linkifier.prototype, "onLinkHover", {
3487 get: function () { return this._onLinkHover.event; },
3488 enumerable: true,
3489 configurable: true
3490 });
3491 Object.defineProperty(Linkifier.prototype, "onLinkLeave", {
3492 get: function () { return this._onLinkLeave.event; },
3493 enumerable: true,
3494 configurable: true
3495 });
3496 Object.defineProperty(Linkifier.prototype, "onLinkTooltip", {
3497 get: function () { return this._onLinkTooltip.event; },
3498 enumerable: true,
3499 configurable: true
3500 });
3501 Linkifier.prototype.attachToDom = function (mouseZoneManager) {
3502 this._mouseZoneManager = mouseZoneManager;
3503 };
3504 Linkifier.prototype.linkifyRows = function (start, end) {
3505 var _this = this;
3506 if (!this._mouseZoneManager) {
3507 return;
3508 }
3509 if (this._rowsToLinkify.start === null) {
3510 this._rowsToLinkify.start = start;
3511 this._rowsToLinkify.end = end;
3512 }
3513 else {
3514 this._rowsToLinkify.start = Math.min(this._rowsToLinkify.start, start);
3515 this._rowsToLinkify.end = Math.max(this._rowsToLinkify.end, end);
3516 }
3517 this._mouseZoneManager.clearAll(start, end);
3518 if (this._rowsTimeoutId) {
3519 clearTimeout(this._rowsTimeoutId);
3520 }
3521 this._rowsTimeoutId = setTimeout(function () { return _this._linkifyRows(); }, Linkifier.TIME_BEFORE_LINKIFY);
3522 };
3523 Linkifier.prototype._linkifyRows = function () {
3524 this._rowsTimeoutId = null;
3525 var buffer = this._terminal.buffer;
3526 var absoluteRowIndexStart = buffer.ydisp + this._rowsToLinkify.start;
3527 if (absoluteRowIndexStart >= buffer.lines.length) {
3528 return;
3529 }
3530 var absoluteRowIndexEnd = buffer.ydisp + Math.min(this._rowsToLinkify.end, this._terminal.rows) + 1;
3531 var overscanLineLimit = Math.ceil(Linkifier.OVERSCAN_CHAR_LIMIT / this._terminal.cols);
3532 var iterator = this._terminal.buffer.iterator(false, absoluteRowIndexStart, absoluteRowIndexEnd, overscanLineLimit, overscanLineLimit);
3533 while (iterator.hasNext()) {
3534 var lineData = iterator.next();
3535 for (var i = 0; i < this._linkMatchers.length; i++) {
3536 this._doLinkifyRow(lineData.range.first, lineData.content, this._linkMatchers[i]);
3537 }
3538 }
3539 this._rowsToLinkify.start = null;
3540 this._rowsToLinkify.end = null;
3541 };
3542 Linkifier.prototype.registerLinkMatcher = function (regex, handler, options) {
3543 if (options === void 0) { options = {}; }
3544 if (!handler) {
3545 throw new Error('handler must be defined');
3546 }
3547 var matcher = {
3548 id: this._nextLinkMatcherId++,
3549 regex: regex,
3550 handler: handler,
3551 matchIndex: options.matchIndex,
3552 validationCallback: options.validationCallback,
3553 hoverTooltipCallback: options.tooltipCallback,
3554 hoverLeaveCallback: options.leaveCallback,
3555 willLinkActivate: options.willLinkActivate,
3556 priority: options.priority || 0
3557 };
3558 this._addLinkMatcherToList(matcher);
3559 return matcher.id;
3560 };
3561 Linkifier.prototype._addLinkMatcherToList = function (matcher) {
3562 if (this._linkMatchers.length === 0) {
3563 this._linkMatchers.push(matcher);
3564 return;
3565 }
3566 for (var i = this._linkMatchers.length - 1; i >= 0; i--) {
3567 if (matcher.priority <= this._linkMatchers[i].priority) {
3568 this._linkMatchers.splice(i + 1, 0, matcher);
3569 return;
3570 }
3571 }
3572 this._linkMatchers.splice(0, 0, matcher);
3573 };
3574 Linkifier.prototype.deregisterLinkMatcher = function (matcherId) {
3575 for (var i = 0; i < this._linkMatchers.length; i++) {
3576 if (this._linkMatchers[i].id === matcherId) {
3577 this._linkMatchers.splice(i, 1);
3578 return true;
3579 }
3580 }
3581 return false;
3582 };
3583 Linkifier.prototype._doLinkifyRow = function (rowIndex, text, matcher) {
3584 var _this = this;
3585 var rex = new RegExp(matcher.regex.source, matcher.regex.flags + 'g');
3586 var match;
3587 var stringIndex = -1;
3588 var _loop_1 = function () {
3589 var uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
3590 if (!uri) {
3591 if (this_1._terminal.debug) {
3592 console.log({ match: match, matcher: matcher });
3593 throw new Error('match found without corresponding matchIndex');
3594 }
3595 return "break";
3596 }
3597 stringIndex = text.indexOf(uri, stringIndex + 1);
3598 rex.lastIndex = stringIndex + uri.length;
3599 if (stringIndex < 0) {
3600 return "break";
3601 }
3602 var bufferIndex = this_1._terminal.buffer.stringIndexToBufferIndex(rowIndex, stringIndex);
3603 if (bufferIndex[0] < 0) {
3604 return "break";
3605 }
3606 var line = this_1._terminal.buffer.lines.get(bufferIndex[0]);
3607 var attr = line.getFg(bufferIndex[1]);
3608 var fg;
3609 if (attr) {
3610 fg = (attr >> 9) & 0x1ff;
3611 }
3612 if (matcher.validationCallback) {
3613 matcher.validationCallback(uri, function (isValid) {
3614 if (_this._rowsTimeoutId) {
3615 return;
3616 }
3617 if (isValid) {
3618 _this._addLink(bufferIndex[1], bufferIndex[0] - _this._terminal.buffer.ydisp, uri, matcher, fg);
3619 }
3620 });
3621 }
3622 else {
3623 this_1._addLink(bufferIndex[1], bufferIndex[0] - this_1._terminal.buffer.ydisp, uri, matcher, fg);
3624 }
3625 };
3626 var this_1 = this;
3627 while ((match = rex.exec(text)) !== null) {
3628 var state_1 = _loop_1();
3629 if (state_1 === "break")
3630 break;
3631 }
3632 };
3633 Linkifier.prototype._addLink = function (x, y, uri, matcher, fg) {
3634 var _this = this;
3635 var width = CharWidth_1.getStringCellWidth(uri);
3636 var x1 = x % this._terminal.cols;
3637 var y1 = y + Math.floor(x / this._terminal.cols);
3638 var x2 = (x1 + width) % this._terminal.cols;
3639 var y2 = y1 + Math.floor((x1 + width) / this._terminal.cols);
3640 if (x2 === 0) {
3641 x2 = this._terminal.cols;
3642 y2--;
3643 }
3644 this._mouseZoneManager.add(new MouseZoneManager_1.MouseZone(x1 + 1, y1 + 1, x2 + 1, y2 + 1, function (e) {
3645 if (matcher.handler) {
3646 return matcher.handler(e, uri);
3647 }
3648 window.open(uri, '_blank');
3649 }, function () {
3650 _this._onLinkHover.fire(_this._createLinkHoverEvent(x1, y1, x2, y2, fg));
3651 _this._terminal.element.classList.add('xterm-cursor-pointer');
3652 }, function (e) {
3653 _this._onLinkTooltip.fire(_this._createLinkHoverEvent(x1, y1, x2, y2, fg));
3654 if (matcher.hoverTooltipCallback) {
3655 matcher.hoverTooltipCallback(e, uri);
3656 }
3657 }, function () {
3658 _this._onLinkLeave.fire(_this._createLinkHoverEvent(x1, y1, x2, y2, fg));
3659 _this._terminal.element.classList.remove('xterm-cursor-pointer');
3660 if (matcher.hoverLeaveCallback) {
3661 matcher.hoverLeaveCallback();
3662 }
3663 }, function (e) {
3664 if (matcher.willLinkActivate) {
3665 return matcher.willLinkActivate(e, uri);
3666 }
3667 return true;
3668 }));
3669 };
3670 Linkifier.prototype._createLinkHoverEvent = function (x1, y1, x2, y2, fg) {
3671 return { x1: x1, y1: y1, x2: x2, y2: y2, cols: this._terminal.cols, fg: fg };
3672 };
3673 Linkifier.TIME_BEFORE_LINKIFY = 200;
3674 Linkifier.OVERSCAN_CHAR_LIMIT = 2000;
3675 return Linkifier;
3676 }());
3677 exports.Linkifier = Linkifier;
3678
3679 },{"./CharWidth":7,"./MouseZoneManager":14,"./common/EventEmitter2":25}],13:[function(require,module,exports){
3680 "use strict";
3681 Object.defineProperty(exports, "__esModule", { value: true });
3682 var MouseHelper = (function () {
3683 function MouseHelper(_renderer) {
3684 this._renderer = _renderer;
3685 }
3686 MouseHelper.prototype.setRenderer = function (renderer) {
3687 this._renderer = renderer;
3688 };
3689 MouseHelper.getCoordsRelativeToElement = function (event, element) {
3690 var rect = element.getBoundingClientRect();
3691 return [event.clientX - rect.left, event.clientY - rect.top];
3692 };
3693 MouseHelper.prototype.getCoords = function (event, element, charMeasure, colCount, rowCount, isSelection) {
3694 if (!charMeasure.width || !charMeasure.height) {
3695 return null;
3696 }
3697 var coords = MouseHelper.getCoordsRelativeToElement(event, element);
3698 if (!coords) {
3699 return null;
3700 }
3701 coords[0] = Math.ceil((coords[0] + (isSelection ? this._renderer.dimensions.actualCellWidth / 2 : 0)) / this._renderer.dimensions.actualCellWidth);
3702 coords[1] = Math.ceil(coords[1] / this._renderer.dimensions.actualCellHeight);
3703 coords[0] = Math.min(Math.max(coords[0], 1), colCount + (isSelection ? 1 : 0));
3704 coords[1] = Math.min(Math.max(coords[1], 1), rowCount);
3705 return coords;
3706 };
3707 MouseHelper.prototype.getRawByteCoords = function (event, element, charMeasure, colCount, rowCount) {
3708 var coords = this.getCoords(event, element, charMeasure, colCount, rowCount);
3709 var x = coords[0];
3710 var y = coords[1];
3711 x += 32;
3712 y += 32;
3713 return { x: x, y: y };
3714 };
3715 return MouseHelper;
3716 }());
3717 exports.MouseHelper = MouseHelper;
3718
3719 },{}],14:[function(require,module,exports){
3720 "use strict";
3721 var __extends = (this && this.__extends) || (function () {
3722 var extendStatics = function (d, b) {
3723 extendStatics = Object.setPrototypeOf ||
3724 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
3725 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3726 return extendStatics(d, b);
3727 };
3728 return function (d, b) {
3729 extendStatics(d, b);
3730 function __() { this.constructor = d; }
3731 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3732 };
3733 })();
3734 Object.defineProperty(exports, "__esModule", { value: true });
3735 var Lifecycle_1 = require("./common/Lifecycle");
3736 var Lifecycle_2 = require("./ui/Lifecycle");
3737 var HOVER_DURATION = 500;
3738 var MouseZoneManager = (function (_super) {
3739 __extends(MouseZoneManager, _super);
3740 function MouseZoneManager(_terminal) {
3741 var _this = _super.call(this) || this;
3742 _this._terminal = _terminal;
3743 _this._zones = [];
3744 _this._areZonesActive = false;
3745 _this._tooltipTimeout = null;
3746 _this._currentZone = null;
3747 _this._lastHoverCoords = [null, null];
3748 _this.register(Lifecycle_2.addDisposableDomListener(_this._terminal.element, 'mousedown', function (e) { return _this._onMouseDown(e); }));
3749 _this._mouseMoveListener = function (e) { return _this._onMouseMove(e); };
3750 _this._mouseLeaveListener = function (e) { return _this._onMouseLeave(e); };
3751 _this._clickListener = function (e) { return _this._onClick(e); };
3752 return _this;
3753 }
3754 MouseZoneManager.prototype.dispose = function () {
3755 _super.prototype.dispose.call(this);
3756 this._deactivate();
3757 };
3758 MouseZoneManager.prototype.add = function (zone) {
3759 this._zones.push(zone);
3760 if (this._zones.length === 1) {
3761 this._activate();
3762 }
3763 };
3764 MouseZoneManager.prototype.clearAll = function (start, end) {
3765 if (this._zones.length === 0) {
3766 return;
3767 }
3768 if (!end) {
3769 start = 0;
3770 end = this._terminal.rows - 1;
3771 }
3772 for (var i = 0; i < this._zones.length; i++) {
3773 var zone = this._zones[i];
3774 if ((zone.y1 > start && zone.y1 <= end + 1) ||
3775 (zone.y2 > start && zone.y2 <= end + 1) ||
3776 (zone.y1 < start && zone.y2 > end + 1)) {
3777 if (this._currentZone && this._currentZone === zone) {
3778 this._currentZone.leaveCallback();
3779 this._currentZone = null;
3780 }
3781 this._zones.splice(i--, 1);
3782 }
3783 }
3784 if (this._zones.length === 0) {
3785 this._deactivate();
3786 }
3787 };
3788 MouseZoneManager.prototype._activate = function () {
3789 if (!this._areZonesActive) {
3790 this._areZonesActive = true;
3791 this._terminal.element.addEventListener('mousemove', this._mouseMoveListener);
3792 this._terminal.element.addEventListener('mouseleave', this._mouseLeaveListener);
3793 this._terminal.element.addEventListener('click', this._clickListener);
3794 }
3795 };
3796 MouseZoneManager.prototype._deactivate = function () {
3797 if (this._areZonesActive) {
3798 this._areZonesActive = false;
3799 this._terminal.element.removeEventListener('mousemove', this._mouseMoveListener);
3800 this._terminal.element.removeEventListener('mouseleave', this._mouseLeaveListener);
3801 this._terminal.element.removeEventListener('click', this._clickListener);
3802 }
3803 };
3804 MouseZoneManager.prototype._onMouseMove = function (e) {
3805 if (this._lastHoverCoords[0] !== e.pageX || this._lastHoverCoords[1] !== e.pageY) {
3806 this._onHover(e);
3807 this._lastHoverCoords = [e.pageX, e.pageY];
3808 }
3809 };
3810 MouseZoneManager.prototype._onHover = function (e) {
3811 var _this = this;
3812 var zone = this._findZoneEventAt(e);
3813 if (zone === this._currentZone) {
3814 return;
3815 }
3816 if (this._currentZone) {
3817 this._currentZone.leaveCallback();
3818 this._currentZone = null;
3819 if (this._tooltipTimeout) {
3820 clearTimeout(this._tooltipTimeout);
3821 }
3822 }
3823 if (!zone) {
3824 return;
3825 }
3826 this._currentZone = zone;
3827 if (zone.hoverCallback) {
3828 zone.hoverCallback(e);
3829 }
3830 this._tooltipTimeout = setTimeout(function () { return _this._onTooltip(e); }, HOVER_DURATION);
3831 };
3832 MouseZoneManager.prototype._onTooltip = function (e) {
3833 this._tooltipTimeout = null;
3834 var zone = this._findZoneEventAt(e);
3835 if (zone && zone.tooltipCallback) {
3836 zone.tooltipCallback(e);
3837 }
3838 };
3839 MouseZoneManager.prototype._onMouseDown = function (e) {
3840 this._initialSelectionLength = this._terminal.getSelection().length;
3841 if (!this._areZonesActive) {
3842 return;
3843 }
3844 var zone = this._findZoneEventAt(e);
3845 if (zone) {
3846 if (zone.willLinkActivate(e)) {
3847 e.preventDefault();
3848 e.stopImmediatePropagation();
3849 }
3850 }
3851 };
3852 MouseZoneManager.prototype._onMouseLeave = function (e) {
3853 if (this._currentZone) {
3854 this._currentZone.leaveCallback();
3855 this._currentZone = null;
3856 if (this._tooltipTimeout) {
3857 clearTimeout(this._tooltipTimeout);
3858 }
3859 }
3860 };
3861 MouseZoneManager.prototype._onClick = function (e) {
3862 var zone = this._findZoneEventAt(e);
3863 var currentSelectionLength = this._terminal.getSelection().length;
3864 if (zone && currentSelectionLength === this._initialSelectionLength) {
3865 zone.clickCallback(e);
3866 e.preventDefault();
3867 e.stopImmediatePropagation();
3868 }
3869 };
3870 MouseZoneManager.prototype._findZoneEventAt = function (e) {
3871 var coords = this._terminal.mouseHelper.getCoords(e, this._terminal.screenElement, this._terminal.charMeasure, this._terminal.cols, this._terminal.rows);
3872 if (!coords) {
3873 return null;
3874 }
3875 var x = coords[0];
3876 var y = coords[1];
3877 for (var i = 0; i < this._zones.length; i++) {
3878 var zone = this._zones[i];
3879 if (zone.y1 === zone.y2) {
3880 if (y === zone.y1 && x >= zone.x1 && x < zone.x2) {
3881 return zone;
3882 }
3883 }
3884 else {
3885 if ((y === zone.y1 && x >= zone.x1) ||
3886 (y === zone.y2 && x < zone.x2) ||
3887 (y > zone.y1 && y < zone.y2)) {
3888 return zone;
3889 }
3890 }
3891 }
3892 return null;
3893 };
3894 return MouseZoneManager;
3895 }(Lifecycle_1.Disposable));
3896 exports.MouseZoneManager = MouseZoneManager;
3897 var MouseZone = (function () {
3898 function MouseZone(x1, y1, x2, y2, clickCallback, hoverCallback, tooltipCallback, leaveCallback, willLinkActivate) {
3899 this.x1 = x1;
3900 this.y1 = y1;
3901 this.x2 = x2;
3902 this.y2 = y2;
3903 this.clickCallback = clickCallback;
3904 this.hoverCallback = hoverCallback;
3905 this.tooltipCallback = tooltipCallback;
3906 this.leaveCallback = leaveCallback;
3907 this.willLinkActivate = willLinkActivate;
3908 }
3909 return MouseZone;
3910 }());
3911 exports.MouseZone = MouseZone;
3912
3913 },{"./common/Lifecycle":26,"./ui/Lifecycle":55}],15:[function(require,module,exports){
3914 "use strict";
3915 Object.defineProperty(exports, "__esModule", { value: true });
3916 var MouseHelper_1 = require("./MouseHelper");
3917 var Browser = require("./common/Platform");
3918 var SelectionModel_1 = require("./SelectionModel");
3919 var AltClickHandler_1 = require("./handlers/AltClickHandler");
3920 var BufferLine_1 = require("./BufferLine");
3921 var EventEmitter2_1 = require("./common/EventEmitter2");
3922 var DRAG_SCROLL_MAX_THRESHOLD = 50;
3923 var DRAG_SCROLL_MAX_SPEED = 15;
3924 var DRAG_SCROLL_INTERVAL = 50;
3925 var ALT_CLICK_MOVE_CURSOR_TIME = 500;
3926 var WORD_SEPARATORS = ' ()[]{}\'"';
3927 var NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
3928 var ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
3929 var SelectionManager = (function () {
3930 function SelectionManager(_terminal, _charMeasure) {
3931 this._terminal = _terminal;
3932 this._charMeasure = _charMeasure;
3933 this._enabled = true;
3934 this._workCell = new BufferLine_1.CellData();
3935 this._onLinuxMouseSelection = new EventEmitter2_1.EventEmitter2();
3936 this._onRedrawRequest = new EventEmitter2_1.EventEmitter2();
3937 this._onSelectionChange = new EventEmitter2_1.EventEmitter2();
3938 this._initListeners();
3939 this.enable();
3940 this._model = new SelectionModel_1.SelectionModel(_terminal);
3941 this._activeSelectionMode = 0;
3942 }
3943 Object.defineProperty(SelectionManager.prototype, "onLinuxMouseSelection", {
3944 get: function () { return this._onLinuxMouseSelection.event; },
3945 enumerable: true,
3946 configurable: true
3947 });
3948 Object.defineProperty(SelectionManager.prototype, "onRedrawRequest", {
3949 get: function () { return this._onRedrawRequest.event; },
3950 enumerable: true,
3951 configurable: true
3952 });
3953 Object.defineProperty(SelectionManager.prototype, "onSelectionChange", {
3954 get: function () { return this._onSelectionChange.event; },
3955 enumerable: true,
3956 configurable: true
3957 });
3958 SelectionManager.prototype.dispose = function () {
3959 this._removeMouseDownListeners();
3960 };
3961 Object.defineProperty(SelectionManager.prototype, "_buffer", {
3962 get: function () {
3963 return this._terminal.buffers.active;
3964 },
3965 enumerable: true,
3966 configurable: true
3967 });
3968 SelectionManager.prototype._initListeners = function () {
3969 var _this = this;
3970 this._mouseMoveListener = function (event) { return _this._onMouseMove(event); };
3971 this._mouseUpListener = function (event) { return _this._onMouseUp(event); };
3972 this.initBuffersListeners();
3973 };
3974 SelectionManager.prototype.initBuffersListeners = function () {
3975 var _this = this;
3976 this._trimListener = this._terminal.buffer.lines.onTrim(function (amount) { return _this._onTrim(amount); });
3977 this._terminal.buffers.onBufferActivate(function (e) { return _this._onBufferActivate(e); });
3978 };
3979 SelectionManager.prototype.disable = function () {
3980 this.clearSelection();
3981 this._enabled = false;
3982 };
3983 SelectionManager.prototype.enable = function () {
3984 this._enabled = true;
3985 };
3986 Object.defineProperty(SelectionManager.prototype, "selectionStart", {
3987 get: function () { return this._model.finalSelectionStart; },
3988 enumerable: true,
3989 configurable: true
3990 });
3991 Object.defineProperty(SelectionManager.prototype, "selectionEnd", {
3992 get: function () { return this._model.finalSelectionEnd; },
3993 enumerable: true,
3994 configurable: true
3995 });
3996 Object.defineProperty(SelectionManager.prototype, "hasSelection", {
3997 get: function () {
3998 var start = this._model.finalSelectionStart;
3999 var end = this._model.finalSelectionEnd;
4000 if (!start || !end) {
4001 return false;
4002 }
4003 return start[0] !== end[0] || start[1] !== end[1];
4004 },
4005 enumerable: true,
4006 configurable: true
4007 });
4008 Object.defineProperty(SelectionManager.prototype, "selectionText", {
4009 get: function () {
4010 var start = this._model.finalSelectionStart;
4011 var end = this._model.finalSelectionEnd;
4012 if (!start || !end) {
4013 return '';
4014 }
4015 var result = [];
4016 if (this._activeSelectionMode === 3) {
4017 if (start[0] === end[0]) {
4018 return '';
4019 }
4020 for (var i = start[1]; i <= end[1]; i++) {
4021 var lineText = this._buffer.translateBufferLineToString(i, true, start[0], end[0]);
4022 result.push(lineText);
4023 }
4024 }
4025 else {
4026 var startRowEndCol = start[1] === end[1] ? end[0] : undefined;
4027 result.push(this._buffer.translateBufferLineToString(start[1], true, start[0], startRowEndCol));
4028 for (var i = start[1] + 1; i <= end[1] - 1; i++) {
4029 var bufferLine = this._buffer.lines.get(i);
4030 var lineText = this._buffer.translateBufferLineToString(i, true);
4031 if (bufferLine.isWrapped) {
4032 result[result.length - 1] += lineText;
4033 }
4034 else {
4035 result.push(lineText);
4036 }
4037 }
4038 if (start[1] !== end[1]) {
4039 var bufferLine = this._buffer.lines.get(end[1]);
4040 var lineText = this._buffer.translateBufferLineToString(end[1], true, 0, end[0]);
4041 if (bufferLine.isWrapped) {
4042 result[result.length - 1] += lineText;
4043 }
4044 else {
4045 result.push(lineText);
4046 }
4047 }
4048 }
4049 var formattedResult = result.map(function (line) {
4050 return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
4051 }).join(Browser.isMSWindows ? '\r\n' : '\n');
4052 return formattedResult;
4053 },
4054 enumerable: true,
4055 configurable: true
4056 });
4057 SelectionManager.prototype.clearSelection = function () {
4058 this._model.clearSelection();
4059 this._removeMouseDownListeners();
4060 this.refresh();
4061 };
4062 SelectionManager.prototype.refresh = function (isLinuxMouseSelection) {
4063 var _this = this;
4064 if (!this._refreshAnimationFrame) {
4065 this._refreshAnimationFrame = window.requestAnimationFrame(function () { return _this._refresh(); });
4066 }
4067 if (Browser.isLinux && isLinuxMouseSelection) {
4068 var selectionText = this.selectionText;
4069 if (selectionText.length) {
4070 this._onLinuxMouseSelection.fire(this.selectionText);
4071 }
4072 }
4073 };
4074 SelectionManager.prototype._refresh = function () {
4075 this._refreshAnimationFrame = null;
4076 this._onRedrawRequest.fire({
4077 start: this._model.finalSelectionStart,
4078 end: this._model.finalSelectionEnd,
4079 columnSelectMode: this._activeSelectionMode === 3
4080 });
4081 };
4082 SelectionManager.prototype.isClickInSelection = function (event) {
4083 var coords = this._getMouseBufferCoords(event);
4084 var start = this._model.finalSelectionStart;
4085 var end = this._model.finalSelectionEnd;
4086 if (!start || !end) {
4087 return false;
4088 }
4089 return this._areCoordsInSelection(coords, start, end);
4090 };
4091 SelectionManager.prototype._areCoordsInSelection = function (coords, start, end) {
4092 return (coords[1] > start[1] && coords[1] < end[1]) ||
4093 (start[1] === end[1] && coords[1] === start[1] && coords[0] >= start[0] && coords[0] < end[0]) ||
4094 (start[1] < end[1] && coords[1] === end[1] && coords[0] < end[0]) ||
4095 (start[1] < end[1] && coords[1] === start[1] && coords[0] >= start[0]);
4096 };
4097 SelectionManager.prototype.selectWordAtCursor = function (event) {
4098 var coords = this._getMouseBufferCoords(event);
4099 if (coords) {
4100 this._selectWordAt(coords, false);
4101 this._model.selectionEnd = null;
4102 this.refresh(true);
4103 }
4104 };
4105 SelectionManager.prototype.selectAll = function () {
4106 this._model.isSelectAllActive = true;
4107 this.refresh();
4108 this._onSelectionChange.fire();
4109 };
4110 SelectionManager.prototype.selectLines = function (start, end) {
4111 this._model.clearSelection();
4112 start = Math.max(start, 0);
4113 end = Math.min(end, this._terminal.buffer.lines.length - 1);
4114 this._model.selectionStart = [0, start];
4115 this._model.selectionEnd = [this._terminal.cols, end];
4116 this.refresh();
4117 this._onSelectionChange.fire();
4118 };
4119 SelectionManager.prototype._onTrim = function (amount) {
4120 var needsRefresh = this._model.onTrim(amount);
4121 if (needsRefresh) {
4122 this.refresh();
4123 }
4124 };
4125 SelectionManager.prototype._getMouseBufferCoords = function (event) {
4126 var coords = this._terminal.mouseHelper.getCoords(event, this._terminal.screenElement, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
4127 if (!coords) {
4128 return null;
4129 }
4130 coords[0]--;
4131 coords[1]--;
4132 coords[1] += this._terminal.buffer.ydisp;
4133 return coords;
4134 };
4135 SelectionManager.prototype._getMouseEventScrollAmount = function (event) {
4136 var offset = MouseHelper_1.MouseHelper.getCoordsRelativeToElement(event, this._terminal.screenElement)[1];
4137 var terminalHeight = this._terminal.rows * Math.ceil(this._charMeasure.height * this._terminal.options.lineHeight);
4138 if (offset >= 0 && offset <= terminalHeight) {
4139 return 0;
4140 }
4141 if (offset > terminalHeight) {
4142 offset -= terminalHeight;
4143 }
4144 offset = Math.min(Math.max(offset, -DRAG_SCROLL_MAX_THRESHOLD), DRAG_SCROLL_MAX_THRESHOLD);
4145 offset /= DRAG_SCROLL_MAX_THRESHOLD;
4146 return (offset / Math.abs(offset)) + Math.round(offset * (DRAG_SCROLL_MAX_SPEED - 1));
4147 };
4148 SelectionManager.prototype.shouldForceSelection = function (event) {
4149 if (Browser.isMac) {
4150 return event.altKey && this._terminal.options.macOptionClickForcesSelection;
4151 }
4152 return event.shiftKey;
4153 };
4154 SelectionManager.prototype.onMouseDown = function (event) {
4155 this._mouseDownTimeStamp = event.timeStamp;
4156 if (event.button === 2 && this.hasSelection) {
4157 return;
4158 }
4159 if (event.button !== 0) {
4160 return;
4161 }
4162 if (!this._enabled) {
4163 if (!this.shouldForceSelection(event)) {
4164 return;
4165 }
4166 event.stopPropagation();
4167 }
4168 event.preventDefault();
4169 this._dragScrollAmount = 0;
4170 if (this._enabled && event.shiftKey) {
4171 this._onIncrementalClick(event);
4172 }
4173 else {
4174 if (event.detail === 1) {
4175 this._onSingleClick(event);
4176 }
4177 else if (event.detail === 2) {
4178 this._onDoubleClick(event);
4179 }
4180 else if (event.detail === 3) {
4181 this._onTripleClick(event);
4182 }
4183 }
4184 this._addMouseDownListeners();
4185 this.refresh(true);
4186 };
4187 SelectionManager.prototype._addMouseDownListeners = function () {
4188 var _this = this;
4189 this._terminal.element.ownerDocument.addEventListener('mousemove', this._mouseMoveListener);
4190 this._terminal.element.ownerDocument.addEventListener('mouseup', this._mouseUpListener);
4191 this._dragScrollIntervalTimer = setInterval(function () { return _this._dragScroll(); }, DRAG_SCROLL_INTERVAL);
4192 };
4193 SelectionManager.prototype._removeMouseDownListeners = function () {
4194 if (this._terminal.element.ownerDocument) {
4195 this._terminal.element.ownerDocument.removeEventListener('mousemove', this._mouseMoveListener);
4196 this._terminal.element.ownerDocument.removeEventListener('mouseup', this._mouseUpListener);
4197 }
4198 clearInterval(this._dragScrollIntervalTimer);
4199 this._dragScrollIntervalTimer = null;
4200 };
4201 SelectionManager.prototype._onIncrementalClick = function (event) {
4202 if (this._model.selectionStart) {
4203 this._model.selectionEnd = this._getMouseBufferCoords(event);
4204 }
4205 };
4206 SelectionManager.prototype._onSingleClick = function (event) {
4207 this._model.selectionStartLength = 0;
4208 this._model.isSelectAllActive = false;
4209 this._activeSelectionMode = this.shouldColumnSelect(event) ? 3 : 0;
4210 this._model.selectionStart = this._getMouseBufferCoords(event);
4211 if (!this._model.selectionStart) {
4212 return;
4213 }
4214 this._model.selectionEnd = null;
4215 var line = this._buffer.lines.get(this._model.selectionStart[1]);
4216 if (!line) {
4217 return;
4218 }
4219 if (line.length >= this._model.selectionStart[0]) {
4220 return;
4221 }
4222 if (line.hasWidth(this._model.selectionStart[0]) === 0) {
4223 this._model.selectionStart[0]++;
4224 }
4225 };
4226 SelectionManager.prototype._onDoubleClick = function (event) {
4227 var coords = this._getMouseBufferCoords(event);
4228 if (coords) {
4229 this._activeSelectionMode = 1;
4230 this._selectWordAt(coords, true);
4231 }
4232 };
4233 SelectionManager.prototype._onTripleClick = function (event) {
4234 var coords = this._getMouseBufferCoords(event);
4235 if (coords) {
4236 this._activeSelectionMode = 2;
4237 this._selectLineAt(coords[1]);
4238 }
4239 };
4240 SelectionManager.prototype.shouldColumnSelect = function (event) {
4241 return event.altKey && !(Browser.isMac && this._terminal.options.macOptionClickForcesSelection);
4242 };
4243 SelectionManager.prototype._onMouseMove = function (event) {
4244 event.stopImmediatePropagation();
4245 var previousSelectionEnd = this._model.selectionEnd ? [this._model.selectionEnd[0], this._model.selectionEnd[1]] : null;
4246 this._model.selectionEnd = this._getMouseBufferCoords(event);
4247 if (!this._model.selectionEnd) {
4248 this.refresh(true);
4249 return;
4250 }
4251 if (this._activeSelectionMode === 2) {
4252 if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
4253 this._model.selectionEnd[0] = 0;
4254 }
4255 else {
4256 this._model.selectionEnd[0] = this._terminal.cols;
4257 }
4258 }
4259 else if (this._activeSelectionMode === 1) {
4260 this._selectToWordAt(this._model.selectionEnd);
4261 }
4262 this._dragScrollAmount = this._getMouseEventScrollAmount(event);
4263 if (this._activeSelectionMode !== 3) {
4264 if (this._dragScrollAmount > 0) {
4265 this._model.selectionEnd[0] = this._terminal.cols;
4266 }
4267 else if (this._dragScrollAmount < 0) {
4268 this._model.selectionEnd[0] = 0;
4269 }
4270 }
4271 if (this._model.selectionEnd[1] < this._buffer.lines.length) {
4272 if (this._buffer.lines.get(this._model.selectionEnd[1]).hasWidth(this._model.selectionEnd[0]) === 0) {
4273 this._model.selectionEnd[0]++;
4274 }
4275 }
4276 if (!previousSelectionEnd ||
4277 previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
4278 previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
4279 this.refresh(true);
4280 }
4281 };
4282 SelectionManager.prototype._dragScroll = function () {
4283 if (this._dragScrollAmount) {
4284 this._terminal.scrollLines(this._dragScrollAmount, false);
4285 if (this._dragScrollAmount > 0) {
4286 if (this._activeSelectionMode !== 3) {
4287 this._model.selectionEnd[0] = this._terminal.cols;
4288 }
4289 this._model.selectionEnd[1] = Math.min(this._terminal.buffer.ydisp + this._terminal.rows, this._terminal.buffer.lines.length - 1);
4290 }
4291 else {
4292 if (this._activeSelectionMode !== 3) {
4293 this._model.selectionEnd[0] = 0;
4294 }
4295 this._model.selectionEnd[1] = this._terminal.buffer.ydisp;
4296 }
4297 this.refresh();
4298 }
4299 };
4300 SelectionManager.prototype._onMouseUp = function (event) {
4301 var timeElapsed = event.timeStamp - this._mouseDownTimeStamp;
4302 this._removeMouseDownListeners();
4303 if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME) {
4304 (new AltClickHandler_1.AltClickHandler(event, this._terminal)).move();
4305 }
4306 else if (this.hasSelection) {
4307 this._onSelectionChange.fire();
4308 }
4309 };
4310 SelectionManager.prototype._onBufferActivate = function (e) {
4311 var _this = this;
4312 this.clearSelection();
4313 if (this._trimListener) {
4314 this._trimListener.dispose();
4315 }
4316 this._trimListener = e.activeBuffer.lines.onTrim(function (amount) { return _this._onTrim(amount); });
4317 };
4318 SelectionManager.prototype._convertViewportColToCharacterIndex = function (bufferLine, coords) {
4319 var charIndex = coords[0];
4320 for (var i = 0; coords[0] >= i; i++) {
4321 var length_1 = bufferLine.loadCell(i, this._workCell).getChars().length;
4322 if (this._workCell.getWidth() === 0) {
4323 charIndex--;
4324 }
4325 else if (length_1 > 1 && coords[0] !== i) {
4326 charIndex += length_1 - 1;
4327 }
4328 }
4329 return charIndex;
4330 };
4331 SelectionManager.prototype.setSelection = function (col, row, length) {
4332 this._model.clearSelection();
4333 this._removeMouseDownListeners();
4334 this._model.selectionStart = [col, row];
4335 this._model.selectionStartLength = length;
4336 this.refresh();
4337 };
4338 SelectionManager.prototype._getWordAt = function (coords, allowWhitespaceOnlySelection, followWrappedLinesAbove, followWrappedLinesBelow) {
4339 if (followWrappedLinesAbove === void 0) { followWrappedLinesAbove = true; }
4340 if (followWrappedLinesBelow === void 0) { followWrappedLinesBelow = true; }
4341 if (coords[0] >= this._terminal.cols) {
4342 return null;
4343 }
4344 var bufferLine = this._buffer.lines.get(coords[1]);
4345 if (!bufferLine) {
4346 return null;
4347 }
4348 var line = this._buffer.translateBufferLineToString(coords[1], false);
4349 var startIndex = this._convertViewportColToCharacterIndex(bufferLine, coords);
4350 var endIndex = startIndex;
4351 var charOffset = coords[0] - startIndex;
4352 var leftWideCharCount = 0;
4353 var rightWideCharCount = 0;
4354 var leftLongCharOffset = 0;
4355 var rightLongCharOffset = 0;
4356 if (line.charAt(startIndex) === ' ') {
4357 while (startIndex > 0 && line.charAt(startIndex - 1) === ' ') {
4358 startIndex--;
4359 }
4360 while (endIndex < line.length && line.charAt(endIndex + 1) === ' ') {
4361 endIndex++;
4362 }
4363 }
4364 else {
4365 var startCol = coords[0];
4366 var endCol = coords[0];
4367 if (bufferLine.getWidth(startCol) === 0) {
4368 leftWideCharCount++;
4369 startCol--;
4370 }
4371 if (bufferLine.getWidth(endCol) === 2) {
4372 rightWideCharCount++;
4373 endCol++;
4374 }
4375 var length_2 = bufferLine.getString(endCol).length;
4376 if (length_2 > 1) {
4377 rightLongCharOffset += length_2 - 1;
4378 endIndex += length_2 - 1;
4379 }
4380 while (startCol > 0 && startIndex > 0 && !this._isCharWordSeparator(bufferLine.loadCell(startCol - 1, this._workCell))) {
4381 bufferLine.loadCell(startCol - 1, this._workCell);
4382 var length_3 = this._workCell.getChars().length;
4383 if (this._workCell.getWidth() === 0) {
4384 leftWideCharCount++;
4385 startCol--;
4386 }
4387 else if (length_3 > 1) {
4388 leftLongCharOffset += length_3 - 1;
4389 startIndex -= length_3 - 1;
4390 }
4391 startIndex--;
4392 startCol--;
4393 }
4394 while (endCol < bufferLine.length && endIndex + 1 < line.length && !this._isCharWordSeparator(bufferLine.loadCell(endCol + 1, this._workCell))) {
4395 bufferLine.loadCell(endCol + 1, this._workCell);
4396 var length_4 = this._workCell.getChars().length;
4397 if (this._workCell.getWidth() === 2) {
4398 rightWideCharCount++;
4399 endCol++;
4400 }
4401 else if (length_4 > 1) {
4402 rightLongCharOffset += length_4 - 1;
4403 endIndex += length_4 - 1;
4404 }
4405 endIndex++;
4406 endCol++;
4407 }
4408 }
4409 endIndex++;
4410 var start = startIndex
4411 + charOffset
4412 - leftWideCharCount
4413 + leftLongCharOffset;
4414 var length = Math.min(this._terminal.cols, endIndex
4415 - startIndex
4416 + leftWideCharCount
4417 + rightWideCharCount
4418 - leftLongCharOffset
4419 - rightLongCharOffset);
4420 if (!allowWhitespaceOnlySelection && line.slice(startIndex, endIndex).trim() === '') {
4421 return null;
4422 }
4423 if (followWrappedLinesAbove) {
4424 if (start === 0 && bufferLine.getCodePoint(0) !== 32) {
4425 var previousBufferLine = this._buffer.lines.get(coords[1] - 1);
4426 if (previousBufferLine && bufferLine.isWrapped && previousBufferLine.getCodePoint(this._terminal.cols - 1) !== 32) {
4427 var previousLineWordPosition = this._getWordAt([this._terminal.cols - 1, coords[1] - 1], false, true, false);
4428 if (previousLineWordPosition) {
4429 var offset = this._terminal.cols - previousLineWordPosition.start;
4430 start -= offset;
4431 length += offset;
4432 }
4433 }
4434 }
4435 }
4436 if (followWrappedLinesBelow) {
4437 if (start + length === this._terminal.cols && bufferLine.getCodePoint(this._terminal.cols - 1) !== 32) {
4438 var nextBufferLine = this._buffer.lines.get(coords[1] + 1);
4439 if (nextBufferLine && nextBufferLine.isWrapped && nextBufferLine.getCodePoint(0) !== 32) {
4440 var nextLineWordPosition = this._getWordAt([0, coords[1] + 1], false, false, true);
4441 if (nextLineWordPosition) {
4442 length += nextLineWordPosition.length;
4443 }
4444 }
4445 }
4446 }
4447 return { start: start, length: length };
4448 };
4449 SelectionManager.prototype._selectWordAt = function (coords, allowWhitespaceOnlySelection) {
4450 var wordPosition = this._getWordAt(coords, allowWhitespaceOnlySelection);
4451 if (wordPosition) {
4452 while (wordPosition.start < 0) {
4453 wordPosition.start += this._terminal.cols;
4454 coords[1]--;
4455 }
4456 this._model.selectionStart = [wordPosition.start, coords[1]];
4457 this._model.selectionStartLength = wordPosition.length;
4458 }
4459 };
4460 SelectionManager.prototype._selectToWordAt = function (coords) {
4461 var wordPosition = this._getWordAt(coords, true);
4462 if (wordPosition) {
4463 var endRow = coords[1];
4464 while (wordPosition.start < 0) {
4465 wordPosition.start += this._terminal.cols;
4466 endRow--;
4467 }
4468 if (!this._model.areSelectionValuesReversed()) {
4469 while (wordPosition.start + wordPosition.length > this._terminal.cols) {
4470 wordPosition.length -= this._terminal.cols;
4471 endRow++;
4472 }
4473 }
4474 this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : wordPosition.start + wordPosition.length, endRow];
4475 }
4476 };
4477 SelectionManager.prototype._isCharWordSeparator = function (cell) {
4478 if (cell.getWidth() === 0) {
4479 return false;
4480 }
4481 return WORD_SEPARATORS.indexOf(cell.getChars()) >= 0;
4482 };
4483 SelectionManager.prototype._selectLineAt = function (line) {
4484 var wrappedRange = this._buffer.getWrappedRangeForLine(line);
4485 this._model.selectionStart = [0, wrappedRange.first];
4486 this._model.selectionEnd = [this._terminal.cols, wrappedRange.last];
4487 this._model.selectionStartLength = 0;
4488 };
4489 return SelectionManager;
4490 }());
4491 exports.SelectionManager = SelectionManager;
4492
4493 },{"./BufferLine":3,"./MouseHelper":13,"./SelectionModel":16,"./common/EventEmitter2":25,"./common/Platform":27,"./handlers/AltClickHandler":33}],16:[function(require,module,exports){
4494 "use strict";
4495 Object.defineProperty(exports, "__esModule", { value: true });
4496 var SelectionModel = (function () {
4497 function SelectionModel(_terminal) {
4498 this._terminal = _terminal;
4499 this.clearSelection();
4500 }
4501 SelectionModel.prototype.clearSelection = function () {
4502 this.selectionStart = null;
4503 this.selectionEnd = null;
4504 this.isSelectAllActive = false;
4505 this.selectionStartLength = 0;
4506 };
4507 Object.defineProperty(SelectionModel.prototype, "finalSelectionStart", {
4508 get: function () {
4509 if (this.isSelectAllActive) {
4510 return [0, 0];
4511 }
4512 if (!this.selectionEnd || !this.selectionStart) {
4513 return this.selectionStart;
4514 }
4515 return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
4516 },
4517 enumerable: true,
4518 configurable: true
4519 });
4520 Object.defineProperty(SelectionModel.prototype, "finalSelectionEnd", {
4521 get: function () {
4522 if (this.isSelectAllActive) {
4523 return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1];
4524 }
4525 if (!this.selectionStart) {
4526 return null;
4527 }
4528 if (!this.selectionEnd || this.areSelectionValuesReversed()) {
4529 var startPlusLength = this.selectionStart[0] + this.selectionStartLength;
4530 if (startPlusLength > this._terminal.cols) {
4531 return [startPlusLength % this._terminal.cols, this.selectionStart[1] + Math.floor(startPlusLength / this._terminal.cols)];
4532 }
4533 return [startPlusLength, this.selectionStart[1]];
4534 }
4535 if (this.selectionStartLength) {
4536 if (this.selectionEnd[1] === this.selectionStart[1]) {
4537 return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]];
4538 }
4539 }
4540 return this.selectionEnd;
4541 },
4542 enumerable: true,
4543 configurable: true
4544 });
4545 SelectionModel.prototype.areSelectionValuesReversed = function () {
4546 var start = this.selectionStart;
4547 var end = this.selectionEnd;
4548 if (!start || !end) {
4549 return false;
4550 }
4551 return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
4552 };
4553 SelectionModel.prototype.onTrim = function (amount) {
4554 if (this.selectionStart) {
4555 this.selectionStart[1] -= amount;
4556 }
4557 if (this.selectionEnd) {
4558 this.selectionEnd[1] -= amount;
4559 }
4560 if (this.selectionEnd && this.selectionEnd[1] < 0) {
4561 this.clearSelection();
4562 return true;
4563 }
4564 if (this.selectionStart && this.selectionStart[1] < 0) {
4565 this.selectionStart[1] = 0;
4566 }
4567 return false;
4568 };
4569 return SelectionModel;
4570 }());
4571 exports.SelectionModel = SelectionModel;
4572
4573 },{}],17:[function(require,module,exports){
4574 "use strict";
4575 Object.defineProperty(exports, "__esModule", { value: true });
4576 exports.DEFAULT_BELL_SOUND = 'data:audio/wav;base64,UklGRigBAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQQBAADpAFgCwAMlBZoG/wdmCcoKRAypDQ8PbRDBEQQTOxRtFYcWlBePGIUZXhoiG88bcBz7HHIdzh0WHlMeZx51HmkeUx4WHs8dah0AHXwc3hs9G4saxRnyGBIYGBcQFv8U4RPAEoYRQBACD70NWwwHC6gJOwjWBloF7gOBAhABkf8b/qv8R/ve+Xf4Ife79W/0JfPZ8Z/wde9N7ijtE+wU6xvqM+lb6H7nw+YX5mrlxuQz5Mzje+Ma49fioeKD4nXiYeJy4pHitOL04j/jn+MN5IPkFOWs5U3mDefM55/ogOl36m7rdOyE7abuyu8D8Unyj/Pg9D/2qfcb+Yn6/vuK/Qj/lAAlAg==';
4577 var SoundManager = (function () {
4578 function SoundManager(_terminal) {
4579 this._terminal = _terminal;
4580 }
4581 Object.defineProperty(SoundManager, "audioContext", {
4582 get: function () {
4583 if (!SoundManager._audioContext) {
4584 var audioContextCtor = window.AudioContext || window.webkitAudioContext;
4585 if (!audioContextCtor) {
4586 console.warn('Web Audio API is not supported by this browser. Consider upgrading to the latest version');
4587 return null;
4588 }
4589 SoundManager._audioContext = new audioContextCtor();
4590 }
4591 return SoundManager._audioContext;
4592 },
4593 enumerable: true,
4594 configurable: true
4595 });
4596 SoundManager.prototype.playBellSound = function () {
4597 var ctx = SoundManager.audioContext;
4598 if (!ctx) {
4599 return;
4600 }
4601 var bellAudioSource = ctx.createBufferSource();
4602 ctx.decodeAudioData(this._base64ToArrayBuffer(this._removeMimeType(this._terminal.options.bellSound)), function (buffer) {
4603 bellAudioSource.buffer = buffer;
4604 bellAudioSource.connect(ctx.destination);
4605 bellAudioSource.start(0);
4606 });
4607 };
4608 SoundManager.prototype._base64ToArrayBuffer = function (base64) {
4609 var binaryString = window.atob(base64);
4610 var len = binaryString.length;
4611 var bytes = new Uint8Array(len);
4612 for (var i = 0; i < len; i++) {
4613 bytes[i] = binaryString.charCodeAt(i);
4614 }
4615 return bytes.buffer;
4616 };
4617 SoundManager.prototype._removeMimeType = function (dataURI) {
4618 var splitUri = dataURI.split(',');
4619 return splitUri[1];
4620 };
4621 return SoundManager;
4622 }());
4623 exports.SoundManager = SoundManager;
4624
4625 },{}],18:[function(require,module,exports){
4626 "use strict";
4627 Object.defineProperty(exports, "__esModule", { value: true });
4628 exports.blankLine = 'Blank line';
4629 exports.promptLabel = 'Terminal input';
4630 exports.tooMuchOutput = 'Too much output to announce, navigate to rows manually to read';
4631
4632 },{}],19:[function(require,module,exports){
4633 "use strict";
4634 var __extends = (this && this.__extends) || (function () {
4635 var extendStatics = function (d, b) {
4636 extendStatics = Object.setPrototypeOf ||
4637 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4638 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
4639 return extendStatics(d, b);
4640 };
4641 return function (d, b) {
4642 extendStatics(d, b);
4643 function __() { this.constructor = d; }
4644 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
4645 };
4646 })();
4647 Object.defineProperty(exports, "__esModule", { value: true });
4648 var BufferSet_1 = require("./BufferSet");
4649 var Buffer_1 = require("./Buffer");
4650 var CompositionHelper_1 = require("./CompositionHelper");
4651 var EventEmitter_1 = require("./common/EventEmitter");
4652 var Viewport_1 = require("./Viewport");
4653 var Clipboard_1 = require("./Clipboard");
4654 var EscapeSequences_1 = require("./common/data/EscapeSequences");
4655 var InputHandler_1 = require("./InputHandler");
4656 var Renderer_1 = require("./renderer/Renderer");
4657 var Linkifier_1 = require("./Linkifier");
4658 var SelectionManager_1 = require("./SelectionManager");
4659 var CharMeasure_1 = require("./CharMeasure");
4660 var Browser = require("./common/Platform");
4661 var Lifecycle_1 = require("./ui/Lifecycle");
4662 var Strings = require("./Strings");
4663 var MouseHelper_1 = require("./MouseHelper");
4664 var SoundManager_1 = require("./SoundManager");
4665 var MouseZoneManager_1 = require("./MouseZoneManager");
4666 var AccessibilityManager_1 = require("./AccessibilityManager");
4667 var ScreenDprMonitor_1 = require("./ui/ScreenDprMonitor");
4668 var CharAtlasCache_1 = require("./renderer/atlas/CharAtlasCache");
4669 var DomRenderer_1 = require("./renderer/dom/DomRenderer");
4670 var Keyboard_1 = require("./core/input/Keyboard");
4671 var Clone_1 = require("./common/Clone");
4672 var EventEmitter2_1 = require("./common/EventEmitter2");
4673 var WindowsMode_1 = require("./WindowsMode");
4674 var document = (typeof window !== 'undefined') ? window.document : null;
4675 var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
4676 var WRITE_TIMEOUT_MS = 12;
4677 var MINIMUM_COLS = 2;
4678 var MINIMUM_ROWS = 1;
4679 var CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows'];
4680 var DEFAULT_OPTIONS = {
4681 cols: 80,
4682 rows: 24,
4683 convertEol: false,
4684 termName: 'xterm',
4685 cursorBlink: false,
4686 cursorStyle: 'block',
4687 bellSound: SoundManager_1.DEFAULT_BELL_SOUND,
4688 bellStyle: 'none',
4689 drawBoldTextInBrightColors: true,
4690 enableBold: true,
4691 experimentalCharAtlas: 'static',
4692 fontFamily: 'courier-new, courier, monospace',
4693 fontSize: 15,
4694 fontWeight: 'normal',
4695 fontWeightBold: 'bold',
4696 lineHeight: 1.0,
4697 letterSpacing: 0,
4698 scrollback: 1000,
4699 screenKeys: false,
4700 screenReaderMode: false,
4701 debug: false,
4702 macOptionIsMeta: false,
4703 macOptionClickForcesSelection: false,
4704 cancelEvents: false,
4705 disableStdin: false,
4706 useFlowControl: false,
4707 allowTransparency: false,
4708 tabStopWidth: 8,
4709 theme: null,
4710 rightClickSelectsWord: Browser.isMac,
4711 rendererType: 'canvas',
4712 windowsMode: false
4713 };
4714 var Terminal = (function (_super) {
4715 __extends(Terminal, _super);
4716 function Terminal(options) {
4717 if (options === void 0) { options = {}; }
4718 var _this = _super.call(this) || this;
4719 _this.browser = Browser;
4720 _this._blankLine = null;
4721 _this._onCursorMove = new EventEmitter2_1.EventEmitter2();
4722 _this._onData = new EventEmitter2_1.EventEmitter2();
4723 _this._onKey = new EventEmitter2_1.EventEmitter2();
4724 _this._onLineFeed = new EventEmitter2_1.EventEmitter2();
4725 _this._onRender = new EventEmitter2_1.EventEmitter2();
4726 _this._onResize = new EventEmitter2_1.EventEmitter2();
4727 _this._onScroll = new EventEmitter2_1.EventEmitter2();
4728 _this._onSelectionChange = new EventEmitter2_1.EventEmitter2();
4729 _this._onTitleChange = new EventEmitter2_1.EventEmitter2();
4730 _this.options = Clone_1.clone(options);
4731 _this._setup();
4732 _this.onCursorMove(function () { return _this.emit('cursormove'); });
4733 _this.onData(function (e) { return _this.emit('data', e); });
4734 _this.onKey(function (e) { return _this.emit('key', e.key, e.domEvent); });
4735 _this.onLineFeed(function () { return _this.emit('linefeed'); });
4736 _this.onRender(function (e) { return _this.emit('refresh', e); });
4737 _this.onResize(function (e) { return _this.emit('resize', e); });
4738 _this.onSelectionChange(function () { return _this.emit('selection'); });
4739 _this.onScroll(function (e) { return _this.emit('scroll', e); });
4740 _this.onTitleChange(function (e) { return _this.emit('title', e); });
4741 return _this;
4742 }
4743 Object.defineProperty(Terminal.prototype, "onCursorMove", {
4744 get: function () { return this._onCursorMove.event; },
4745 enumerable: true,
4746 configurable: true
4747 });
4748 Object.defineProperty(Terminal.prototype, "onData", {
4749 get: function () { return this._onData.event; },
4750 enumerable: true,
4751 configurable: true
4752 });
4753 Object.defineProperty(Terminal.prototype, "onKey", {
4754 get: function () { return this._onKey.event; },
4755 enumerable: true,
4756 configurable: true
4757 });
4758 Object.defineProperty(Terminal.prototype, "onLineFeed", {
4759 get: function () { return this._onLineFeed.event; },
4760 enumerable: true,
4761 configurable: true
4762 });
4763 Object.defineProperty(Terminal.prototype, "onRender", {
4764 get: function () { return this._onRender.event; },
4765 enumerable: true,
4766 configurable: true
4767 });
4768 Object.defineProperty(Terminal.prototype, "onResize", {
4769 get: function () { return this._onResize.event; },
4770 enumerable: true,
4771 configurable: true
4772 });
4773 Object.defineProperty(Terminal.prototype, "onScroll", {
4774 get: function () { return this._onScroll.event; },
4775 enumerable: true,
4776 configurable: true
4777 });
4778 Object.defineProperty(Terminal.prototype, "onSelectionChange", {
4779 get: function () { return this._onSelectionChange.event; },
4780 enumerable: true,
4781 configurable: true
4782 });
4783 Object.defineProperty(Terminal.prototype, "onTitleChange", {
4784 get: function () { return this._onTitleChange.event; },
4785 enumerable: true,
4786 configurable: true
4787 });
4788 Terminal.prototype.dispose = function () {
4789 _super.prototype.dispose.call(this);
4790 if (this._windowsMode) {
4791 this._windowsMode.dispose();
4792 this._windowsMode = undefined;
4793 }
4794 this._customKeyEventHandler = null;
4795 CharAtlasCache_1.removeTerminalFromCache(this);
4796 this.handler = function () { };
4797 this.write = function () { };
4798 if (this.element && this.element.parentNode) {
4799 this.element.parentNode.removeChild(this.element);
4800 }
4801 };
4802 Terminal.prototype.destroy = function () {
4803 this.dispose();
4804 };
4805 Terminal.prototype._setup = function () {
4806 var _this = this;
4807 Object.keys(DEFAULT_OPTIONS).forEach(function (key) {
4808 if (_this.options[key] === null || _this.options[key] === undefined) {
4809 _this.options[key] = DEFAULT_OPTIONS[key];
4810 }
4811 });
4812 this._parent = document ? document.body : null;
4813 this.cols = Math.max(this.options.cols, MINIMUM_COLS);
4814 this.rows = Math.max(this.options.rows, MINIMUM_ROWS);
4815 if (this.options.handler) {
4816 this.onData(this.options.handler);
4817 }
4818 this.cursorState = 0;
4819 this.cursorHidden = false;
4820 this._customKeyEventHandler = null;
4821 this.applicationKeypad = false;
4822 this.applicationCursor = false;
4823 this.originMode = false;
4824 this.insertMode = false;
4825 this.wraparoundMode = true;
4826 this.bracketedPasteMode = false;
4827 this.charset = null;
4828 this.gcharset = null;
4829 this.glevel = 0;
4830 this.charsets = [null];
4831 this.curAttrData = Buffer_1.DEFAULT_ATTR_DATA.clone();
4832 this._eraseAttrData = Buffer_1.DEFAULT_ATTR_DATA.clone();
4833 this.params = [];
4834 this.currentParam = 0;
4835 this.writeBuffer = [];
4836 this._writeInProgress = false;
4837 this._xoffSentToCatchUp = false;
4838 this._userScrolling = false;
4839 this._inputHandler = new InputHandler_1.InputHandler(this);
4840 this._inputHandler.onCursorMove(function () { return _this._onCursorMove.fire(); });
4841 this._inputHandler.onLineFeed(function () { return _this._onLineFeed.fire(); });
4842 this._inputHandler.onData(function (e) { return _this._onData.fire(e); });
4843 this.register(this._inputHandler);
4844 this.renderer = this.renderer || null;
4845 this.selectionManager = this.selectionManager || null;
4846 this.linkifier = this.linkifier || new Linkifier_1.Linkifier(this);
4847 this._mouseZoneManager = this._mouseZoneManager || null;
4848 this.soundManager = this.soundManager || new SoundManager_1.SoundManager(this);
4849 this.buffers = new BufferSet_1.BufferSet(this);
4850 if (this.selectionManager) {
4851 this.selectionManager.clearSelection();
4852 this.selectionManager.initBuffersListeners();
4853 }
4854 if (this.options.windowsMode) {
4855 this._windowsMode = WindowsMode_1.applyWindowsMode(this);
4856 }
4857 };
4858 Object.defineProperty(Terminal.prototype, "buffer", {
4859 get: function () {
4860 return this.buffers.active;
4861 },
4862 enumerable: true,
4863 configurable: true
4864 });
4865 Terminal.prototype.eraseAttrData = function () {
4866 this._eraseAttrData.bg &= ~(50331648 | 0xFFFFFF);
4867 this._eraseAttrData.bg |= this.curAttrData.bg & ~0xFC000000;
4868 return this._eraseAttrData;
4869 };
4870 Terminal.prototype.focus = function () {
4871 if (this.textarea) {
4872 this.textarea.focus({ preventScroll: true });
4873 }
4874 };
4875 Object.defineProperty(Terminal.prototype, "isFocused", {
4876 get: function () {
4877 return document.activeElement === this.textarea && document.hasFocus();
4878 },
4879 enumerable: true,
4880 configurable: true
4881 });
4882 Terminal.prototype.getOption = function (key) {
4883 if (!(key in DEFAULT_OPTIONS)) {
4884 throw new Error('No option with key "' + key + '"');
4885 }
4886 return this.options[key];
4887 };
4888 Terminal.prototype.setOption = function (key, value) {
4889 if (!(key in DEFAULT_OPTIONS)) {
4890 throw new Error('No option with key "' + key + '"');
4891 }
4892 if (CONSTRUCTOR_ONLY_OPTIONS.indexOf(key) !== -1) {
4893 console.error("Option \"" + key + "\" can only be set in the constructor");
4894 }
4895 if (this.options[key] === value) {
4896 return;
4897 }
4898 switch (key) {
4899 case 'bellStyle':
4900 if (!value) {
4901 value = 'none';
4902 }
4903 break;
4904 case 'cursorStyle':
4905 if (!value) {
4906 value = 'block';
4907 }
4908 break;
4909 case 'fontWeight':
4910 if (!value) {
4911 value = 'normal';
4912 }
4913 break;
4914 case 'fontWeightBold':
4915 if (!value) {
4916 value = 'bold';
4917 }
4918 break;
4919 case 'lineHeight':
4920 if (value < 1) {
4921 console.warn(key + " cannot be less than 1, value: " + value);
4922 return;
4923 }
4924 case 'rendererType':
4925 if (!value) {
4926 value = 'canvas';
4927 }
4928 break;
4929 case 'tabStopWidth':
4930 if (value < 1) {
4931 console.warn(key + " cannot be less than 1, value: " + value);
4932 return;
4933 }
4934 break;
4935 case 'theme':
4936 if (this.renderer) {
4937 this._setTheme(value);
4938 return;
4939 }
4940 break;
4941 case 'scrollback':
4942 value = Math.min(value, Buffer_1.MAX_BUFFER_SIZE);
4943 if (value < 0) {
4944 console.warn(key + " cannot be less than 0, value: " + value);
4945 return;
4946 }
4947 if (this.options[key] !== value) {
4948 var newBufferLength = this.rows + value;
4949 if (this.buffer.lines.length > newBufferLength) {
4950 var amountToTrim = this.buffer.lines.length - newBufferLength;
4951 var needsRefresh = (this.buffer.ydisp - amountToTrim < 0);
4952 this.buffer.lines.trimStart(amountToTrim);
4953 this.buffer.ybase = Math.max(this.buffer.ybase - amountToTrim, 0);
4954 this.buffer.ydisp = Math.max(this.buffer.ydisp - amountToTrim, 0);
4955 if (needsRefresh) {
4956 this.refresh(0, this.rows - 1);
4957 }
4958 }
4959 }
4960 break;
4961 }
4962 this.options[key] = value;
4963 switch (key) {
4964 case 'fontFamily':
4965 case 'fontSize':
4966 if (this.renderer) {
4967 this.renderer.clear();
4968 this.charMeasure.measure(this.options);
4969 }
4970 break;
4971 case 'drawBoldTextInBrightColors':
4972 case 'experimentalCharAtlas':
4973 case 'enableBold':
4974 case 'letterSpacing':
4975 case 'lineHeight':
4976 case 'fontWeight':
4977 case 'fontWeightBold':
4978 if (this.renderer) {
4979 this.renderer.clear();
4980 this.renderer.onResize(this.cols, this.rows);
4981 this.refresh(0, this.rows - 1);
4982 }
4983 break;
4984 case 'rendererType':
4985 if (this.renderer) {
4986 this.unregister(this.renderer);
4987 this.renderer.dispose();
4988 this.renderer = null;
4989 }
4990 this._setupRenderer();
4991 this.renderer.onCharSizeChanged();
4992 if (this._theme) {
4993 this.renderer.setTheme(this._theme);
4994 }
4995 this.mouseHelper.setRenderer(this.renderer);
4996 break;
4997 case 'scrollback':
4998 this.buffers.resize(this.cols, this.rows);
4999 if (this.viewport) {
5000 this.viewport.syncScrollArea();
5001 }
5002 break;
5003 case 'screenReaderMode':
5004 if (value) {
5005 if (!this._accessibilityManager) {
5006 this._accessibilityManager = new AccessibilityManager_1.AccessibilityManager(this);
5007 }
5008 }
5009 else {
5010 if (this._accessibilityManager) {
5011 this._accessibilityManager.dispose();
5012 this._accessibilityManager = null;
5013 }
5014 }
5015 break;
5016 case 'tabStopWidth':
5017 this.buffers.setupTabStops();
5018 break;
5019 case 'windowsMode':
5020 if (value) {
5021 if (!this._windowsMode) {
5022 this._windowsMode = WindowsMode_1.applyWindowsMode(this);
5023 }
5024 }
5025 else {
5026 if (this._windowsMode) {
5027 this._windowsMode.dispose();
5028 this._windowsMode = undefined;
5029 }
5030 }
5031 break;
5032 }
5033 if (this.renderer) {
5034 this.renderer.onOptionsChanged();
5035 }
5036 };
5037 Terminal.prototype._onTextAreaFocus = function (ev) {
5038 if (this.sendFocus) {
5039 this.handler(EscapeSequences_1.C0.ESC + '[I');
5040 }
5041 this.updateCursorStyle(ev);
5042 this.element.classList.add('focus');
5043 this.showCursor();
5044 this.emit('focus');
5045 };
5046 Terminal.prototype.blur = function () {
5047 return this.textarea.blur();
5048 };
5049 Terminal.prototype._onTextAreaBlur = function () {
5050 this.textarea.value = '';
5051 this.refresh(this.buffer.y, this.buffer.y);
5052 if (this.sendFocus) {
5053 this.handler(EscapeSequences_1.C0.ESC + '[O');
5054 }
5055 this.element.classList.remove('focus');
5056 this.emit('blur');
5057 };
5058 Terminal.prototype._initGlobal = function () {
5059 var _this = this;
5060 this._bindKeys();
5061 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'copy', function (event) {
5062 if (!_this.hasSelection()) {
5063 return;
5064 }
5065 Clipboard_1.copyHandler(event, _this, _this.selectionManager);
5066 }));
5067 var pasteHandlerWrapper = function (event) { return Clipboard_1.pasteHandler(event, _this); };
5068 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'paste', pasteHandlerWrapper));
5069 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'paste', pasteHandlerWrapper));
5070 if (Browser.isFirefox) {
5071 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'mousedown', function (event) {
5072 if (event.button === 2) {
5073 Clipboard_1.rightClickHandler(event, _this, _this.selectionManager, _this.options.rightClickSelectsWord);
5074 }
5075 }));
5076 }
5077 else {
5078 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'contextmenu', function (event) {
5079 Clipboard_1.rightClickHandler(event, _this, _this.selectionManager, _this.options.rightClickSelectsWord);
5080 }));
5081 }
5082 if (Browser.isLinux) {
5083 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'auxclick', function (event) {
5084 if (event.button === 1) {
5085 Clipboard_1.moveTextAreaUnderMouseCursor(event, _this);
5086 }
5087 }));
5088 }
5089 };
5090 Terminal.prototype._bindKeys = function () {
5091 var _this = this;
5092 var self = this;
5093 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'keydown', function (ev) {
5094 if (document.activeElement !== this) {
5095 return;
5096 }
5097 self._keyDown(ev);
5098 }, true));
5099 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'keypress', function (ev) {
5100 if (document.activeElement !== this) {
5101 return;
5102 }
5103 self._keyPress(ev);
5104 }, true));
5105 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'keyup', function (ev) {
5106 if (!wasModifierKeyOnlyEvent(ev)) {
5107 _this.focus();
5108 }
5109 self._keyUp(ev);
5110 }, true));
5111 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'keydown', function (ev) { return _this._keyDown(ev); }, true));
5112 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'keypress', function (ev) { return _this._keyPress(ev); }, true));
5113 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'compositionstart', function () { return _this._compositionHelper.compositionstart(); }));
5114 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'compositionupdate', function (e) { return _this._compositionHelper.compositionupdate(e); }));
5115 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'compositionend', function () { return _this._compositionHelper.compositionend(); }));
5116 this.register(this.onRender(function () { return _this._compositionHelper.updateCompositionElements(); }));
5117 this.register(this.onRender(function (e) { return _this._queueLinkification(e.start, e.end); }));
5118 };
5119 Terminal.prototype.open = function (parent) {
5120 var _this = this;
5121 this._parent = parent || this._parent;
5122 if (!this._parent) {
5123 throw new Error('Terminal requires a parent element.');
5124 }
5125 this._context = this._parent.ownerDocument.defaultView;
5126 this._document = this._parent.ownerDocument;
5127 this._screenDprMonitor = new ScreenDprMonitor_1.ScreenDprMonitor();
5128 this._screenDprMonitor.setListener(function () { return _this.emit('dprchange', window.devicePixelRatio); });
5129 this.register(this._screenDprMonitor);
5130 this.element = this._document.createElement('div');
5131 this.element.dir = 'ltr';
5132 this.element.classList.add('terminal');
5133 this.element.classList.add('xterm');
5134 this.element.setAttribute('tabindex', '0');
5135 this._parent.appendChild(this.element);
5136 var fragment = document.createDocumentFragment();
5137 this._viewportElement = document.createElement('div');
5138 this._viewportElement.classList.add('xterm-viewport');
5139 fragment.appendChild(this._viewportElement);
5140 this._viewportScrollArea = document.createElement('div');
5141 this._viewportScrollArea.classList.add('xterm-scroll-area');
5142 this._viewportElement.appendChild(this._viewportScrollArea);
5143 this.screenElement = document.createElement('div');
5144 this.screenElement.classList.add('xterm-screen');
5145 this._helperContainer = document.createElement('div');
5146 this._helperContainer.classList.add('xterm-helpers');
5147 this.screenElement.appendChild(this._helperContainer);
5148 fragment.appendChild(this.screenElement);
5149 this._mouseZoneManager = new MouseZoneManager_1.MouseZoneManager(this);
5150 this.register(this._mouseZoneManager);
5151 this.register(this.onScroll(function () { return _this._mouseZoneManager.clearAll(); }));
5152 this.linkifier.attachToDom(this._mouseZoneManager);
5153 this.textarea = document.createElement('textarea');
5154 this.textarea.classList.add('xterm-helper-textarea');
5155 this.textarea.setAttribute('aria-label', Strings.promptLabel);
5156 this.textarea.setAttribute('aria-multiline', 'false');
5157 this.textarea.setAttribute('autocorrect', 'off');
5158 this.textarea.setAttribute('autocapitalize', 'off');
5159 this.textarea.setAttribute('spellcheck', 'false');
5160 this.textarea.tabIndex = 0;
5161 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'focus', function (ev) { return _this._onTextAreaFocus(ev); }));
5162 this.register(Lifecycle_1.addDisposableDomListener(this.textarea, 'blur', function () { return _this._onTextAreaBlur(); }));
5163 this._helperContainer.appendChild(this.textarea);
5164 this._compositionView = document.createElement('div');
5165 this._compositionView.classList.add('composition-view');
5166 this._compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this._compositionView, this);
5167 this._helperContainer.appendChild(this._compositionView);
5168 this.charMeasure = new CharMeasure_1.CharMeasure(document, this._helperContainer);
5169 this.element.appendChild(fragment);
5170 this._setupRenderer();
5171 this._theme = this.options.theme;
5172 this.options.theme = null;
5173 this.viewport = new Viewport_1.Viewport(this, this._viewportElement, this._viewportScrollArea, this.charMeasure);
5174 this.viewport.onThemeChanged(this.renderer.colorManager.colors);
5175 this.register(this.viewport);
5176 this.register(this.onCursorMove(function () { return _this.renderer.onCursorMove(); }));
5177 this.register(this.onResize(function () { return _this.renderer.onResize(_this.cols, _this.rows); }));
5178 this.register(this.addDisposableListener('blur', function () { return _this.renderer.onBlur(); }));
5179 this.register(this.addDisposableListener('focus', function () { return _this.renderer.onFocus(); }));
5180 this.register(this.addDisposableListener('dprchange', function () { return _this.renderer.onWindowResize(window.devicePixelRatio); }));
5181 this.register(Lifecycle_1.addDisposableDomListener(window, 'resize', function () { return _this.renderer.onWindowResize(window.devicePixelRatio); }));
5182 this.register(this.charMeasure.onCharSizeChanged(function () { return _this.renderer.onCharSizeChanged(); }));
5183 this.register(this.renderer.onCanvasResize(function () { return _this.viewport.syncScrollArea(); }));
5184 this.selectionManager = new SelectionManager_1.SelectionManager(this, this.charMeasure);
5185 this.register(this.selectionManager.onSelectionChange(function () { return _this._onSelectionChange.fire(); }));
5186 this.register(Lifecycle_1.addDisposableDomListener(this.element, 'mousedown', function (e) { return _this.selectionManager.onMouseDown(e); }));
5187 this.register(this.selectionManager.onRedrawRequest(function (e) { return _this.renderer.onSelectionChanged(e.start, e.end, e.columnSelectMode); }));
5188 this.register(this.selectionManager.onLinuxMouseSelection(function (text) {
5189 _this.textarea.value = text;
5190 _this.textarea.focus();
5191 _this.textarea.select();
5192 }));
5193 this.register(this.onScroll(function () {
5194 _this.viewport.syncScrollArea();
5195 _this.selectionManager.refresh();
5196 }));
5197 this.register(Lifecycle_1.addDisposableDomListener(this._viewportElement, 'scroll', function () { return _this.selectionManager.refresh(); }));
5198 this.mouseHelper = new MouseHelper_1.MouseHelper(this.renderer);
5199 this.element.classList.toggle('enable-mouse-events', this.mouseEvents);
5200 if (this.mouseEvents) {
5201 this.selectionManager.disable();
5202 }
5203 else {
5204 this.selectionManager.enable();
5205 }
5206 if (this.options.screenReaderMode) {
5207 this._accessibilityManager = new AccessibilityManager_1.AccessibilityManager(this);
5208 }
5209 this.charMeasure.measure(this.options);
5210 this.refresh(0, this.rows - 1);
5211 this._initGlobal();
5212 this.bindMouse();
5213 };
5214 Terminal.prototype._setupRenderer = function () {
5215 var _this = this;
5216 switch (this.options.rendererType) {
5217 case 'canvas':
5218 this.renderer = new Renderer_1.Renderer(this, this.options.theme);
5219 break;
5220 case 'dom':
5221 this.renderer = new DomRenderer_1.DomRenderer(this, this.options.theme);
5222 break;
5223 default: throw new Error("Unrecognized rendererType \"" + this.options.rendererType + "\"");
5224 }
5225 this.renderer.onRender(function (e) { return _this._onRender.fire(e); });
5226 this.register(this.renderer);
5227 };
5228 Terminal.prototype._setTheme = function (theme) {
5229 this._theme = theme;
5230 var colors = this.renderer.setTheme(theme);
5231 if (this.viewport) {
5232 this.viewport.onThemeChanged(colors);
5233 }
5234 };
5235 Terminal.prototype.bindMouse = function () {
5236 var _this = this;
5237 var el = this.element;
5238 var self = this;
5239 var pressed = 32;
5240 function sendButton(ev) {
5241 var button;
5242 var pos;
5243 button = getButton(ev);
5244 pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.cols, self.rows);
5245 if (!pos)
5246 return;
5247 sendEvent(button, pos);
5248 switch (ev.overrideType || ev.type) {
5249 case 'mousedown':
5250 pressed = button;
5251 break;
5252 case 'mouseup':
5253 pressed = 32;
5254 break;
5255 case 'wheel':
5256 break;
5257 }
5258 }
5259 function sendMove(ev) {
5260 var button = pressed;
5261 var pos = self.mouseHelper.getRawByteCoords(ev, self.screenElement, self.charMeasure, self.cols, self.rows);
5262 if (!pos)
5263 return;
5264 button += 32;
5265 sendEvent(button, pos);
5266 }
5267 function encode(data, ch) {
5268 if (!self.utfMouse) {
5269 if (ch === 255) {
5270 data.push(0);
5271 return;
5272 }
5273 if (ch > 127)
5274 ch = 127;
5275 data.push(ch);
5276 }
5277 else {
5278 if (ch > 2047) {
5279 data.push(2047);
5280 return;
5281 }
5282 data.push(ch);
5283 }
5284 }
5285 function sendEvent(button, pos) {
5286 if (self._vt300Mouse) {
5287 button &= 3;
5288 pos.x -= 32;
5289 pos.y -= 32;
5290 var data_1 = EscapeSequences_1.C0.ESC + '[24';
5291 if (button === 0)
5292 data_1 += '1';
5293 else if (button === 1)
5294 data_1 += '3';
5295 else if (button === 2)
5296 data_1 += '5';
5297 else if (button === 3)
5298 return;
5299 else
5300 data_1 += '0';
5301 data_1 += '~[' + pos.x + ',' + pos.y + ']\r';
5302 self.handler(data_1);
5303 return;
5304 }
5305 if (self._decLocator) {
5306 button &= 3;
5307 pos.x -= 32;
5308 pos.y -= 32;
5309 if (button === 0)
5310 button = 2;
5311 else if (button === 1)
5312 button = 4;
5313 else if (button === 2)
5314 button = 6;
5315 else if (button === 3)
5316 button = 3;
5317 self.handler(EscapeSequences_1.C0.ESC + '['
5318 + button
5319 + ';'
5320 + (button === 3 ? 4 : 0)
5321 + ';'
5322 + pos.y
5323 + ';'
5324 + pos.x
5325 + ';'
5326 + pos.page || 0
5327 + '&w');
5328 return;
5329 }
5330 if (self.urxvtMouse) {
5331 pos.x -= 32;
5332 pos.y -= 32;
5333 pos.x++;
5334 pos.y++;
5335 self.handler(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
5336 return;
5337 }
5338 if (self.sgrMouse) {
5339 pos.x -= 32;
5340 pos.y -= 32;
5341 self.handler(EscapeSequences_1.C0.ESC + '[<'
5342 + (((button & 3) === 3 ? button & ~3 : button) - 32)
5343 + ';'
5344 + pos.x
5345 + ';'
5346 + pos.y
5347 + ((button & 3) === 3 ? 'm' : 'M'));
5348 return;
5349 }
5350 var data = [];
5351 encode(data, button);
5352 encode(data, pos.x);
5353 encode(data, pos.y);
5354 self.handler(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
5355 }
5356 function getButton(ev) {
5357 var button;
5358 var shift;
5359 var meta;
5360 var ctrl;
5361 var mod;
5362 switch (ev.overrideType || ev.type) {
5363 case 'mousedown':
5364 button = ev.button !== null && ev.button !== undefined
5365 ? +ev.button
5366 : ev.which !== null && ev.which !== undefined
5367 ? ev.which - 1
5368 : null;
5369 if (Browser.isMSIE) {
5370 button = button === 1 ? 0 : button === 4 ? 1 : button;
5371 }
5372 break;
5373 case 'mouseup':
5374 button = 3;
5375 break;
5376 case 'DOMMouseScroll':
5377 button = ev.detail < 0
5378 ? 64
5379 : 65;
5380 break;
5381 case 'wheel':
5382 button = ev.deltaY < 0
5383 ? 64
5384 : 65;
5385 break;
5386 }
5387 shift = ev.shiftKey ? 4 : 0;
5388 meta = ev.metaKey ? 8 : 0;
5389 ctrl = ev.ctrlKey ? 16 : 0;
5390 mod = shift | meta | ctrl;
5391 if (self.vt200Mouse) {
5392 mod &= ctrl;
5393 }
5394 else if (!self.normalMouse) {
5395 mod = 0;
5396 }
5397 button = (32 + (mod << 2)) + button;
5398 return button;
5399 }
5400 this.register(Lifecycle_1.addDisposableDomListener(el, 'mousedown', function (ev) {
5401 ev.preventDefault();
5402 _this.focus();
5403 if (!_this.mouseEvents || _this.selectionManager.shouldForceSelection(ev)) {
5404 return;
5405 }
5406 sendButton(ev);
5407 if (_this.vt200Mouse) {
5408 ev.overrideType = 'mouseup';
5409 sendButton(ev);
5410 return _this.cancel(ev);
5411 }
5412 var moveHandler;
5413 if (_this.normalMouse) {
5414 moveHandler = function (event) {
5415 if (!_this.normalMouse) {
5416 return;
5417 }
5418 sendMove(event);
5419 };
5420 _this._document.addEventListener('mousemove', moveHandler);
5421 }
5422 var handler = function (ev) {
5423 if (_this.normalMouse && !_this.x10Mouse) {
5424 sendButton(ev);
5425 }
5426 if (moveHandler) {
5427 _this._document.removeEventListener('mousemove', moveHandler);
5428 moveHandler = null;
5429 }
5430 _this._document.removeEventListener('mouseup', handler);
5431 return _this.cancel(ev);
5432 };
5433 _this._document.addEventListener('mouseup', handler);
5434 return _this.cancel(ev);
5435 }));
5436 this.register(Lifecycle_1.addDisposableDomListener(el, 'wheel', function (ev) {
5437 if (!_this.mouseEvents) {
5438 if (!_this.buffer.hasScrollback) {
5439 var amount = _this.viewport.getLinesScrolled(ev);
5440 if (amount === 0) {
5441 return;
5442 }
5443 var sequence = EscapeSequences_1.C0.ESC + (_this.applicationCursor ? 'O' : '[') + (ev.deltaY < 0 ? 'A' : 'B');
5444 var data = '';
5445 for (var i = 0; i < Math.abs(amount); i++) {
5446 data += sequence;
5447 }
5448 _this.handler(data);
5449 }
5450 return;
5451 }
5452 if (_this.x10Mouse || _this._vt300Mouse || _this._decLocator)
5453 return;
5454 sendButton(ev);
5455 ev.preventDefault();
5456 }));
5457 this.register(Lifecycle_1.addDisposableDomListener(el, 'wheel', function (ev) {
5458 if (_this.mouseEvents)
5459 return;
5460 _this.viewport.onWheel(ev);
5461 return _this.cancel(ev);
5462 }));
5463 this.register(Lifecycle_1.addDisposableDomListener(el, 'touchstart', function (ev) {
5464 if (_this.mouseEvents)
5465 return;
5466 _this.viewport.onTouchStart(ev);
5467 return _this.cancel(ev);
5468 }));
5469 this.register(Lifecycle_1.addDisposableDomListener(el, 'touchmove', function (ev) {
5470 if (_this.mouseEvents)
5471 return;
5472 _this.viewport.onTouchMove(ev);
5473 return _this.cancel(ev);
5474 }));
5475 };
5476 Terminal.prototype.refresh = function (start, end) {
5477 if (this.renderer) {
5478 this.renderer.refreshRows(start, end);
5479 }
5480 };
5481 Terminal.prototype._queueLinkification = function (start, end) {
5482 if (this.linkifier) {
5483 this.linkifier.linkifyRows(start, end);
5484 }
5485 };
5486 Terminal.prototype.updateCursorStyle = function (ev) {
5487 if (this.selectionManager && this.selectionManager.shouldColumnSelect(ev)) {
5488 this.element.classList.add('column-select');
5489 }
5490 else {
5491 this.element.classList.remove('column-select');
5492 }
5493 };
5494 Terminal.prototype.showCursor = function () {
5495 if (!this.cursorState) {
5496 this.cursorState = 1;
5497 this.refresh(this.buffer.y, this.buffer.y);
5498 }
5499 };
5500 Terminal.prototype.scroll = function (isWrapped) {
5501 if (isWrapped === void 0) { isWrapped = false; }
5502 var newLine;
5503 newLine = this._blankLine;
5504 var eraseAttr = this.eraseAttrData();
5505 if (!newLine || newLine.length !== this.cols || newLine.getFg(0) !== eraseAttr.fg || newLine.getBg(0) !== eraseAttr.bg) {
5506 newLine = this.buffer.getBlankLine(eraseAttr, isWrapped);
5507 this._blankLine = newLine;
5508 }
5509 newLine.isWrapped = isWrapped;
5510 var topRow = this.buffer.ybase + this.buffer.scrollTop;
5511 var bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
5512 if (this.buffer.scrollTop === 0) {
5513 var willBufferBeTrimmed = this.buffer.lines.isFull;
5514 if (bottomRow === this.buffer.lines.length - 1) {
5515 if (willBufferBeTrimmed) {
5516 this.buffer.lines.recycle().copyFrom(newLine);
5517 }
5518 else {
5519 this.buffer.lines.push(newLine.clone());
5520 }
5521 }
5522 else {
5523 this.buffer.lines.splice(bottomRow + 1, 0, newLine.clone());
5524 }
5525 if (!willBufferBeTrimmed) {
5526 this.buffer.ybase++;
5527 if (!this._userScrolling) {
5528 this.buffer.ydisp++;
5529 }
5530 }
5531 else {
5532 if (this._userScrolling) {
5533 this.buffer.ydisp = Math.max(this.buffer.ydisp - 1, 0);
5534 }
5535 }
5536 }
5537 else {
5538 var scrollRegionHeight = bottomRow - topRow + 1;
5539 this.buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
5540 this.buffer.lines.set(bottomRow, newLine.clone());
5541 }
5542 if (!this._userScrolling) {
5543 this.buffer.ydisp = this.buffer.ybase;
5544 }
5545 this.updateRange(this.buffer.scrollTop);
5546 this.updateRange(this.buffer.scrollBottom);
5547 this._onScroll.fire(this.buffer.ydisp);
5548 };
5549 Terminal.prototype.scrollLines = function (disp, suppressScrollEvent) {
5550 if (disp < 0) {
5551 if (this.buffer.ydisp === 0) {
5552 return;
5553 }
5554 this._userScrolling = true;
5555 }
5556 else if (disp + this.buffer.ydisp >= this.buffer.ybase) {
5557 this._userScrolling = false;
5558 }
5559 var oldYdisp = this.buffer.ydisp;
5560 this.buffer.ydisp = Math.max(Math.min(this.buffer.ydisp + disp, this.buffer.ybase), 0);
5561 if (oldYdisp === this.buffer.ydisp) {
5562 return;
5563 }
5564 if (!suppressScrollEvent) {
5565 this._onScroll.fire(this.buffer.ydisp);
5566 }
5567 this.refresh(0, this.rows - 1);
5568 };
5569 Terminal.prototype.scrollPages = function (pageCount) {
5570 this.scrollLines(pageCount * (this.rows - 1));
5571 };
5572 Terminal.prototype.scrollToTop = function () {
5573 this.scrollLines(-this.buffer.ydisp);
5574 };
5575 Terminal.prototype.scrollToBottom = function () {
5576 this.scrollLines(this.buffer.ybase - this.buffer.ydisp);
5577 };
5578 Terminal.prototype.scrollToLine = function (line) {
5579 var scrollAmount = line - this.buffer.ydisp;
5580 if (scrollAmount !== 0) {
5581 this.scrollLines(scrollAmount);
5582 }
5583 };
5584 Terminal.prototype.write = function (data) {
5585 var _this = this;
5586 if (this._isDisposed) {
5587 return;
5588 }
5589 if (!data) {
5590 return;
5591 }
5592 this.writeBuffer.push(data);
5593 if (this.options.useFlowControl && !this._xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
5594 this.handler(EscapeSequences_1.C0.DC3);
5595 this._xoffSentToCatchUp = true;
5596 }
5597 if (!this._writeInProgress && this.writeBuffer.length > 0) {
5598 this._writeInProgress = true;
5599 setTimeout(function () {
5600 _this._innerWrite();
5601 });
5602 }
5603 };
5604 Terminal.prototype._innerWrite = function (bufferOffset) {
5605 var _this = this;
5606 if (bufferOffset === void 0) { bufferOffset = 0; }
5607 if (this._isDisposed) {
5608 this.writeBuffer = [];
5609 }
5610 var startTime = Date.now();
5611 while (this.writeBuffer.length > bufferOffset) {
5612 var data = this.writeBuffer[bufferOffset];
5613 bufferOffset++;
5614 if (this._xoffSentToCatchUp && this.writeBuffer.length === bufferOffset) {
5615 this.handler(EscapeSequences_1.C0.DC1);
5616 this._xoffSentToCatchUp = false;
5617 }
5618 this._refreshStart = this.buffer.y;
5619 this._refreshEnd = this.buffer.y;
5620 this._inputHandler.parse(data);
5621 this.updateRange(this.buffer.y);
5622 this.refresh(this._refreshStart, this._refreshEnd);
5623 if (Date.now() - startTime >= WRITE_TIMEOUT_MS) {
5624 break;
5625 }
5626 }
5627 if (this.writeBuffer.length > bufferOffset) {
5628 setTimeout(function () { return _this._innerWrite(bufferOffset); }, 0);
5629 }
5630 else {
5631 this._writeInProgress = false;
5632 this.writeBuffer = [];
5633 }
5634 };
5635 Terminal.prototype.writeln = function (data) {
5636 this.write(data + '\r\n');
5637 };
5638 Terminal.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler) {
5639 this._customKeyEventHandler = customKeyEventHandler;
5640 };
5641 Terminal.prototype.addCsiHandler = function (flag, callback) {
5642 return this._inputHandler.addCsiHandler(flag, callback);
5643 };
5644 Terminal.prototype.addOscHandler = function (ident, callback) {
5645 return this._inputHandler.addOscHandler(ident, callback);
5646 };
5647 Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
5648 var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
5649 this.refresh(0, this.rows - 1);
5650 return matcherId;
5651 };
5652 Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
5653 if (this.linkifier.deregisterLinkMatcher(matcherId)) {
5654 this.refresh(0, this.rows - 1);
5655 }
5656 };
5657 Terminal.prototype.registerCharacterJoiner = function (handler) {
5658 var joinerId = this.renderer.registerCharacterJoiner(handler);
5659 this.refresh(0, this.rows - 1);
5660 return joinerId;
5661 };
5662 Terminal.prototype.deregisterCharacterJoiner = function (joinerId) {
5663 if (this.renderer.deregisterCharacterJoiner(joinerId)) {
5664 this.refresh(0, this.rows - 1);
5665 }
5666 };
5667 Object.defineProperty(Terminal.prototype, "markers", {
5668 get: function () {
5669 return this.buffer.markers;
5670 },
5671 enumerable: true,
5672 configurable: true
5673 });
5674 Terminal.prototype.addMarker = function (cursorYOffset) {
5675 if (this.buffer !== this.buffers.normal) {
5676 return;
5677 }
5678 return this.buffer.addMarker(this.buffer.ybase + this.buffer.y + cursorYOffset);
5679 };
5680 Terminal.prototype.hasSelection = function () {
5681 return this.selectionManager ? this.selectionManager.hasSelection : false;
5682 };
5683 Terminal.prototype.getSelection = function () {
5684 return this.selectionManager ? this.selectionManager.selectionText : '';
5685 };
5686 Terminal.prototype.clearSelection = function () {
5687 if (this.selectionManager) {
5688 this.selectionManager.clearSelection();
5689 }
5690 };
5691 Terminal.prototype.selectAll = function () {
5692 if (this.selectionManager) {
5693 this.selectionManager.selectAll();
5694 }
5695 };
5696 Terminal.prototype.selectLines = function (start, end) {
5697 if (this.selectionManager) {
5698 this.selectionManager.selectLines(start, end);
5699 }
5700 };
5701 Terminal.prototype._keyDown = function (event) {
5702 if (this._customKeyEventHandler && this._customKeyEventHandler(event) === false) {
5703 return false;
5704 }
5705 if (!this._compositionHelper.keydown(event)) {
5706 if (this.buffer.ybase !== this.buffer.ydisp) {
5707 this.scrollToBottom();
5708 }
5709 return false;
5710 }
5711 var result = Keyboard_1.evaluateKeyboardEvent(event, this.applicationCursor, this.browser.isMac, this.options.macOptionIsMeta);
5712 this.updateCursorStyle(event);
5713 if (result.type === 3 || result.type === 2) {
5714 var scrollCount = this.rows - 1;
5715 this.scrollLines(result.type === 2 ? -scrollCount : scrollCount);
5716 return this.cancel(event, true);
5717 }
5718 if (result.type === 1) {
5719 this.selectAll();
5720 }
5721 if (this._isThirdLevelShift(this.browser, event)) {
5722 return true;
5723 }
5724 if (result.cancel) {
5725 this.cancel(event, true);
5726 }
5727 if (!result.key) {
5728 return true;
5729 }
5730 this.emit('keydown', event);
5731 this._onKey.fire({ key: result.key, domEvent: event });
5732 this.showCursor();
5733 this.handler(result.key);
5734 return this.cancel(event, true);
5735 };
5736 Terminal.prototype._isThirdLevelShift = function (browser, ev) {
5737 var thirdLevelKey = (browser.isMac && !this.options.macOptionIsMeta && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
5738 (browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
5739 if (ev.type === 'keypress') {
5740 return thirdLevelKey;
5741 }
5742 return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
5743 };
5744 Terminal.prototype.setgLevel = function (g) {
5745 this.glevel = g;
5746 this.charset = this.charsets[g];
5747 };
5748 Terminal.prototype.setgCharset = function (g, charset) {
5749 this.charsets[g] = charset;
5750 if (this.glevel === g) {
5751 this.charset = charset;
5752 }
5753 };
5754 Terminal.prototype._keyUp = function (ev) {
5755 this.updateCursorStyle(ev);
5756 };
5757 Terminal.prototype._keyPress = function (ev) {
5758 var key;
5759 if (this._customKeyEventHandler && this._customKeyEventHandler(ev) === false) {
5760 return false;
5761 }
5762 this.cancel(ev);
5763 if (ev.charCode) {
5764 key = ev.charCode;
5765 }
5766 else if (ev.which === null || ev.which === undefined) {
5767 key = ev.keyCode;
5768 }
5769 else if (ev.which !== 0 && ev.charCode !== 0) {
5770 key = ev.which;
5771 }
5772 else {
5773 return false;
5774 }
5775 if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !this._isThirdLevelShift(this.browser, ev))) {
5776 return false;
5777 }
5778 key = String.fromCharCode(key);
5779 this.emit('keypress', key, ev);
5780 this._onKey.fire({ key: key, domEvent: ev });
5781 this.showCursor();
5782 this.handler(key);
5783 return true;
5784 };
5785 Terminal.prototype.bell = function () {
5786 var _this = this;
5787 this.emit('bell');
5788 if (this._soundBell()) {
5789 this.soundManager.playBellSound();
5790 }
5791 if (this._visualBell()) {
5792 this.element.classList.add('visual-bell-active');
5793 clearTimeout(this._visualBellTimer);
5794 this._visualBellTimer = window.setTimeout(function () {
5795 _this.element.classList.remove('visual-bell-active');
5796 }, 200);
5797 }
5798 };
5799 Terminal.prototype.log = function (text, data) {
5800 if (!this.options.debug)
5801 return;
5802 if (!this._context.console || !this._context.console.log)
5803 return;
5804 this._context.console.log(text, data);
5805 };
5806 Terminal.prototype.error = function (text, data) {
5807 if (!this.options.debug)
5808 return;
5809 if (!this._context.console || !this._context.console.error)
5810 return;
5811 this._context.console.error(text, data);
5812 };
5813 Terminal.prototype.resize = function (x, y) {
5814 if (isNaN(x) || isNaN(y)) {
5815 return;
5816 }
5817 if (x === this.cols && y === this.rows) {
5818 if (this.charMeasure && (!this.charMeasure.width || !this.charMeasure.height)) {
5819 this.charMeasure.measure(this.options);
5820 }
5821 return;
5822 }
5823 if (x < MINIMUM_COLS)
5824 x = MINIMUM_COLS;
5825 if (y < MINIMUM_ROWS)
5826 y = MINIMUM_ROWS;
5827 this.buffers.resize(x, y);
5828 this.cols = x;
5829 this.rows = y;
5830 this.buffers.setupTabStops(this.cols);
5831 if (this.charMeasure) {
5832 this.charMeasure.measure(this.options);
5833 }
5834 this.refresh(0, this.rows - 1);
5835 this._onResize.fire({ cols: x, rows: y });
5836 };
5837 Terminal.prototype.updateRange = function (y) {
5838 if (y < this._refreshStart)
5839 this._refreshStart = y;
5840 if (y > this._refreshEnd)
5841 this._refreshEnd = y;
5842 };
5843 Terminal.prototype.maxRange = function () {
5844 this._refreshStart = 0;
5845 this._refreshEnd = this.rows - 1;
5846 };
5847 Terminal.prototype.clear = function () {
5848 if (this.buffer.ybase === 0 && this.buffer.y === 0) {
5849 return;
5850 }
5851 this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y));
5852 this.buffer.lines.length = 1;
5853 this.buffer.ydisp = 0;
5854 this.buffer.ybase = 0;
5855 this.buffer.y = 0;
5856 for (var i = 1; i < this.rows; i++) {
5857 this.buffer.lines.push(this.buffer.getBlankLine(Buffer_1.DEFAULT_ATTR_DATA));
5858 }
5859 this.refresh(0, this.rows - 1);
5860 this._onScroll.fire(this.buffer.ydisp);
5861 };
5862 Terminal.prototype.is = function (term) {
5863 return (this.options.termName + '').indexOf(term) === 0;
5864 };
5865 Terminal.prototype.handler = function (data) {
5866 if (this.options.disableStdin) {
5867 return;
5868 }
5869 if (this.selectionManager && this.selectionManager.hasSelection) {
5870 this.selectionManager.clearSelection();
5871 }
5872 if (this.buffer.ybase !== this.buffer.ydisp) {
5873 this.scrollToBottom();
5874 }
5875 this._onData.fire(data);
5876 };
5877 Terminal.prototype.handleTitle = function (title) {
5878 this._onTitleChange.fire(title);
5879 };
5880 Terminal.prototype.index = function () {
5881 this.buffer.y++;
5882 if (this.buffer.y > this.buffer.scrollBottom) {
5883 this.buffer.y--;
5884 this.scroll();
5885 }
5886 if (this.buffer.x >= this.cols) {
5887 this.buffer.x--;
5888 }
5889 };
5890 Terminal.prototype.reverseIndex = function () {
5891 if (this.buffer.y === this.buffer.scrollTop) {
5892 var scrollRegionHeight = this.buffer.scrollBottom - this.buffer.scrollTop;
5893 this.buffer.lines.shiftElements(this.buffer.y + this.buffer.ybase, scrollRegionHeight, 1);
5894 this.buffer.lines.set(this.buffer.y + this.buffer.ybase, this.buffer.getBlankLine(this.eraseAttrData()));
5895 this.updateRange(this.buffer.scrollTop);
5896 this.updateRange(this.buffer.scrollBottom);
5897 }
5898 else {
5899 this.buffer.y--;
5900 }
5901 };
5902 Terminal.prototype.reset = function () {
5903 this.options.rows = this.rows;
5904 this.options.cols = this.cols;
5905 var customKeyEventHandler = this._customKeyEventHandler;
5906 var inputHandler = this._inputHandler;
5907 var cursorState = this.cursorState;
5908 this._setup();
5909 this._customKeyEventHandler = customKeyEventHandler;
5910 this._inputHandler = inputHandler;
5911 this.cursorState = cursorState;
5912 this.refresh(0, this.rows - 1);
5913 if (this.viewport) {
5914 this.viewport.syncScrollArea();
5915 }
5916 };
5917 Terminal.prototype.tabSet = function () {
5918 this.buffer.tabs[this.buffer.x] = true;
5919 };
5920 Terminal.prototype.cancel = function (ev, force) {
5921 if (!this.options.cancelEvents && !force) {
5922 return;
5923 }
5924 ev.preventDefault();
5925 ev.stopPropagation();
5926 return false;
5927 };
5928 Terminal.prototype._visualBell = function () {
5929 return false;
5930 };
5931 Terminal.prototype._soundBell = function () {
5932 return this.options.bellStyle === 'sound';
5933 };
5934 return Terminal;
5935 }(EventEmitter_1.EventEmitter));
5936 exports.Terminal = Terminal;
5937 function wasModifierKeyOnlyEvent(ev) {
5938 return ev.keyCode === 16 ||
5939 ev.keyCode === 17 ||
5940 ev.keyCode === 18;
5941 }
5942
5943 },{"./AccessibilityManager":1,"./Buffer":2,"./BufferSet":5,"./CharMeasure":6,"./Clipboard":8,"./CompositionHelper":9,"./InputHandler":11,"./Linkifier":12,"./MouseHelper":13,"./MouseZoneManager":14,"./SelectionManager":15,"./SoundManager":17,"./Strings":18,"./Viewport":20,"./WindowsMode":21,"./common/Clone":23,"./common/EventEmitter":24,"./common/EventEmitter2":25,"./common/Platform":27,"./common/data/EscapeSequences":29,"./core/input/Keyboard":31,"./renderer/Renderer":41,"./renderer/atlas/CharAtlasCache":45,"./renderer/dom/DomRenderer":53,"./ui/Lifecycle":55,"./ui/ScreenDprMonitor":57}],20:[function(require,module,exports){
5944 "use strict";
5945 var __extends = (this && this.__extends) || (function () {
5946 var extendStatics = function (d, b) {
5947 extendStatics = Object.setPrototypeOf ||
5948 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5949 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5950 return extendStatics(d, b);
5951 };
5952 return function (d, b) {
5953 extendStatics(d, b);
5954 function __() { this.constructor = d; }
5955 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5956 };
5957 })();
5958 Object.defineProperty(exports, "__esModule", { value: true });
5959 var Lifecycle_1 = require("./common/Lifecycle");
5960 var Lifecycle_2 = require("./ui/Lifecycle");
5961 var FALLBACK_SCROLL_BAR_WIDTH = 15;
5962 var Viewport = (function (_super) {
5963 __extends(Viewport, _super);
5964 function Viewport(_terminal, _viewportElement, _scrollArea, _charMeasure) {
5965 var _this = _super.call(this) || this;
5966 _this._terminal = _terminal;
5967 _this._viewportElement = _viewportElement;
5968 _this._scrollArea = _scrollArea;
5969 _this._charMeasure = _charMeasure;
5970 _this.scrollBarWidth = 0;
5971 _this._currentRowHeight = 0;
5972 _this._lastRecordedBufferLength = 0;
5973 _this._lastRecordedViewportHeight = 0;
5974 _this._lastRecordedBufferHeight = 0;
5975 _this._lastScrollTop = 0;
5976 _this._wheelPartialScroll = 0;
5977 _this._refreshAnimationFrame = null;
5978 _this._ignoreNextScrollEvent = false;
5979 _this.scrollBarWidth = (_this._viewportElement.offsetWidth - _this._scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH;
5980 _this.register(Lifecycle_2.addDisposableDomListener(_this._viewportElement, 'scroll', _this._onScroll.bind(_this)));
5981 setTimeout(function () { return _this.syncScrollArea(); }, 0);
5982 return _this;
5983 }
5984 Viewport.prototype.onThemeChanged = function (colors) {
5985 this._viewportElement.style.backgroundColor = colors.background.css;
5986 };
5987 Viewport.prototype._refresh = function () {
5988 var _this = this;
5989 if (this._refreshAnimationFrame === null) {
5990 this._refreshAnimationFrame = requestAnimationFrame(function () { return _this._innerRefresh(); });
5991 }
5992 };
5993 Viewport.prototype._innerRefresh = function () {
5994 if (this._charMeasure.height > 0) {
5995 this._currentRowHeight = this._terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio;
5996 this._lastRecordedViewportHeight = this._viewportElement.offsetHeight;
5997 var newBufferHeight = Math.round(this._currentRowHeight * this._lastRecordedBufferLength) + (this._lastRecordedViewportHeight - this._terminal.renderer.dimensions.canvasHeight);
5998 if (this._lastRecordedBufferHeight !== newBufferHeight) {
5999 this._lastRecordedBufferHeight = newBufferHeight;
6000 this._scrollArea.style.height = this._lastRecordedBufferHeight + 'px';
6001 }
6002 }
6003 var scrollTop = this._terminal.buffer.ydisp * this._currentRowHeight;
6004 if (this._viewportElement.scrollTop !== scrollTop) {
6005 this._ignoreNextScrollEvent = true;
6006 this._viewportElement.scrollTop = scrollTop;
6007 }
6008 this._refreshAnimationFrame = null;
6009 };
6010 Viewport.prototype.syncScrollArea = function () {
6011 if (this._lastRecordedBufferLength !== this._terminal.buffer.lines.length) {
6012 this._lastRecordedBufferLength = this._terminal.buffer.lines.length;
6013 this._refresh();
6014 return;
6015 }
6016 if (this._lastRecordedViewportHeight !== this._terminal.renderer.dimensions.canvasHeight) {
6017 this._refresh();
6018 return;
6019 }
6020 var newScrollTop = this._terminal.buffer.ydisp * this._currentRowHeight;
6021 if (this._lastScrollTop !== newScrollTop) {
6022 this._refresh();
6023 return;
6024 }
6025 if (this._lastScrollTop !== this._viewportElement.scrollTop) {
6026 this._refresh();
6027 return;
6028 }
6029 if (this._terminal.renderer.dimensions.scaledCellHeight / window.devicePixelRatio !== this._currentRowHeight) {
6030 this._refresh();
6031 return;
6032 }
6033 };
6034 Viewport.prototype._onScroll = function (ev) {
6035 this._lastScrollTop = this._viewportElement.scrollTop;
6036 if (!this._viewportElement.offsetParent) {
6037 return;
6038 }
6039 if (this._ignoreNextScrollEvent) {
6040 this._ignoreNextScrollEvent = false;
6041 return;
6042 }
6043 var newRow = Math.round(this._lastScrollTop / this._currentRowHeight);
6044 var diff = newRow - this._terminal.buffer.ydisp;
6045 this._terminal.scrollLines(diff, true);
6046 };
6047 Viewport.prototype.onWheel = function (ev) {
6048 var amount = this._getPixelsScrolled(ev);
6049 if (amount === 0) {
6050 return;
6051 }
6052 this._viewportElement.scrollTop += amount;
6053 ev.preventDefault();
6054 };
6055 Viewport.prototype._getPixelsScrolled = function (ev) {
6056 if (ev.deltaY === 0) {
6057 return 0;
6058 }
6059 var amount = ev.deltaY;
6060 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
6061 amount *= this._currentRowHeight;
6062 }
6063 else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
6064 amount *= this._currentRowHeight * this._terminal.rows;
6065 }
6066 return amount;
6067 };
6068 Viewport.prototype.getLinesScrolled = function (ev) {
6069 if (ev.deltaY === 0) {
6070 return 0;
6071 }
6072 var amount = ev.deltaY;
6073 if (ev.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
6074 amount /= this._currentRowHeight + 0.0;
6075 this._wheelPartialScroll += amount;
6076 amount = Math.floor(Math.abs(this._wheelPartialScroll)) * (this._wheelPartialScroll > 0 ? 1 : -1);
6077 this._wheelPartialScroll %= 1;
6078 }
6079 else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
6080 amount *= this._terminal.rows;
6081 }
6082 return amount;
6083 };
6084 Viewport.prototype.onTouchStart = function (ev) {
6085 this._lastTouchY = ev.touches[0].pageY;
6086 };
6087 Viewport.prototype.onTouchMove = function (ev) {
6088 var deltaY = this._lastTouchY - ev.touches[0].pageY;
6089 this._lastTouchY = ev.touches[0].pageY;
6090 if (deltaY === 0) {
6091 return;
6092 }
6093 this._viewportElement.scrollTop += deltaY;
6094 ev.preventDefault();
6095 };
6096 return Viewport;
6097 }(Lifecycle_1.Disposable));
6098 exports.Viewport = Viewport;
6099
6100 },{"./common/Lifecycle":26,"./ui/Lifecycle":55}],21:[function(require,module,exports){
6101 "use strict";
6102 Object.defineProperty(exports, "__esModule", { value: true });
6103 var Buffer_1 = require("./Buffer");
6104 function applyWindowsMode(terminal) {
6105 return terminal.onLineFeed(function () {
6106 var line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1);
6107 var lastChar = line.get(terminal.cols - 1);
6108 if (lastChar[Buffer_1.CHAR_DATA_CODE_INDEX] !== Buffer_1.NULL_CELL_CODE && lastChar[Buffer_1.CHAR_DATA_CODE_INDEX] !== Buffer_1.WHITESPACE_CELL_CODE) {
6109 var nextLine = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y);
6110 nextLine.isWrapped = true;
6111 }
6112 });
6113 }
6114 exports.applyWindowsMode = applyWindowsMode;
6115
6116 },{"./Buffer":2}],22:[function(require,module,exports){
6117 "use strict";
6118 Object.defineProperty(exports, "__esModule", { value: true });
6119 var EventEmitter2_1 = require("./EventEmitter2");
6120 var CircularList = (function () {
6121 function CircularList(_maxLength) {
6122 this._maxLength = _maxLength;
6123 this.onDeleteEmitter = new EventEmitter2_1.EventEmitter2();
6124 this.onInsertEmitter = new EventEmitter2_1.EventEmitter2();
6125 this.onTrimEmitter = new EventEmitter2_1.EventEmitter2();
6126 this._array = new Array(this._maxLength);
6127 this._startIndex = 0;
6128 this._length = 0;
6129 }
6130 Object.defineProperty(CircularList.prototype, "onDelete", {
6131 get: function () { return this.onDeleteEmitter.event; },
6132 enumerable: true,
6133 configurable: true
6134 });
6135 Object.defineProperty(CircularList.prototype, "onInsert", {
6136 get: function () { return this.onInsertEmitter.event; },
6137 enumerable: true,
6138 configurable: true
6139 });
6140 Object.defineProperty(CircularList.prototype, "onTrim", {
6141 get: function () { return this.onTrimEmitter.event; },
6142 enumerable: true,
6143 configurable: true
6144 });
6145 Object.defineProperty(CircularList.prototype, "maxLength", {
6146 get: function () {
6147 return this._maxLength;
6148 },
6149 set: function (newMaxLength) {
6150 if (this._maxLength === newMaxLength) {
6151 return;
6152 }
6153 var newArray = new Array(newMaxLength);
6154 for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
6155 newArray[i] = this._array[this._getCyclicIndex(i)];
6156 }
6157 this._array = newArray;
6158 this._maxLength = newMaxLength;
6159 this._startIndex = 0;
6160 },
6161 enumerable: true,
6162 configurable: true
6163 });
6164 Object.defineProperty(CircularList.prototype, "length", {
6165 get: function () {
6166 return this._length;
6167 },
6168 set: function (newLength) {
6169 if (newLength > this._length) {
6170 for (var i = this._length; i < newLength; i++) {
6171 this._array[i] = undefined;
6172 }
6173 }
6174 this._length = newLength;
6175 },
6176 enumerable: true,
6177 configurable: true
6178 });
6179 CircularList.prototype.get = function (index) {
6180 return this._array[this._getCyclicIndex(index)];
6181 };
6182 CircularList.prototype.set = function (index, value) {
6183 this._array[this._getCyclicIndex(index)] = value;
6184 };
6185 CircularList.prototype.push = function (value) {
6186 this._array[this._getCyclicIndex(this._length)] = value;
6187 if (this._length === this._maxLength) {
6188 this._startIndex = ++this._startIndex % this._maxLength;
6189 this.onTrimEmitter.fire(1);
6190 }
6191 else {
6192 this._length++;
6193 }
6194 };
6195 CircularList.prototype.recycle = function () {
6196 if (this._length !== this._maxLength) {
6197 throw new Error('Can only recycle when the buffer is full');
6198 }
6199 this._startIndex = ++this._startIndex % this._maxLength;
6200 this.onTrimEmitter.fire(1);
6201 return this._array[this._getCyclicIndex(this._length - 1)];
6202 };
6203 Object.defineProperty(CircularList.prototype, "isFull", {
6204 get: function () {
6205 return this._length === this._maxLength;
6206 },
6207 enumerable: true,
6208 configurable: true
6209 });
6210 CircularList.prototype.pop = function () {
6211 return this._array[this._getCyclicIndex(this._length-- - 1)];
6212 };
6213 CircularList.prototype.splice = function (start, deleteCount) {
6214 var items = [];
6215 for (var _i = 2; _i < arguments.length; _i++) {
6216 items[_i - 2] = arguments[_i];
6217 }
6218 if (deleteCount) {
6219 for (var i = start; i < this._length - deleteCount; i++) {
6220 this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
6221 }
6222 this._length -= deleteCount;
6223 }
6224 for (var i = this._length - 1; i >= start; i--) {
6225 this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
6226 }
6227 for (var i = 0; i < items.length; i++) {
6228 this._array[this._getCyclicIndex(start + i)] = items[i];
6229 }
6230 if (this._length + items.length > this._maxLength) {
6231 var countToTrim = (this._length + items.length) - this._maxLength;
6232 this._startIndex += countToTrim;
6233 this._length = this._maxLength;
6234 this.onTrimEmitter.fire(countToTrim);
6235 }
6236 else {
6237 this._length += items.length;
6238 }
6239 };
6240 CircularList.prototype.trimStart = function (count) {
6241 if (count > this._length) {
6242 count = this._length;
6243 }
6244 this._startIndex += count;
6245 this._length -= count;
6246 this.onTrimEmitter.fire(count);
6247 };
6248 CircularList.prototype.shiftElements = function (start, count, offset) {
6249 if (count <= 0) {
6250 return;
6251 }
6252 if (start < 0 || start >= this._length) {
6253 throw new Error('start argument out of range');
6254 }
6255 if (start + offset < 0) {
6256 throw new Error('Cannot shift elements in list beyond index 0');
6257 }
6258 if (offset > 0) {
6259 for (var i = count - 1; i >= 0; i--) {
6260 this.set(start + i + offset, this.get(start + i));
6261 }
6262 var expandListBy = (start + count + offset) - this._length;
6263 if (expandListBy > 0) {
6264 this._length += expandListBy;
6265 while (this._length > this._maxLength) {
6266 this._length--;
6267 this._startIndex++;
6268 this.onTrimEmitter.fire(1);
6269 }
6270 }
6271 }
6272 else {
6273 for (var i = 0; i < count; i++) {
6274 this.set(start + i + offset, this.get(start + i));
6275 }
6276 }
6277 };
6278 CircularList.prototype._getCyclicIndex = function (index) {
6279 return (this._startIndex + index) % this._maxLength;
6280 };
6281 return CircularList;
6282 }());
6283 exports.CircularList = CircularList;
6284
6285 },{"./EventEmitter2":25}],23:[function(require,module,exports){
6286 "use strict";
6287 Object.defineProperty(exports, "__esModule", { value: true });
6288 function clone(val, depth) {
6289 if (depth === void 0) { depth = 5; }
6290 if (typeof val !== 'object') {
6291 return val;
6292 }
6293 if (val === null) {
6294 return null;
6295 }
6296 var clonedObject = Array.isArray(val) ? [] : {};
6297 for (var key in val) {
6298 clonedObject[key] = depth <= 1 ? val[key] : clone(val[key], depth - 1);
6299 }
6300 return clonedObject;
6301 }
6302 exports.clone = clone;
6303
6304 },{}],24:[function(require,module,exports){
6305 "use strict";
6306 var __extends = (this && this.__extends) || (function () {
6307 var extendStatics = function (d, b) {
6308 extendStatics = Object.setPrototypeOf ||
6309 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6310 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6311 return extendStatics(d, b);
6312 };
6313 return function (d, b) {
6314 extendStatics(d, b);
6315 function __() { this.constructor = d; }
6316 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6317 };
6318 })();
6319 Object.defineProperty(exports, "__esModule", { value: true });
6320 var Lifecycle_1 = require("./Lifecycle");
6321 var EventEmitter = (function (_super) {
6322 __extends(EventEmitter, _super);
6323 function EventEmitter() {
6324 var _this = _super.call(this) || this;
6325 _this._events = _this._events || {};
6326 return _this;
6327 }
6328 EventEmitter.prototype.on = function (type, listener) {
6329 this._events[type] = this._events[type] || [];
6330 this._events[type].push(listener);
6331 };
6332 EventEmitter.prototype.addDisposableListener = function (type, handler) {
6333 var _this = this;
6334 this.on(type, handler);
6335 var disposed = false;
6336 return {
6337 dispose: function () {
6338 if (disposed) {
6339 return;
6340 }
6341 _this.off(type, handler);
6342 disposed = true;
6343 }
6344 };
6345 };
6346 EventEmitter.prototype.off = function (type, listener) {
6347 if (!this._events[type]) {
6348 return;
6349 }
6350 var obj = this._events[type];
6351 var i = obj.length;
6352 while (i--) {
6353 if (obj[i] === listener) {
6354 obj.splice(i, 1);
6355 return;
6356 }
6357 }
6358 };
6359 EventEmitter.prototype.removeAllListeners = function (type) {
6360 if (this._events[type]) {
6361 delete this._events[type];
6362 }
6363 };
6364 EventEmitter.prototype.emit = function (type) {
6365 var args = [];
6366 for (var _i = 1; _i < arguments.length; _i++) {
6367 args[_i - 1] = arguments[_i];
6368 }
6369 if (!this._events[type]) {
6370 return;
6371 }
6372 var obj = this._events[type];
6373 for (var i = 0; i < obj.length; i++) {
6374 obj[i].apply(this, args);
6375 }
6376 };
6377 EventEmitter.prototype.emitMayRemoveListeners = function (type) {
6378 var args = [];
6379 for (var _i = 1; _i < arguments.length; _i++) {
6380 args[_i - 1] = arguments[_i];
6381 }
6382 if (!this._events[type]) {
6383 return;
6384 }
6385 var obj = this._events[type];
6386 var length = obj.length;
6387 for (var i = 0; i < obj.length; i++) {
6388 obj[i].apply(this, args);
6389 i -= length - obj.length;
6390 length = obj.length;
6391 }
6392 };
6393 EventEmitter.prototype.listeners = function (type) {
6394 return this._events[type] || [];
6395 };
6396 EventEmitter.prototype.dispose = function () {
6397 _super.prototype.dispose.call(this);
6398 this._events = {};
6399 };
6400 return EventEmitter;
6401 }(Lifecycle_1.Disposable));
6402 exports.EventEmitter = EventEmitter;
6403
6404 },{"./Lifecycle":26}],25:[function(require,module,exports){
6405 "use strict";
6406 Object.defineProperty(exports, "__esModule", { value: true });
6407 var EventEmitter2 = (function () {
6408 function EventEmitter2() {
6409 this._listeners = [];
6410 }
6411 Object.defineProperty(EventEmitter2.prototype, "event", {
6412 get: function () {
6413 var _this = this;
6414 if (!this._event) {
6415 this._event = function (listener) {
6416 _this._listeners.push(listener);
6417 var disposable = {
6418 dispose: function () {
6419 for (var i = 0; i < _this._listeners.length; i++) {
6420 if (_this._listeners[i] === listener) {
6421 _this._listeners.splice(i, 1);
6422 return;
6423 }
6424 }
6425 }
6426 };
6427 return disposable;
6428 };
6429 }
6430 return this._event;
6431 },
6432 enumerable: true,
6433 configurable: true
6434 });
6435 EventEmitter2.prototype.fire = function (data) {
6436 var queue = [];
6437 for (var i = 0; i < this._listeners.length; i++) {
6438 queue.push(this._listeners[i]);
6439 }
6440 for (var i = 0; i < queue.length; i++) {
6441 queue[i].call(undefined, data);
6442 }
6443 };
6444 return EventEmitter2;
6445 }());
6446 exports.EventEmitter2 = EventEmitter2;
6447
6448 },{}],26:[function(require,module,exports){
6449 "use strict";
6450 Object.defineProperty(exports, "__esModule", { value: true });
6451 var Disposable = (function () {
6452 function Disposable() {
6453 this._disposables = [];
6454 this._isDisposed = false;
6455 }
6456 Disposable.prototype.dispose = function () {
6457 this._isDisposed = true;
6458 this._disposables.forEach(function (d) { return d.dispose(); });
6459 this._disposables.length = 0;
6460 };
6461 Disposable.prototype.register = function (d) {
6462 this._disposables.push(d);
6463 };
6464 Disposable.prototype.unregister = function (d) {
6465 var index = this._disposables.indexOf(d);
6466 if (index !== -1) {
6467 this._disposables.splice(index, 1);
6468 }
6469 };
6470 return Disposable;
6471 }());
6472 exports.Disposable = Disposable;
6473
6474 },{}],27:[function(require,module,exports){
6475 "use strict";
6476 Object.defineProperty(exports, "__esModule", { value: true });
6477 var isNode = (typeof navigator === 'undefined') ? true : false;
6478 var userAgent = (isNode) ? 'node' : navigator.userAgent;
6479 var platform = (isNode) ? 'node' : navigator.platform;
6480 exports.isFirefox = !!~userAgent.indexOf('Firefox');
6481 exports.isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
6482 exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
6483 exports.isMac = contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
6484 exports.isIpad = platform === 'iPad';
6485 exports.isIphone = platform === 'iPhone';
6486 exports.isMSWindows = contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
6487 exports.isLinux = platform.indexOf('Linux') >= 0;
6488 function contains(arr, el) {
6489 return arr.indexOf(el) >= 0;
6490 }
6491
6492 },{}],28:[function(require,module,exports){
6493 "use strict";
6494 Object.defineProperty(exports, "__esModule", { value: true });
6495 function fill(array, value, start, end) {
6496 if (array.fill) {
6497 return array.fill(value, start, end);
6498 }
6499 return fillFallback(array, value, start, end);
6500 }
6501 exports.fill = fill;
6502 function fillFallback(array, value, start, end) {
6503 if (start === void 0) { start = 0; }
6504 if (end === void 0) { end = array.length; }
6505 if (start >= array.length) {
6506 return array;
6507 }
6508 start = (array.length + start) % array.length;
6509 if (end >= array.length) {
6510 end = array.length;
6511 }
6512 else {
6513 end = (array.length + end) % array.length;
6514 }
6515 for (var i = start; i < end; ++i) {
6516 array[i] = value;
6517 }
6518 return array;
6519 }
6520 exports.fillFallback = fillFallback;
6521 function concat(a, b) {
6522 var result = new a.constructor(a.length + b.length);
6523 result.set(a);
6524 result.set(b, a.length);
6525 return result;
6526 }
6527 exports.concat = concat;
6528
6529 },{}],29:[function(require,module,exports){
6530 "use strict";
6531 Object.defineProperty(exports, "__esModule", { value: true });
6532 var C0;
6533 (function (C0) {
6534 C0.NUL = '\x00';
6535 C0.SOH = '\x01';
6536 C0.STX = '\x02';
6537 C0.ETX = '\x03';
6538 C0.EOT = '\x04';
6539 C0.ENQ = '\x05';
6540 C0.ACK = '\x06';
6541 C0.BEL = '\x07';
6542 C0.BS = '\x08';
6543 C0.HT = '\x09';
6544 C0.LF = '\x0a';
6545 C0.VT = '\x0b';
6546 C0.FF = '\x0c';
6547 C0.CR = '\x0d';
6548 C0.SO = '\x0e';
6549 C0.SI = '\x0f';
6550 C0.DLE = '\x10';
6551 C0.DC1 = '\x11';
6552 C0.DC2 = '\x12';
6553 C0.DC3 = '\x13';
6554 C0.DC4 = '\x14';
6555 C0.NAK = '\x15';
6556 C0.SYN = '\x16';
6557 C0.ETB = '\x17';
6558 C0.CAN = '\x18';
6559 C0.EM = '\x19';
6560 C0.SUB = '\x1a';
6561 C0.ESC = '\x1b';
6562 C0.FS = '\x1c';
6563 C0.GS = '\x1d';
6564 C0.RS = '\x1e';
6565 C0.US = '\x1f';
6566 C0.SP = '\x20';
6567 C0.DEL = '\x7f';
6568 })(C0 = exports.C0 || (exports.C0 = {}));
6569 var C1;
6570 (function (C1) {
6571 C1.PAD = '\x80';
6572 C1.HOP = '\x81';
6573 C1.BPH = '\x82';
6574 C1.NBH = '\x83';
6575 C1.IND = '\x84';
6576 C1.NEL = '\x85';
6577 C1.SSA = '\x86';
6578 C1.ESA = '\x87';
6579 C1.HTS = '\x88';
6580 C1.HTJ = '\x89';
6581 C1.VTS = '\x8a';
6582 C1.PLD = '\x8b';
6583 C1.PLU = '\x8c';
6584 C1.RI = '\x8d';
6585 C1.SS2 = '\x8e';
6586 C1.SS3 = '\x8f';
6587 C1.DCS = '\x90';
6588 C1.PU1 = '\x91';
6589 C1.PU2 = '\x92';
6590 C1.STS = '\x93';
6591 C1.CCH = '\x94';
6592 C1.MW = '\x95';
6593 C1.SPA = '\x96';
6594 C1.EPA = '\x97';
6595 C1.SOS = '\x98';
6596 C1.SGCI = '\x99';
6597 C1.SCI = '\x9a';
6598 C1.CSI = '\x9b';
6599 C1.ST = '\x9c';
6600 C1.OSC = '\x9d';
6601 C1.PM = '\x9e';
6602 C1.APC = '\x9f';
6603 })(C1 = exports.C1 || (exports.C1 = {}));
6604
6605 },{}],30:[function(require,module,exports){
6606 "use strict";
6607 Object.defineProperty(exports, "__esModule", { value: true });
6608 exports.CHARSETS = {};
6609 exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
6610 exports.CHARSETS['0'] = {
6611 '`': '\u25c6',
6612 'a': '\u2592',
6613 'b': '\u0009',
6614 'c': '\u000c',
6615 'd': '\u000d',
6616 'e': '\u000a',
6617 'f': '\u00b0',
6618 'g': '\u00b1',
6619 'h': '\u2424',
6620 'i': '\u000b',
6621 'j': '\u2518',
6622 'k': '\u2510',
6623 'l': '\u250c',
6624 'm': '\u2514',
6625 'n': '\u253c',
6626 'o': '\u23ba',
6627 'p': '\u23bb',
6628 'q': '\u2500',
6629 'r': '\u23bc',
6630 's': '\u23bd',
6631 't': '\u251c',
6632 'u': '\u2524',
6633 'v': '\u2534',
6634 'w': '\u252c',
6635 'x': '\u2502',
6636 'y': '\u2264',
6637 'z': '\u2265',
6638 '{': '\u03c0',
6639 '|': '\u2260',
6640 '}': '\u00a3',
6641 '~': '\u00b7'
6642 };
6643 exports.CHARSETS['A'] = {
6644 '#': '£'
6645 };
6646 exports.CHARSETS['B'] = null;
6647 exports.CHARSETS['4'] = {
6648 '#': '£',
6649 '@': '¾',
6650 '[': 'ij',
6651 '\\': '½',
6652 ']': '|',
6653 '{': '¨',
6654 '|': 'f',
6655 '}': '¼',
6656 '~': '´'
6657 };
6658 exports.CHARSETS['C'] =
6659 exports.CHARSETS['5'] = {
6660 '[': 'Ä',
6661 '\\': 'Ö',
6662 ']': 'Ã…',
6663 '^': 'Ü',
6664 '`': 'é',
6665 '{': 'ä',
6666 '|': 'ö',
6667 '}': 'Ã¥',
6668 '~': 'ü'
6669 };
6670 exports.CHARSETS['R'] = {
6671 '#': '£',
6672 '@': 'à',
6673 '[': '°',
6674 '\\': 'ç',
6675 ']': '§',
6676 '{': 'é',
6677 '|': 'ù',
6678 '}': 'è',
6679 '~': '¨'
6680 };
6681 exports.CHARSETS['Q'] = {
6682 '@': 'à',
6683 '[': 'â',
6684 '\\': 'ç',
6685 ']': 'ê',
6686 '^': 'î',
6687 '`': 'ô',
6688 '{': 'é',
6689 '|': 'ù',
6690 '}': 'è',
6691 '~': 'û'
6692 };
6693 exports.CHARSETS['K'] = {
6694 '@': '§',
6695 '[': 'Ä',
6696 '\\': 'Ö',
6697 ']': 'Ü',
6698 '{': 'ä',
6699 '|': 'ö',
6700 '}': 'ü',
6701 '~': 'ß'
6702 };
6703 exports.CHARSETS['Y'] = {
6704 '#': '£',
6705 '@': '§',
6706 '[': '°',
6707 '\\': 'ç',
6708 ']': 'é',
6709 '`': 'ù',
6710 '{': 'à',
6711 '|': 'ò',
6712 '}': 'è',
6713 '~': 'ì'
6714 };
6715 exports.CHARSETS['E'] =
6716 exports.CHARSETS['6'] = {
6717 '@': 'Ä',
6718 '[': 'Æ',
6719 '\\': 'Ø',
6720 ']': 'Ã…',
6721 '^': 'Ü',
6722 '`': 'ä',
6723 '{': 'æ',
6724 '|': 'ø',
6725 '}': 'Ã¥',
6726 '~': 'ü'
6727 };
6728 exports.CHARSETS['Z'] = {
6729 '#': '£',
6730 '@': '§',
6731 '[': '¡',
6732 '\\': 'Ñ',
6733 ']': '¿',
6734 '{': '°',
6735 '|': 'ñ',
6736 '}': 'ç'
6737 };
6738 exports.CHARSETS['H'] =
6739 exports.CHARSETS['7'] = {
6740 '@': 'É',
6741 '[': 'Ä',
6742 '\\': 'Ö',
6743 ']': 'Ã…',
6744 '^': 'Ü',
6745 '`': 'é',
6746 '{': 'ä',
6747 '|': 'ö',
6748 '}': 'Ã¥',
6749 '~': 'ü'
6750 };
6751 exports.CHARSETS['='] = {
6752 '#': 'ù',
6753 '@': 'à',
6754 '[': 'é',
6755 '\\': 'ç',
6756 ']': 'ê',
6757 '^': 'î',
6758 '_': 'è',
6759 '`': 'ô',
6760 '{': 'ä',
6761 '|': 'ö',
6762 '}': 'ü',
6763 '~': 'û'
6764 };
6765
6766 },{}],31:[function(require,module,exports){
6767 "use strict";
6768 Object.defineProperty(exports, "__esModule", { value: true });
6769 var EscapeSequences_1 = require("../../common/data/EscapeSequences");
6770 var KEYCODE_KEY_MAPPINGS = {
6771 48: ['0', ')'],
6772 49: ['1', '!'],
6773 50: ['2', '@'],
6774 51: ['3', '#'],
6775 52: ['4', '$'],
6776 53: ['5', '%'],
6777 54: ['6', '^'],
6778 55: ['7', '&'],
6779 56: ['8', '*'],
6780 57: ['9', '('],
6781 186: [';', ':'],
6782 187: ['=', '+'],
6783 188: [',', '<'],
6784 189: ['-', '_'],
6785 190: ['.', '>'],
6786 191: ['/', '?'],
6787 192: ['`', '~'],
6788 219: ['[', '{'],
6789 220: ['\\', '|'],
6790 221: [']', '}'],
6791 222: ['\'', '"']
6792 };
6793 function evaluateKeyboardEvent(ev, applicationCursorMode, isMac, macOptionIsMeta) {
6794 var result = {
6795 type: 0,
6796 cancel: false,
6797 key: undefined
6798 };
6799 var modifiers = (ev.shiftKey ? 1 : 0) | (ev.altKey ? 2 : 0) | (ev.ctrlKey ? 4 : 0) | (ev.metaKey ? 8 : 0);
6800 switch (ev.keyCode) {
6801 case 0:
6802 if (ev.key === 'UIKeyInputUpArrow') {
6803 if (applicationCursorMode) {
6804 result.key = EscapeSequences_1.C0.ESC + 'OA';
6805 }
6806 else {
6807 result.key = EscapeSequences_1.C0.ESC + '[A';
6808 }
6809 }
6810 else if (ev.key === 'UIKeyInputLeftArrow') {
6811 if (applicationCursorMode) {
6812 result.key = EscapeSequences_1.C0.ESC + 'OD';
6813 }
6814 else {
6815 result.key = EscapeSequences_1.C0.ESC + '[D';
6816 }
6817 }
6818 else if (ev.key === 'UIKeyInputRightArrow') {
6819 if (applicationCursorMode) {
6820 result.key = EscapeSequences_1.C0.ESC + 'OC';
6821 }
6822 else {
6823 result.key = EscapeSequences_1.C0.ESC + '[C';
6824 }
6825 }
6826 else if (ev.key === 'UIKeyInputDownArrow') {
6827 if (applicationCursorMode) {
6828 result.key = EscapeSequences_1.C0.ESC + 'OB';
6829 }
6830 else {
6831 result.key = EscapeSequences_1.C0.ESC + '[B';
6832 }
6833 }
6834 break;
6835 case 8:
6836 if (ev.shiftKey) {
6837 result.key = EscapeSequences_1.C0.BS;
6838 break;
6839 }
6840 else if (ev.altKey) {
6841 result.key = EscapeSequences_1.C0.ESC + EscapeSequences_1.C0.DEL;
6842 break;
6843 }
6844 result.key = EscapeSequences_1.C0.DEL;
6845 break;
6846 case 9:
6847 if (ev.shiftKey) {
6848 result.key = EscapeSequences_1.C0.ESC + '[Z';
6849 break;
6850 }
6851 result.key = EscapeSequences_1.C0.HT;
6852 result.cancel = true;
6853 break;
6854 case 13:
6855 result.key = EscapeSequences_1.C0.CR;
6856 result.cancel = true;
6857 break;
6858 case 27:
6859 result.key = EscapeSequences_1.C0.ESC;
6860 result.cancel = true;
6861 break;
6862 case 37:
6863 if (modifiers) {
6864 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
6865 if (result.key === EscapeSequences_1.C0.ESC + '[1;3D') {
6866 result.key = isMac ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
6867 }
6868 }
6869 else if (applicationCursorMode) {
6870 result.key = EscapeSequences_1.C0.ESC + 'OD';
6871 }
6872 else {
6873 result.key = EscapeSequences_1.C0.ESC + '[D';
6874 }
6875 break;
6876 case 39:
6877 if (modifiers) {
6878 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
6879 if (result.key === EscapeSequences_1.C0.ESC + '[1;3C') {
6880 result.key = isMac ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
6881 }
6882 }
6883 else if (applicationCursorMode) {
6884 result.key = EscapeSequences_1.C0.ESC + 'OC';
6885 }
6886 else {
6887 result.key = EscapeSequences_1.C0.ESC + '[C';
6888 }
6889 break;
6890 case 38:
6891 if (modifiers) {
6892 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
6893 if (result.key === EscapeSequences_1.C0.ESC + '[1;3A') {
6894 result.key = EscapeSequences_1.C0.ESC + '[1;5A';
6895 }
6896 }
6897 else if (applicationCursorMode) {
6898 result.key = EscapeSequences_1.C0.ESC + 'OA';
6899 }
6900 else {
6901 result.key = EscapeSequences_1.C0.ESC + '[A';
6902 }
6903 break;
6904 case 40:
6905 if (modifiers) {
6906 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
6907 if (result.key === EscapeSequences_1.C0.ESC + '[1;3B') {
6908 result.key = EscapeSequences_1.C0.ESC + '[1;5B';
6909 }
6910 }
6911 else if (applicationCursorMode) {
6912 result.key = EscapeSequences_1.C0.ESC + 'OB';
6913 }
6914 else {
6915 result.key = EscapeSequences_1.C0.ESC + '[B';
6916 }
6917 break;
6918 case 45:
6919 if (!ev.shiftKey && !ev.ctrlKey) {
6920 result.key = EscapeSequences_1.C0.ESC + '[2~';
6921 }
6922 break;
6923 case 46:
6924 if (modifiers) {
6925 result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
6926 }
6927 else {
6928 result.key = EscapeSequences_1.C0.ESC + '[3~';
6929 }
6930 break;
6931 case 36:
6932 if (modifiers) {
6933 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
6934 }
6935 else if (applicationCursorMode) {
6936 result.key = EscapeSequences_1.C0.ESC + 'OH';
6937 }
6938 else {
6939 result.key = EscapeSequences_1.C0.ESC + '[H';
6940 }
6941 break;
6942 case 35:
6943 if (modifiers) {
6944 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
6945 }
6946 else if (applicationCursorMode) {
6947 result.key = EscapeSequences_1.C0.ESC + 'OF';
6948 }
6949 else {
6950 result.key = EscapeSequences_1.C0.ESC + '[F';
6951 }
6952 break;
6953 case 33:
6954 if (ev.shiftKey) {
6955 result.type = 2;
6956 }
6957 else {
6958 result.key = EscapeSequences_1.C0.ESC + '[5~';
6959 }
6960 break;
6961 case 34:
6962 if (ev.shiftKey) {
6963 result.type = 3;
6964 }
6965 else {
6966 result.key = EscapeSequences_1.C0.ESC + '[6~';
6967 }
6968 break;
6969 case 112:
6970 if (modifiers) {
6971 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
6972 }
6973 else {
6974 result.key = EscapeSequences_1.C0.ESC + 'OP';
6975 }
6976 break;
6977 case 113:
6978 if (modifiers) {
6979 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
6980 }
6981 else {
6982 result.key = EscapeSequences_1.C0.ESC + 'OQ';
6983 }
6984 break;
6985 case 114:
6986 if (modifiers) {
6987 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
6988 }
6989 else {
6990 result.key = EscapeSequences_1.C0.ESC + 'OR';
6991 }
6992 break;
6993 case 115:
6994 if (modifiers) {
6995 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
6996 }
6997 else {
6998 result.key = EscapeSequences_1.C0.ESC + 'OS';
6999 }
7000 break;
7001 case 116:
7002 if (modifiers) {
7003 result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
7004 }
7005 else {
7006 result.key = EscapeSequences_1.C0.ESC + '[15~';
7007 }
7008 break;
7009 case 117:
7010 if (modifiers) {
7011 result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
7012 }
7013 else {
7014 result.key = EscapeSequences_1.C0.ESC + '[17~';
7015 }
7016 break;
7017 case 118:
7018 if (modifiers) {
7019 result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
7020 }
7021 else {
7022 result.key = EscapeSequences_1.C0.ESC + '[18~';
7023 }
7024 break;
7025 case 119:
7026 if (modifiers) {
7027 result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
7028 }
7029 else {
7030 result.key = EscapeSequences_1.C0.ESC + '[19~';
7031 }
7032 break;
7033 case 120:
7034 if (modifiers) {
7035 result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
7036 }
7037 else {
7038 result.key = EscapeSequences_1.C0.ESC + '[20~';
7039 }
7040 break;
7041 case 121:
7042 if (modifiers) {
7043 result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
7044 }
7045 else {
7046 result.key = EscapeSequences_1.C0.ESC + '[21~';
7047 }
7048 break;
7049 case 122:
7050 if (modifiers) {
7051 result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
7052 }
7053 else {
7054 result.key = EscapeSequences_1.C0.ESC + '[23~';
7055 }
7056 break;
7057 case 123:
7058 if (modifiers) {
7059 result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
7060 }
7061 else {
7062 result.key = EscapeSequences_1.C0.ESC + '[24~';
7063 }
7064 break;
7065 default:
7066 if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
7067 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
7068 result.key = String.fromCharCode(ev.keyCode - 64);
7069 }
7070 else if (ev.keyCode === 32) {
7071 result.key = String.fromCharCode(0);
7072 }
7073 else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
7074 result.key = String.fromCharCode(ev.keyCode - 51 + 27);
7075 }
7076 else if (ev.keyCode === 56) {
7077 result.key = String.fromCharCode(127);
7078 }
7079 else if (ev.keyCode === 219) {
7080 result.key = String.fromCharCode(27);
7081 }
7082 else if (ev.keyCode === 220) {
7083 result.key = String.fromCharCode(28);
7084 }
7085 else if (ev.keyCode === 221) {
7086 result.key = String.fromCharCode(29);
7087 }
7088 }
7089 else if ((!isMac || macOptionIsMeta) && ev.altKey && !ev.metaKey) {
7090 var keyMapping = KEYCODE_KEY_MAPPINGS[ev.keyCode];
7091 var key = keyMapping && keyMapping[!ev.shiftKey ? 0 : 1];
7092 if (key) {
7093 result.key = EscapeSequences_1.C0.ESC + key;
7094 }
7095 else if (ev.keyCode >= 65 && ev.keyCode <= 90) {
7096 var keyCode = ev.ctrlKey ? ev.keyCode - 64 : ev.keyCode + 32;
7097 result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(keyCode);
7098 }
7099 }
7100 else if (isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
7101 if (ev.keyCode === 65) {
7102 result.type = 1;
7103 }
7104 }
7105 else if (ev.key && !ev.ctrlKey && !ev.altKey && !ev.metaKey && ev.keyCode >= 48 && ev.key.length === 1) {
7106 result.key = ev.key;
7107 }
7108 else if (ev.key && ev.ctrlKey) {
7109 if (ev.key === '_') {
7110 result.key = EscapeSequences_1.C0.US;
7111 }
7112 }
7113 break;
7114 }
7115 return result;
7116 }
7117 exports.evaluateKeyboardEvent = evaluateKeyboardEvent;
7118
7119 },{"../../common/data/EscapeSequences":29}],32:[function(require,module,exports){
7120 "use strict";
7121 Object.defineProperty(exports, "__esModule", { value: true });
7122 var StringToUtf32 = (function () {
7123 function StringToUtf32() {
7124 this._interim = 0;
7125 }
7126 StringToUtf32.prototype.clear = function () {
7127 this._interim = 0;
7128 };
7129 StringToUtf32.prototype.decode = function (input, target) {
7130 var length = input.length;
7131 if (!length) {
7132 return 0;
7133 }
7134 var size = 0;
7135 var startPos = 0;
7136 if (this._interim) {
7137 var second = input.charCodeAt(startPos++);
7138 if (0xDC00 <= second && second <= 0xDFFF) {
7139 target[size++] = (this._interim - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7140 }
7141 else {
7142 target[size++] = this._interim;
7143 target[size++] = second;
7144 }
7145 this._interim = 0;
7146 }
7147 for (var i = startPos; i < length; ++i) {
7148 var code = input.charCodeAt(i);
7149 if (0xD800 <= code && code <= 0xDBFF) {
7150 if (++i >= length) {
7151 this._interim = code;
7152 return size;
7153 }
7154 var second = input.charCodeAt(i);
7155 if (0xDC00 <= second && second <= 0xDFFF) {
7156 target[size++] = (code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
7157 }
7158 else {
7159 target[size++] = code;
7160 target[size++] = second;
7161 }
7162 continue;
7163 }
7164 target[size++] = code;
7165 }
7166 return size;
7167 };
7168 return StringToUtf32;
7169 }());
7170 exports.StringToUtf32 = StringToUtf32;
7171 function stringFromCodePoint(codePoint) {
7172 if (codePoint > 0xFFFF) {
7173 codePoint -= 0x10000;
7174 return String.fromCharCode((codePoint >> 10) + 0xD800) + String.fromCharCode((codePoint % 0x400) + 0xDC00);
7175 }
7176 return String.fromCharCode(codePoint);
7177 }
7178 exports.stringFromCodePoint = stringFromCodePoint;
7179 function utf32ToString(data, start, end) {
7180 if (start === void 0) { start = 0; }
7181 if (end === void 0) { end = data.length; }
7182 var result = '';
7183 for (var i = start; i < end; ++i) {
7184 var codepoint = data[i];
7185 if (codepoint > 0xFFFF) {
7186 codepoint -= 0x10000;
7187 result += String.fromCharCode((codepoint >> 10) + 0xD800) + String.fromCharCode((codepoint % 0x400) + 0xDC00);
7188 }
7189 else {
7190 result += String.fromCharCode(codepoint);
7191 }
7192 }
7193 return result;
7194 }
7195 exports.utf32ToString = utf32ToString;
7196
7197 },{}],33:[function(require,module,exports){
7198 "use strict";
7199 Object.defineProperty(exports, "__esModule", { value: true });
7200 var EscapeSequences_1 = require("../common/data/EscapeSequences");
7201 var AltClickHandler = (function () {
7202 function AltClickHandler(_mouseEvent, _terminal) {
7203 var _a;
7204 this._mouseEvent = _mouseEvent;
7205 this._terminal = _terminal;
7206 this._lines = this._terminal.buffer.lines;
7207 this._startCol = this._terminal.buffer.x;
7208 this._startRow = this._terminal.buffer.y;
7209 var coordinates = this._terminal.mouseHelper.getCoords(this._mouseEvent, this._terminal.element, this._terminal.charMeasure, this._terminal.cols, this._terminal.rows, false);
7210 if (coordinates) {
7211 _a = coordinates.map(function (coordinate) {
7212 return coordinate - 1;
7213 }), this._endCol = _a[0], this._endRow = _a[1];
7214 }
7215 }
7216 AltClickHandler.prototype.move = function () {
7217 if (this._mouseEvent.altKey && this._endCol !== undefined && this._endRow !== undefined) {
7218 this._terminal.handler(this._arrowSequences());
7219 }
7220 };
7221 AltClickHandler.prototype._arrowSequences = function () {
7222 if (!this._terminal.buffer.hasScrollback) {
7223 return this._resetStartingRow() + this._moveToRequestedRow() + this._moveToRequestedCol();
7224 }
7225 return this._moveHorizontallyOnly();
7226 };
7227 AltClickHandler.prototype._resetStartingRow = function () {
7228 if (this._moveToRequestedRow().length === 0) {
7229 return '';
7230 }
7231 return repeat(this._bufferLine(this._startCol, this._startRow, this._startCol, this._startRow - this._wrappedRowsForRow(this._startRow), false).length, this._sequence("D"));
7232 };
7233 AltClickHandler.prototype._moveToRequestedRow = function () {
7234 var startRow = this._startRow - this._wrappedRowsForRow(this._startRow);
7235 var endRow = this._endRow - this._wrappedRowsForRow(this._endRow);
7236 var rowsToMove = Math.abs(startRow - endRow) - this._wrappedRowsCount();
7237 return repeat(rowsToMove, this._sequence(this._verticalDirection()));
7238 };
7239 AltClickHandler.prototype._moveToRequestedCol = function () {
7240 var startRow;
7241 if (this._moveToRequestedRow().length > 0) {
7242 startRow = this._endRow - this._wrappedRowsForRow(this._endRow);
7243 }
7244 else {
7245 startRow = this._startRow;
7246 }
7247 var endRow = this._endRow;
7248 var direction = this._horizontalDirection();
7249 return repeat(this._bufferLine(this._startCol, startRow, this._endCol, endRow, direction === "C").length, this._sequence(direction));
7250 };
7251 AltClickHandler.prototype._moveHorizontallyOnly = function () {
7252 var direction = this._horizontalDirection();
7253 return repeat(Math.abs(this._startCol - this._endCol), this._sequence(direction));
7254 };
7255 AltClickHandler.prototype._wrappedRowsCount = function () {
7256 var wrappedRows = 0;
7257 var startRow = this._startRow - this._wrappedRowsForRow(this._startRow);
7258 var endRow = this._endRow - this._wrappedRowsForRow(this._endRow);
7259 for (var i = 0; i < Math.abs(startRow - endRow); i++) {
7260 var direction = this._verticalDirection() === "A" ? -1 : 1;
7261 if (this._lines.get(startRow + (direction * i)).isWrapped) {
7262 wrappedRows++;
7263 }
7264 }
7265 return wrappedRows;
7266 };
7267 AltClickHandler.prototype._wrappedRowsForRow = function (currentRow) {
7268 var rowCount = 0;
7269 var lineWraps = this._lines.get(currentRow).isWrapped;
7270 while (lineWraps && currentRow >= 0 && currentRow < this._terminal.rows) {
7271 rowCount++;
7272 currentRow--;
7273 lineWraps = this._lines.get(currentRow).isWrapped;
7274 }
7275 return rowCount;
7276 };
7277 AltClickHandler.prototype._horizontalDirection = function () {
7278 var startRow;
7279 if (this._moveToRequestedRow().length > 0) {
7280 startRow = this._endRow - this._wrappedRowsForRow(this._endRow);
7281 }
7282 else {
7283 startRow = this._startRow;
7284 }
7285 if ((this._startCol < this._endCol &&
7286 startRow <= this._endRow) ||
7287 (this._startCol >= this._endCol &&
7288 startRow < this._endRow)) {
7289 return "C";
7290 }
7291 return "D";
7292 };
7293 AltClickHandler.prototype._verticalDirection = function () {
7294 if (this._startRow > this._endRow) {
7295 return "A";
7296 }
7297 return "B";
7298 };
7299 AltClickHandler.prototype._bufferLine = function (startCol, startRow, endCol, endRow, forward) {
7300 var currentCol = startCol;
7301 var currentRow = startRow;
7302 var bufferStr = '';
7303 while (currentCol !== endCol || currentRow !== endRow) {
7304 currentCol += forward ? 1 : -1;
7305 if (forward && currentCol > this._terminal.cols - 1) {
7306 bufferStr += this._terminal.buffer.translateBufferLineToString(currentRow, false, startCol, currentCol);
7307 currentCol = 0;
7308 startCol = 0;
7309 currentRow++;
7310 }
7311 else if (!forward && currentCol < 0) {
7312 bufferStr += this._terminal.buffer.translateBufferLineToString(currentRow, false, 0, startCol + 1);
7313 currentCol = this._terminal.cols - 1;
7314 startCol = currentCol;
7315 currentRow--;
7316 }
7317 }
7318 return bufferStr + this._terminal.buffer.translateBufferLineToString(currentRow, false, startCol, currentCol);
7319 };
7320 AltClickHandler.prototype._sequence = function (direction) {
7321 var mod = this._terminal.applicationCursor ? 'O' : '[';
7322 return EscapeSequences_1.C0.ESC + mod + direction;
7323 };
7324 return AltClickHandler;
7325 }());
7326 exports.AltClickHandler = AltClickHandler;
7327 function repeat(count, str) {
7328 count = Math.floor(count);
7329 var rpt = '';
7330 for (var i = 0; i < count; i++) {
7331 rpt += str;
7332 }
7333 return rpt;
7334 }
7335
7336 },{"../common/data/EscapeSequences":29}],34:[function(require,module,exports){
7337 "use strict";
7338 Object.defineProperty(exports, "__esModule", { value: true });
7339 var Terminal_1 = require("../Terminal");
7340 var Strings = require("../Strings");
7341 var Terminal = (function () {
7342 function Terminal(options) {
7343 this._core = new Terminal_1.Terminal(options);
7344 }
7345 Object.defineProperty(Terminal.prototype, "onCursorMove", {
7346 get: function () { return this._core.onCursorMove; },
7347 enumerable: true,
7348 configurable: true
7349 });
7350 Object.defineProperty(Terminal.prototype, "onLineFeed", {
7351 get: function () { return this._core.onLineFeed; },
7352 enumerable: true,
7353 configurable: true
7354 });
7355 Object.defineProperty(Terminal.prototype, "onSelectionChange", {
7356 get: function () { return this._core.onSelectionChange; },
7357 enumerable: true,
7358 configurable: true
7359 });
7360 Object.defineProperty(Terminal.prototype, "onData", {
7361 get: function () { return this._core.onData; },
7362 enumerable: true,
7363 configurable: true
7364 });
7365 Object.defineProperty(Terminal.prototype, "onTitleChange", {
7366 get: function () { return this._core.onTitleChange; },
7367 enumerable: true,
7368 configurable: true
7369 });
7370 Object.defineProperty(Terminal.prototype, "onScroll", {
7371 get: function () { return this._core.onScroll; },
7372 enumerable: true,
7373 configurable: true
7374 });
7375 Object.defineProperty(Terminal.prototype, "onKey", {
7376 get: function () { return this._core.onKey; },
7377 enumerable: true,
7378 configurable: true
7379 });
7380 Object.defineProperty(Terminal.prototype, "onRender", {
7381 get: function () { return this._core.onRender; },
7382 enumerable: true,
7383 configurable: true
7384 });
7385 Object.defineProperty(Terminal.prototype, "onResize", {
7386 get: function () { return this._core.onResize; },
7387 enumerable: true,
7388 configurable: true
7389 });
7390 Object.defineProperty(Terminal.prototype, "element", {
7391 get: function () { return this._core.element; },
7392 enumerable: true,
7393 configurable: true
7394 });
7395 Object.defineProperty(Terminal.prototype, "textarea", {
7396 get: function () { return this._core.textarea; },
7397 enumerable: true,
7398 configurable: true
7399 });
7400 Object.defineProperty(Terminal.prototype, "rows", {
7401 get: function () { return this._core.rows; },
7402 enumerable: true,
7403 configurable: true
7404 });
7405 Object.defineProperty(Terminal.prototype, "cols", {
7406 get: function () { return this._core.cols; },
7407 enumerable: true,
7408 configurable: true
7409 });
7410 Object.defineProperty(Terminal.prototype, "markers", {
7411 get: function () { return this._core.markers; },
7412 enumerable: true,
7413 configurable: true
7414 });
7415 Terminal.prototype.blur = function () {
7416 this._core.blur();
7417 };
7418 Terminal.prototype.focus = function () {
7419 this._core.focus();
7420 };
7421 Terminal.prototype.on = function (type, listener) {
7422 this._core.on(type, listener);
7423 };
7424 Terminal.prototype.off = function (type, listener) {
7425 this._core.off(type, listener);
7426 };
7427 Terminal.prototype.emit = function (type, data) {
7428 this._core.emit(type, data);
7429 };
7430 Terminal.prototype.addDisposableListener = function (type, handler) {
7431 return this._core.addDisposableListener(type, handler);
7432 };
7433 Terminal.prototype.resize = function (columns, rows) {
7434 this._core.resize(columns, rows);
7435 };
7436 Terminal.prototype.writeln = function (data) {
7437 this._core.writeln(data);
7438 };
7439 Terminal.prototype.open = function (parent) {
7440 this._core.open(parent);
7441 };
7442 Terminal.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler) {
7443 this._core.attachCustomKeyEventHandler(customKeyEventHandler);
7444 };
7445 Terminal.prototype.addCsiHandler = function (flag, callback) {
7446 return this._core.addCsiHandler(flag, callback);
7447 };
7448 Terminal.prototype.addOscHandler = function (ident, callback) {
7449 return this._core.addOscHandler(ident, callback);
7450 };
7451 Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
7452 return this._core.registerLinkMatcher(regex, handler, options);
7453 };
7454 Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
7455 this._core.deregisterLinkMatcher(matcherId);
7456 };
7457 Terminal.prototype.registerCharacterJoiner = function (handler) {
7458 return this._core.registerCharacterJoiner(handler);
7459 };
7460 Terminal.prototype.deregisterCharacterJoiner = function (joinerId) {
7461 this._core.deregisterCharacterJoiner(joinerId);
7462 };
7463 Terminal.prototype.addMarker = function (cursorYOffset) {
7464 return this._core.addMarker(cursorYOffset);
7465 };
7466 Terminal.prototype.hasSelection = function () {
7467 return this._core.hasSelection();
7468 };
7469 Terminal.prototype.getSelection = function () {
7470 return this._core.getSelection();
7471 };
7472 Terminal.prototype.clearSelection = function () {
7473 this._core.clearSelection();
7474 };
7475 Terminal.prototype.selectAll = function () {
7476 this._core.selectAll();
7477 };
7478 Terminal.prototype.selectLines = function (start, end) {
7479 this._core.selectLines(start, end);
7480 };
7481 Terminal.prototype.dispose = function () {
7482 this._core.dispose();
7483 };
7484 Terminal.prototype.destroy = function () {
7485 this._core.destroy();
7486 };
7487 Terminal.prototype.scrollLines = function (amount) {
7488 this._core.scrollLines(amount);
7489 };
7490 Terminal.prototype.scrollPages = function (pageCount) {
7491 this._core.scrollPages(pageCount);
7492 };
7493 Terminal.prototype.scrollToTop = function () {
7494 this._core.scrollToTop();
7495 };
7496 Terminal.prototype.scrollToBottom = function () {
7497 this._core.scrollToBottom();
7498 };
7499 Terminal.prototype.scrollToLine = function (line) {
7500 this._core.scrollToLine(line);
7501 };
7502 Terminal.prototype.clear = function () {
7503 this._core.clear();
7504 };
7505 Terminal.prototype.write = function (data) {
7506 this._core.write(data);
7507 };
7508 Terminal.prototype.getOption = function (key) {
7509 return this._core.getOption(key);
7510 };
7511 Terminal.prototype.setOption = function (key, value) {
7512 this._core.setOption(key, value);
7513 };
7514 Terminal.prototype.refresh = function (start, end) {
7515 this._core.refresh(start, end);
7516 };
7517 Terminal.prototype.reset = function () {
7518 this._core.reset();
7519 };
7520 Terminal.applyAddon = function (addon) {
7521 addon.apply(Terminal);
7522 };
7523 Object.defineProperty(Terminal, "strings", {
7524 get: function () {
7525 return Strings;
7526 },
7527 enumerable: true,
7528 configurable: true
7529 });
7530 return Terminal;
7531 }());
7532 exports.Terminal = Terminal;
7533
7534 },{"../Strings":18,"../Terminal":19}],35:[function(require,module,exports){
7535 "use strict";
7536 Object.defineProperty(exports, "__esModule", { value: true });
7537 var Types_1 = require("./atlas/Types");
7538 var CharAtlasCache_1 = require("./atlas/CharAtlasCache");
7539 var BufferLine_1 = require("../BufferLine");
7540 var Buffer_1 = require("../Buffer");
7541 var CharacterJoinerRegistry_1 = require("./CharacterJoinerRegistry");
7542 var BaseRenderLayer = (function () {
7543 function BaseRenderLayer(_container, id, zIndex, _alpha, _colors) {
7544 this._container = _container;
7545 this._alpha = _alpha;
7546 this._colors = _colors;
7547 this._scaledCharWidth = 0;
7548 this._scaledCharHeight = 0;
7549 this._scaledCellWidth = 0;
7550 this._scaledCellHeight = 0;
7551 this._scaledCharLeft = 0;
7552 this._scaledCharTop = 0;
7553 this._currentGlyphIdentifier = {
7554 chars: '',
7555 code: 0,
7556 bg: 0,
7557 fg: 0,
7558 bold: false,
7559 dim: false,
7560 italic: false
7561 };
7562 this._canvas = document.createElement('canvas');
7563 this._canvas.classList.add("xterm-" + id + "-layer");
7564 this._canvas.style.zIndex = zIndex.toString();
7565 this._initCanvas();
7566 this._container.appendChild(this._canvas);
7567 }
7568 BaseRenderLayer.prototype.dispose = function () {
7569 this._container.removeChild(this._canvas);
7570 if (this._charAtlas) {
7571 this._charAtlas.dispose();
7572 }
7573 };
7574 BaseRenderLayer.prototype._initCanvas = function () {
7575 this._ctx = this._canvas.getContext('2d', { alpha: this._alpha });
7576 if (!this._alpha) {
7577 this.clearAll();
7578 }
7579 };
7580 BaseRenderLayer.prototype.onOptionsChanged = function (terminal) { };
7581 BaseRenderLayer.prototype.onBlur = function (terminal) { };
7582 BaseRenderLayer.prototype.onFocus = function (terminal) { };
7583 BaseRenderLayer.prototype.onCursorMove = function (terminal) { };
7584 BaseRenderLayer.prototype.onGridChanged = function (terminal, startRow, endRow) { };
7585 BaseRenderLayer.prototype.onSelectionChanged = function (terminal, start, end, columnSelectMode) {
7586 if (columnSelectMode === void 0) { columnSelectMode = false; }
7587 };
7588 BaseRenderLayer.prototype.onThemeChanged = function (terminal, colorSet) {
7589 this._refreshCharAtlas(terminal, colorSet);
7590 };
7591 BaseRenderLayer.prototype.setTransparency = function (terminal, alpha) {
7592 if (alpha === this._alpha) {
7593 return;
7594 }
7595 var oldCanvas = this._canvas;
7596 this._alpha = alpha;
7597 this._canvas = this._canvas.cloneNode();
7598 this._initCanvas();
7599 this._container.replaceChild(this._canvas, oldCanvas);
7600 this._refreshCharAtlas(terminal, this._colors);
7601 this.onGridChanged(terminal, 0, terminal.rows - 1);
7602 };
7603 BaseRenderLayer.prototype._refreshCharAtlas = function (terminal, colorSet) {
7604 if (this._scaledCharWidth <= 0 && this._scaledCharHeight <= 0) {
7605 return;
7606 }
7607 this._charAtlas = CharAtlasCache_1.acquireCharAtlas(terminal, colorSet, this._scaledCharWidth, this._scaledCharHeight);
7608 this._charAtlas.warmUp();
7609 };
7610 BaseRenderLayer.prototype.resize = function (terminal, dim) {
7611 this._scaledCellWidth = dim.scaledCellWidth;
7612 this._scaledCellHeight = dim.scaledCellHeight;
7613 this._scaledCharWidth = dim.scaledCharWidth;
7614 this._scaledCharHeight = dim.scaledCharHeight;
7615 this._scaledCharLeft = dim.scaledCharLeft;
7616 this._scaledCharTop = dim.scaledCharTop;
7617 this._canvas.width = dim.scaledCanvasWidth;
7618 this._canvas.height = dim.scaledCanvasHeight;
7619 this._canvas.style.width = dim.canvasWidth + "px";
7620 this._canvas.style.height = dim.canvasHeight + "px";
7621 if (!this._alpha) {
7622 this.clearAll();
7623 }
7624 this._refreshCharAtlas(terminal, this._colors);
7625 };
7626 BaseRenderLayer.prototype.fillCells = function (x, y, width, height) {
7627 this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
7628 };
7629 BaseRenderLayer.prototype.fillBottomLineAtCells = function (x, y, width) {
7630 if (width === void 0) { width = 1; }
7631 this._ctx.fillRect(x * this._scaledCellWidth, (y + 1) * this._scaledCellHeight - window.devicePixelRatio - 1, width * this._scaledCellWidth, window.devicePixelRatio);
7632 };
7633 BaseRenderLayer.prototype.fillLeftLineAtCell = function (x, y) {
7634 this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, window.devicePixelRatio, this._scaledCellHeight);
7635 };
7636 BaseRenderLayer.prototype.strokeRectAtCell = function (x, y, width, height) {
7637 this._ctx.lineWidth = window.devicePixelRatio;
7638 this._ctx.strokeRect(x * this._scaledCellWidth + window.devicePixelRatio / 2, y * this._scaledCellHeight + (window.devicePixelRatio / 2), width * this._scaledCellWidth - window.devicePixelRatio, (height * this._scaledCellHeight) - window.devicePixelRatio);
7639 };
7640 BaseRenderLayer.prototype.clearAll = function () {
7641 if (this._alpha) {
7642 this._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);
7643 }
7644 else {
7645 this._ctx.fillStyle = this._colors.background.css;
7646 this._ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);
7647 }
7648 };
7649 BaseRenderLayer.prototype.clearCells = function (x, y, width, height) {
7650 if (this._alpha) {
7651 this._ctx.clearRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
7652 }
7653 else {
7654 this._ctx.fillStyle = this._colors.background.css;
7655 this._ctx.fillRect(x * this._scaledCellWidth, y * this._scaledCellHeight, width * this._scaledCellWidth, height * this._scaledCellHeight);
7656 }
7657 };
7658 BaseRenderLayer.prototype.fillCharTrueColor = function (terminal, cell, x, y) {
7659 this._ctx.font = this._getFont(terminal, false, false);
7660 this._ctx.textBaseline = 'middle';
7661 this._clipRow(terminal, y);
7662 this._ctx.fillText(cell.getChars(), x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop + this._scaledCharHeight / 2);
7663 };
7664 BaseRenderLayer.prototype.drawChars = function (terminal, cell, x, y) {
7665 if (cell.isFgRGB() || cell.isBgRGB() || cell instanceof CharacterJoinerRegistry_1.JoinedCellData) {
7666 this._drawUncachedChars(terminal, cell, x, y);
7667 return;
7668 }
7669 var fg;
7670 var bg;
7671 if (cell.isInverse()) {
7672 fg = (cell.isBgDefault()) ? Types_1.INVERTED_DEFAULT_COLOR : cell.getBgColor();
7673 bg = (cell.isFgDefault()) ? Types_1.INVERTED_DEFAULT_COLOR : cell.getFgColor();
7674 }
7675 else {
7676 bg = (cell.isBgDefault()) ? Types_1.DEFAULT_COLOR : cell.getBgColor();
7677 fg = (cell.isFgDefault()) ? Types_1.DEFAULT_COLOR : cell.getFgColor();
7678 }
7679 var drawInBrightColor = terminal.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8 && fg !== Types_1.INVERTED_DEFAULT_COLOR;
7680 fg += drawInBrightColor ? 8 : 0;
7681 this._currentGlyphIdentifier.chars = cell.getChars() || Buffer_1.WHITESPACE_CELL_CHAR;
7682 this._currentGlyphIdentifier.code = cell.getCode() || Buffer_1.WHITESPACE_CELL_CODE;
7683 this._currentGlyphIdentifier.bg = bg;
7684 this._currentGlyphIdentifier.fg = fg;
7685 this._currentGlyphIdentifier.bold = cell.isBold() && terminal.options.enableBold;
7686 this._currentGlyphIdentifier.dim = !!cell.isDim();
7687 this._currentGlyphIdentifier.italic = !!cell.isItalic();
7688 var atlasDidDraw = this._charAtlas && this._charAtlas.draw(this._ctx, this._currentGlyphIdentifier, x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop);
7689 if (!atlasDidDraw) {
7690 this._drawUncachedChars(terminal, cell, x, y);
7691 }
7692 };
7693 BaseRenderLayer.prototype._drawUncachedChars = function (terminal, cell, x, y) {
7694 this._ctx.save();
7695 this._ctx.font = this._getFont(terminal, cell.isBold() && terminal.options.enableBold, !!cell.isItalic());
7696 this._ctx.textBaseline = 'middle';
7697 if (cell.isInverse()) {
7698 if (cell.isBgDefault()) {
7699 this._ctx.fillStyle = this._colors.background.css;
7700 }
7701 else if (cell.isBgRGB()) {
7702 this._ctx.fillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getBgColor()).join(',') + ")";
7703 }
7704 else {
7705 this._ctx.fillStyle = this._colors.ansi[cell.getBgColor()].css;
7706 }
7707 }
7708 else {
7709 if (cell.isFgDefault()) {
7710 this._ctx.fillStyle = this._colors.foreground.css;
7711 }
7712 else if (cell.isFgRGB()) {
7713 this._ctx.fillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getFgColor()).join(',') + ")";
7714 }
7715 else {
7716 var fg = cell.getFgColor();
7717 if (terminal.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8) {
7718 fg += 8;
7719 }
7720 this._ctx.fillStyle = this._colors.ansi[fg].css;
7721 }
7722 }
7723 this._clipRow(terminal, y);
7724 if (cell.isDim()) {
7725 this._ctx.globalAlpha = Types_1.DIM_OPACITY;
7726 }
7727 this._ctx.fillText(cell.getChars(), x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop + this._scaledCharHeight / 2);
7728 this._ctx.restore();
7729 };
7730 BaseRenderLayer.prototype._clipRow = function (terminal, y) {
7731 this._ctx.beginPath();
7732 this._ctx.rect(0, y * this._scaledCellHeight, terminal.cols * this._scaledCellWidth, this._scaledCellHeight);
7733 this._ctx.clip();
7734 };
7735 BaseRenderLayer.prototype._getFont = function (terminal, isBold, isItalic) {
7736 var fontWeight = isBold ? terminal.options.fontWeightBold : terminal.options.fontWeight;
7737 var fontStyle = isItalic ? 'italic' : '';
7738 return fontStyle + " " + fontWeight + " " + terminal.options.fontSize * window.devicePixelRatio + "px " + terminal.options.fontFamily;
7739 };
7740 return BaseRenderLayer;
7741 }());
7742 exports.BaseRenderLayer = BaseRenderLayer;
7743
7744 },{"../Buffer":2,"../BufferLine":3,"./CharacterJoinerRegistry":36,"./atlas/CharAtlasCache":45,"./atlas/Types":52}],36:[function(require,module,exports){
7745 "use strict";
7746 var __extends = (this && this.__extends) || (function () {
7747 var extendStatics = function (d, b) {
7748 extendStatics = Object.setPrototypeOf ||
7749 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7750 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7751 return extendStatics(d, b);
7752 };
7753 return function (d, b) {
7754 extendStatics(d, b);
7755 function __() { this.constructor = d; }
7756 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
7757 };
7758 })();
7759 Object.defineProperty(exports, "__esModule", { value: true });
7760 var BufferLine_1 = require("../BufferLine");
7761 var Buffer_1 = require("../Buffer");
7762 var JoinedCellData = (function (_super) {
7763 __extends(JoinedCellData, _super);
7764 function JoinedCellData(firstCell, chars, width) {
7765 var _this = _super.call(this) || this;
7766 _this.content = 0;
7767 _this.combinedData = '';
7768 _this.fg = firstCell.fg;
7769 _this.bg = firstCell.bg;
7770 _this.combinedData = chars;
7771 _this._width = width;
7772 return _this;
7773 }
7774 JoinedCellData.prototype.isCombined = function () {
7775 return 2097152;
7776 };
7777 JoinedCellData.prototype.getWidth = function () {
7778 return this._width;
7779 };
7780 JoinedCellData.prototype.getChars = function () {
7781 return this.combinedData;
7782 };
7783 JoinedCellData.prototype.getCode = function () {
7784 return 0x1FFFFF;
7785 };
7786 JoinedCellData.prototype.setFromCharData = function (value) {
7787 throw new Error('not implemented');
7788 };
7789 JoinedCellData.prototype.getAsCharData = function () {
7790 return [this.fg, this.getChars(), this.getWidth(), this.getCode()];
7791 };
7792 return JoinedCellData;
7793 }(BufferLine_1.AttributeData));
7794 exports.JoinedCellData = JoinedCellData;
7795 var CharacterJoinerRegistry = (function () {
7796 function CharacterJoinerRegistry(_terminal) {
7797 this._terminal = _terminal;
7798 this._characterJoiners = [];
7799 this._nextCharacterJoinerId = 0;
7800 this._workCell = new BufferLine_1.CellData();
7801 }
7802 CharacterJoinerRegistry.prototype.registerCharacterJoiner = function (handler) {
7803 var joiner = {
7804 id: this._nextCharacterJoinerId++,
7805 handler: handler
7806 };
7807 this._characterJoiners.push(joiner);
7808 return joiner.id;
7809 };
7810 CharacterJoinerRegistry.prototype.deregisterCharacterJoiner = function (joinerId) {
7811 for (var i = 0; i < this._characterJoiners.length; i++) {
7812 if (this._characterJoiners[i].id === joinerId) {
7813 this._characterJoiners.splice(i, 1);
7814 return true;
7815 }
7816 }
7817 return false;
7818 };
7819 CharacterJoinerRegistry.prototype.getJoinedCharacters = function (row) {
7820 if (this._characterJoiners.length === 0) {
7821 return [];
7822 }
7823 var line = this._terminal.buffer.lines.get(row);
7824 if (line.length === 0) {
7825 return [];
7826 }
7827 var ranges = [];
7828 var lineStr = line.translateToString(true);
7829 var rangeStartColumn = 0;
7830 var currentStringIndex = 0;
7831 var rangeStartStringIndex = 0;
7832 var rangeAttrFG = line.getFg(0);
7833 var rangeAttrBG = line.getBg(0);
7834 for (var x = 0; x < line.getTrimmedLength(); x++) {
7835 line.loadCell(x, this._workCell);
7836 if (this._workCell.getWidth() === 0) {
7837 continue;
7838 }
7839 if (this._workCell.fg !== rangeAttrFG || this._workCell.bg !== rangeAttrBG) {
7840 if (x - rangeStartColumn > 1) {
7841 var joinedRanges = this._getJoinedRanges(lineStr, rangeStartStringIndex, currentStringIndex, line, rangeStartColumn);
7842 for (var i = 0; i < joinedRanges.length; i++) {
7843 ranges.push(joinedRanges[i]);
7844 }
7845 }
7846 rangeStartColumn = x;
7847 rangeStartStringIndex = currentStringIndex;
7848 rangeAttrFG = this._workCell.fg;
7849 rangeAttrBG = this._workCell.bg;
7850 }
7851 currentStringIndex += this._workCell.getChars().length || Buffer_1.WHITESPACE_CELL_CHAR.length;
7852 }
7853 if (this._terminal.cols - rangeStartColumn > 1) {
7854 var joinedRanges = this._getJoinedRanges(lineStr, rangeStartStringIndex, currentStringIndex, line, rangeStartColumn);
7855 for (var i = 0; i < joinedRanges.length; i++) {
7856 ranges.push(joinedRanges[i]);
7857 }
7858 }
7859 return ranges;
7860 };
7861 CharacterJoinerRegistry.prototype._getJoinedRanges = function (line, startIndex, endIndex, lineData, startCol) {
7862 var text = line.substring(startIndex, endIndex);
7863 var joinedRanges = this._characterJoiners[0].handler(text);
7864 for (var i = 1; i < this._characterJoiners.length; i++) {
7865 var joinerRanges = this._characterJoiners[i].handler(text);
7866 for (var j = 0; j < joinerRanges.length; j++) {
7867 CharacterJoinerRegistry._mergeRanges(joinedRanges, joinerRanges[j]);
7868 }
7869 }
7870 this._stringRangesToCellRanges(joinedRanges, lineData, startCol);
7871 return joinedRanges;
7872 };
7873 CharacterJoinerRegistry.prototype._stringRangesToCellRanges = function (ranges, line, startCol) {
7874 var currentRangeIndex = 0;
7875 var currentRangeStarted = false;
7876 var currentStringIndex = 0;
7877 var currentRange = ranges[currentRangeIndex];
7878 if (!currentRange) {
7879 return;
7880 }
7881 for (var x = startCol; x < this._terminal.cols; x++) {
7882 var width = line.getWidth(x);
7883 var length_1 = line.getString(x).length || Buffer_1.WHITESPACE_CELL_CHAR.length;
7884 if (width === 0) {
7885 continue;
7886 }
7887 if (!currentRangeStarted && currentRange[0] <= currentStringIndex) {
7888 currentRange[0] = x;
7889 currentRangeStarted = true;
7890 }
7891 if (currentRange[1] <= currentStringIndex) {
7892 currentRange[1] = x;
7893 currentRange = ranges[++currentRangeIndex];
7894 if (!currentRange) {
7895 break;
7896 }
7897 if (currentRange[0] <= currentStringIndex) {
7898 currentRange[0] = x;
7899 currentRangeStarted = true;
7900 }
7901 else {
7902 currentRangeStarted = false;
7903 }
7904 }
7905 currentStringIndex += length_1;
7906 }
7907 if (currentRange) {
7908 currentRange[1] = this._terminal.cols;
7909 }
7910 };
7911 CharacterJoinerRegistry._mergeRanges = function (ranges, newRange) {
7912 var inRange = false;
7913 for (var i = 0; i < ranges.length; i++) {
7914 var range = ranges[i];
7915 if (!inRange) {
7916 if (newRange[1] <= range[0]) {
7917 ranges.splice(i, 0, newRange);
7918 return ranges;
7919 }
7920 if (newRange[1] <= range[1]) {
7921 range[0] = Math.min(newRange[0], range[0]);
7922 return ranges;
7923 }
7924 if (newRange[0] < range[1]) {
7925 range[0] = Math.min(newRange[0], range[0]);
7926 inRange = true;
7927 }
7928 continue;
7929 }
7930 else {
7931 if (newRange[1] <= range[0]) {
7932 ranges[i - 1][1] = newRange[1];
7933 return ranges;
7934 }
7935 if (newRange[1] <= range[1]) {
7936 ranges[i - 1][1] = Math.max(newRange[1], range[1]);
7937 ranges.splice(i, 1);
7938 inRange = false;
7939 return ranges;
7940 }
7941 ranges.splice(i, 1);
7942 i--;
7943 }
7944 }
7945 if (inRange) {
7946 ranges[ranges.length - 1][1] = newRange[1];
7947 }
7948 else {
7949 ranges.push(newRange);
7950 }
7951 return ranges;
7952 };
7953 return CharacterJoinerRegistry;
7954 }());
7955 exports.CharacterJoinerRegistry = CharacterJoinerRegistry;
7956
7957 },{"../Buffer":2,"../BufferLine":3}],37:[function(require,module,exports){
7958 "use strict";
7959 Object.defineProperty(exports, "__esModule", { value: true });
7960 var DEFAULT_FOREGROUND = fromHex('#ffffff');
7961 var DEFAULT_BACKGROUND = fromHex('#000000');
7962 var DEFAULT_CURSOR = fromHex('#ffffff');
7963 var DEFAULT_CURSOR_ACCENT = fromHex('#000000');
7964 var DEFAULT_SELECTION = {
7965 css: 'rgba(255, 255, 255, 0.3)',
7966 rgba: 0xFFFFFF77
7967 };
7968 exports.DEFAULT_ANSI_COLORS = (function () {
7969 var colors = [
7970 fromHex('#2e3436'),
7971 fromHex('#cc0000'),
7972 fromHex('#4e9a06'),
7973 fromHex('#c4a000'),
7974 fromHex('#3465a4'),
7975 fromHex('#75507b'),
7976 fromHex('#06989a'),
7977 fromHex('#d3d7cf'),
7978 fromHex('#555753'),
7979 fromHex('#ef2929'),
7980 fromHex('#8ae234'),
7981 fromHex('#fce94f'),
7982 fromHex('#729fcf'),
7983 fromHex('#ad7fa8'),
7984 fromHex('#34e2e2'),
7985 fromHex('#eeeeec')
7986 ];
7987 var v = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];
7988 for (var i = 0; i < 216; i++) {
7989 var r = v[(i / 36) % 6 | 0];
7990 var g = v[(i / 6) % 6 | 0];
7991 var b = v[i % 6];
7992 colors.push({
7993 css: "#" + toPaddedHex(r) + toPaddedHex(g) + toPaddedHex(b),
7994 rgba: ((r << 24) | (g << 16) | (b << 8) | 0xFF) >>> 0
7995 });
7996 }
7997 for (var i = 0; i < 24; i++) {
7998 var c = 8 + i * 10;
7999 var ch = toPaddedHex(c);
8000 colors.push({
8001 css: "#" + ch + ch + ch,
8002 rgba: ((c << 24) | (c << 16) | (c << 8) | 0xFF) >>> 0
8003 });
8004 }
8005 return colors;
8006 })();
8007 function fromHex(css) {
8008 return {
8009 css: css,
8010 rgba: parseInt(css.slice(1), 16) << 8 | 0xFF
8011 };
8012 }
8013 function toPaddedHex(c) {
8014 var s = c.toString(16);
8015 return s.length < 2 ? '0' + s : s;
8016 }
8017 var ColorManager = (function () {
8018 function ColorManager(document, allowTransparency) {
8019 this.allowTransparency = allowTransparency;
8020 var canvas = document.createElement('canvas');
8021 canvas.width = 1;
8022 canvas.height = 1;
8023 this._ctx = canvas.getContext('2d');
8024 this._ctx.globalCompositeOperation = 'copy';
8025 this._litmusColor = this._ctx.createLinearGradient(0, 0, 1, 1);
8026 this.colors = {
8027 foreground: DEFAULT_FOREGROUND,
8028 background: DEFAULT_BACKGROUND,
8029 cursor: DEFAULT_CURSOR,
8030 cursorAccent: DEFAULT_CURSOR_ACCENT,
8031 selection: DEFAULT_SELECTION,
8032 ansi: exports.DEFAULT_ANSI_COLORS.slice()
8033 };
8034 }
8035 ColorManager.prototype.setTheme = function (theme) {
8036 this.colors.foreground = this._parseColor(theme.foreground, DEFAULT_FOREGROUND);
8037 this.colors.background = this._parseColor(theme.background, DEFAULT_BACKGROUND);
8038 this.colors.cursor = this._parseColor(theme.cursor, DEFAULT_CURSOR, true);
8039 this.colors.cursorAccent = this._parseColor(theme.cursorAccent, DEFAULT_CURSOR_ACCENT, true);
8040 this.colors.selection = this._parseColor(theme.selection, DEFAULT_SELECTION, true);
8041 this.colors.ansi[0] = this._parseColor(theme.black, exports.DEFAULT_ANSI_COLORS[0]);
8042 this.colors.ansi[1] = this._parseColor(theme.red, exports.DEFAULT_ANSI_COLORS[1]);
8043 this.colors.ansi[2] = this._parseColor(theme.green, exports.DEFAULT_ANSI_COLORS[2]);
8044 this.colors.ansi[3] = this._parseColor(theme.yellow, exports.DEFAULT_ANSI_COLORS[3]);
8045 this.colors.ansi[4] = this._parseColor(theme.blue, exports.DEFAULT_ANSI_COLORS[4]);
8046 this.colors.ansi[5] = this._parseColor(theme.magenta, exports.DEFAULT_ANSI_COLORS[5]);
8047 this.colors.ansi[6] = this._parseColor(theme.cyan, exports.DEFAULT_ANSI_COLORS[6]);
8048 this.colors.ansi[7] = this._parseColor(theme.white, exports.DEFAULT_ANSI_COLORS[7]);
8049 this.colors.ansi[8] = this._parseColor(theme.brightBlack, exports.DEFAULT_ANSI_COLORS[8]);
8050 this.colors.ansi[9] = this._parseColor(theme.brightRed, exports.DEFAULT_ANSI_COLORS[9]);
8051 this.colors.ansi[10] = this._parseColor(theme.brightGreen, exports.DEFAULT_ANSI_COLORS[10]);
8052 this.colors.ansi[11] = this._parseColor(theme.brightYellow, exports.DEFAULT_ANSI_COLORS[11]);
8053 this.colors.ansi[12] = this._parseColor(theme.brightBlue, exports.DEFAULT_ANSI_COLORS[12]);
8054 this.colors.ansi[13] = this._parseColor(theme.brightMagenta, exports.DEFAULT_ANSI_COLORS[13]);
8055 this.colors.ansi[14] = this._parseColor(theme.brightCyan, exports.DEFAULT_ANSI_COLORS[14]);
8056 this.colors.ansi[15] = this._parseColor(theme.brightWhite, exports.DEFAULT_ANSI_COLORS[15]);
8057 };
8058 ColorManager.prototype._parseColor = function (css, fallback, allowTransparency) {
8059 if (allowTransparency === void 0) { allowTransparency = this.allowTransparency; }
8060 if (!css) {
8061 return fallback;
8062 }
8063 this._ctx.fillStyle = this._litmusColor;
8064 this._ctx.fillStyle = css;
8065 if (typeof this._ctx.fillStyle !== 'string') {
8066 console.warn("Color: " + css + " is invalid using fallback " + fallback.css);
8067 return fallback;
8068 }
8069 this._ctx.fillRect(0, 0, 1, 1);
8070 var data = this._ctx.getImageData(0, 0, 1, 1).data;
8071 if (!allowTransparency && data[3] !== 0xFF) {
8072 console.warn("Color: " + css + " is using transparency, but allowTransparency is false. " +
8073 ("Using fallback " + fallback.css + "."));
8074 return fallback;
8075 }
8076 return {
8077 css: css,
8078 rgba: (data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]) >>> 0
8079 };
8080 };
8081 return ColorManager;
8082 }());
8083 exports.ColorManager = ColorManager;
8084
8085 },{}],38:[function(require,module,exports){
8086 "use strict";
8087 var __extends = (this && this.__extends) || (function () {
8088 var extendStatics = function (d, b) {
8089 extendStatics = Object.setPrototypeOf ||
8090 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8091 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8092 return extendStatics(d, b);
8093 };
8094 return function (d, b) {
8095 extendStatics(d, b);
8096 function __() { this.constructor = d; }
8097 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8098 };
8099 })();
8100 Object.defineProperty(exports, "__esModule", { value: true });
8101 var BaseRenderLayer_1 = require("./BaseRenderLayer");
8102 var BufferLine_1 = require("../BufferLine");
8103 var BLINK_INTERVAL = 600;
8104 var CursorRenderLayer = (function (_super) {
8105 __extends(CursorRenderLayer, _super);
8106 function CursorRenderLayer(container, zIndex, colors) {
8107 var _this = _super.call(this, container, 'cursor', zIndex, true, colors) || this;
8108 _this._cell = new BufferLine_1.CellData();
8109 _this._state = {
8110 x: null,
8111 y: null,
8112 isFocused: null,
8113 style: null,
8114 width: null
8115 };
8116 _this._cursorRenderers = {
8117 'bar': _this._renderBarCursor.bind(_this),
8118 'block': _this._renderBlockCursor.bind(_this),
8119 'underline': _this._renderUnderlineCursor.bind(_this)
8120 };
8121 return _this;
8122 }
8123 CursorRenderLayer.prototype.resize = function (terminal, dim) {
8124 _super.prototype.resize.call(this, terminal, dim);
8125 this._state = {
8126 x: null,
8127 y: null,
8128 isFocused: null,
8129 style: null,
8130 width: null
8131 };
8132 };
8133 CursorRenderLayer.prototype.reset = function (terminal) {
8134 this._clearCursor();
8135 if (this._cursorBlinkStateManager) {
8136 this._cursorBlinkStateManager.dispose();
8137 this._cursorBlinkStateManager = null;
8138 this.onOptionsChanged(terminal);
8139 }
8140 };
8141 CursorRenderLayer.prototype.onBlur = function (terminal) {
8142 if (this._cursorBlinkStateManager) {
8143 this._cursorBlinkStateManager.pause();
8144 }
8145 terminal.refresh(terminal.buffer.y, terminal.buffer.y);
8146 };
8147 CursorRenderLayer.prototype.onFocus = function (terminal) {
8148 if (this._cursorBlinkStateManager) {
8149 this._cursorBlinkStateManager.resume(terminal);
8150 }
8151 else {
8152 terminal.refresh(terminal.buffer.y, terminal.buffer.y);
8153 }
8154 };
8155 CursorRenderLayer.prototype.onOptionsChanged = function (terminal) {
8156 var _this = this;
8157 if (terminal.options.cursorBlink) {
8158 if (!this._cursorBlinkStateManager) {
8159 this._cursorBlinkStateManager = new CursorBlinkStateManager(terminal, function () {
8160 _this._render(terminal, true);
8161 });
8162 }
8163 }
8164 else {
8165 if (this._cursorBlinkStateManager) {
8166 this._cursorBlinkStateManager.dispose();
8167 this._cursorBlinkStateManager = null;
8168 }
8169 terminal.refresh(terminal.buffer.y, terminal.buffer.y);
8170 }
8171 };
8172 CursorRenderLayer.prototype.onCursorMove = function (terminal) {
8173 if (this._cursorBlinkStateManager) {
8174 this._cursorBlinkStateManager.restartBlinkAnimation(terminal);
8175 }
8176 };
8177 CursorRenderLayer.prototype.onGridChanged = function (terminal, startRow, endRow) {
8178 if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
8179 this._render(terminal, false);
8180 }
8181 else {
8182 this._cursorBlinkStateManager.restartBlinkAnimation(terminal);
8183 }
8184 };
8185 CursorRenderLayer.prototype._render = function (terminal, triggeredByAnimationFrame) {
8186 if (!terminal.cursorState || terminal.cursorHidden) {
8187 this._clearCursor();
8188 return;
8189 }
8190 var cursorY = terminal.buffer.ybase + terminal.buffer.y;
8191 var viewportRelativeCursorY = cursorY - terminal.buffer.ydisp;
8192 if (viewportRelativeCursorY < 0 || viewportRelativeCursorY >= terminal.rows) {
8193 this._clearCursor();
8194 return;
8195 }
8196 terminal.buffer.lines.get(cursorY).loadCell(terminal.buffer.x, this._cell);
8197 if (this._cell.content === undefined) {
8198 return;
8199 }
8200 if (!terminal.isFocused) {
8201 this._clearCursor();
8202 this._ctx.save();
8203 this._ctx.fillStyle = this._colors.cursor.css;
8204 this._renderBlurCursor(terminal, terminal.buffer.x, viewportRelativeCursorY, this._cell);
8205 this._ctx.restore();
8206 this._state.x = terminal.buffer.x;
8207 this._state.y = viewportRelativeCursorY;
8208 this._state.isFocused = false;
8209 this._state.style = terminal.options.cursorStyle;
8210 this._state.width = this._cell.getWidth();
8211 return;
8212 }
8213 if (this._cursorBlinkStateManager && !this._cursorBlinkStateManager.isCursorVisible) {
8214 this._clearCursor();
8215 return;
8216 }
8217 if (this._state) {
8218 if (this._state.x === terminal.buffer.x &&
8219 this._state.y === viewportRelativeCursorY &&
8220 this._state.isFocused === terminal.isFocused &&
8221 this._state.style === terminal.options.cursorStyle &&
8222 this._state.width === this._cell.getWidth()) {
8223 return;
8224 }
8225 this._clearCursor();
8226 }
8227 this._ctx.save();
8228 this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, this._cell);
8229 this._ctx.restore();
8230 this._state.x = terminal.buffer.x;
8231 this._state.y = viewportRelativeCursorY;
8232 this._state.isFocused = false;
8233 this._state.style = terminal.options.cursorStyle;
8234 this._state.width = this._cell.getWidth();
8235 };
8236 CursorRenderLayer.prototype._clearCursor = function () {
8237 if (this._state) {
8238 this.clearCells(this._state.x, this._state.y, this._state.width, 1);
8239 this._state = {
8240 x: null,
8241 y: null,
8242 isFocused: null,
8243 style: null,
8244 width: null
8245 };
8246 }
8247 };
8248 CursorRenderLayer.prototype._renderBarCursor = function (terminal, x, y, cell) {
8249 this._ctx.save();
8250 this._ctx.fillStyle = this._colors.cursor.css;
8251 this.fillLeftLineAtCell(x, y);
8252 this._ctx.restore();
8253 };
8254 CursorRenderLayer.prototype._renderBlockCursor = function (terminal, x, y, cell) {
8255 this._ctx.save();
8256 this._ctx.fillStyle = this._colors.cursor.css;
8257 this.fillCells(x, y, cell.getWidth(), 1);
8258 this._ctx.fillStyle = this._colors.cursorAccent.css;
8259 this.fillCharTrueColor(terminal, cell, x, y);
8260 this._ctx.restore();
8261 };
8262 CursorRenderLayer.prototype._renderUnderlineCursor = function (terminal, x, y, cell) {
8263 this._ctx.save();
8264 this._ctx.fillStyle = this._colors.cursor.css;
8265 this.fillBottomLineAtCells(x, y);
8266 this._ctx.restore();
8267 };
8268 CursorRenderLayer.prototype._renderBlurCursor = function (terminal, x, y, cell) {
8269 this._ctx.save();
8270 this._ctx.strokeStyle = this._colors.cursor.css;
8271 this.strokeRectAtCell(x, y, cell.getWidth(), 1);
8272 this._ctx.restore();
8273 };
8274 return CursorRenderLayer;
8275 }(BaseRenderLayer_1.BaseRenderLayer));
8276 exports.CursorRenderLayer = CursorRenderLayer;
8277 var CursorBlinkStateManager = (function () {
8278 function CursorBlinkStateManager(terminal, _renderCallback) {
8279 this._renderCallback = _renderCallback;
8280 this.isCursorVisible = true;
8281 if (terminal.isFocused) {
8282 this._restartInterval();
8283 }
8284 }
8285 Object.defineProperty(CursorBlinkStateManager.prototype, "isPaused", {
8286 get: function () { return !(this._blinkStartTimeout || this._blinkInterval); },
8287 enumerable: true,
8288 configurable: true
8289 });
8290 CursorBlinkStateManager.prototype.dispose = function () {
8291 if (this._blinkInterval) {
8292 window.clearInterval(this._blinkInterval);
8293 this._blinkInterval = null;
8294 }
8295 if (this._blinkStartTimeout) {
8296 window.clearTimeout(this._blinkStartTimeout);
8297 this._blinkStartTimeout = null;
8298 }
8299 if (this._animationFrame) {
8300 window.cancelAnimationFrame(this._animationFrame);
8301 this._animationFrame = null;
8302 }
8303 };
8304 CursorBlinkStateManager.prototype.restartBlinkAnimation = function (terminal) {
8305 var _this = this;
8306 if (this.isPaused) {
8307 return;
8308 }
8309 this._animationTimeRestarted = Date.now();
8310 this.isCursorVisible = true;
8311 if (!this._animationFrame) {
8312 this._animationFrame = window.requestAnimationFrame(function () {
8313 _this._renderCallback();
8314 _this._animationFrame = null;
8315 });
8316 }
8317 };
8318 CursorBlinkStateManager.prototype._restartInterval = function (timeToStart) {
8319 var _this = this;
8320 if (timeToStart === void 0) { timeToStart = BLINK_INTERVAL; }
8321 if (this._blinkInterval) {
8322 window.clearInterval(this._blinkInterval);
8323 }
8324 this._blinkStartTimeout = setTimeout(function () {
8325 if (_this._animationTimeRestarted) {
8326 var time = BLINK_INTERVAL - (Date.now() - _this._animationTimeRestarted);
8327 _this._animationTimeRestarted = null;
8328 if (time > 0) {
8329 _this._restartInterval(time);
8330 return;
8331 }
8332 }
8333 _this.isCursorVisible = false;
8334 _this._animationFrame = window.requestAnimationFrame(function () {
8335 _this._renderCallback();
8336 _this._animationFrame = null;
8337 });
8338 _this._blinkInterval = setInterval(function () {
8339 if (_this._animationTimeRestarted) {
8340 var time = BLINK_INTERVAL - (Date.now() - _this._animationTimeRestarted);
8341 _this._animationTimeRestarted = null;
8342 _this._restartInterval(time);
8343 return;
8344 }
8345 _this.isCursorVisible = !_this.isCursorVisible;
8346 _this._animationFrame = window.requestAnimationFrame(function () {
8347 _this._renderCallback();
8348 _this._animationFrame = null;
8349 });
8350 }, BLINK_INTERVAL);
8351 }, timeToStart);
8352 };
8353 CursorBlinkStateManager.prototype.pause = function () {
8354 this.isCursorVisible = true;
8355 if (this._blinkInterval) {
8356 window.clearInterval(this._blinkInterval);
8357 this._blinkInterval = null;
8358 }
8359 if (this._blinkStartTimeout) {
8360 window.clearTimeout(this._blinkStartTimeout);
8361 this._blinkStartTimeout = null;
8362 }
8363 if (this._animationFrame) {
8364 window.cancelAnimationFrame(this._animationFrame);
8365 this._animationFrame = null;
8366 }
8367 };
8368 CursorBlinkStateManager.prototype.resume = function (terminal) {
8369 this._animationTimeRestarted = null;
8370 this._restartInterval();
8371 this.restartBlinkAnimation(terminal);
8372 };
8373 return CursorBlinkStateManager;
8374 }());
8375
8376 },{"../BufferLine":3,"./BaseRenderLayer":35}],39:[function(require,module,exports){
8377 "use strict";
8378 Object.defineProperty(exports, "__esModule", { value: true });
8379 var GridCache = (function () {
8380 function GridCache() {
8381 this.cache = [];
8382 }
8383 GridCache.prototype.resize = function (width, height) {
8384 for (var x = 0; x < width; x++) {
8385 if (this.cache.length <= x) {
8386 this.cache.push([]);
8387 }
8388 for (var y = this.cache[x].length; y < height; y++) {
8389 this.cache[x].push(null);
8390 }
8391 this.cache[x].length = height;
8392 }
8393 this.cache.length = width;
8394 };
8395 GridCache.prototype.clear = function () {
8396 for (var x = 0; x < this.cache.length; x++) {
8397 for (var y = 0; y < this.cache[x].length; y++) {
8398 this.cache[x][y] = null;
8399 }
8400 }
8401 };
8402 return GridCache;
8403 }());
8404 exports.GridCache = GridCache;
8405
8406 },{}],40:[function(require,module,exports){
8407 "use strict";
8408 var __extends = (this && this.__extends) || (function () {
8409 var extendStatics = function (d, b) {
8410 extendStatics = Object.setPrototypeOf ||
8411 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8412 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8413 return extendStatics(d, b);
8414 };
8415 return function (d, b) {
8416 extendStatics(d, b);
8417 function __() { this.constructor = d; }
8418 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8419 };
8420 })();
8421 Object.defineProperty(exports, "__esModule", { value: true });
8422 var BaseRenderLayer_1 = require("./BaseRenderLayer");
8423 var Types_1 = require("./atlas/Types");
8424 var CharAtlasUtils_1 = require("./atlas/CharAtlasUtils");
8425 var LinkRenderLayer = (function (_super) {
8426 __extends(LinkRenderLayer, _super);
8427 function LinkRenderLayer(container, zIndex, colors, terminal) {
8428 var _this = _super.call(this, container, 'link', zIndex, true, colors) || this;
8429 _this._state = null;
8430 terminal.linkifier.onLinkHover(function (e) { return _this._onLinkHover(e); });
8431 terminal.linkifier.onLinkLeave(function (e) { return _this._onLinkLeave(e); });
8432 return _this;
8433 }
8434 LinkRenderLayer.prototype.resize = function (terminal, dim) {
8435 _super.prototype.resize.call(this, terminal, dim);
8436 this._state = null;
8437 };
8438 LinkRenderLayer.prototype.reset = function (terminal) {
8439 this._clearCurrentLink();
8440 };
8441 LinkRenderLayer.prototype._clearCurrentLink = function () {
8442 if (this._state) {
8443 this.clearCells(this._state.x1, this._state.y1, this._state.cols - this._state.x1, 1);
8444 var middleRowCount = this._state.y2 - this._state.y1 - 1;
8445 if (middleRowCount > 0) {
8446 this.clearCells(0, this._state.y1 + 1, this._state.cols, middleRowCount);
8447 }
8448 this.clearCells(0, this._state.y2, this._state.x2, 1);
8449 this._state = null;
8450 }
8451 };
8452 LinkRenderLayer.prototype._onLinkHover = function (e) {
8453 if (e.fg === Types_1.INVERTED_DEFAULT_COLOR) {
8454 this._ctx.fillStyle = this._colors.background.css;
8455 }
8456 else if (CharAtlasUtils_1.is256Color(e.fg)) {
8457 this._ctx.fillStyle = this._colors.ansi[e.fg].css;
8458 }
8459 else {
8460 this._ctx.fillStyle = this._colors.foreground.css;
8461 }
8462 if (e.y1 === e.y2) {
8463 this.fillBottomLineAtCells(e.x1, e.y1, e.x2 - e.x1);
8464 }
8465 else {
8466 this.fillBottomLineAtCells(e.x1, e.y1, e.cols - e.x1);
8467 for (var y = e.y1 + 1; y < e.y2; y++) {
8468 this.fillBottomLineAtCells(0, y, e.cols);
8469 }
8470 this.fillBottomLineAtCells(0, e.y2, e.x2);
8471 }
8472 this._state = e;
8473 };
8474 LinkRenderLayer.prototype._onLinkLeave = function (e) {
8475 this._clearCurrentLink();
8476 };
8477 return LinkRenderLayer;
8478 }(BaseRenderLayer_1.BaseRenderLayer));
8479 exports.LinkRenderLayer = LinkRenderLayer;
8480
8481 },{"./BaseRenderLayer":35,"./atlas/CharAtlasUtils":47,"./atlas/Types":52}],41:[function(require,module,exports){
8482 "use strict";
8483 var __extends = (this && this.__extends) || (function () {
8484 var extendStatics = function (d, b) {
8485 extendStatics = Object.setPrototypeOf ||
8486 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8487 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8488 return extendStatics(d, b);
8489 };
8490 return function (d, b) {
8491 extendStatics(d, b);
8492 function __() { this.constructor = d; }
8493 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8494 };
8495 })();
8496 Object.defineProperty(exports, "__esModule", { value: true });
8497 var TextRenderLayer_1 = require("./TextRenderLayer");
8498 var SelectionRenderLayer_1 = require("./SelectionRenderLayer");
8499 var CursorRenderLayer_1 = require("./CursorRenderLayer");
8500 var ColorManager_1 = require("./ColorManager");
8501 var LinkRenderLayer_1 = require("./LinkRenderLayer");
8502 var RenderDebouncer_1 = require("../ui/RenderDebouncer");
8503 var ScreenDprMonitor_1 = require("../ui/ScreenDprMonitor");
8504 var CharacterJoinerRegistry_1 = require("../renderer/CharacterJoinerRegistry");
8505 var EventEmitter2_1 = require("../common/EventEmitter2");
8506 var Lifecycle_1 = require("../common/Lifecycle");
8507 var Renderer = (function (_super) {
8508 __extends(Renderer, _super);
8509 function Renderer(_terminal, theme) {
8510 var _this = _super.call(this) || this;
8511 _this._terminal = _terminal;
8512 _this._isPaused = false;
8513 _this._needsFullRefresh = false;
8514 _this._onCanvasResize = new EventEmitter2_1.EventEmitter2();
8515 _this._onRender = new EventEmitter2_1.EventEmitter2();
8516 var allowTransparency = _this._terminal.options.allowTransparency;
8517 _this.colorManager = new ColorManager_1.ColorManager(document, allowTransparency);
8518 _this._characterJoinerRegistry = new CharacterJoinerRegistry_1.CharacterJoinerRegistry(_terminal);
8519 if (theme) {
8520 _this.colorManager.setTheme(theme);
8521 }
8522 _this._renderLayers = [
8523 new TextRenderLayer_1.TextRenderLayer(_this._terminal.screenElement, 0, _this.colorManager.colors, _this._characterJoinerRegistry, allowTransparency),
8524 new SelectionRenderLayer_1.SelectionRenderLayer(_this._terminal.screenElement, 1, _this.colorManager.colors),
8525 new LinkRenderLayer_1.LinkRenderLayer(_this._terminal.screenElement, 2, _this.colorManager.colors, _this._terminal),
8526 new CursorRenderLayer_1.CursorRenderLayer(_this._terminal.screenElement, 3, _this.colorManager.colors)
8527 ];
8528 _this.dimensions = {
8529 scaledCharWidth: null,
8530 scaledCharHeight: null,
8531 scaledCellWidth: null,
8532 scaledCellHeight: null,
8533 scaledCharLeft: null,
8534 scaledCharTop: null,
8535 scaledCanvasWidth: null,
8536 scaledCanvasHeight: null,
8537 canvasWidth: null,
8538 canvasHeight: null,
8539 actualCellWidth: null,
8540 actualCellHeight: null
8541 };
8542 _this._devicePixelRatio = window.devicePixelRatio;
8543 _this._updateDimensions();
8544 _this.onOptionsChanged();
8545 _this._renderDebouncer = new RenderDebouncer_1.RenderDebouncer(_this._renderRows.bind(_this));
8546 _this._screenDprMonitor = new ScreenDprMonitor_1.ScreenDprMonitor();
8547 _this._screenDprMonitor.setListener(function () { return _this.onWindowResize(window.devicePixelRatio); });
8548 _this.register(_this._screenDprMonitor);
8549 if ('IntersectionObserver' in window) {
8550 var observer_1 = new IntersectionObserver(function (e) { return _this.onIntersectionChange(e[e.length - 1]); }, { threshold: 0 });
8551 observer_1.observe(_this._terminal.element);
8552 _this.register({ dispose: function () { return observer_1.disconnect(); } });
8553 }
8554 return _this;
8555 }
8556 Object.defineProperty(Renderer.prototype, "onCanvasResize", {
8557 get: function () { return this._onCanvasResize.event; },
8558 enumerable: true,
8559 configurable: true
8560 });
8561 Object.defineProperty(Renderer.prototype, "onRender", {
8562 get: function () { return this._onRender.event; },
8563 enumerable: true,
8564 configurable: true
8565 });
8566 Renderer.prototype.dispose = function () {
8567 _super.prototype.dispose.call(this);
8568 this._renderLayers.forEach(function (l) { return l.dispose(); });
8569 };
8570 Renderer.prototype.onIntersectionChange = function (entry) {
8571 this._isPaused = entry.intersectionRatio === 0;
8572 if (!this._isPaused && this._needsFullRefresh) {
8573 this._terminal.refresh(0, this._terminal.rows - 1);
8574 this._needsFullRefresh = false;
8575 }
8576 };
8577 Renderer.prototype.onWindowResize = function (devicePixelRatio) {
8578 if (this._devicePixelRatio !== devicePixelRatio) {
8579 this._devicePixelRatio = devicePixelRatio;
8580 this.onResize(this._terminal.cols, this._terminal.rows);
8581 }
8582 };
8583 Renderer.prototype.setTheme = function (theme) {
8584 var _this = this;
8585 this.colorManager.setTheme(theme);
8586 this._renderLayers.forEach(function (l) {
8587 l.onThemeChanged(_this._terminal, _this.colorManager.colors);
8588 l.reset(_this._terminal);
8589 });
8590 if (this._isPaused) {
8591 this._needsFullRefresh = true;
8592 }
8593 else {
8594 this._terminal.refresh(0, this._terminal.rows - 1);
8595 }
8596 return this.colorManager.colors;
8597 };
8598 Renderer.prototype.onResize = function (cols, rows) {
8599 var _this = this;
8600 this._updateDimensions();
8601 this._renderLayers.forEach(function (l) { return l.resize(_this._terminal, _this.dimensions); });
8602 if (this._isPaused) {
8603 this._needsFullRefresh = true;
8604 }
8605 else {
8606 this._terminal.refresh(0, this._terminal.rows - 1);
8607 }
8608 this._terminal.screenElement.style.width = this.dimensions.canvasWidth + "px";
8609 this._terminal.screenElement.style.height = this.dimensions.canvasHeight + "px";
8610 this._onCanvasResize.fire({
8611 width: this.dimensions.canvasWidth,
8612 height: this.dimensions.canvasHeight
8613 });
8614 };
8615 Renderer.prototype.onCharSizeChanged = function () {
8616 this.onResize(this._terminal.cols, this._terminal.rows);
8617 };
8618 Renderer.prototype.onBlur = function () {
8619 var _this = this;
8620 this._runOperation(function (l) { return l.onBlur(_this._terminal); });
8621 };
8622 Renderer.prototype.onFocus = function () {
8623 var _this = this;
8624 this._runOperation(function (l) { return l.onFocus(_this._terminal); });
8625 };
8626 Renderer.prototype.onSelectionChanged = function (start, end, columnSelectMode) {
8627 var _this = this;
8628 if (columnSelectMode === void 0) { columnSelectMode = false; }
8629 this._runOperation(function (l) { return l.onSelectionChanged(_this._terminal, start, end, columnSelectMode); });
8630 };
8631 Renderer.prototype.onCursorMove = function () {
8632 var _this = this;
8633 this._runOperation(function (l) { return l.onCursorMove(_this._terminal); });
8634 };
8635 Renderer.prototype.onOptionsChanged = function () {
8636 var _this = this;
8637 this.colorManager.allowTransparency = this._terminal.options.allowTransparency;
8638 this._runOperation(function (l) { return l.onOptionsChanged(_this._terminal); });
8639 };
8640 Renderer.prototype.clear = function () {
8641 var _this = this;
8642 this._runOperation(function (l) { return l.reset(_this._terminal); });
8643 };
8644 Renderer.prototype._runOperation = function (operation) {
8645 if (this._isPaused) {
8646 this._needsFullRefresh = true;
8647 }
8648 else {
8649 this._renderLayers.forEach(function (l) { return operation(l); });
8650 }
8651 };
8652 Renderer.prototype.refreshRows = function (start, end) {
8653 if (this._isPaused) {
8654 this._needsFullRefresh = true;
8655 return;
8656 }
8657 this._renderDebouncer.refresh(start, end, this._terminal.rows);
8658 };
8659 Renderer.prototype._renderRows = function (start, end) {
8660 var _this = this;
8661 this._renderLayers.forEach(function (l) { return l.onGridChanged(_this._terminal, start, end); });
8662 this._onRender.fire({ start: start, end: end });
8663 };
8664 Renderer.prototype._updateDimensions = function () {
8665 if (!this._terminal.charMeasure.width || !this._terminal.charMeasure.height) {
8666 return;
8667 }
8668 this.dimensions.scaledCharWidth = Math.floor(this._terminal.charMeasure.width * window.devicePixelRatio);
8669 this.dimensions.scaledCharHeight = Math.ceil(this._terminal.charMeasure.height * window.devicePixelRatio);
8670 this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight);
8671 this.dimensions.scaledCharTop = this._terminal.options.lineHeight === 1 ? 0 : Math.round((this.dimensions.scaledCellHeight - this.dimensions.scaledCharHeight) / 2);
8672 this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing);
8673 this.dimensions.scaledCharLeft = Math.floor(this._terminal.options.letterSpacing / 2);
8674 this.dimensions.scaledCanvasHeight = this._terminal.rows * this.dimensions.scaledCellHeight;
8675 this.dimensions.scaledCanvasWidth = this._terminal.cols * this.dimensions.scaledCellWidth;
8676 this.dimensions.canvasHeight = Math.round(this.dimensions.scaledCanvasHeight / window.devicePixelRatio);
8677 this.dimensions.canvasWidth = Math.round(this.dimensions.scaledCanvasWidth / window.devicePixelRatio);
8678 this.dimensions.actualCellHeight = this.dimensions.canvasHeight / this._terminal.rows;
8679 this.dimensions.actualCellWidth = this.dimensions.canvasWidth / this._terminal.cols;
8680 };
8681 Renderer.prototype.registerCharacterJoiner = function (handler) {
8682 return this._characterJoinerRegistry.registerCharacterJoiner(handler);
8683 };
8684 Renderer.prototype.deregisterCharacterJoiner = function (joinerId) {
8685 return this._characterJoinerRegistry.deregisterCharacterJoiner(joinerId);
8686 };
8687 return Renderer;
8688 }(Lifecycle_1.Disposable));
8689 exports.Renderer = Renderer;
8690
8691 },{"../common/EventEmitter2":25,"../common/Lifecycle":26,"../renderer/CharacterJoinerRegistry":36,"../ui/RenderDebouncer":56,"../ui/ScreenDprMonitor":57,"./ColorManager":37,"./CursorRenderLayer":38,"./LinkRenderLayer":40,"./SelectionRenderLayer":42,"./TextRenderLayer":43}],42:[function(require,module,exports){
8692 "use strict";
8693 var __extends = (this && this.__extends) || (function () {
8694 var extendStatics = function (d, b) {
8695 extendStatics = Object.setPrototypeOf ||
8696 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8697 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8698 return extendStatics(d, b);
8699 };
8700 return function (d, b) {
8701 extendStatics(d, b);
8702 function __() { this.constructor = d; }
8703 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8704 };
8705 })();
8706 Object.defineProperty(exports, "__esModule", { value: true });
8707 var BaseRenderLayer_1 = require("./BaseRenderLayer");
8708 var SelectionRenderLayer = (function (_super) {
8709 __extends(SelectionRenderLayer, _super);
8710 function SelectionRenderLayer(container, zIndex, colors) {
8711 var _this = _super.call(this, container, 'selection', zIndex, true, colors) || this;
8712 _this._clearState();
8713 return _this;
8714 }
8715 SelectionRenderLayer.prototype._clearState = function () {
8716 this._state = {
8717 start: null,
8718 end: null,
8719 columnSelectMode: null,
8720 ydisp: null
8721 };
8722 };
8723 SelectionRenderLayer.prototype.resize = function (terminal, dim) {
8724 _super.prototype.resize.call(this, terminal, dim);
8725 this._clearState();
8726 };
8727 SelectionRenderLayer.prototype.reset = function (terminal) {
8728 if (this._state.start && this._state.end) {
8729 this._clearState();
8730 this.clearAll();
8731 }
8732 };
8733 SelectionRenderLayer.prototype.onSelectionChanged = function (terminal, start, end, columnSelectMode) {
8734 if (!this._didStateChange(start, end, columnSelectMode, terminal.buffer.ydisp)) {
8735 return;
8736 }
8737 this.clearAll();
8738 if (!start || !end) {
8739 this._clearState();
8740 return;
8741 }
8742 var viewportStartRow = start[1] - terminal.buffer.ydisp;
8743 var viewportEndRow = end[1] - terminal.buffer.ydisp;
8744 var viewportCappedStartRow = Math.max(viewportStartRow, 0);
8745 var viewportCappedEndRow = Math.min(viewportEndRow, terminal.rows - 1);
8746 if (viewportCappedStartRow >= terminal.rows || viewportCappedEndRow < 0) {
8747 return;
8748 }
8749 this._ctx.fillStyle = this._colors.selection.css;
8750 if (columnSelectMode) {
8751 var startCol = start[0];
8752 var width = end[0] - startCol;
8753 var height = viewportCappedEndRow - viewportCappedStartRow + 1;
8754 this.fillCells(startCol, viewportCappedStartRow, width, height);
8755 }
8756 else {
8757 var startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
8758 var startRowEndCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : terminal.cols;
8759 this.fillCells(startCol, viewportCappedStartRow, startRowEndCol - startCol, 1);
8760 var middleRowsCount = Math.max(viewportCappedEndRow - viewportCappedStartRow - 1, 0);
8761 this.fillCells(0, viewportCappedStartRow + 1, terminal.cols, middleRowsCount);
8762 if (viewportCappedStartRow !== viewportCappedEndRow) {
8763 var endCol = viewportEndRow === viewportCappedEndRow ? end[0] : terminal.cols;
8764 this.fillCells(0, viewportCappedEndRow, endCol, 1);
8765 }
8766 }
8767 this._state.start = [start[0], start[1]];
8768 this._state.end = [end[0], end[1]];
8769 this._state.columnSelectMode = columnSelectMode;
8770 this._state.ydisp = terminal.buffer.ydisp;
8771 };
8772 SelectionRenderLayer.prototype._didStateChange = function (start, end, columnSelectMode, ydisp) {
8773 return !this._areCoordinatesEqual(start, this._state.start) ||
8774 !this._areCoordinatesEqual(end, this._state.end) ||
8775 columnSelectMode !== this._state.columnSelectMode ||
8776 ydisp !== this._state.ydisp;
8777 };
8778 SelectionRenderLayer.prototype._areCoordinatesEqual = function (coord1, coord2) {
8779 if (!coord1 || !coord2) {
8780 return false;
8781 }
8782 return coord1[0] === coord2[0] && coord1[1] === coord2[1];
8783 };
8784 return SelectionRenderLayer;
8785 }(BaseRenderLayer_1.BaseRenderLayer));
8786 exports.SelectionRenderLayer = SelectionRenderLayer;
8787
8788 },{"./BaseRenderLayer":35}],43:[function(require,module,exports){
8789 "use strict";
8790 var __extends = (this && this.__extends) || (function () {
8791 var extendStatics = function (d, b) {
8792 extendStatics = Object.setPrototypeOf ||
8793 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8794 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8795 return extendStatics(d, b);
8796 };
8797 return function (d, b) {
8798 extendStatics(d, b);
8799 function __() { this.constructor = d; }
8800 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8801 };
8802 })();
8803 Object.defineProperty(exports, "__esModule", { value: true });
8804 var Buffer_1 = require("../Buffer");
8805 var GridCache_1 = require("./GridCache");
8806 var BaseRenderLayer_1 = require("./BaseRenderLayer");
8807 var BufferLine_1 = require("../BufferLine");
8808 var CharacterJoinerRegistry_1 = require("./CharacterJoinerRegistry");
8809 var TextRenderLayer = (function (_super) {
8810 __extends(TextRenderLayer, _super);
8811 function TextRenderLayer(container, zIndex, colors, characterJoinerRegistry, alpha) {
8812 var _this = _super.call(this, container, 'text', zIndex, alpha, colors) || this;
8813 _this._characterOverlapCache = {};
8814 _this._workCell = new BufferLine_1.CellData();
8815 _this._state = new GridCache_1.GridCache();
8816 _this._characterJoinerRegistry = characterJoinerRegistry;
8817 return _this;
8818 }
8819 TextRenderLayer.prototype.resize = function (terminal, dim) {
8820 _super.prototype.resize.call(this, terminal, dim);
8821 var terminalFont = this._getFont(terminal, false, false);
8822 if (this._characterWidth !== dim.scaledCharWidth || this._characterFont !== terminalFont) {
8823 this._characterWidth = dim.scaledCharWidth;
8824 this._characterFont = terminalFont;
8825 this._characterOverlapCache = {};
8826 }
8827 this._state.clear();
8828 this._state.resize(terminal.cols, terminal.rows);
8829 };
8830 TextRenderLayer.prototype.reset = function (terminal) {
8831 this._state.clear();
8832 this.clearAll();
8833 };
8834 TextRenderLayer.prototype._forEachCell = function (terminal, firstRow, lastRow, joinerRegistry, callback) {
8835 for (var y = firstRow; y <= lastRow; y++) {
8836 var row = y + terminal.buffer.ydisp;
8837 var line = terminal.buffer.lines.get(row);
8838 var joinedRanges = joinerRegistry ? joinerRegistry.getJoinedCharacters(row) : [];
8839 for (var x = 0; x < terminal.cols; x++) {
8840 line.loadCell(x, this._workCell);
8841 var cell = this._workCell;
8842 var isJoined = false;
8843 var lastCharX = x;
8844 if (cell.getWidth() === 0) {
8845 continue;
8846 }
8847 if (joinedRanges.length > 0 && x === joinedRanges[0][0]) {
8848 isJoined = true;
8849 var range = joinedRanges.shift();
8850 cell = new CharacterJoinerRegistry_1.JoinedCellData(this._workCell, line.translateToString(true, range[0], range[1]), range[1] - range[0]);
8851 lastCharX = range[1] - 1;
8852 }
8853 if (!isJoined && this._isOverlapping(cell)) {
8854 if (lastCharX < line.length - 1 && line.getCodePoint(lastCharX + 1) === Buffer_1.NULL_CELL_CODE) {
8855 cell.content &= ~12582912;
8856 cell.content |= 2 << 22;
8857 }
8858 }
8859 callback(cell, x, y);
8860 x = lastCharX;
8861 }
8862 }
8863 };
8864 TextRenderLayer.prototype._drawBackground = function (terminal, firstRow, lastRow) {
8865 var _this = this;
8866 var ctx = this._ctx;
8867 var cols = terminal.cols;
8868 var startX = 0;
8869 var startY = 0;
8870 var prevFillStyle = null;
8871 ctx.save();
8872 this._forEachCell(terminal, firstRow, lastRow, null, function (cell, x, y) {
8873 var nextFillStyle = null;
8874 if (cell.isInverse()) {
8875 if (cell.isFgDefault()) {
8876 nextFillStyle = _this._colors.foreground.css;
8877 }
8878 else if (cell.isFgRGB()) {
8879 nextFillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getFgColor()).join(',') + ")";
8880 }
8881 else {
8882 nextFillStyle = _this._colors.ansi[cell.getFgColor()].css;
8883 }
8884 }
8885 else if (cell.isBgRGB()) {
8886 nextFillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getBgColor()).join(',') + ")";
8887 }
8888 else if (cell.isBgPalette()) {
8889 nextFillStyle = _this._colors.ansi[cell.getBgColor()].css;
8890 }
8891 if (prevFillStyle === null) {
8892 startX = x;
8893 startY = y;
8894 }
8895 if (y !== startY) {
8896 ctx.fillStyle = prevFillStyle;
8897 _this.fillCells(startX, startY, cols - startX, 1);
8898 startX = x;
8899 startY = y;
8900 }
8901 else if (prevFillStyle !== nextFillStyle) {
8902 ctx.fillStyle = prevFillStyle;
8903 _this.fillCells(startX, startY, x - startX, 1);
8904 startX = x;
8905 startY = y;
8906 }
8907 prevFillStyle = nextFillStyle;
8908 });
8909 if (prevFillStyle !== null) {
8910 ctx.fillStyle = prevFillStyle;
8911 this.fillCells(startX, startY, cols - startX, 1);
8912 }
8913 ctx.restore();
8914 };
8915 TextRenderLayer.prototype._drawForeground = function (terminal, firstRow, lastRow) {
8916 var _this = this;
8917 this._forEachCell(terminal, firstRow, lastRow, this._characterJoinerRegistry, function (cell, x, y) {
8918 if (cell.isInvisible()) {
8919 return;
8920 }
8921 if (cell.isUnderline()) {
8922 _this._ctx.save();
8923 if (cell.isInverse()) {
8924 if (cell.isBgDefault()) {
8925 _this._ctx.fillStyle = _this._colors.background.css;
8926 }
8927 else if (cell.isBgRGB()) {
8928 _this._ctx.fillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getBgColor()).join(',') + ")";
8929 }
8930 else {
8931 _this._ctx.fillStyle = _this._colors.ansi[cell.getBgColor()].css;
8932 }
8933 }
8934 else {
8935 if (cell.isFgDefault()) {
8936 _this._ctx.fillStyle = _this._colors.foreground.css;
8937 }
8938 else if (cell.isFgRGB()) {
8939 _this._ctx.fillStyle = "rgb(" + BufferLine_1.AttributeData.toColorRGB(cell.getFgColor()).join(',') + ")";
8940 }
8941 else {
8942 var fg = cell.getFgColor();
8943 if (terminal.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8) {
8944 fg += 8;
8945 }
8946 _this._ctx.fillStyle = _this._colors.ansi[fg].css;
8947 }
8948 }
8949 _this.fillBottomLineAtCells(x, y, cell.getWidth());
8950 _this._ctx.restore();
8951 }
8952 _this.drawChars(terminal, cell, x, y);
8953 });
8954 };
8955 TextRenderLayer.prototype.onGridChanged = function (terminal, firstRow, lastRow) {
8956 if (this._state.cache.length === 0) {
8957 return;
8958 }
8959 if (this._charAtlas) {
8960 this._charAtlas.beginFrame();
8961 }
8962 this.clearCells(0, firstRow, terminal.cols, lastRow - firstRow + 1);
8963 this._drawBackground(terminal, firstRow, lastRow);
8964 this._drawForeground(terminal, firstRow, lastRow);
8965 };
8966 TextRenderLayer.prototype.onOptionsChanged = function (terminal) {
8967 this.setTransparency(terminal, terminal.options.allowTransparency);
8968 };
8969 TextRenderLayer.prototype._isOverlapping = function (cell) {
8970 if (cell.getWidth() !== 1) {
8971 return false;
8972 }
8973 if (cell.getCode() < 256) {
8974 return false;
8975 }
8976 var chars = cell.getChars();
8977 if (this._characterOverlapCache.hasOwnProperty(chars)) {
8978 return this._characterOverlapCache[chars];
8979 }
8980 this._ctx.save();
8981 this._ctx.font = this._characterFont;
8982 var overlaps = Math.floor(this._ctx.measureText(chars).width) > this._characterWidth;
8983 this._ctx.restore();
8984 this._characterOverlapCache[chars] = overlaps;
8985 return overlaps;
8986 };
8987 return TextRenderLayer;
8988 }(BaseRenderLayer_1.BaseRenderLayer));
8989 exports.TextRenderLayer = TextRenderLayer;
8990
8991 },{"../Buffer":2,"../BufferLine":3,"./BaseRenderLayer":35,"./CharacterJoinerRegistry":36,"./GridCache":39}],44:[function(require,module,exports){
8992 "use strict";
8993 Object.defineProperty(exports, "__esModule", { value: true });
8994 var BaseCharAtlas = (function () {
8995 function BaseCharAtlas() {
8996 this._didWarmUp = false;
8997 }
8998 BaseCharAtlas.prototype.dispose = function () { };
8999 BaseCharAtlas.prototype.warmUp = function () {
9000 if (!this._didWarmUp) {
9001 this._doWarmUp();
9002 this._didWarmUp = true;
9003 }
9004 };
9005 BaseCharAtlas.prototype._doWarmUp = function () { };
9006 BaseCharAtlas.prototype.beginFrame = function () { };
9007 return BaseCharAtlas;
9008 }());
9009 exports.default = BaseCharAtlas;
9010
9011 },{}],45:[function(require,module,exports){
9012 "use strict";
9013 Object.defineProperty(exports, "__esModule", { value: true });
9014 var CharAtlasUtils_1 = require("./CharAtlasUtils");
9015 var DynamicCharAtlas_1 = require("./DynamicCharAtlas");
9016 var NoneCharAtlas_1 = require("./NoneCharAtlas");
9017 var StaticCharAtlas_1 = require("./StaticCharAtlas");
9018 var charAtlasImplementations = {
9019 'none': NoneCharAtlas_1.default,
9020 'static': StaticCharAtlas_1.default,
9021 'dynamic': DynamicCharAtlas_1.default
9022 };
9023 var charAtlasCache = [];
9024 function acquireCharAtlas(terminal, colors, scaledCharWidth, scaledCharHeight) {
9025 var newConfig = CharAtlasUtils_1.generateConfig(scaledCharWidth, scaledCharHeight, terminal, colors);
9026 for (var i = 0; i < charAtlasCache.length; i++) {
9027 var entry = charAtlasCache[i];
9028 var ownedByIndex = entry.ownedBy.indexOf(terminal);
9029 if (ownedByIndex >= 0) {
9030 if (CharAtlasUtils_1.configEquals(entry.config, newConfig)) {
9031 return entry.atlas;
9032 }
9033 if (entry.ownedBy.length === 1) {
9034 entry.atlas.dispose();
9035 charAtlasCache.splice(i, 1);
9036 }
9037 else {
9038 entry.ownedBy.splice(ownedByIndex, 1);
9039 }
9040 break;
9041 }
9042 }
9043 for (var i = 0; i < charAtlasCache.length; i++) {
9044 var entry = charAtlasCache[i];
9045 if (CharAtlasUtils_1.configEquals(entry.config, newConfig)) {
9046 entry.ownedBy.push(terminal);
9047 return entry.atlas;
9048 }
9049 }
9050 var newEntry = {
9051 atlas: new charAtlasImplementations[terminal.options.experimentalCharAtlas](document, newConfig),
9052 config: newConfig,
9053 ownedBy: [terminal]
9054 };
9055 charAtlasCache.push(newEntry);
9056 return newEntry.atlas;
9057 }
9058 exports.acquireCharAtlas = acquireCharAtlas;
9059 function removeTerminalFromCache(terminal) {
9060 for (var i = 0; i < charAtlasCache.length; i++) {
9061 var index = charAtlasCache[i].ownedBy.indexOf(terminal);
9062 if (index !== -1) {
9063 if (charAtlasCache[i].ownedBy.length === 1) {
9064 charAtlasCache[i].atlas.dispose();
9065 charAtlasCache.splice(i, 1);
9066 }
9067 else {
9068 charAtlasCache[i].ownedBy.splice(index, 1);
9069 }
9070 break;
9071 }
9072 }
9073 }
9074 exports.removeTerminalFromCache = removeTerminalFromCache;
9075
9076 },{"./CharAtlasUtils":47,"./DynamicCharAtlas":48,"./NoneCharAtlas":50,"./StaticCharAtlas":51}],46:[function(require,module,exports){
9077 "use strict";
9078 Object.defineProperty(exports, "__esModule", { value: true });
9079 var Platform_1 = require("../../common/Platform");
9080 var Types_1 = require("./Types");
9081 function generateStaticCharAtlasTexture(context, canvasFactory, config) {
9082 var cellWidth = config.scaledCharWidth + Types_1.CHAR_ATLAS_CELL_SPACING;
9083 var cellHeight = config.scaledCharHeight + Types_1.CHAR_ATLAS_CELL_SPACING;
9084 var canvas = canvasFactory(255 * cellWidth, (2 + 16 + 16) * cellHeight);
9085 var ctx = canvas.getContext('2d', { alpha: config.allowTransparency });
9086 ctx.fillStyle = config.colors.background.css;
9087 ctx.fillRect(0, 0, canvas.width, canvas.height);
9088 ctx.save();
9089 ctx.fillStyle = config.colors.foreground.css;
9090 ctx.font = getFont(config.fontWeight, config);
9091 ctx.textBaseline = 'middle';
9092 for (var i = 0; i < 256; i++) {
9093 ctx.save();
9094 ctx.beginPath();
9095 ctx.rect(i * cellWidth, 0, cellWidth, cellHeight);
9096 ctx.clip();
9097 ctx.fillText(String.fromCharCode(i), i * cellWidth, cellHeight / 2);
9098 ctx.restore();
9099 }
9100 ctx.save();
9101 ctx.font = getFont(config.fontWeightBold, config);
9102 for (var i = 0; i < 256; i++) {
9103 ctx.save();
9104 ctx.beginPath();
9105 ctx.rect(i * cellWidth, cellHeight, cellWidth, cellHeight);
9106 ctx.clip();
9107 ctx.fillText(String.fromCharCode(i), i * cellWidth, cellHeight * 1.5);
9108 ctx.restore();
9109 }
9110 ctx.restore();
9111 ctx.font = getFont(config.fontWeight, config);
9112 for (var colorIndex = 0; colorIndex < 16; colorIndex++) {
9113 var y = (colorIndex + 2) * cellHeight;
9114 for (var i = 0; i < 256; i++) {
9115 ctx.save();
9116 ctx.beginPath();
9117 ctx.rect(i * cellWidth, y, cellWidth, cellHeight);
9118 ctx.clip();
9119 ctx.fillStyle = config.colors.ansi[colorIndex].css;
9120 ctx.fillText(String.fromCharCode(i), i * cellWidth, y + cellHeight / 2);
9121 ctx.restore();
9122 }
9123 }
9124 ctx.font = getFont(config.fontWeightBold, config);
9125 for (var colorIndex = 0; colorIndex < 16; colorIndex++) {
9126 var y = (colorIndex + 2 + 16) * cellHeight;
9127 for (var i = 0; i < 256; i++) {
9128 ctx.save();
9129 ctx.beginPath();
9130 ctx.rect(i * cellWidth, y, cellWidth, cellHeight);
9131 ctx.clip();
9132 ctx.fillStyle = config.colors.ansi[colorIndex].css;
9133 ctx.fillText(String.fromCharCode(i), i * cellWidth, y + cellHeight / 2);
9134 ctx.restore();
9135 }
9136 }
9137 ctx.restore();
9138 if (!('createImageBitmap' in context) || Platform_1.isFirefox || Platform_1.isSafari) {
9139 return canvas;
9140 }
9141 var charAtlasImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
9142 clearColor(charAtlasImageData, config.colors.background);
9143 return context.createImageBitmap(charAtlasImageData);
9144 }
9145 exports.generateStaticCharAtlasTexture = generateStaticCharAtlasTexture;
9146 function clearColor(imageData, color) {
9147 var isEmpty = true;
9148 var r = color.rgba >>> 24;
9149 var g = color.rgba >>> 16 & 0xFF;
9150 var b = color.rgba >>> 8 & 0xFF;
9151 for (var offset = 0; offset < imageData.data.length; offset += 4) {
9152 if (imageData.data[offset] === r &&
9153 imageData.data[offset + 1] === g &&
9154 imageData.data[offset + 2] === b) {
9155 imageData.data[offset + 3] = 0;
9156 }
9157 else {
9158 isEmpty = false;
9159 }
9160 }
9161 return isEmpty;
9162 }
9163 exports.clearColor = clearColor;
9164 function getFont(fontWeight, config) {
9165 return fontWeight + " " + config.fontSize * config.devicePixelRatio + "px " + config.fontFamily;
9166 }
9167
9168 },{"../../common/Platform":27,"./Types":52}],47:[function(require,module,exports){
9169 "use strict";
9170 Object.defineProperty(exports, "__esModule", { value: true });
9171 var Types_1 = require("./Types");
9172 function generateConfig(scaledCharWidth, scaledCharHeight, terminal, colors) {
9173 var clonedColors = {
9174 foreground: colors.foreground,
9175 background: colors.background,
9176 cursor: null,
9177 cursorAccent: null,
9178 selection: null,
9179 ansi: colors.ansi.slice(0, 16)
9180 };
9181 return {
9182 type: terminal.options.experimentalCharAtlas,
9183 devicePixelRatio: window.devicePixelRatio,
9184 scaledCharWidth: scaledCharWidth,
9185 scaledCharHeight: scaledCharHeight,
9186 fontFamily: terminal.options.fontFamily,
9187 fontSize: terminal.options.fontSize,
9188 fontWeight: terminal.options.fontWeight,
9189 fontWeightBold: terminal.options.fontWeightBold,
9190 allowTransparency: terminal.options.allowTransparency,
9191 colors: clonedColors
9192 };
9193 }
9194 exports.generateConfig = generateConfig;
9195 function configEquals(a, b) {
9196 for (var i = 0; i < a.colors.ansi.length; i++) {
9197 if (a.colors.ansi[i].rgba !== b.colors.ansi[i].rgba) {
9198 return false;
9199 }
9200 }
9201 return a.type === b.type &&
9202 a.devicePixelRatio === b.devicePixelRatio &&
9203 a.fontFamily === b.fontFamily &&
9204 a.fontSize === b.fontSize &&
9205 a.fontWeight === b.fontWeight &&
9206 a.fontWeightBold === b.fontWeightBold &&
9207 a.allowTransparency === b.allowTransparency &&
9208 a.scaledCharWidth === b.scaledCharWidth &&
9209 a.scaledCharHeight === b.scaledCharHeight &&
9210 a.colors.foreground === b.colors.foreground &&
9211 a.colors.background === b.colors.background;
9212 }
9213 exports.configEquals = configEquals;
9214 function is256Color(colorCode) {
9215 return colorCode < Types_1.DEFAULT_COLOR;
9216 }
9217 exports.is256Color = is256Color;
9218
9219 },{"./Types":52}],48:[function(require,module,exports){
9220 "use strict";
9221 var __extends = (this && this.__extends) || (function () {
9222 var extendStatics = function (d, b) {
9223 extendStatics = Object.setPrototypeOf ||
9224 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9225 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9226 return extendStatics(d, b);
9227 };
9228 return function (d, b) {
9229 extendStatics(d, b);
9230 function __() { this.constructor = d; }
9231 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9232 };
9233 })();
9234 Object.defineProperty(exports, "__esModule", { value: true });
9235 var Types_1 = require("./Types");
9236 var BaseCharAtlas_1 = require("./BaseCharAtlas");
9237 var ColorManager_1 = require("../ColorManager");
9238 var CharAtlasGenerator_1 = require("./CharAtlasGenerator");
9239 var LRUMap_1 = require("./LRUMap");
9240 var Platform_1 = require("../../common/Platform");
9241 var TEXTURE_WIDTH = 1024;
9242 var TEXTURE_HEIGHT = 1024;
9243 var TRANSPARENT_COLOR = {
9244 css: 'rgba(0, 0, 0, 0)',
9245 rgba: 0
9246 };
9247 var FRAME_CACHE_DRAW_LIMIT = 100;
9248 var GLYPH_BITMAP_COMMIT_DELAY = 100;
9249 function getGlyphCacheKey(glyph) {
9250 return glyph.code << 21 | glyph.bg << 12 | glyph.fg << 3 | (glyph.bold ? 0 : 4) + (glyph.dim ? 0 : 2) + (glyph.italic ? 0 : 1);
9251 }
9252 exports.getGlyphCacheKey = getGlyphCacheKey;
9253 var DynamicCharAtlas = (function (_super) {
9254 __extends(DynamicCharAtlas, _super);
9255 function DynamicCharAtlas(document, _config) {
9256 var _this = _super.call(this) || this;
9257 _this._config = _config;
9258 _this._drawToCacheCount = 0;
9259 _this._glyphsWaitingOnBitmap = [];
9260 _this._bitmapCommitTimeout = null;
9261 _this._bitmap = null;
9262 _this._cacheCanvas = document.createElement('canvas');
9263 _this._cacheCanvas.width = TEXTURE_WIDTH;
9264 _this._cacheCanvas.height = TEXTURE_HEIGHT;
9265 _this._cacheCtx = _this._cacheCanvas.getContext('2d', { alpha: true });
9266 var tmpCanvas = document.createElement('canvas');
9267 tmpCanvas.width = _this._config.scaledCharWidth;
9268 tmpCanvas.height = _this._config.scaledCharHeight;
9269 _this._tmpCtx = tmpCanvas.getContext('2d', { alpha: _this._config.allowTransparency });
9270 _this._width = Math.floor(TEXTURE_WIDTH / _this._config.scaledCharWidth);
9271 _this._height = Math.floor(TEXTURE_HEIGHT / _this._config.scaledCharHeight);
9272 var capacity = _this._width * _this._height;
9273 _this._cacheMap = new LRUMap_1.default(capacity);
9274 _this._cacheMap.prealloc(capacity);
9275 return _this;
9276 }
9277 DynamicCharAtlas.prototype.dispose = function () {
9278 if (this._bitmapCommitTimeout !== null) {
9279 window.clearTimeout(this._bitmapCommitTimeout);
9280 this._bitmapCommitTimeout = null;
9281 }
9282 };
9283 DynamicCharAtlas.prototype.beginFrame = function () {
9284 this._drawToCacheCount = 0;
9285 };
9286 DynamicCharAtlas.prototype.draw = function (ctx, glyph, x, y) {
9287 if (glyph.code === 32) {
9288 return true;
9289 }
9290 if (!this._canCache(glyph)) {
9291 return false;
9292 }
9293 var glyphKey = getGlyphCacheKey(glyph);
9294 var cacheValue = this._cacheMap.get(glyphKey);
9295 if (cacheValue !== null && cacheValue !== undefined) {
9296 this._drawFromCache(ctx, cacheValue, x, y);
9297 return true;
9298 }
9299 else if (this._drawToCacheCount < FRAME_CACHE_DRAW_LIMIT) {
9300 var index = void 0;
9301 if (this._cacheMap.size < this._cacheMap.capacity) {
9302 index = this._cacheMap.size;
9303 }
9304 else {
9305 index = this._cacheMap.peek().index;
9306 }
9307 var cacheValue_1 = this._drawToCache(glyph, index);
9308 this._cacheMap.set(glyphKey, cacheValue_1);
9309 this._drawFromCache(ctx, cacheValue_1, x, y);
9310 return true;
9311 }
9312 return false;
9313 };
9314 DynamicCharAtlas.prototype._canCache = function (glyph) {
9315 return glyph.code < 256;
9316 };
9317 DynamicCharAtlas.prototype._toCoordinateX = function (index) {
9318 return (index % this._width) * this._config.scaledCharWidth;
9319 };
9320 DynamicCharAtlas.prototype._toCoordinateY = function (index) {
9321 return Math.floor(index / this._width) * this._config.scaledCharHeight;
9322 };
9323 DynamicCharAtlas.prototype._drawFromCache = function (ctx, cacheValue, x, y) {
9324 if (cacheValue.isEmpty) {
9325 return;
9326 }
9327 var cacheX = this._toCoordinateX(cacheValue.index);
9328 var cacheY = this._toCoordinateY(cacheValue.index);
9329 ctx.drawImage(cacheValue.inBitmap ? this._bitmap : this._cacheCanvas, cacheX, cacheY, this._config.scaledCharWidth, this._config.scaledCharHeight, x, y, this._config.scaledCharWidth, this._config.scaledCharHeight);
9330 };
9331 DynamicCharAtlas.prototype._getColorFromAnsiIndex = function (idx) {
9332 if (idx < this._config.colors.ansi.length) {
9333 return this._config.colors.ansi[idx];
9334 }
9335 return ColorManager_1.DEFAULT_ANSI_COLORS[idx];
9336 };
9337 DynamicCharAtlas.prototype._getBackgroundColor = function (glyph) {
9338 if (this._config.allowTransparency) {
9339 return TRANSPARENT_COLOR;
9340 }
9341 else if (glyph.bg === Types_1.INVERTED_DEFAULT_COLOR) {
9342 return this._config.colors.foreground;
9343 }
9344 else if (glyph.bg < 256) {
9345 return this._getColorFromAnsiIndex(glyph.bg);
9346 }
9347 return this._config.colors.background;
9348 };
9349 DynamicCharAtlas.prototype._getForegroundColor = function (glyph) {
9350 if (glyph.fg === Types_1.INVERTED_DEFAULT_COLOR) {
9351 return this._config.colors.background;
9352 }
9353 else if (glyph.fg < 256) {
9354 return this._getColorFromAnsiIndex(glyph.fg);
9355 }
9356 return this._config.colors.foreground;
9357 };
9358 DynamicCharAtlas.prototype._drawToCache = function (glyph, index) {
9359 this._drawToCacheCount++;
9360 this._tmpCtx.save();
9361 var backgroundColor = this._getBackgroundColor(glyph);
9362 this._tmpCtx.globalCompositeOperation = 'copy';
9363 this._tmpCtx.fillStyle = backgroundColor.css;
9364 this._tmpCtx.fillRect(0, 0, this._config.scaledCharWidth, this._config.scaledCharHeight);
9365 this._tmpCtx.globalCompositeOperation = 'source-over';
9366 var fontWeight = glyph.bold ? this._config.fontWeightBold : this._config.fontWeight;
9367 var fontStyle = glyph.italic ? 'italic' : '';
9368 this._tmpCtx.font =
9369 fontStyle + " " + fontWeight + " " + this._config.fontSize * this._config.devicePixelRatio + "px " + this._config.fontFamily;
9370 this._tmpCtx.textBaseline = 'middle';
9371 this._tmpCtx.fillStyle = this._getForegroundColor(glyph).css;
9372 if (glyph.dim) {
9373 this._tmpCtx.globalAlpha = Types_1.DIM_OPACITY;
9374 }
9375 this._tmpCtx.fillText(glyph.chars, 0, this._config.scaledCharHeight / 2);
9376 this._tmpCtx.restore();
9377 var imageData = this._tmpCtx.getImageData(0, 0, this._config.scaledCharWidth, this._config.scaledCharHeight);
9378 var isEmpty = false;
9379 if (!this._config.allowTransparency) {
9380 isEmpty = CharAtlasGenerator_1.clearColor(imageData, backgroundColor);
9381 }
9382 var x = this._toCoordinateX(index);
9383 var y = this._toCoordinateY(index);
9384 this._cacheCtx.putImageData(imageData, x, y);
9385 var cacheValue = {
9386 index: index,
9387 isEmpty: isEmpty,
9388 inBitmap: false
9389 };
9390 this._addGlyphToBitmap(cacheValue);
9391 return cacheValue;
9392 };
9393 DynamicCharAtlas.prototype._addGlyphToBitmap = function (cacheValue) {
9394 var _this = this;
9395 if (!('createImageBitmap' in window) || Platform_1.isFirefox || Platform_1.isSafari) {
9396 return;
9397 }
9398 this._glyphsWaitingOnBitmap.push(cacheValue);
9399 if (this._bitmapCommitTimeout !== null) {
9400 return;
9401 }
9402 this._bitmapCommitTimeout = window.setTimeout(function () { return _this._generateBitmap(); }, GLYPH_BITMAP_COMMIT_DELAY);
9403 };
9404 DynamicCharAtlas.prototype._generateBitmap = function () {
9405 var _this = this;
9406 var glyphsMovingToBitmap = this._glyphsWaitingOnBitmap;
9407 this._glyphsWaitingOnBitmap = [];
9408 window.createImageBitmap(this._cacheCanvas).then(function (bitmap) {
9409 _this._bitmap = bitmap;
9410 for (var i = 0; i < glyphsMovingToBitmap.length; i++) {
9411 var value = glyphsMovingToBitmap[i];
9412 value.inBitmap = true;
9413 }
9414 });
9415 this._bitmapCommitTimeout = null;
9416 };
9417 return DynamicCharAtlas;
9418 }(BaseCharAtlas_1.default));
9419 exports.default = DynamicCharAtlas;
9420
9421 },{"../../common/Platform":27,"../ColorManager":37,"./BaseCharAtlas":44,"./CharAtlasGenerator":46,"./LRUMap":49,"./Types":52}],49:[function(require,module,exports){
9422 "use strict";
9423 Object.defineProperty(exports, "__esModule", { value: true });
9424 var LRUMap = (function () {
9425 function LRUMap(capacity) {
9426 this.capacity = capacity;
9427 this._map = {};
9428 this._head = null;
9429 this._tail = null;
9430 this._nodePool = [];
9431 this.size = 0;
9432 }
9433 LRUMap.prototype._unlinkNode = function (node) {
9434 var prev = node.prev;
9435 var next = node.next;
9436 if (node === this._head) {
9437 this._head = next;
9438 }
9439 if (node === this._tail) {
9440 this._tail = prev;
9441 }
9442 if (prev !== null) {
9443 prev.next = next;
9444 }
9445 if (next !== null) {
9446 next.prev = prev;
9447 }
9448 };
9449 LRUMap.prototype._appendNode = function (node) {
9450 var tail = this._tail;
9451 if (tail !== null) {
9452 tail.next = node;
9453 }
9454 node.prev = tail;
9455 node.next = null;
9456 this._tail = node;
9457 if (this._head === null) {
9458 this._head = node;
9459 }
9460 };
9461 LRUMap.prototype.prealloc = function (count) {
9462 var nodePool = this._nodePool;
9463 for (var i = 0; i < count; i++) {
9464 nodePool.push({
9465 prev: null,
9466 next: null,
9467 key: null,
9468 value: null
9469 });
9470 }
9471 };
9472 LRUMap.prototype.get = function (key) {
9473 var node = this._map[key];
9474 if (node !== undefined) {
9475 this._unlinkNode(node);
9476 this._appendNode(node);
9477 return node.value;
9478 }
9479 return null;
9480 };
9481 LRUMap.prototype.peekValue = function (key) {
9482 var node = this._map[key];
9483 if (node !== undefined) {
9484 return node.value;
9485 }
9486 return null;
9487 };
9488 LRUMap.prototype.peek = function () {
9489 var head = this._head;
9490 return head === null ? null : head.value;
9491 };
9492 LRUMap.prototype.set = function (key, value) {
9493 var node = this._map[key];
9494 if (node !== undefined) {
9495 node = this._map[key];
9496 this._unlinkNode(node);
9497 node.value = value;
9498 }
9499 else if (this.size >= this.capacity) {
9500 node = this._head;
9501 this._unlinkNode(node);
9502 delete this._map[node.key];
9503 node.key = key;
9504 node.value = value;
9505 this._map[key] = node;
9506 }
9507 else {
9508 var nodePool = this._nodePool;
9509 if (nodePool.length > 0) {
9510 node = nodePool.pop();
9511 node.key = key;
9512 node.value = value;
9513 }
9514 else {
9515 node = {
9516 prev: null,
9517 next: null,
9518 key: key,
9519 value: value
9520 };
9521 }
9522 this._map[key] = node;
9523 this.size++;
9524 }
9525 this._appendNode(node);
9526 };
9527 return LRUMap;
9528 }());
9529 exports.default = LRUMap;
9530
9531 },{}],50:[function(require,module,exports){
9532 "use strict";
9533 var __extends = (this && this.__extends) || (function () {
9534 var extendStatics = function (d, b) {
9535 extendStatics = Object.setPrototypeOf ||
9536 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9537 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9538 return extendStatics(d, b);
9539 };
9540 return function (d, b) {
9541 extendStatics(d, b);
9542 function __() { this.constructor = d; }
9543 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9544 };
9545 })();
9546 Object.defineProperty(exports, "__esModule", { value: true });
9547 var BaseCharAtlas_1 = require("./BaseCharAtlas");
9548 var NoneCharAtlas = (function (_super) {
9549 __extends(NoneCharAtlas, _super);
9550 function NoneCharAtlas(document, config) {
9551 return _super.call(this) || this;
9552 }
9553 NoneCharAtlas.prototype.draw = function (ctx, glyph, x, y) {
9554 return false;
9555 };
9556 return NoneCharAtlas;
9557 }(BaseCharAtlas_1.default));
9558 exports.default = NoneCharAtlas;
9559
9560 },{"./BaseCharAtlas":44}],51:[function(require,module,exports){
9561 "use strict";
9562 var __extends = (this && this.__extends) || (function () {
9563 var extendStatics = function (d, b) {
9564 extendStatics = Object.setPrototypeOf ||
9565 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9566 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9567 return extendStatics(d, b);
9568 };
9569 return function (d, b) {
9570 extendStatics(d, b);
9571 function __() { this.constructor = d; }
9572 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9573 };
9574 })();
9575 Object.defineProperty(exports, "__esModule", { value: true });
9576 var Types_1 = require("./Types");
9577 var CharAtlasGenerator_1 = require("./CharAtlasGenerator");
9578 var BaseCharAtlas_1 = require("./BaseCharAtlas");
9579 var CharAtlasUtils_1 = require("./CharAtlasUtils");
9580 var StaticCharAtlas = (function (_super) {
9581 __extends(StaticCharAtlas, _super);
9582 function StaticCharAtlas(_document, _config) {
9583 var _this = _super.call(this) || this;
9584 _this._document = _document;
9585 _this._config = _config;
9586 _this._canvasFactory = function (width, height) {
9587 var canvas = _this._document.createElement('canvas');
9588 canvas.width = width;
9589 canvas.height = height;
9590 return canvas;
9591 };
9592 return _this;
9593 }
9594 StaticCharAtlas.prototype._doWarmUp = function () {
9595 var _this = this;
9596 var result = CharAtlasGenerator_1.generateStaticCharAtlasTexture(window, this._canvasFactory, this._config);
9597 if (result instanceof HTMLCanvasElement) {
9598 this._texture = result;
9599 }
9600 else {
9601 result.then(function (texture) {
9602 _this._texture = texture;
9603 });
9604 }
9605 };
9606 StaticCharAtlas.prototype._isCached = function (glyph, colorIndex) {
9607 var isAscii = glyph.code < 256;
9608 var isBasicColor = glyph.fg < 16;
9609 var isDefaultColor = glyph.fg === Types_1.DEFAULT_COLOR;
9610 var isDefaultBackground = glyph.bg === Types_1.DEFAULT_COLOR;
9611 return isAscii && (isBasicColor || isDefaultColor) && isDefaultBackground && !glyph.italic;
9612 };
9613 StaticCharAtlas.prototype.draw = function (ctx, glyph, x, y) {
9614 if (this._texture === null || this._texture === undefined) {
9615 return false;
9616 }
9617 var colorIndex = 0;
9618 if (CharAtlasUtils_1.is256Color(glyph.fg)) {
9619 colorIndex = 2 + glyph.fg + (glyph.bold ? 16 : 0);
9620 }
9621 else if (glyph.fg === Types_1.DEFAULT_COLOR) {
9622 if (glyph.bold) {
9623 colorIndex = 1;
9624 }
9625 }
9626 if (!this._isCached(glyph, colorIndex)) {
9627 return false;
9628 }
9629 ctx.save();
9630 var charAtlasCellWidth = this._config.scaledCharWidth + Types_1.CHAR_ATLAS_CELL_SPACING;
9631 var charAtlasCellHeight = this._config.scaledCharHeight + Types_1.CHAR_ATLAS_CELL_SPACING;
9632 if (glyph.dim) {
9633 ctx.globalAlpha = Types_1.DIM_OPACITY;
9634 }
9635 ctx.drawImage(this._texture, glyph.code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._config.scaledCharHeight, x, y, charAtlasCellWidth, this._config.scaledCharHeight);
9636 ctx.restore();
9637 return true;
9638 };
9639 return StaticCharAtlas;
9640 }(BaseCharAtlas_1.default));
9641 exports.default = StaticCharAtlas;
9642
9643 },{"./BaseCharAtlas":44,"./CharAtlasGenerator":46,"./CharAtlasUtils":47,"./Types":52}],52:[function(require,module,exports){
9644 "use strict";
9645 Object.defineProperty(exports, "__esModule", { value: true });
9646 exports.DEFAULT_COLOR = 256;
9647 exports.INVERTED_DEFAULT_COLOR = 257;
9648 exports.DIM_OPACITY = 0.5;
9649 exports.CHAR_ATLAS_CELL_SPACING = 1;
9650
9651 },{}],53:[function(require,module,exports){
9652 "use strict";
9653 var __extends = (this && this.__extends) || (function () {
9654 var extendStatics = function (d, b) {
9655 extendStatics = Object.setPrototypeOf ||
9656 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9657 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9658 return extendStatics(d, b);
9659 };
9660 return function (d, b) {
9661 extendStatics(d, b);
9662 function __() { this.constructor = d; }
9663 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9664 };
9665 })();
9666 Object.defineProperty(exports, "__esModule", { value: true });
9667 var ColorManager_1 = require("../ColorManager");
9668 var RenderDebouncer_1 = require("../../ui/RenderDebouncer");
9669 var DomRendererRowFactory_1 = require("./DomRendererRowFactory");
9670 var Types_1 = require("../atlas/Types");
9671 var EventEmitter2_1 = require("../../common/EventEmitter2");
9672 var Lifecycle_1 = require("../../common/Lifecycle");
9673 var TERMINAL_CLASS_PREFIX = 'xterm-dom-renderer-owner-';
9674 var ROW_CONTAINER_CLASS = 'xterm-rows';
9675 var FG_CLASS_PREFIX = 'xterm-fg-';
9676 var BG_CLASS_PREFIX = 'xterm-bg-';
9677 var FOCUS_CLASS = 'xterm-focus';
9678 var SELECTION_CLASS = 'xterm-selection';
9679 var nextTerminalId = 1;
9680 var DomRenderer = (function (_super) {
9681 __extends(DomRenderer, _super);
9682 function DomRenderer(_terminal, theme) {
9683 var _this = _super.call(this) || this;
9684 _this._terminal = _terminal;
9685 _this._terminalClass = nextTerminalId++;
9686 _this._rowElements = [];
9687 _this._onCanvasResize = new EventEmitter2_1.EventEmitter2();
9688 _this._onRender = new EventEmitter2_1.EventEmitter2();
9689 var allowTransparency = _this._terminal.options.allowTransparency;
9690 _this.colorManager = new ColorManager_1.ColorManager(document, allowTransparency);
9691 _this.setTheme(theme);
9692 _this._rowContainer = document.createElement('div');
9693 _this._rowContainer.classList.add(ROW_CONTAINER_CLASS);
9694 _this._rowContainer.style.lineHeight = 'normal';
9695 _this._rowContainer.setAttribute('aria-hidden', 'true');
9696 _this._refreshRowElements(_this._terminal.cols, _this._terminal.rows);
9697 _this._selectionContainer = document.createElement('div');
9698 _this._selectionContainer.classList.add(SELECTION_CLASS);
9699 _this._selectionContainer.setAttribute('aria-hidden', 'true');
9700 _this.dimensions = {
9701 scaledCharWidth: null,
9702 scaledCharHeight: null,
9703 scaledCellWidth: null,
9704 scaledCellHeight: null,
9705 scaledCharLeft: null,
9706 scaledCharTop: null,
9707 scaledCanvasWidth: null,
9708 scaledCanvasHeight: null,
9709 canvasWidth: null,
9710 canvasHeight: null,
9711 actualCellWidth: null,
9712 actualCellHeight: null
9713 };
9714 _this._updateDimensions();
9715 _this._renderDebouncer = new RenderDebouncer_1.RenderDebouncer(_this._renderRows.bind(_this));
9716 _this._rowFactory = new DomRendererRowFactory_1.DomRendererRowFactory(_terminal.options, document);
9717 _this._terminal.element.classList.add(TERMINAL_CLASS_PREFIX + _this._terminalClass);
9718 _this._terminal.screenElement.appendChild(_this._rowContainer);
9719 _this._terminal.screenElement.appendChild(_this._selectionContainer);
9720 _this._terminal.linkifier.onLinkHover(function (e) { return _this._onLinkHover(e); });
9721 _this._terminal.linkifier.onLinkLeave(function (e) { return _this._onLinkLeave(e); });
9722 return _this;
9723 }
9724 Object.defineProperty(DomRenderer.prototype, "onCanvasResize", {
9725 get: function () { return this._onCanvasResize.event; },
9726 enumerable: true,
9727 configurable: true
9728 });
9729 Object.defineProperty(DomRenderer.prototype, "onRender", {
9730 get: function () { return this._onRender.event; },
9731 enumerable: true,
9732 configurable: true
9733 });
9734 DomRenderer.prototype.dispose = function () {
9735 this._terminal.element.classList.remove(TERMINAL_CLASS_PREFIX + this._terminalClass);
9736 this._terminal.screenElement.removeChild(this._rowContainer);
9737 this._terminal.screenElement.removeChild(this._selectionContainer);
9738 this._terminal.screenElement.removeChild(this._themeStyleElement);
9739 this._terminal.screenElement.removeChild(this._dimensionsStyleElement);
9740 _super.prototype.dispose.call(this);
9741 };
9742 DomRenderer.prototype._updateDimensions = function () {
9743 var _this = this;
9744 this.dimensions.scaledCharWidth = Math.floor(this._terminal.charMeasure.width * window.devicePixelRatio);
9745 this.dimensions.scaledCharHeight = Math.ceil(this._terminal.charMeasure.height * window.devicePixelRatio);
9746 this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing);
9747 this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight);
9748 this.dimensions.scaledCharLeft = 0;
9749 this.dimensions.scaledCharTop = 0;
9750 this.dimensions.scaledCanvasWidth = this.dimensions.scaledCellWidth * this._terminal.cols;
9751 this.dimensions.scaledCanvasHeight = this.dimensions.scaledCellHeight * this._terminal.rows;
9752 this.dimensions.canvasWidth = Math.round(this.dimensions.scaledCanvasWidth / window.devicePixelRatio);
9753 this.dimensions.canvasHeight = Math.round(this.dimensions.scaledCanvasHeight / window.devicePixelRatio);
9754 this.dimensions.actualCellWidth = this.dimensions.canvasWidth / this._terminal.cols;
9755 this.dimensions.actualCellHeight = this.dimensions.canvasHeight / this._terminal.rows;
9756 this._rowElements.forEach(function (element) {
9757 element.style.width = _this.dimensions.canvasWidth + "px";
9758 element.style.height = _this.dimensions.actualCellHeight + "px";
9759 element.style.lineHeight = _this.dimensions.actualCellHeight + "px";
9760 element.style.overflow = 'hidden';
9761 });
9762 if (!this._dimensionsStyleElement) {
9763 this._dimensionsStyleElement = document.createElement('style');
9764 this._terminal.screenElement.appendChild(this._dimensionsStyleElement);
9765 }
9766 var styles = this._terminalSelector + " ." + ROW_CONTAINER_CLASS + " span {" +
9767 " display: inline-block;" +
9768 " height: 100%;" +
9769 " vertical-align: top;" +
9770 (" width: " + this.dimensions.actualCellWidth + "px") +
9771 "}";
9772 this._dimensionsStyleElement.innerHTML = styles;
9773 this._selectionContainer.style.height = this._terminal._viewportElement.style.height;
9774 this._terminal.screenElement.style.width = this.dimensions.canvasWidth + "px";
9775 this._terminal.screenElement.style.height = this.dimensions.canvasHeight + "px";
9776 };
9777 DomRenderer.prototype.setTheme = function (theme) {
9778 var _this = this;
9779 if (theme) {
9780 this.colorManager.setTheme(theme);
9781 }
9782 if (!this._themeStyleElement) {
9783 this._themeStyleElement = document.createElement('style');
9784 this._terminal.screenElement.appendChild(this._themeStyleElement);
9785 }
9786 var styles = this._terminalSelector + " ." + ROW_CONTAINER_CLASS + " {" +
9787 (" color: " + this.colorManager.colors.foreground.css + ";") +
9788 (" background-color: " + this.colorManager.colors.background.css + ";") +
9789 (" font-family: " + this._terminal.getOption('fontFamily') + ";") +
9790 (" font-size: " + this._terminal.getOption('fontSize') + "px;") +
9791 "}";
9792 styles +=
9793 this._terminalSelector + " span:not(." + DomRendererRowFactory_1.BOLD_CLASS + ") {" +
9794 (" font-weight: " + this._terminal.options.fontWeight + ";") +
9795 "}" +
9796 (this._terminalSelector + " span." + DomRendererRowFactory_1.BOLD_CLASS + " {") +
9797 (" font-weight: " + this._terminal.options.fontWeightBold + ";") +
9798 "}" +
9799 (this._terminalSelector + " span." + DomRendererRowFactory_1.ITALIC_CLASS + " {") +
9800 " font-style: italic;" +
9801 "}";
9802 styles +=
9803 "@keyframes blink {" +
9804 " 0% { opacity: 1.0; }" +
9805 " 50% { opacity: 0.0; }" +
9806 " 100% { opacity: 1.0; }" +
9807 "}";
9808 styles +=
9809 this._terminalSelector + " ." + ROW_CONTAINER_CLASS + ":not(." + FOCUS_CLASS + ") ." + DomRendererRowFactory_1.CURSOR_CLASS + " {" +
9810 (" outline: 1px solid " + this.colorManager.colors.cursor.css + ";") +
9811 " outline-offset: -1px;" +
9812 "}" +
9813 (this._terminalSelector + " ." + ROW_CONTAINER_CLASS + "." + FOCUS_CLASS + " ." + DomRendererRowFactory_1.CURSOR_CLASS + "." + DomRendererRowFactory_1.CURSOR_BLINK_CLASS + " {") +
9814 " animation: blink 1s step-end infinite;" +
9815 "}" +
9816 (this._terminalSelector + " ." + ROW_CONTAINER_CLASS + "." + FOCUS_CLASS + " ." + DomRendererRowFactory_1.CURSOR_CLASS + "." + DomRendererRowFactory_1.CURSOR_STYLE_BLOCK_CLASS + " {") +
9817 (" background-color: " + this.colorManager.colors.cursor.css + ";") +
9818 (" color: " + this.colorManager.colors.cursorAccent.css + ";") +
9819 "}" +
9820 (this._terminalSelector + " ." + ROW_CONTAINER_CLASS + "." + FOCUS_CLASS + " ." + DomRendererRowFactory_1.CURSOR_CLASS + "." + DomRendererRowFactory_1.CURSOR_STYLE_BAR_CLASS + " {") +
9821 (" box-shadow: 1px 0 0 " + this.colorManager.colors.cursor.css + " inset;") +
9822 "}" +
9823 (this._terminalSelector + " ." + ROW_CONTAINER_CLASS + "." + FOCUS_CLASS + " ." + DomRendererRowFactory_1.CURSOR_CLASS + "." + DomRendererRowFactory_1.CURSOR_STYLE_UNDERLINE_CLASS + " {") +
9824 (" box-shadow: 0 -1px 0 " + this.colorManager.colors.cursor.css + " inset;") +
9825 "}";
9826 styles +=
9827 this._terminalSelector + " ." + SELECTION_CLASS + " {" +
9828 " position: absolute;" +
9829 " top: 0;" +
9830 " left: 0;" +
9831 " z-index: 1;" +
9832 " pointer-events: none;" +
9833 "}" +
9834 (this._terminalSelector + " ." + SELECTION_CLASS + " div {") +
9835 " position: absolute;" +
9836 (" background-color: " + this.colorManager.colors.selection.css + ";") +
9837 "}";
9838 this.colorManager.colors.ansi.forEach(function (c, i) {
9839 styles +=
9840 _this._terminalSelector + " ." + FG_CLASS_PREFIX + i + " { color: " + c.css + "; }" +
9841 (_this._terminalSelector + " ." + BG_CLASS_PREFIX + i + " { background-color: " + c.css + "; }");
9842 });
9843 styles +=
9844 this._terminalSelector + " ." + FG_CLASS_PREFIX + Types_1.INVERTED_DEFAULT_COLOR + " { color: " + this.colorManager.colors.background.css + "; }" +
9845 (this._terminalSelector + " ." + BG_CLASS_PREFIX + Types_1.INVERTED_DEFAULT_COLOR + " { background-color: " + this.colorManager.colors.foreground.css + "; }");
9846 this._themeStyleElement.innerHTML = styles;
9847 return this.colorManager.colors;
9848 };
9849 DomRenderer.prototype.onWindowResize = function (devicePixelRatio) {
9850 this._updateDimensions();
9851 };
9852 DomRenderer.prototype._refreshRowElements = function (cols, rows) {
9853 for (var i = this._rowElements.length; i <= rows; i++) {
9854 var row = document.createElement('div');
9855 this._rowContainer.appendChild(row);
9856 this._rowElements.push(row);
9857 }
9858 while (this._rowElements.length > rows) {
9859 this._rowContainer.removeChild(this._rowElements.pop());
9860 }
9861 };
9862 DomRenderer.prototype.onResize = function (cols, rows) {
9863 this._refreshRowElements(cols, rows);
9864 this._updateDimensions();
9865 this._onCanvasResize.fire({
9866 width: this.dimensions.canvasWidth,
9867 height: this.dimensions.canvasHeight
9868 });
9869 };
9870 DomRenderer.prototype.onCharSizeChanged = function () {
9871 this._updateDimensions();
9872 };
9873 DomRenderer.prototype.onBlur = function () {
9874 this._rowContainer.classList.remove(FOCUS_CLASS);
9875 };
9876 DomRenderer.prototype.onFocus = function () {
9877 this._rowContainer.classList.add(FOCUS_CLASS);
9878 };
9879 DomRenderer.prototype.onSelectionChanged = function (start, end, columnSelectMode) {
9880 while (this._selectionContainer.children.length) {
9881 this._selectionContainer.removeChild(this._selectionContainer.children[0]);
9882 }
9883 if (!start || !end) {
9884 return;
9885 }
9886 var viewportStartRow = start[1] - this._terminal.buffer.ydisp;
9887 var viewportEndRow = end[1] - this._terminal.buffer.ydisp;
9888 var viewportCappedStartRow = Math.max(viewportStartRow, 0);
9889 var viewportCappedEndRow = Math.min(viewportEndRow, this._terminal.rows - 1);
9890 if (viewportCappedStartRow >= this._terminal.rows || viewportCappedEndRow < 0) {
9891 return;
9892 }
9893 var documentFragment = document.createDocumentFragment();
9894 if (columnSelectMode) {
9895 documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow, start[0], end[0], viewportCappedEndRow - viewportCappedStartRow + 1));
9896 }
9897 else {
9898 var startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
9899 var endCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
9900 documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow, startCol, endCol));
9901 var middleRowsCount = viewportCappedEndRow - viewportCappedStartRow - 1;
9902 documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow + 1, 0, this._terminal.cols, middleRowsCount));
9903 if (viewportCappedStartRow !== viewportCappedEndRow) {
9904 var endCol_1 = viewportEndRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
9905 documentFragment.appendChild(this._createSelectionElement(viewportCappedEndRow, 0, endCol_1));
9906 }
9907 }
9908 this._selectionContainer.appendChild(documentFragment);
9909 };
9910 DomRenderer.prototype._createSelectionElement = function (row, colStart, colEnd, rowCount) {
9911 if (rowCount === void 0) { rowCount = 1; }
9912 var element = document.createElement('div');
9913 element.style.height = rowCount * this.dimensions.actualCellHeight + "px";
9914 element.style.top = row * this.dimensions.actualCellHeight + "px";
9915 element.style.left = colStart * this.dimensions.actualCellWidth + "px";
9916 element.style.width = this.dimensions.actualCellWidth * (colEnd - colStart) + "px";
9917 return element;
9918 };
9919 DomRenderer.prototype.onCursorMove = function () {
9920 };
9921 DomRenderer.prototype.onOptionsChanged = function () {
9922 this._updateDimensions();
9923 this.setTheme(undefined);
9924 this._terminal.refresh(0, this._terminal.rows - 1);
9925 };
9926 DomRenderer.prototype.clear = function () {
9927 this._rowElements.forEach(function (e) { return e.innerHTML = ''; });
9928 };
9929 DomRenderer.prototype.refreshRows = function (start, end) {
9930 this._renderDebouncer.refresh(start, end, this._terminal.rows);
9931 };
9932 DomRenderer.prototype._renderRows = function (start, end) {
9933 var terminal = this._terminal;
9934 var cursorAbsoluteY = terminal.buffer.ybase + terminal.buffer.y;
9935 var cursorX = this._terminal.buffer.x;
9936 var cursorBlink = this._terminal.options.cursorBlink;
9937 for (var y = start; y <= end; y++) {
9938 var rowElement = this._rowElements[y];
9939 rowElement.innerHTML = '';
9940 var row = y + terminal.buffer.ydisp;
9941 var lineData = terminal.buffer.lines.get(row);
9942 var cursorStyle = terminal.options.cursorStyle;
9943 rowElement.appendChild(this._rowFactory.createRow(lineData, row === cursorAbsoluteY, cursorStyle, cursorX, cursorBlink, this.dimensions.actualCellWidth, terminal.cols));
9944 }
9945 this._onRender.fire({ start: start, end: end });
9946 };
9947 Object.defineProperty(DomRenderer.prototype, "_terminalSelector", {
9948 get: function () {
9949 return "." + TERMINAL_CLASS_PREFIX + this._terminalClass;
9950 },
9951 enumerable: true,
9952 configurable: true
9953 });
9954 DomRenderer.prototype.registerCharacterJoiner = function (handler) { return -1; };
9955 DomRenderer.prototype.deregisterCharacterJoiner = function (joinerId) { return false; };
9956 DomRenderer.prototype._onLinkHover = function (e) {
9957 this._setCellUnderline(e.x1, e.x2, e.y1, e.y2, e.cols, true);
9958 };
9959 DomRenderer.prototype._onLinkLeave = function (e) {
9960 this._setCellUnderline(e.x1, e.x2, e.y1, e.y2, e.cols, false);
9961 };
9962 DomRenderer.prototype._setCellUnderline = function (x, x2, y, y2, cols, enabled) {
9963 while (x !== x2 || y !== y2) {
9964 var row = this._rowElements[y];
9965 if (!row) {
9966 return;
9967 }
9968 var span = row.children[x];
9969 if (span) {
9970 span.style.textDecoration = enabled ? 'underline' : 'none';
9971 }
9972 if (++x >= cols) {
9973 x = 0;
9974 y++;
9975 }
9976 }
9977 };
9978 return DomRenderer;
9979 }(Lifecycle_1.Disposable));
9980 exports.DomRenderer = DomRenderer;
9981
9982 },{"../../common/EventEmitter2":25,"../../common/Lifecycle":26,"../../ui/RenderDebouncer":56,"../ColorManager":37,"../atlas/Types":52,"./DomRendererRowFactory":54}],54:[function(require,module,exports){
9983 "use strict";
9984 Object.defineProperty(exports, "__esModule", { value: true });
9985 var Buffer_1 = require("../../Buffer");
9986 var Types_1 = require("../atlas/Types");
9987 var BufferLine_1 = require("../../BufferLine");
9988 exports.BOLD_CLASS = 'xterm-bold';
9989 exports.DIM_CLASS = 'xterm-dim';
9990 exports.ITALIC_CLASS = 'xterm-italic';
9991 exports.UNDERLINE_CLASS = 'xterm-underline';
9992 exports.CURSOR_CLASS = 'xterm-cursor';
9993 exports.CURSOR_BLINK_CLASS = 'xterm-cursor-blink';
9994 exports.CURSOR_STYLE_BLOCK_CLASS = 'xterm-cursor-block';
9995 exports.CURSOR_STYLE_BAR_CLASS = 'xterm-cursor-bar';
9996 exports.CURSOR_STYLE_UNDERLINE_CLASS = 'xterm-cursor-underline';
9997 var DomRendererRowFactory = (function () {
9998 function DomRendererRowFactory(_terminalOptions, _document) {
9999 this._terminalOptions = _terminalOptions;
10000 this._document = _document;
10001 this._workCell = new BufferLine_1.CellData();
10002 }
10003 DomRendererRowFactory.prototype.createRow = function (lineData, isCursorRow, cursorStyle, cursorX, cursorBlink, cellWidth, cols) {
10004 var fragment = this._document.createDocumentFragment();
10005 var lineLength = 0;
10006 for (var x = Math.min(lineData.length, cols) - 1; x >= 0; x--) {
10007 if (lineData.loadCell(x, this._workCell).getCode() !== Buffer_1.NULL_CELL_CODE || (isCursorRow && x === cursorX)) {
10008 lineLength = x + 1;
10009 break;
10010 }
10011 }
10012 for (var x = 0; x < lineLength; x++) {
10013 lineData.loadCell(x, this._workCell);
10014 var width = this._workCell.getWidth();
10015 if (width === 0) {
10016 continue;
10017 }
10018 var charElement = this._document.createElement('span');
10019 if (width > 1) {
10020 charElement.style.width = cellWidth * width + "px";
10021 }
10022 if (isCursorRow && x === cursorX) {
10023 charElement.classList.add(exports.CURSOR_CLASS);
10024 if (cursorBlink) {
10025 charElement.classList.add(exports.CURSOR_BLINK_CLASS);
10026 }
10027 switch (cursorStyle) {
10028 case 'bar':
10029 charElement.classList.add(exports.CURSOR_STYLE_BAR_CLASS);
10030 break;
10031 case 'underline':
10032 charElement.classList.add(exports.CURSOR_STYLE_UNDERLINE_CLASS);
10033 break;
10034 default:
10035 charElement.classList.add(exports.CURSOR_STYLE_BLOCK_CLASS);
10036 break;
10037 }
10038 }
10039 if (this._workCell.isBold() && this._terminalOptions.enableBold) {
10040 charElement.classList.add(exports.BOLD_CLASS);
10041 }
10042 if (this._workCell.isItalic()) {
10043 charElement.classList.add(exports.ITALIC_CLASS);
10044 }
10045 if (this._workCell.isDim()) {
10046 charElement.classList.add(exports.DIM_CLASS);
10047 }
10048 if (this._workCell.isUnderline()) {
10049 charElement.classList.add(exports.UNDERLINE_CLASS);
10050 }
10051 charElement.textContent = this._workCell.getChars() || Buffer_1.WHITESPACE_CELL_CHAR;
10052 var swapColor = this._workCell.isInverse();
10053 if (this._workCell.isFgRGB()) {
10054 var style = charElement.getAttribute('style') || '';
10055 style += (swapColor ? 'background-' : '') + "color:rgb(" + (BufferLine_1.AttributeData.toColorRGB(this._workCell.getFgColor())).join(',') + ");";
10056 charElement.setAttribute('style', style);
10057 }
10058 else if (this._workCell.isFgPalette()) {
10059 var fg = this._workCell.getFgColor();
10060 if (this._workCell.isBold() && fg < 8 && !swapColor &&
10061 this._terminalOptions.enableBold && this._terminalOptions.drawBoldTextInBrightColors) {
10062 fg += 8;
10063 }
10064 charElement.classList.add("xterm-" + (swapColor ? 'b' : 'f') + "g-" + fg);
10065 }
10066 else if (swapColor) {
10067 charElement.classList.add("xterm-bg-" + Types_1.INVERTED_DEFAULT_COLOR);
10068 }
10069 if (this._workCell.isBgRGB()) {
10070 var style = charElement.getAttribute('style') || '';
10071 style += (swapColor ? '' : 'background-') + "color:rgb(" + (BufferLine_1.AttributeData.toColorRGB(this._workCell.getBgColor())).join(',') + ");";
10072 charElement.setAttribute('style', style);
10073 }
10074 else if (this._workCell.isBgPalette()) {
10075 charElement.classList.add("xterm-" + (swapColor ? 'f' : 'b') + "g-" + this._workCell.getBgColor());
10076 }
10077 else if (swapColor) {
10078 charElement.classList.add("xterm-fg-" + Types_1.INVERTED_DEFAULT_COLOR);
10079 }
10080 fragment.appendChild(charElement);
10081 }
10082 return fragment;
10083 };
10084 return DomRendererRowFactory;
10085 }());
10086 exports.DomRendererRowFactory = DomRendererRowFactory;
10087
10088 },{"../../Buffer":2,"../../BufferLine":3,"../atlas/Types":52}],55:[function(require,module,exports){
10089 "use strict";
10090 Object.defineProperty(exports, "__esModule", { value: true });
10091 function addDisposableDomListener(node, type, handler, useCapture) {
10092 node.addEventListener(type, handler, useCapture);
10093 return {
10094 dispose: function () {
10095 if (!handler) {
10096 return;
10097 }
10098 node.removeEventListener(type, handler, useCapture);
10099 }
10100 };
10101 }
10102 exports.addDisposableDomListener = addDisposableDomListener;
10103
10104 },{}],56:[function(require,module,exports){
10105 "use strict";
10106 Object.defineProperty(exports, "__esModule", { value: true });
10107 var RenderDebouncer = (function () {
10108 function RenderDebouncer(_renderCallback) {
10109 this._renderCallback = _renderCallback;
10110 }
10111 RenderDebouncer.prototype.dispose = function () {
10112 if (this._animationFrame) {
10113 window.cancelAnimationFrame(this._animationFrame);
10114 this._animationFrame = undefined;
10115 }
10116 };
10117 RenderDebouncer.prototype.refresh = function (rowStart, rowEnd, rowCount) {
10118 var _this = this;
10119 this._rowCount = rowCount;
10120 rowStart = rowStart !== undefined ? rowStart : 0;
10121 rowEnd = rowEnd !== undefined ? rowEnd : this._rowCount - 1;
10122 this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
10123 this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
10124 if (this._animationFrame) {
10125 return;
10126 }
10127 this._animationFrame = window.requestAnimationFrame(function () { return _this._innerRefresh(); });
10128 };
10129 RenderDebouncer.prototype._innerRefresh = function () {
10130 if (this._rowStart === undefined || this._rowEnd === undefined || this._rowCount === undefined) {
10131 return;
10132 }
10133 this._rowStart = Math.max(this._rowStart, 0);
10134 this._rowEnd = Math.min(this._rowEnd, this._rowCount - 1);
10135 this._renderCallback(this._rowStart, this._rowEnd);
10136 this._rowStart = undefined;
10137 this._rowEnd = undefined;
10138 this._animationFrame = undefined;
10139 };
10140 return RenderDebouncer;
10141 }());
10142 exports.RenderDebouncer = RenderDebouncer;
10143
10144 },{}],57:[function(require,module,exports){
10145 "use strict";
10146 var __extends = (this && this.__extends) || (function () {
10147 var extendStatics = function (d, b) {
10148 extendStatics = Object.setPrototypeOf ||
10149 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10150 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
10151 return extendStatics(d, b);
10152 };
10153 return function (d, b) {
10154 extendStatics(d, b);
10155 function __() { this.constructor = d; }
10156 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10157 };
10158 })();
10159 Object.defineProperty(exports, "__esModule", { value: true });
10160 var Lifecycle_1 = require("../common/Lifecycle");
10161 var ScreenDprMonitor = (function (_super) {
10162 __extends(ScreenDprMonitor, _super);
10163 function ScreenDprMonitor() {
10164 var _this = _super !== null && _super.apply(this, arguments) || this;
10165 _this._currentDevicePixelRatio = window.devicePixelRatio;
10166 return _this;
10167 }
10168 ScreenDprMonitor.prototype.setListener = function (listener) {
10169 var _this = this;
10170 if (this._listener) {
10171 this.clearListener();
10172 }
10173 this._listener = listener;
10174 this._outerListener = function () {
10175 if (!_this._listener) {
10176 return;
10177 }
10178 _this._listener(window.devicePixelRatio, _this._currentDevicePixelRatio);
10179 _this._updateDpr();
10180 };
10181 this._updateDpr();
10182 };
10183 ScreenDprMonitor.prototype.dispose = function () {
10184 _super.prototype.dispose.call(this);
10185 this.clearListener();
10186 };
10187 ScreenDprMonitor.prototype._updateDpr = function () {
10188 if (!this._resolutionMediaMatchList || !this._outerListener) {
10189 return;
10190 }
10191 this._resolutionMediaMatchList.removeListener(this._outerListener);
10192 this._currentDevicePixelRatio = window.devicePixelRatio;
10193 this._resolutionMediaMatchList = window.matchMedia("screen and (resolution: " + window.devicePixelRatio + "dppx)");
10194 this._resolutionMediaMatchList.addListener(this._outerListener);
10195 };
10196 ScreenDprMonitor.prototype.clearListener = function () {
10197 if (!this._resolutionMediaMatchList || !this._listener || !this._outerListener) {
10198 return;
10199 }
10200 this._resolutionMediaMatchList.removeListener(this._outerListener);
10201 this._resolutionMediaMatchList = undefined;
10202 this._listener = undefined;
10203 this._outerListener = undefined;
10204 };
10205 return ScreenDprMonitor;
10206 }(Lifecycle_1.Disposable));
10207 exports.ScreenDprMonitor = ScreenDprMonitor;
10208
10209 },{"../common/Lifecycle":26}],58:[function(require,module,exports){
10210 "use strict";
10211 Object.defineProperty(exports, "__esModule", { value: true });
10212 var Terminal_1 = require("./public/Terminal");
10213 module.exports = Terminal_1.Terminal;
10214
10215 },{"./public/Terminal":34}]},{},[58])(58)
10216 });
10217 //# sourceMappingURL=xterm.js.map