]> git.proxmox.com Git - mirror_xterm.js.git/blob - dist/xterm.js
Merge pull request #926 from ficristo/search-fix
[mirror_xterm.js.git] / dist / 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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 "use strict";
3 Object.defineProperty(exports, "__esModule", { value: true });
4 var CircularList_1 = require("./utils/CircularList");
5 var Buffer = (function () {
6 function Buffer(_terminal) {
7 this._terminal = _terminal;
8 this.clear();
9 }
10 Object.defineProperty(Buffer.prototype, "lines", {
11 get: function () {
12 return this._lines;
13 },
14 enumerable: true,
15 configurable: true
16 });
17 Buffer.prototype.fillViewportRows = function () {
18 if (this._lines.length === 0) {
19 var i = this._terminal.rows;
20 while (i--) {
21 this.lines.push(this._terminal.blankLine());
22 }
23 }
24 };
25 Buffer.prototype.clear = function () {
26 this.ydisp = 0;
27 this.ybase = 0;
28 this.y = 0;
29 this.x = 0;
30 this.scrollBottom = 0;
31 this.scrollTop = 0;
32 this.tabs = {};
33 this._lines = new CircularList_1.CircularList(this._terminal.scrollback);
34 this.scrollBottom = this._terminal.rows - 1;
35 };
36 Buffer.prototype.resize = function (newCols, newRows) {
37 if (this._lines.length === 0) {
38 return;
39 }
40 if (this._terminal.cols < newCols) {
41 var ch = [this._terminal.defAttr, ' ', 1];
42 for (var i = 0; i < this._lines.length; i++) {
43 if (this._lines.get(i) === undefined) {
44 this._lines.set(i, this._terminal.blankLine(undefined, undefined, newCols));
45 }
46 while (this._lines.get(i).length < newCols) {
47 this._lines.get(i).push(ch);
48 }
49 }
50 }
51 var addToY = 0;
52 if (this._terminal.rows < newRows) {
53 for (var y = this._terminal.rows; y < newRows; y++) {
54 if (this._lines.length < newRows + this.ybase) {
55 if (this.ybase > 0 && this._lines.length <= this.ybase + this.y + addToY + 1) {
56 this.ybase--;
57 addToY++;
58 if (this.ydisp > 0) {
59 this.ydisp--;
60 }
61 }
62 else {
63 this._lines.push(this._terminal.blankLine(undefined, undefined, newCols));
64 }
65 }
66 }
67 }
68 else {
69 for (var y = this._terminal.rows; y > newRows; y--) {
70 if (this._lines.length > newRows + this.ybase) {
71 if (this._lines.length > this.ybase + this.y + 1) {
72 this._lines.pop();
73 }
74 else {
75 this.ybase++;
76 this.ydisp++;
77 }
78 }
79 }
80 }
81 if (this.y >= newRows) {
82 this.y = newRows - 1;
83 }
84 if (addToY) {
85 this.y += addToY;
86 }
87 if (this.x >= newCols) {
88 this.x = newCols - 1;
89 }
90 this.scrollTop = 0;
91 this.scrollBottom = newRows - 1;
92 };
93 return Buffer;
94 }());
95 exports.Buffer = Buffer;
96
97
98
99 },{"./utils/CircularList":18}],2:[function(require,module,exports){
100 "use strict";
101 var __extends = (this && this.__extends) || (function () {
102 var extendStatics = Object.setPrototypeOf ||
103 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
104 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
105 return function (d, b) {
106 extendStatics(d, b);
107 function __() { this.constructor = d; }
108 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
109 };
110 })();
111 Object.defineProperty(exports, "__esModule", { value: true });
112 var Buffer_1 = require("./Buffer");
113 var EventEmitter_1 = require("./EventEmitter");
114 var BufferSet = (function (_super) {
115 __extends(BufferSet, _super);
116 function BufferSet(_terminal) {
117 var _this = _super.call(this) || this;
118 _this._terminal = _terminal;
119 _this._normal = new Buffer_1.Buffer(_this._terminal);
120 _this._normal.fillViewportRows();
121 _this._alt = new Buffer_1.Buffer(_this._terminal);
122 _this._activeBuffer = _this._normal;
123 return _this;
124 }
125 Object.defineProperty(BufferSet.prototype, "alt", {
126 get: function () {
127 return this._alt;
128 },
129 enumerable: true,
130 configurable: true
131 });
132 Object.defineProperty(BufferSet.prototype, "active", {
133 get: function () {
134 return this._activeBuffer;
135 },
136 enumerable: true,
137 configurable: true
138 });
139 Object.defineProperty(BufferSet.prototype, "normal", {
140 get: function () {
141 return this._normal;
142 },
143 enumerable: true,
144 configurable: true
145 });
146 BufferSet.prototype.activateNormalBuffer = function () {
147 this._alt.clear();
148 this._activeBuffer = this._normal;
149 this.emit('activate', this._normal);
150 };
151 BufferSet.prototype.activateAltBuffer = function () {
152 this._alt.fillViewportRows();
153 this._activeBuffer = this._alt;
154 this.emit('activate', this._alt);
155 };
156 BufferSet.prototype.resize = function (newCols, newRows) {
157 this._normal.resize(newCols, newRows);
158 this._alt.resize(newCols, newRows);
159 };
160 return BufferSet;
161 }(EventEmitter_1.EventEmitter));
162 exports.BufferSet = BufferSet;
163
164
165
166 },{"./Buffer":1,"./EventEmitter":6}],3:[function(require,module,exports){
167 "use strict";
168 Object.defineProperty(exports, "__esModule", { value: true });
169 exports.CHARSETS = {};
170 exports.DEFAULT_CHARSET = exports.CHARSETS['B'];
171 exports.CHARSETS['0'] = {
172 '`': '\u25c6',
173 'a': '\u2592',
174 'b': '\u0009',
175 'c': '\u000c',
176 'd': '\u000d',
177 'e': '\u000a',
178 'f': '\u00b0',
179 'g': '\u00b1',
180 'h': '\u2424',
181 'i': '\u000b',
182 'j': '\u2518',
183 'k': '\u2510',
184 'l': '\u250c',
185 'm': '\u2514',
186 'n': '\u253c',
187 'o': '\u23ba',
188 'p': '\u23bb',
189 'q': '\u2500',
190 'r': '\u23bc',
191 's': '\u23bd',
192 't': '\u251c',
193 'u': '\u2524',
194 'v': '\u2534',
195 'w': '\u252c',
196 'x': '\u2502',
197 'y': '\u2264',
198 'z': '\u2265',
199 '{': '\u03c0',
200 '|': '\u2260',
201 '}': '\u00a3',
202 '~': '\u00b7'
203 };
204 exports.CHARSETS['A'] = {
205 '#': '£'
206 };
207 exports.CHARSETS['B'] = null;
208 exports.CHARSETS['4'] = {
209 '#': '£',
210 '@': '¾',
211 '[': 'ij',
212 '\\': '½',
213 ']': '|',
214 '{': '¨',
215 '|': 'f',
216 '}': '¼',
217 '~': '´'
218 };
219 exports.CHARSETS['C'] =
220 exports.CHARSETS['5'] = {
221 '[': 'Ä',
222 '\\': 'Ö',
223 ']': 'Ã…',
224 '^': 'Ü',
225 '`': 'é',
226 '{': 'ä',
227 '|': 'ö',
228 '}': 'Ã¥',
229 '~': 'ü'
230 };
231 exports.CHARSETS['R'] = {
232 '#': '£',
233 '@': 'à',
234 '[': '°',
235 '\\': 'ç',
236 ']': '§',
237 '{': 'é',
238 '|': 'ù',
239 '}': 'è',
240 '~': '¨'
241 };
242 exports.CHARSETS['Q'] = {
243 '@': 'à',
244 '[': 'â',
245 '\\': 'ç',
246 ']': 'ê',
247 '^': 'î',
248 '`': 'ô',
249 '{': 'é',
250 '|': 'ù',
251 '}': 'è',
252 '~': 'û'
253 };
254 exports.CHARSETS['K'] = {
255 '@': '§',
256 '[': 'Ä',
257 '\\': 'Ö',
258 ']': 'Ü',
259 '{': 'ä',
260 '|': 'ö',
261 '}': 'ü',
262 '~': 'ß'
263 };
264 exports.CHARSETS['Y'] = {
265 '#': '£',
266 '@': '§',
267 '[': '°',
268 '\\': 'ç',
269 ']': 'é',
270 '`': 'ù',
271 '{': 'à',
272 '|': 'ò',
273 '}': 'è',
274 '~': 'ì'
275 };
276 exports.CHARSETS['E'] =
277 exports.CHARSETS['6'] = {
278 '@': 'Ä',
279 '[': 'Æ',
280 '\\': 'Ø',
281 ']': 'Ã…',
282 '^': 'Ü',
283 '`': 'ä',
284 '{': 'æ',
285 '|': 'ø',
286 '}': 'Ã¥',
287 '~': 'ü'
288 };
289 exports.CHARSETS['Z'] = {
290 '#': '£',
291 '@': '§',
292 '[': '¡',
293 '\\': 'Ñ',
294 ']': '¿',
295 '{': '°',
296 '|': 'ñ',
297 '}': 'ç'
298 };
299 exports.CHARSETS['H'] =
300 exports.CHARSETS['7'] = {
301 '@': 'É',
302 '[': 'Ä',
303 '\\': 'Ö',
304 ']': 'Ã…',
305 '^': 'Ü',
306 '`': 'é',
307 '{': 'ä',
308 '|': 'ö',
309 '}': 'Ã¥',
310 '~': 'ü'
311 };
312 exports.CHARSETS['='] = {
313 '#': 'ù',
314 '@': 'à',
315 '[': 'é',
316 '\\': 'ç',
317 ']': 'ê',
318 '^': 'î',
319 '_': 'è',
320 '`': 'ô',
321 '{': 'ä',
322 '|': 'ö',
323 '}': 'ü',
324 '~': 'û'
325 };
326
327
328
329 },{}],4:[function(require,module,exports){
330 "use strict";
331 Object.defineProperty(exports, "__esModule", { value: true });
332 var CompositionHelper = (function () {
333 function CompositionHelper(textarea, compositionView, terminal) {
334 this.textarea = textarea;
335 this.compositionView = compositionView;
336 this.terminal = terminal;
337 this.isComposing = false;
338 this.isSendingComposition = false;
339 this.compositionPosition = { start: null, end: null };
340 }
341 CompositionHelper.prototype.compositionstart = function () {
342 this.isComposing = true;
343 this.compositionPosition.start = this.textarea.value.length;
344 this.compositionView.textContent = '';
345 this.compositionView.classList.add('active');
346 };
347 CompositionHelper.prototype.compositionupdate = function (ev) {
348 var _this = this;
349 this.compositionView.textContent = ev.data;
350 this.updateCompositionElements();
351 setTimeout(function () {
352 _this.compositionPosition.end = _this.textarea.value.length;
353 }, 0);
354 };
355 CompositionHelper.prototype.compositionend = function () {
356 this.finalizeComposition(true);
357 };
358 CompositionHelper.prototype.keydown = function (ev) {
359 if (this.isComposing || this.isSendingComposition) {
360 if (ev.keyCode === 229) {
361 return false;
362 }
363 else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
364 return false;
365 }
366 else {
367 this.finalizeComposition(false);
368 }
369 }
370 if (ev.keyCode === 229) {
371 this.handleAnyTextareaChanges();
372 return false;
373 }
374 return true;
375 };
376 CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) {
377 var _this = this;
378 this.compositionView.classList.remove('active');
379 this.isComposing = false;
380 this.clearTextareaPosition();
381 if (!waitForPropogation) {
382 this.isSendingComposition = false;
383 var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
384 this.terminal.handler(input);
385 }
386 else {
387 var currentCompositionPosition_1 = {
388 start: this.compositionPosition.start,
389 end: this.compositionPosition.end,
390 };
391 this.isSendingComposition = true;
392 setTimeout(function () {
393 if (_this.isSendingComposition) {
394 _this.isSendingComposition = false;
395 var input = void 0;
396 if (_this.isComposing) {
397 input = _this.textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end);
398 }
399 else {
400 input = _this.textarea.value.substring(currentCompositionPosition_1.start);
401 }
402 _this.terminal.handler(input);
403 }
404 }, 0);
405 }
406 };
407 CompositionHelper.prototype.handleAnyTextareaChanges = function () {
408 var _this = this;
409 var oldValue = this.textarea.value;
410 setTimeout(function () {
411 if (!_this.isComposing) {
412 var newValue = _this.textarea.value;
413 var diff = newValue.replace(oldValue, '');
414 if (diff.length > 0) {
415 _this.terminal.handler(diff);
416 }
417 }
418 }, 0);
419 };
420 CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) {
421 var _this = this;
422 if (!this.isComposing) {
423 return;
424 }
425 var cursor = this.terminal.element.querySelector('.terminal-cursor');
426 if (cursor) {
427 var xtermRows = this.terminal.element.querySelector('.xterm-rows');
428 var cursorTop = xtermRows.offsetTop + cursor.offsetTop;
429 this.compositionView.style.left = cursor.offsetLeft + 'px';
430 this.compositionView.style.top = cursorTop + 'px';
431 this.compositionView.style.height = cursor.offsetHeight + 'px';
432 this.compositionView.style.lineHeight = cursor.offsetHeight + 'px';
433 var compositionViewBounds = this.compositionView.getBoundingClientRect();
434 this.textarea.style.left = cursor.offsetLeft + 'px';
435 this.textarea.style.top = cursorTop + 'px';
436 this.textarea.style.width = compositionViewBounds.width + 'px';
437 this.textarea.style.height = compositionViewBounds.height + 'px';
438 this.textarea.style.lineHeight = compositionViewBounds.height + 'px';
439 }
440 if (!dontRecurse) {
441 setTimeout(function () { return _this.updateCompositionElements(true); }, 0);
442 }
443 };
444 ;
445 CompositionHelper.prototype.clearTextareaPosition = function () {
446 this.textarea.style.left = '';
447 this.textarea.style.top = '';
448 };
449 ;
450 return CompositionHelper;
451 }());
452 exports.CompositionHelper = CompositionHelper;
453
454
455
456 },{}],5:[function(require,module,exports){
457 "use strict";
458 Object.defineProperty(exports, "__esModule", { value: true });
459 var C0;
460 (function (C0) {
461 C0.NUL = '\x00';
462 C0.SOH = '\x01';
463 C0.STX = '\x02';
464 C0.ETX = '\x03';
465 C0.EOT = '\x04';
466 C0.ENQ = '\x05';
467 C0.ACK = '\x06';
468 C0.BEL = '\x07';
469 C0.BS = '\x08';
470 C0.HT = '\x09';
471 C0.LF = '\x0a';
472 C0.VT = '\x0b';
473 C0.FF = '\x0c';
474 C0.CR = '\x0d';
475 C0.SO = '\x0e';
476 C0.SI = '\x0f';
477 C0.DLE = '\x10';
478 C0.DC1 = '\x11';
479 C0.DC2 = '\x12';
480 C0.DC3 = '\x13';
481 C0.DC4 = '\x14';
482 C0.NAK = '\x15';
483 C0.SYN = '\x16';
484 C0.ETB = '\x17';
485 C0.CAN = '\x18';
486 C0.EM = '\x19';
487 C0.SUB = '\x1a';
488 C0.ESC = '\x1b';
489 C0.FS = '\x1c';
490 C0.GS = '\x1d';
491 C0.RS = '\x1e';
492 C0.US = '\x1f';
493 C0.SP = '\x20';
494 C0.DEL = '\x7f';
495 })(C0 = exports.C0 || (exports.C0 = {}));
496 ;
497
498
499
500 },{}],6:[function(require,module,exports){
501 "use strict";
502 Object.defineProperty(exports, "__esModule", { value: true });
503 ;
504 var EventEmitter = (function () {
505 function EventEmitter() {
506 this._events = this._events || {};
507 }
508 EventEmitter.prototype.on = function (type, listener) {
509 this._events[type] = this._events[type] || [];
510 this._events[type].push(listener);
511 };
512 EventEmitter.prototype.off = function (type, listener) {
513 if (!this._events[type]) {
514 return;
515 }
516 var obj = this._events[type];
517 var i = obj.length;
518 while (i--) {
519 if (obj[i] === listener || obj[i].listener === listener) {
520 obj.splice(i, 1);
521 return;
522 }
523 }
524 };
525 EventEmitter.prototype.removeAllListeners = function (type) {
526 if (this._events[type]) {
527 delete this._events[type];
528 }
529 };
530 EventEmitter.prototype.once = function (type, listener) {
531 function on() {
532 var args = Array.prototype.slice.call(arguments);
533 this.off(type, on);
534 return listener.apply(this, args);
535 }
536 on.listener = listener;
537 return this.on(type, on);
538 };
539 EventEmitter.prototype.emit = function (type) {
540 var args = [];
541 for (var _i = 1; _i < arguments.length; _i++) {
542 args[_i - 1] = arguments[_i];
543 }
544 if (!this._events[type]) {
545 return;
546 }
547 var obj = this._events[type];
548 for (var i = 0; i < obj.length; i++) {
549 obj[i].apply(this, args);
550 }
551 };
552 EventEmitter.prototype.listeners = function (type) {
553 return this._events[type] || [];
554 };
555 return EventEmitter;
556 }());
557 exports.EventEmitter = EventEmitter;
558
559
560
561 },{}],7:[function(require,module,exports){
562 "use strict";
563 Object.defineProperty(exports, "__esModule", { value: true });
564 var EscapeSequences_1 = require("./EscapeSequences");
565 var Charsets_1 = require("./Charsets");
566 var InputHandler = (function () {
567 function InputHandler(_terminal) {
568 this._terminal = _terminal;
569 }
570 InputHandler.prototype.addChar = function (char, code) {
571 if (char >= ' ') {
572 var ch_width = exports.wcwidth(code);
573 if (this._terminal.charset && this._terminal.charset[char]) {
574 char = this._terminal.charset[char];
575 }
576 var row = this._terminal.buffer.y + this._terminal.buffer.ybase;
577 if (!ch_width && this._terminal.buffer.x) {
578 if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1]) {
579 if (!this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][2]) {
580 if (this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2])
581 this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 2][1] += char;
582 }
583 else {
584 this._terminal.buffer.lines.get(row)[this._terminal.buffer.x - 1][1] += char;
585 }
586 this._terminal.updateRange(this._terminal.buffer.y);
587 }
588 return;
589 }
590 if (this._terminal.buffer.x + ch_width - 1 >= this._terminal.cols) {
591 if (this._terminal.wraparoundMode) {
592 this._terminal.buffer.x = 0;
593 this._terminal.buffer.y++;
594 if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
595 this._terminal.buffer.y--;
596 this._terminal.scroll(true);
597 }
598 else {
599 this._terminal.buffer.lines.get(this._terminal.buffer.y).isWrapped = true;
600 }
601 }
602 else {
603 if (ch_width === 2)
604 return;
605 }
606 }
607 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
608 if (this._terminal.insertMode) {
609 for (var moves = 0; moves < ch_width; ++moves) {
610 var removed = this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).pop();
611 if (removed[2] === 0
612 && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2]
613 && this._terminal.buffer.lines.get(row)[this._terminal.cols - 2][2] === 2) {
614 this._terminal.buffer.lines.get(row)[this._terminal.cols - 2] = [this._terminal.curAttr, ' ', 1];
615 }
616 this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 0, [this._terminal.curAttr, ' ', 1]);
617 }
618 }
619 this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, char, ch_width];
620 this._terminal.buffer.x++;
621 this._terminal.updateRange(this._terminal.buffer.y);
622 if (ch_width === 2) {
623 this._terminal.buffer.lines.get(row)[this._terminal.buffer.x] = [this._terminal.curAttr, '', 0];
624 this._terminal.buffer.x++;
625 }
626 }
627 };
628 InputHandler.prototype.bell = function () {
629 var _this = this;
630 if (!this._terminal.visualBell) {
631 return;
632 }
633 this._terminal.element.style.borderColor = 'white';
634 setTimeout(function () { return _this._terminal.element.style.borderColor = ''; }, 10);
635 if (this._terminal.popOnBell) {
636 this._terminal.focus();
637 }
638 };
639 InputHandler.prototype.lineFeed = function () {
640 if (this._terminal.convertEol) {
641 this._terminal.buffer.x = 0;
642 }
643 this._terminal.buffer.y++;
644 if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
645 this._terminal.buffer.y--;
646 this._terminal.scroll();
647 }
648 if (this._terminal.buffer.x >= this._terminal.cols) {
649 this._terminal.buffer.x--;
650 }
651 this._terminal.emit('lineFeed');
652 };
653 InputHandler.prototype.carriageReturn = function () {
654 this._terminal.buffer.x = 0;
655 };
656 InputHandler.prototype.backspace = function () {
657 if (this._terminal.buffer.x > 0) {
658 this._terminal.buffer.x--;
659 }
660 };
661 InputHandler.prototype.tab = function () {
662 this._terminal.buffer.x = this._terminal.nextStop();
663 };
664 InputHandler.prototype.shiftOut = function () {
665 this._terminal.setgLevel(1);
666 };
667 InputHandler.prototype.shiftIn = function () {
668 this._terminal.setgLevel(0);
669 };
670 InputHandler.prototype.insertChars = function (params) {
671 var param, row, j, ch;
672 param = params[0];
673 if (param < 1)
674 param = 1;
675 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
676 j = this._terminal.buffer.x;
677 ch = [this._terminal.eraseAttr(), ' ', 1];
678 while (param-- && j < this._terminal.cols) {
679 this._terminal.buffer.lines.get(row).splice(j++, 0, ch);
680 this._terminal.buffer.lines.get(row).pop();
681 }
682 };
683 InputHandler.prototype.cursorUp = function (params) {
684 var param = params[0];
685 if (param < 1) {
686 param = 1;
687 }
688 this._terminal.buffer.y -= param;
689 if (this._terminal.buffer.y < 0) {
690 this._terminal.buffer.y = 0;
691 }
692 };
693 InputHandler.prototype.cursorDown = function (params) {
694 var param = params[0];
695 if (param < 1) {
696 param = 1;
697 }
698 this._terminal.buffer.y += param;
699 if (this._terminal.buffer.y >= this._terminal.rows) {
700 this._terminal.buffer.y = this._terminal.rows - 1;
701 }
702 if (this._terminal.buffer.x >= this._terminal.cols) {
703 this._terminal.buffer.x--;
704 }
705 };
706 InputHandler.prototype.cursorForward = function (params) {
707 var param = params[0];
708 if (param < 1) {
709 param = 1;
710 }
711 this._terminal.buffer.x += param;
712 if (this._terminal.buffer.x >= this._terminal.cols) {
713 this._terminal.buffer.x = this._terminal.cols - 1;
714 }
715 };
716 InputHandler.prototype.cursorBackward = function (params) {
717 var param = params[0];
718 if (param < 1) {
719 param = 1;
720 }
721 if (this._terminal.buffer.x >= this._terminal.cols) {
722 this._terminal.buffer.x--;
723 }
724 this._terminal.buffer.x -= param;
725 if (this._terminal.buffer.x < 0) {
726 this._terminal.buffer.x = 0;
727 }
728 };
729 InputHandler.prototype.cursorNextLine = function (params) {
730 var param = params[0];
731 if (param < 1) {
732 param = 1;
733 }
734 this._terminal.buffer.y += param;
735 if (this._terminal.buffer.y >= this._terminal.rows) {
736 this._terminal.buffer.y = this._terminal.rows - 1;
737 }
738 this._terminal.buffer.x = 0;
739 };
740 InputHandler.prototype.cursorPrecedingLine = function (params) {
741 var param = params[0];
742 if (param < 1) {
743 param = 1;
744 }
745 this._terminal.buffer.y -= param;
746 if (this._terminal.buffer.y < 0) {
747 this._terminal.buffer.y = 0;
748 }
749 this._terminal.buffer.x = 0;
750 };
751 InputHandler.prototype.cursorCharAbsolute = function (params) {
752 var param = params[0];
753 if (param < 1) {
754 param = 1;
755 }
756 this._terminal.buffer.x = param - 1;
757 };
758 InputHandler.prototype.cursorPosition = function (params) {
759 var row, col;
760 row = params[0] - 1;
761 if (params.length >= 2) {
762 col = params[1] - 1;
763 }
764 else {
765 col = 0;
766 }
767 if (row < 0) {
768 row = 0;
769 }
770 else if (row >= this._terminal.rows) {
771 row = this._terminal.rows - 1;
772 }
773 if (col < 0) {
774 col = 0;
775 }
776 else if (col >= this._terminal.cols) {
777 col = this._terminal.cols - 1;
778 }
779 this._terminal.buffer.x = col;
780 this._terminal.buffer.y = row;
781 };
782 InputHandler.prototype.cursorForwardTab = function (params) {
783 var param = params[0] || 1;
784 while (param--) {
785 this._terminal.buffer.x = this._terminal.nextStop();
786 }
787 };
788 InputHandler.prototype.eraseInDisplay = function (params) {
789 var j;
790 switch (params[0]) {
791 case 0:
792 this._terminal.eraseRight(this._terminal.buffer.x, this._terminal.buffer.y);
793 j = this._terminal.buffer.y + 1;
794 for (; j < this._terminal.rows; j++) {
795 this._terminal.eraseLine(j);
796 }
797 break;
798 case 1:
799 this._terminal.eraseLeft(this._terminal.buffer.x, this._terminal.buffer.y);
800 j = this._terminal.buffer.y;
801 while (j--) {
802 this._terminal.eraseLine(j);
803 }
804 break;
805 case 2:
806 j = this._terminal.rows;
807 while (j--)
808 this._terminal.eraseLine(j);
809 break;
810 case 3:
811 var scrollBackSize = this._terminal.buffer.lines.length - this._terminal.rows;
812 if (scrollBackSize > 0) {
813 this._terminal.buffer.lines.trimStart(scrollBackSize);
814 this._terminal.buffer.ybase = Math.max(this._terminal.buffer.ybase - scrollBackSize, 0);
815 this._terminal.buffer.ydisp = Math.max(this._terminal.buffer.ydisp - scrollBackSize, 0);
816 this._terminal.emit('scroll', 0);
817 }
818 break;
819 }
820 };
821 InputHandler.prototype.eraseInLine = function (params) {
822 switch (params[0]) {
823 case 0:
824 this._terminal.eraseRight(this._terminal.buffer.x, this._terminal.buffer.y);
825 break;
826 case 1:
827 this._terminal.eraseLeft(this._terminal.buffer.x, this._terminal.buffer.y);
828 break;
829 case 2:
830 this._terminal.eraseLine(this._terminal.buffer.y);
831 break;
832 }
833 };
834 InputHandler.prototype.insertLines = function (params) {
835 var param, row, j;
836 param = params[0];
837 if (param < 1) {
838 param = 1;
839 }
840 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
841 j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
842 j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j + 1;
843 while (param--) {
844 if (this._terminal.buffer.lines.length === this._terminal.buffer.lines.maxLength) {
845 this._terminal.buffer.lines.trimStart(1);
846 this._terminal.buffer.ybase--;
847 this._terminal.buffer.ydisp--;
848 row--;
849 j--;
850 }
851 this._terminal.buffer.lines.splice(row, 0, this._terminal.blankLine(true));
852 this._terminal.buffer.lines.splice(j, 1);
853 }
854 this._terminal.updateRange(this._terminal.buffer.y);
855 this._terminal.updateRange(this._terminal.buffer.scrollBottom);
856 };
857 InputHandler.prototype.deleteLines = function (params) {
858 var param, row, j;
859 param = params[0];
860 if (param < 1) {
861 param = 1;
862 }
863 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
864 j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
865 j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;
866 while (param--) {
867 if (this._terminal.buffer.lines.length === this._terminal.buffer.lines.maxLength) {
868 this._terminal.buffer.lines.trimStart(1);
869 this._terminal.buffer.ybase -= 1;
870 this._terminal.buffer.ydisp -= 1;
871 }
872 this._terminal.buffer.lines.splice(j + 1, 0, this._terminal.blankLine(true));
873 this._terminal.buffer.lines.splice(row, 1);
874 }
875 this._terminal.updateRange(this._terminal.buffer.y);
876 this._terminal.updateRange(this._terminal.buffer.scrollBottom);
877 };
878 InputHandler.prototype.deleteChars = function (params) {
879 var param, row, ch;
880 param = params[0];
881 if (param < 1) {
882 param = 1;
883 }
884 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
885 ch = [this._terminal.eraseAttr(), ' ', 1];
886 while (param--) {
887 this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 1);
888 this._terminal.buffer.lines.get(row).push(ch);
889 }
890 };
891 InputHandler.prototype.scrollUp = function (params) {
892 var param = params[0] || 1;
893 while (param--) {
894 this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 1);
895 this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 0, this._terminal.blankLine());
896 }
897 this._terminal.updateRange(this._terminal.buffer.scrollTop);
898 this._terminal.updateRange(this._terminal.buffer.scrollBottom);
899 };
900 InputHandler.prototype.scrollDown = function (params) {
901 var param = params[0] || 1;
902 while (param--) {
903 this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollBottom, 1);
904 this._terminal.buffer.lines.splice(this._terminal.buffer.ybase + this._terminal.buffer.scrollTop, 0, this._terminal.blankLine());
905 }
906 this._terminal.updateRange(this._terminal.buffer.scrollTop);
907 this._terminal.updateRange(this._terminal.buffer.scrollBottom);
908 };
909 InputHandler.prototype.eraseChars = function (params) {
910 var param, row, j, ch;
911 param = params[0];
912 if (param < 1) {
913 param = 1;
914 }
915 row = this._terminal.buffer.y + this._terminal.buffer.ybase;
916 j = this._terminal.buffer.x;
917 ch = [this._terminal.eraseAttr(), ' ', 1];
918 while (param-- && j < this._terminal.cols) {
919 this._terminal.buffer.lines.get(row)[j++] = ch;
920 }
921 };
922 InputHandler.prototype.cursorBackwardTab = function (params) {
923 var param = params[0] || 1;
924 while (param--) {
925 this._terminal.buffer.x = this._terminal.prevStop();
926 }
927 };
928 InputHandler.prototype.charPosAbsolute = function (params) {
929 var param = params[0];
930 if (param < 1) {
931 param = 1;
932 }
933 this._terminal.buffer.x = param - 1;
934 if (this._terminal.buffer.x >= this._terminal.cols) {
935 this._terminal.buffer.x = this._terminal.cols - 1;
936 }
937 };
938 InputHandler.prototype.HPositionRelative = function (params) {
939 var param = params[0];
940 if (param < 1) {
941 param = 1;
942 }
943 this._terminal.buffer.x += param;
944 if (this._terminal.buffer.x >= this._terminal.cols) {
945 this._terminal.buffer.x = this._terminal.cols - 1;
946 }
947 };
948 InputHandler.prototype.repeatPrecedingCharacter = function (params) {
949 var param = params[0] || 1, line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + this._terminal.buffer.y), ch = line[this._terminal.buffer.x - 1] || [this._terminal.defAttr, ' ', 1];
950 while (param--) {
951 line[this._terminal.buffer.x++] = ch;
952 }
953 };
954 InputHandler.prototype.sendDeviceAttributes = function (params) {
955 if (params[0] > 0) {
956 return;
957 }
958 if (!this._terminal.prefix) {
959 if (this._terminal.is('xterm') || this._terminal.is('rxvt-unicode') || this._terminal.is('screen')) {
960 this._terminal.send(EscapeSequences_1.C0.ESC + '[?1;2c');
961 }
962 else if (this._terminal.is('linux')) {
963 this._terminal.send(EscapeSequences_1.C0.ESC + '[?6c');
964 }
965 }
966 else if (this._terminal.prefix === '>') {
967 if (this._terminal.is('xterm')) {
968 this._terminal.send(EscapeSequences_1.C0.ESC + '[>0;276;0c');
969 }
970 else if (this._terminal.is('rxvt-unicode')) {
971 this._terminal.send(EscapeSequences_1.C0.ESC + '[>85;95;0c');
972 }
973 else if (this._terminal.is('linux')) {
974 this._terminal.send(params[0] + 'c');
975 }
976 else if (this._terminal.is('screen')) {
977 this._terminal.send(EscapeSequences_1.C0.ESC + '[>83;40003;0c');
978 }
979 }
980 };
981 InputHandler.prototype.linePosAbsolute = function (params) {
982 var param = params[0];
983 if (param < 1) {
984 param = 1;
985 }
986 this._terminal.buffer.y = param - 1;
987 if (this._terminal.buffer.y >= this._terminal.rows) {
988 this._terminal.buffer.y = this._terminal.rows - 1;
989 }
990 };
991 InputHandler.prototype.VPositionRelative = function (params) {
992 var param = params[0];
993 if (param < 1) {
994 param = 1;
995 }
996 this._terminal.buffer.y += param;
997 if (this._terminal.buffer.y >= this._terminal.rows) {
998 this._terminal.buffer.y = this._terminal.rows - 1;
999 }
1000 if (this._terminal.buffer.x >= this._terminal.cols) {
1001 this._terminal.buffer.x--;
1002 }
1003 };
1004 InputHandler.prototype.HVPosition = function (params) {
1005 if (params[0] < 1)
1006 params[0] = 1;
1007 if (params[1] < 1)
1008 params[1] = 1;
1009 this._terminal.buffer.y = params[0] - 1;
1010 if (this._terminal.buffer.y >= this._terminal.rows) {
1011 this._terminal.buffer.y = this._terminal.rows - 1;
1012 }
1013 this._terminal.buffer.x = params[1] - 1;
1014 if (this._terminal.buffer.x >= this._terminal.cols) {
1015 this._terminal.buffer.x = this._terminal.cols - 1;
1016 }
1017 };
1018 InputHandler.prototype.tabClear = function (params) {
1019 var param = params[0];
1020 if (param <= 0) {
1021 delete this._terminal.buffer.tabs[this._terminal.buffer.x];
1022 }
1023 else if (param === 3) {
1024 this._terminal.buffer.tabs = {};
1025 }
1026 };
1027 InputHandler.prototype.setMode = function (params) {
1028 if (params.length > 1) {
1029 for (var i = 0; i < params.length; i++) {
1030 this.setMode([params[i]]);
1031 }
1032 return;
1033 }
1034 if (!this._terminal.prefix) {
1035 switch (params[0]) {
1036 case 4:
1037 this._terminal.insertMode = true;
1038 break;
1039 case 20:
1040 break;
1041 }
1042 }
1043 else if (this._terminal.prefix === '?') {
1044 switch (params[0]) {
1045 case 1:
1046 this._terminal.applicationCursor = true;
1047 break;
1048 case 2:
1049 this._terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
1050 this._terminal.setgCharset(1, Charsets_1.DEFAULT_CHARSET);
1051 this._terminal.setgCharset(2, Charsets_1.DEFAULT_CHARSET);
1052 this._terminal.setgCharset(3, Charsets_1.DEFAULT_CHARSET);
1053 break;
1054 case 3:
1055 this._terminal.savedCols = this._terminal.cols;
1056 this._terminal.resize(132, this._terminal.rows);
1057 break;
1058 case 6:
1059 this._terminal.originMode = true;
1060 break;
1061 case 7:
1062 this._terminal.wraparoundMode = true;
1063 break;
1064 case 12:
1065 break;
1066 case 66:
1067 this._terminal.log('Serial port requested application keypad.');
1068 this._terminal.applicationKeypad = true;
1069 this._terminal.viewport.syncScrollArea();
1070 break;
1071 case 9:
1072 case 1000:
1073 case 1002:
1074 case 1003:
1075 this._terminal.x10Mouse = params[0] === 9;
1076 this._terminal.vt200Mouse = params[0] === 1000;
1077 this._terminal.normalMouse = params[0] > 1000;
1078 this._terminal.mouseEvents = true;
1079 this._terminal.element.classList.add('enable-mouse-events');
1080 this._terminal.selectionManager.disable();
1081 this._terminal.log('Binding to mouse events.');
1082 break;
1083 case 1004:
1084 this._terminal.sendFocus = true;
1085 break;
1086 case 1005:
1087 this._terminal.utfMouse = true;
1088 break;
1089 case 1006:
1090 this._terminal.sgrMouse = true;
1091 break;
1092 case 1015:
1093 this._terminal.urxvtMouse = true;
1094 break;
1095 case 25:
1096 this._terminal.cursorHidden = false;
1097 break;
1098 case 1049:
1099 case 47:
1100 case 1047:
1101 this._terminal.buffers.activateAltBuffer();
1102 this._terminal.viewport.syncScrollArea();
1103 this._terminal.showCursor();
1104 break;
1105 }
1106 }
1107 };
1108 InputHandler.prototype.resetMode = function (params) {
1109 if (params.length > 1) {
1110 for (var i = 0; i < params.length; i++) {
1111 this.resetMode([params[i]]);
1112 }
1113 return;
1114 }
1115 if (!this._terminal.prefix) {
1116 switch (params[0]) {
1117 case 4:
1118 this._terminal.insertMode = false;
1119 break;
1120 case 20:
1121 break;
1122 }
1123 }
1124 else if (this._terminal.prefix === '?') {
1125 switch (params[0]) {
1126 case 1:
1127 this._terminal.applicationCursor = false;
1128 break;
1129 case 3:
1130 if (this._terminal.cols === 132 && this._terminal.savedCols) {
1131 this._terminal.resize(this._terminal.savedCols, this._terminal.rows);
1132 }
1133 delete this._terminal.savedCols;
1134 break;
1135 case 6:
1136 this._terminal.originMode = false;
1137 break;
1138 case 7:
1139 this._terminal.wraparoundMode = false;
1140 break;
1141 case 12:
1142 break;
1143 case 66:
1144 this._terminal.log('Switching back to normal keypad.');
1145 this._terminal.applicationKeypad = false;
1146 this._terminal.viewport.syncScrollArea();
1147 break;
1148 case 9:
1149 case 1000:
1150 case 1002:
1151 case 1003:
1152 this._terminal.x10Mouse = false;
1153 this._terminal.vt200Mouse = false;
1154 this._terminal.normalMouse = false;
1155 this._terminal.mouseEvents = false;
1156 this._terminal.element.classList.remove('enable-mouse-events');
1157 this._terminal.selectionManager.enable();
1158 break;
1159 case 1004:
1160 this._terminal.sendFocus = false;
1161 break;
1162 case 1005:
1163 this._terminal.utfMouse = false;
1164 break;
1165 case 1006:
1166 this._terminal.sgrMouse = false;
1167 break;
1168 case 1015:
1169 this._terminal.urxvtMouse = false;
1170 break;
1171 case 25:
1172 this._terminal.cursorHidden = true;
1173 break;
1174 case 1049:
1175 case 47:
1176 case 1047:
1177 this._terminal.buffers.activateNormalBuffer();
1178 this._terminal.selectionManager.setBuffer(this._terminal.buffer.lines);
1179 this._terminal.refresh(0, this._terminal.rows - 1);
1180 this._terminal.viewport.syncScrollArea();
1181 this._terminal.showCursor();
1182 break;
1183 }
1184 }
1185 };
1186 InputHandler.prototype.charAttributes = function (params) {
1187 if (params.length === 1 && params[0] === 0) {
1188 this._terminal.curAttr = this._terminal.defAttr;
1189 return;
1190 }
1191 var l = params.length, i = 0, flags = this._terminal.curAttr >> 18, fg = (this._terminal.curAttr >> 9) & 0x1ff, bg = this._terminal.curAttr & 0x1ff, p;
1192 for (; i < l; i++) {
1193 p = params[i];
1194 if (p >= 30 && p <= 37) {
1195 fg = p - 30;
1196 }
1197 else if (p >= 40 && p <= 47) {
1198 bg = p - 40;
1199 }
1200 else if (p >= 90 && p <= 97) {
1201 p += 8;
1202 fg = p - 90;
1203 }
1204 else if (p >= 100 && p <= 107) {
1205 p += 8;
1206 bg = p - 100;
1207 }
1208 else if (p === 0) {
1209 flags = this._terminal.defAttr >> 18;
1210 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1211 bg = this._terminal.defAttr & 0x1ff;
1212 }
1213 else if (p === 1) {
1214 flags |= 1;
1215 }
1216 else if (p === 4) {
1217 flags |= 2;
1218 }
1219 else if (p === 5) {
1220 flags |= 4;
1221 }
1222 else if (p === 7) {
1223 flags |= 8;
1224 }
1225 else if (p === 8) {
1226 flags |= 16;
1227 }
1228 else if (p === 22) {
1229 flags &= ~1;
1230 }
1231 else if (p === 24) {
1232 flags &= ~2;
1233 }
1234 else if (p === 25) {
1235 flags &= ~4;
1236 }
1237 else if (p === 27) {
1238 flags &= ~8;
1239 }
1240 else if (p === 28) {
1241 flags &= ~16;
1242 }
1243 else if (p === 39) {
1244 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1245 }
1246 else if (p === 49) {
1247 bg = this._terminal.defAttr & 0x1ff;
1248 }
1249 else if (p === 38) {
1250 if (params[i + 1] === 2) {
1251 i += 2;
1252 fg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
1253 if (fg === -1)
1254 fg = 0x1ff;
1255 i += 2;
1256 }
1257 else if (params[i + 1] === 5) {
1258 i += 2;
1259 p = params[i] & 0xff;
1260 fg = p;
1261 }
1262 }
1263 else if (p === 48) {
1264 if (params[i + 1] === 2) {
1265 i += 2;
1266 bg = this._terminal.matchColor(params[i] & 0xff, params[i + 1] & 0xff, params[i + 2] & 0xff);
1267 if (bg === -1)
1268 bg = 0x1ff;
1269 i += 2;
1270 }
1271 else if (params[i + 1] === 5) {
1272 i += 2;
1273 p = params[i] & 0xff;
1274 bg = p;
1275 }
1276 }
1277 else if (p === 100) {
1278 fg = (this._terminal.defAttr >> 9) & 0x1ff;
1279 bg = this._terminal.defAttr & 0x1ff;
1280 }
1281 else {
1282 this._terminal.error('Unknown SGR attribute: %d.', p);
1283 }
1284 }
1285 this._terminal.curAttr = (flags << 18) | (fg << 9) | bg;
1286 };
1287 InputHandler.prototype.deviceStatus = function (params) {
1288 if (!this._terminal.prefix) {
1289 switch (params[0]) {
1290 case 5:
1291 this._terminal.send(EscapeSequences_1.C0.ESC + '[0n');
1292 break;
1293 case 6:
1294 this._terminal.send(EscapeSequences_1.C0.ESC + '['
1295 + (this._terminal.buffer.y + 1)
1296 + ';'
1297 + (this._terminal.buffer.x + 1)
1298 + 'R');
1299 break;
1300 }
1301 }
1302 else if (this._terminal.prefix === '?') {
1303 switch (params[0]) {
1304 case 6:
1305 this._terminal.send(EscapeSequences_1.C0.ESC + '[?'
1306 + (this._terminal.buffer.y + 1)
1307 + ';'
1308 + (this._terminal.buffer.x + 1)
1309 + 'R');
1310 break;
1311 case 15:
1312 break;
1313 case 25:
1314 break;
1315 case 26:
1316 break;
1317 case 53:
1318 break;
1319 }
1320 }
1321 };
1322 InputHandler.prototype.softReset = function (params) {
1323 this._terminal.cursorHidden = false;
1324 this._terminal.insertMode = false;
1325 this._terminal.originMode = false;
1326 this._terminal.wraparoundMode = true;
1327 this._terminal.applicationKeypad = false;
1328 this._terminal.viewport.syncScrollArea();
1329 this._terminal.applicationCursor = false;
1330 this._terminal.buffer.scrollTop = 0;
1331 this._terminal.buffer.scrollBottom = this._terminal.rows - 1;
1332 this._terminal.curAttr = this._terminal.defAttr;
1333 this._terminal.buffer.x = this._terminal.buffer.y = 0;
1334 this._terminal.charset = null;
1335 this._terminal.glevel = 0;
1336 this._terminal.charsets = [null];
1337 };
1338 InputHandler.prototype.setCursorStyle = function (params) {
1339 var param = params[0] < 1 ? 1 : params[0];
1340 switch (param) {
1341 case 1:
1342 case 2:
1343 this._terminal.setOption('cursorStyle', 'block');
1344 break;
1345 case 3:
1346 case 4:
1347 this._terminal.setOption('cursorStyle', 'underline');
1348 break;
1349 case 5:
1350 case 6:
1351 this._terminal.setOption('cursorStyle', 'bar');
1352 break;
1353 }
1354 var isBlinking = param % 2 === 1;
1355 this._terminal.setOption('cursorBlink', isBlinking);
1356 };
1357 InputHandler.prototype.setScrollRegion = function (params) {
1358 if (this._terminal.prefix)
1359 return;
1360 this._terminal.buffer.scrollTop = (params[0] || 1) - 1;
1361 this._terminal.buffer.scrollBottom = (params[1] && params[1] <= this._terminal.rows ? params[1] : this._terminal.rows) - 1;
1362 this._terminal.buffer.x = 0;
1363 this._terminal.buffer.y = 0;
1364 };
1365 InputHandler.prototype.saveCursor = function (params) {
1366 this._terminal.buffer.savedX = this._terminal.buffer.x;
1367 this._terminal.buffer.savedY = this._terminal.buffer.y;
1368 };
1369 InputHandler.prototype.restoreCursor = function (params) {
1370 this._terminal.buffer.x = this._terminal.buffer.savedX || 0;
1371 this._terminal.buffer.y = this._terminal.buffer.savedY || 0;
1372 };
1373 return InputHandler;
1374 }());
1375 exports.InputHandler = InputHandler;
1376 exports.wcwidth = (function (opts) {
1377 var COMBINING_BMP = [
1378 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1379 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1380 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1381 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1382 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1383 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1384 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1385 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1386 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1387 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1388 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1389 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1390 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1391 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1392 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1393 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1394 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1395 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1396 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1397 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1398 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1399 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1400 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1401 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1402 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1403 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1404 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1405 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1406 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1407 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1408 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1409 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1410 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1411 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1412 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1413 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1414 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1415 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1416 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1417 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1418 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1419 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1420 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1421 ];
1422 var COMBINING_HIGH = [
1423 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1424 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1425 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1426 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1427 [0xE0100, 0xE01EF]
1428 ];
1429 function bisearch(ucs, data) {
1430 var min = 0;
1431 var max = data.length - 1;
1432 var mid;
1433 if (ucs < data[0][0] || ucs > data[max][1])
1434 return false;
1435 while (max >= min) {
1436 mid = (min + max) >> 1;
1437 if (ucs > data[mid][1])
1438 min = mid + 1;
1439 else if (ucs < data[mid][0])
1440 max = mid - 1;
1441 else
1442 return true;
1443 }
1444 return false;
1445 }
1446 function wcwidthBMP(ucs) {
1447 if (ucs === 0)
1448 return opts.nul;
1449 if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0))
1450 return opts.control;
1451 if (bisearch(ucs, COMBINING_BMP))
1452 return 0;
1453 if (isWideBMP(ucs)) {
1454 return 2;
1455 }
1456 return 1;
1457 }
1458 function isWideBMP(ucs) {
1459 return (ucs >= 0x1100 && (ucs <= 0x115f ||
1460 ucs === 0x2329 ||
1461 ucs === 0x232a ||
1462 (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs !== 0x303f) ||
1463 (ucs >= 0xac00 && ucs <= 0xd7a3) ||
1464 (ucs >= 0xf900 && ucs <= 0xfaff) ||
1465 (ucs >= 0xfe10 && ucs <= 0xfe19) ||
1466 (ucs >= 0xfe30 && ucs <= 0xfe6f) ||
1467 (ucs >= 0xff00 && ucs <= 0xff60) ||
1468 (ucs >= 0xffe0 && ucs <= 0xffe6)));
1469 }
1470 function wcwidthHigh(ucs) {
1471 if (bisearch(ucs, COMBINING_HIGH))
1472 return 0;
1473 if ((ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd)) {
1474 return 2;
1475 }
1476 return 1;
1477 }
1478 var control = opts.control | 0;
1479 var table = null;
1480 function init_table() {
1481 var CODEPOINTS = 65536;
1482 var BITWIDTH = 2;
1483 var ITEMSIZE = 32;
1484 var CONTAINERSIZE = CODEPOINTS * BITWIDTH / ITEMSIZE;
1485 var CODEPOINTS_PER_ITEM = ITEMSIZE / BITWIDTH;
1486 table = (typeof Uint32Array === 'undefined')
1487 ? new Array(CONTAINERSIZE)
1488 : new Uint32Array(CONTAINERSIZE);
1489 for (var i = 0; i < CONTAINERSIZE; ++i) {
1490 var num = 0;
1491 var pos = CODEPOINTS_PER_ITEM;
1492 while (pos--)
1493 num = (num << 2) | wcwidthBMP(CODEPOINTS_PER_ITEM * i + pos);
1494 table[i] = num;
1495 }
1496 return table;
1497 }
1498 return function (num) {
1499 num = num | 0;
1500 if (num < 32)
1501 return control | 0;
1502 if (num < 127)
1503 return 1;
1504 var t = table || init_table();
1505 if (num < 65536)
1506 return t[num >> 4] >> ((num & 15) << 1) & 3;
1507 return wcwidthHigh(num);
1508 };
1509 })({ nul: 0, control: 0 });
1510
1511
1512
1513 },{"./Charsets":3,"./EscapeSequences":5}],8:[function(require,module,exports){
1514 "use strict";
1515 Object.defineProperty(exports, "__esModule", { value: true });
1516 var INVALID_LINK_CLASS = 'xterm-invalid-link';
1517 var protocolClause = '(https?:\\/\\/)';
1518 var domainCharacterSet = '[\\da-z\\.-]+';
1519 var negatedDomainCharacterSet = '[^\\da-z\\.-]+';
1520 var domainBodyClause = '(' + domainCharacterSet + ')';
1521 var tldClause = '([a-z\\.]{2,6})';
1522 var ipClause = '((\\d{1,3}\\.){3}\\d{1,3})';
1523 var localHostClause = '(localhost)';
1524 var portClause = '(:\\d{1,5})';
1525 var hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?';
1526 var pathClause = '(\\/[\\/\\w\\.\\-%~]*)*';
1527 var queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1528 var queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?';
1529 var hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?';
1530 var negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';
1531 var bodyClause = hostClause + pathClause + queryStringClause + hashFragmentClause;
1532 var start = '(?:^|' + negatedDomainCharacterSet + ')(';
1533 var end = ')($|' + negatedPathCharacterSet + ')';
1534 var strictUrlRegex = new RegExp(start + protocolClause + bodyClause + end);
1535 var HYPERTEXT_LINK_MATCHER_ID = 0;
1536 var Linkifier = (function () {
1537 function Linkifier() {
1538 this._nextLinkMatcherId = HYPERTEXT_LINK_MATCHER_ID;
1539 this._rowTimeoutIds = [];
1540 this._linkMatchers = [];
1541 this.registerLinkMatcher(strictUrlRegex, null, { matchIndex: 1 });
1542 }
1543 Linkifier.prototype.attachToDom = function (document, rows) {
1544 this._document = document;
1545 this._rows = rows;
1546 };
1547 Linkifier.prototype.linkifyRow = function (rowIndex) {
1548 if (!this._document) {
1549 return;
1550 }
1551 var timeoutId = this._rowTimeoutIds[rowIndex];
1552 if (timeoutId) {
1553 clearTimeout(timeoutId);
1554 }
1555 this._rowTimeoutIds[rowIndex] = setTimeout(this._linkifyRow.bind(this, rowIndex), Linkifier.TIME_BEFORE_LINKIFY);
1556 };
1557 Linkifier.prototype.setHypertextLinkHandler = function (handler) {
1558 this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].handler = handler;
1559 };
1560 Linkifier.prototype.setHypertextValidationCallback = function (callback) {
1561 this._linkMatchers[HYPERTEXT_LINK_MATCHER_ID].validationCallback = callback;
1562 };
1563 Linkifier.prototype.registerLinkMatcher = function (regex, handler, options) {
1564 if (options === void 0) { options = {}; }
1565 if (this._nextLinkMatcherId !== HYPERTEXT_LINK_MATCHER_ID && !handler) {
1566 throw new Error('handler must be defined');
1567 }
1568 var matcher = {
1569 id: this._nextLinkMatcherId++,
1570 regex: regex,
1571 handler: handler,
1572 matchIndex: options.matchIndex,
1573 validationCallback: options.validationCallback,
1574 priority: options.priority || 0
1575 };
1576 this._addLinkMatcherToList(matcher);
1577 return matcher.id;
1578 };
1579 Linkifier.prototype._addLinkMatcherToList = function (matcher) {
1580 if (this._linkMatchers.length === 0) {
1581 this._linkMatchers.push(matcher);
1582 return;
1583 }
1584 for (var i = this._linkMatchers.length - 1; i >= 0; i--) {
1585 if (matcher.priority <= this._linkMatchers[i].priority) {
1586 this._linkMatchers.splice(i + 1, 0, matcher);
1587 return;
1588 }
1589 }
1590 this._linkMatchers.splice(0, 0, matcher);
1591 };
1592 Linkifier.prototype.deregisterLinkMatcher = function (matcherId) {
1593 for (var i = 1; i < this._linkMatchers.length; i++) {
1594 if (this._linkMatchers[i].id === matcherId) {
1595 this._linkMatchers.splice(i, 1);
1596 return true;
1597 }
1598 }
1599 return false;
1600 };
1601 Linkifier.prototype._linkifyRow = function (rowIndex) {
1602 var row = this._rows[rowIndex];
1603 if (!row) {
1604 return;
1605 }
1606 var text = row.textContent;
1607 for (var i = 0; i < this._linkMatchers.length; i++) {
1608 var matcher = this._linkMatchers[i];
1609 var linkElements = this._doLinkifyRow(row, matcher);
1610 if (linkElements.length > 0) {
1611 if (matcher.validationCallback) {
1612 var _loop_1 = function (j) {
1613 var element = linkElements[j];
1614 matcher.validationCallback(element.textContent, element, function (isValid) {
1615 if (!isValid) {
1616 element.classList.add(INVALID_LINK_CLASS);
1617 }
1618 });
1619 };
1620 for (var j = 0; j < linkElements.length; j++) {
1621 _loop_1(j);
1622 }
1623 }
1624 return;
1625 }
1626 }
1627 };
1628 Linkifier.prototype._doLinkifyRow = function (row, matcher) {
1629 var result = [];
1630 var isHttpLinkMatcher = matcher.id === HYPERTEXT_LINK_MATCHER_ID;
1631 var nodes = row.childNodes;
1632 var match = row.textContent.match(matcher.regex);
1633 if (!match || match.length === 0) {
1634 return result;
1635 }
1636 var uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
1637 var rowStartIndex = match.index + uri.length;
1638 for (var i = 0; i < nodes.length; i++) {
1639 var node = nodes[i];
1640 var searchIndex = node.textContent.indexOf(uri);
1641 if (searchIndex >= 0) {
1642 var linkElement = this._createAnchorElement(uri, matcher.handler, isHttpLinkMatcher);
1643 if (node.textContent.length === uri.length) {
1644 if (node.nodeType === 3) {
1645 this._replaceNode(node, linkElement);
1646 }
1647 else {
1648 var element = node;
1649 if (element.nodeName === 'A') {
1650 return result;
1651 }
1652 element.innerHTML = '';
1653 element.appendChild(linkElement);
1654 }
1655 }
1656 else if (node.childNodes.length > 1) {
1657 for (var j = 0; j < node.childNodes.length; j++) {
1658 var childNode = node.childNodes[j];
1659 var childSearchIndex = childNode.textContent.indexOf(uri);
1660 if (childSearchIndex !== -1) {
1661 this._replaceNodeSubstringWithNode(childNode, linkElement, uri, childSearchIndex);
1662 break;
1663 }
1664 }
1665 }
1666 else {
1667 var nodesAdded = this._replaceNodeSubstringWithNode(node, linkElement, uri, searchIndex);
1668 i += nodesAdded;
1669 }
1670 result.push(linkElement);
1671 match = row.textContent.substring(rowStartIndex).match(matcher.regex);
1672 if (!match || match.length === 0) {
1673 return result;
1674 }
1675 uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex];
1676 rowStartIndex += match.index + uri.length;
1677 }
1678 }
1679 return result;
1680 };
1681 Linkifier.prototype._createAnchorElement = function (uri, handler, isHypertextLinkHandler) {
1682 var element = this._document.createElement('a');
1683 element.textContent = uri;
1684 element.draggable = false;
1685 if (isHypertextLinkHandler) {
1686 element.href = uri;
1687 element.target = '_blank';
1688 element.addEventListener('click', function (event) {
1689 if (handler) {
1690 return handler(event, uri);
1691 }
1692 });
1693 }
1694 else {
1695 element.addEventListener('click', function (event) {
1696 if (element.classList.contains(INVALID_LINK_CLASS)) {
1697 return;
1698 }
1699 return handler(event, uri);
1700 });
1701 }
1702 return element;
1703 };
1704 Linkifier.prototype._replaceNode = function (oldNode) {
1705 var newNodes = [];
1706 for (var _i = 1; _i < arguments.length; _i++) {
1707 newNodes[_i - 1] = arguments[_i];
1708 }
1709 var parent = oldNode.parentNode;
1710 for (var i = 0; i < newNodes.length; i++) {
1711 parent.insertBefore(newNodes[i], oldNode);
1712 }
1713 parent.removeChild(oldNode);
1714 };
1715 Linkifier.prototype._replaceNodeSubstringWithNode = function (targetNode, newNode, substring, substringIndex) {
1716 if (targetNode.childNodes.length === 1) {
1717 targetNode = targetNode.childNodes[0];
1718 }
1719 if (targetNode.nodeType !== 3) {
1720 throw new Error('targetNode must be a text node or only contain a single text node');
1721 }
1722 var fullText = targetNode.textContent;
1723 if (substringIndex === 0) {
1724 var rightText_1 = fullText.substring(substring.length);
1725 var rightTextNode_1 = this._document.createTextNode(rightText_1);
1726 this._replaceNode(targetNode, newNode, rightTextNode_1);
1727 return 0;
1728 }
1729 if (substringIndex === targetNode.textContent.length - substring.length) {
1730 var leftText_1 = fullText.substring(0, substringIndex);
1731 var leftTextNode_1 = this._document.createTextNode(leftText_1);
1732 this._replaceNode(targetNode, leftTextNode_1, newNode);
1733 return 0;
1734 }
1735 var leftText = fullText.substring(0, substringIndex);
1736 var leftTextNode = this._document.createTextNode(leftText);
1737 var rightText = fullText.substring(substringIndex + substring.length);
1738 var rightTextNode = this._document.createTextNode(rightText);
1739 this._replaceNode(targetNode, leftTextNode, newNode, rightTextNode);
1740 return 1;
1741 };
1742 return Linkifier;
1743 }());
1744 Linkifier.TIME_BEFORE_LINKIFY = 200;
1745 exports.Linkifier = Linkifier;
1746
1747
1748
1749 },{}],9:[function(require,module,exports){
1750 "use strict";
1751 Object.defineProperty(exports, "__esModule", { value: true });
1752 var EscapeSequences_1 = require("./EscapeSequences");
1753 var Charsets_1 = require("./Charsets");
1754 var normalStateHandler = {};
1755 normalStateHandler[EscapeSequences_1.C0.BEL] = function (parser, handler) { return handler.bell(); };
1756 normalStateHandler[EscapeSequences_1.C0.LF] = function (parser, handler) { return handler.lineFeed(); };
1757 normalStateHandler[EscapeSequences_1.C0.VT] = normalStateHandler[EscapeSequences_1.C0.LF];
1758 normalStateHandler[EscapeSequences_1.C0.FF] = normalStateHandler[EscapeSequences_1.C0.LF];
1759 normalStateHandler[EscapeSequences_1.C0.CR] = function (parser, handler) { return handler.carriageReturn(); };
1760 normalStateHandler[EscapeSequences_1.C0.BS] = function (parser, handler) { return handler.backspace(); };
1761 normalStateHandler[EscapeSequences_1.C0.HT] = function (parser, handler) { return handler.tab(); };
1762 normalStateHandler[EscapeSequences_1.C0.SO] = function (parser, handler) { return handler.shiftOut(); };
1763 normalStateHandler[EscapeSequences_1.C0.SI] = function (parser, handler) { return handler.shiftIn(); };
1764 normalStateHandler[EscapeSequences_1.C0.ESC] = function (parser, handler) { return parser.setState(ParserState.ESCAPED); };
1765 var escapedStateHandler = {};
1766 escapedStateHandler['['] = function (parser, terminal) {
1767 terminal.params = [];
1768 terminal.currentParam = 0;
1769 parser.setState(ParserState.CSI_PARAM);
1770 };
1771 escapedStateHandler[']'] = function (parser, terminal) {
1772 terminal.params = [];
1773 terminal.currentParam = 0;
1774 parser.setState(ParserState.OSC);
1775 };
1776 escapedStateHandler['P'] = function (parser, terminal) {
1777 terminal.params = [];
1778 terminal.currentParam = 0;
1779 parser.setState(ParserState.DCS);
1780 };
1781 escapedStateHandler['_'] = function (parser, terminal) {
1782 parser.setState(ParserState.IGNORE);
1783 };
1784 escapedStateHandler['^'] = function (parser, terminal) {
1785 parser.setState(ParserState.IGNORE);
1786 };
1787 escapedStateHandler['c'] = function (parser, terminal) {
1788 terminal.reset();
1789 };
1790 escapedStateHandler['E'] = function (parser, terminal) {
1791 terminal.buffer.x = 0;
1792 terminal.index();
1793 parser.setState(ParserState.NORMAL);
1794 };
1795 escapedStateHandler['D'] = function (parser, terminal) {
1796 terminal.index();
1797 parser.setState(ParserState.NORMAL);
1798 };
1799 escapedStateHandler['M'] = function (parser, terminal) {
1800 terminal.reverseIndex();
1801 parser.setState(ParserState.NORMAL);
1802 };
1803 escapedStateHandler['%'] = function (parser, terminal) {
1804 terminal.setgLevel(0);
1805 terminal.setgCharset(0, Charsets_1.DEFAULT_CHARSET);
1806 parser.setState(ParserState.NORMAL);
1807 parser.skipNextChar();
1808 };
1809 escapedStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1810 var csiParamStateHandler = {};
1811 csiParamStateHandler['?'] = function (parser) { return parser.setPrefix('?'); };
1812 csiParamStateHandler['>'] = function (parser) { return parser.setPrefix('>'); };
1813 csiParamStateHandler['!'] = function (parser) { return parser.setPrefix('!'); };
1814 csiParamStateHandler['0'] = function (parser) { return parser.setParam(parser.getParam() * 10); };
1815 csiParamStateHandler['1'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 1); };
1816 csiParamStateHandler['2'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 2); };
1817 csiParamStateHandler['3'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 3); };
1818 csiParamStateHandler['4'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 4); };
1819 csiParamStateHandler['5'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 5); };
1820 csiParamStateHandler['6'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 6); };
1821 csiParamStateHandler['7'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 7); };
1822 csiParamStateHandler['8'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 8); };
1823 csiParamStateHandler['9'] = function (parser) { return parser.setParam(parser.getParam() * 10 + 9); };
1824 csiParamStateHandler['$'] = function (parser) { return parser.setPostfix('$'); };
1825 csiParamStateHandler['"'] = function (parser) { return parser.setPostfix('"'); };
1826 csiParamStateHandler[' '] = function (parser) { return parser.setPostfix(' '); };
1827 csiParamStateHandler['\''] = function (parser) { return parser.setPostfix('\''); };
1828 csiParamStateHandler[';'] = function (parser) { return parser.finalizeParam(); };
1829 csiParamStateHandler[EscapeSequences_1.C0.CAN] = function (parser) { return parser.setState(ParserState.NORMAL); };
1830 var csiStateHandler = {};
1831 csiStateHandler['@'] = function (handler, params, prefix) { return handler.insertChars(params); };
1832 csiStateHandler['A'] = function (handler, params, prefix) { return handler.cursorUp(params); };
1833 csiStateHandler['B'] = function (handler, params, prefix) { return handler.cursorDown(params); };
1834 csiStateHandler['C'] = function (handler, params, prefix) { return handler.cursorForward(params); };
1835 csiStateHandler['D'] = function (handler, params, prefix) { return handler.cursorBackward(params); };
1836 csiStateHandler['E'] = function (handler, params, prefix) { return handler.cursorNextLine(params); };
1837 csiStateHandler['F'] = function (handler, params, prefix) { return handler.cursorPrecedingLine(params); };
1838 csiStateHandler['G'] = function (handler, params, prefix) { return handler.cursorCharAbsolute(params); };
1839 csiStateHandler['H'] = function (handler, params, prefix) { return handler.cursorPosition(params); };
1840 csiStateHandler['I'] = function (handler, params, prefix) { return handler.cursorForwardTab(params); };
1841 csiStateHandler['J'] = function (handler, params, prefix) { return handler.eraseInDisplay(params); };
1842 csiStateHandler['K'] = function (handler, params, prefix) { return handler.eraseInLine(params); };
1843 csiStateHandler['L'] = function (handler, params, prefix) { return handler.insertLines(params); };
1844 csiStateHandler['M'] = function (handler, params, prefix) { return handler.deleteLines(params); };
1845 csiStateHandler['P'] = function (handler, params, prefix) { return handler.deleteChars(params); };
1846 csiStateHandler['S'] = function (handler, params, prefix) { return handler.scrollUp(params); };
1847 csiStateHandler['T'] = function (handler, params, prefix) {
1848 if (params.length < 2 && !prefix) {
1849 handler.scrollDown(params);
1850 }
1851 };
1852 csiStateHandler['X'] = function (handler, params, prefix) { return handler.eraseChars(params); };
1853 csiStateHandler['Z'] = function (handler, params, prefix) { return handler.cursorBackwardTab(params); };
1854 csiStateHandler['`'] = function (handler, params, prefix) { return handler.charPosAbsolute(params); };
1855 csiStateHandler['a'] = function (handler, params, prefix) { return handler.HPositionRelative(params); };
1856 csiStateHandler['b'] = function (handler, params, prefix) { return handler.repeatPrecedingCharacter(params); };
1857 csiStateHandler['c'] = function (handler, params, prefix) { return handler.sendDeviceAttributes(params); };
1858 csiStateHandler['d'] = function (handler, params, prefix) { return handler.linePosAbsolute(params); };
1859 csiStateHandler['e'] = function (handler, params, prefix) { return handler.VPositionRelative(params); };
1860 csiStateHandler['f'] = function (handler, params, prefix) { return handler.HVPosition(params); };
1861 csiStateHandler['g'] = function (handler, params, prefix) { return handler.tabClear(params); };
1862 csiStateHandler['h'] = function (handler, params, prefix) { return handler.setMode(params); };
1863 csiStateHandler['l'] = function (handler, params, prefix) { return handler.resetMode(params); };
1864 csiStateHandler['m'] = function (handler, params, prefix) { return handler.charAttributes(params); };
1865 csiStateHandler['n'] = function (handler, params, prefix) { return handler.deviceStatus(params); };
1866 csiStateHandler['p'] = function (handler, params, prefix) {
1867 switch (prefix) {
1868 case '!':
1869 handler.softReset(params);
1870 break;
1871 }
1872 };
1873 csiStateHandler['q'] = function (handler, params, prefix, postfix) {
1874 if (postfix === ' ') {
1875 handler.setCursorStyle(params);
1876 }
1877 };
1878 csiStateHandler['r'] = function (handler, params) { return handler.setScrollRegion(params); };
1879 csiStateHandler['s'] = function (handler, params) { return handler.saveCursor(params); };
1880 csiStateHandler['u'] = function (handler, params) { return handler.restoreCursor(params); };
1881 csiStateHandler[EscapeSequences_1.C0.CAN] = function (handler, params, prefix, postfix, parser) { return parser.setState(ParserState.NORMAL); };
1882 var ParserState;
1883 (function (ParserState) {
1884 ParserState[ParserState["NORMAL"] = 0] = "NORMAL";
1885 ParserState[ParserState["ESCAPED"] = 1] = "ESCAPED";
1886 ParserState[ParserState["CSI_PARAM"] = 2] = "CSI_PARAM";
1887 ParserState[ParserState["CSI"] = 3] = "CSI";
1888 ParserState[ParserState["OSC"] = 4] = "OSC";
1889 ParserState[ParserState["CHARSET"] = 5] = "CHARSET";
1890 ParserState[ParserState["DCS"] = 6] = "DCS";
1891 ParserState[ParserState["IGNORE"] = 7] = "IGNORE";
1892 })(ParserState || (ParserState = {}));
1893 var Parser = (function () {
1894 function Parser(_inputHandler, _terminal) {
1895 this._inputHandler = _inputHandler;
1896 this._terminal = _terminal;
1897 this._state = ParserState.NORMAL;
1898 }
1899 Parser.prototype.parse = function (data) {
1900 var l = data.length, j, cs, ch, code, low;
1901 if (this._terminal.debug) {
1902 this._terminal.log('data: ' + data);
1903 }
1904 this._position = 0;
1905 if (this._terminal.surrogate_high) {
1906 data = this._terminal.surrogate_high + data;
1907 this._terminal.surrogate_high = '';
1908 }
1909 for (; this._position < l; this._position++) {
1910 ch = data[this._position];
1911 code = data.charCodeAt(this._position);
1912 if (0xD800 <= code && code <= 0xDBFF) {
1913 low = data.charCodeAt(this._position + 1);
1914 if (isNaN(low)) {
1915 this._terminal.surrogate_high = ch;
1916 continue;
1917 }
1918 code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
1919 ch += data.charAt(this._position + 1);
1920 }
1921 if (0xDC00 <= code && code <= 0xDFFF)
1922 continue;
1923 switch (this._state) {
1924 case ParserState.NORMAL:
1925 if (ch in normalStateHandler) {
1926 normalStateHandler[ch](this, this._inputHandler);
1927 }
1928 else {
1929 this._inputHandler.addChar(ch, code);
1930 }
1931 break;
1932 case ParserState.ESCAPED:
1933 if (ch in escapedStateHandler) {
1934 escapedStateHandler[ch](this, this._terminal);
1935 break;
1936 }
1937 switch (ch) {
1938 case '(':
1939 case ')':
1940 case '*':
1941 case '+':
1942 case '-':
1943 case '.':
1944 switch (ch) {
1945 case '(':
1946 this._terminal.gcharset = 0;
1947 break;
1948 case ')':
1949 this._terminal.gcharset = 1;
1950 break;
1951 case '*':
1952 this._terminal.gcharset = 2;
1953 break;
1954 case '+':
1955 this._terminal.gcharset = 3;
1956 break;
1957 case '-':
1958 this._terminal.gcharset = 1;
1959 break;
1960 case '.':
1961 this._terminal.gcharset = 2;
1962 break;
1963 }
1964 this._state = ParserState.CHARSET;
1965 break;
1966 case '/':
1967 this._terminal.gcharset = 3;
1968 this._state = ParserState.CHARSET;
1969 this._position--;
1970 break;
1971 case 'N':
1972 break;
1973 case 'O':
1974 break;
1975 case 'n':
1976 this._terminal.setgLevel(2);
1977 break;
1978 case 'o':
1979 this._terminal.setgLevel(3);
1980 break;
1981 case '|':
1982 this._terminal.setgLevel(3);
1983 break;
1984 case '}':
1985 this._terminal.setgLevel(2);
1986 break;
1987 case '~':
1988 this._terminal.setgLevel(1);
1989 break;
1990 case '7':
1991 this._inputHandler.saveCursor();
1992 this._state = ParserState.NORMAL;
1993 break;
1994 case '8':
1995 this._inputHandler.restoreCursor();
1996 this._state = ParserState.NORMAL;
1997 break;
1998 case '#':
1999 this._state = ParserState.NORMAL;
2000 this._position++;
2001 break;
2002 case 'H':
2003 this._terminal.tabSet();
2004 this._state = ParserState.NORMAL;
2005 break;
2006 case '=':
2007 this._terminal.log('Serial port requested application keypad.');
2008 this._terminal.applicationKeypad = true;
2009 this._terminal.viewport.syncScrollArea();
2010 this._state = ParserState.NORMAL;
2011 break;
2012 case '>':
2013 this._terminal.log('Switching back to normal keypad.');
2014 this._terminal.applicationKeypad = false;
2015 this._terminal.viewport.syncScrollArea();
2016 this._state = ParserState.NORMAL;
2017 break;
2018 default:
2019 this._state = ParserState.NORMAL;
2020 this._terminal.error('Unknown ESC control: %s.', ch);
2021 break;
2022 }
2023 break;
2024 case ParserState.CHARSET:
2025 if (ch in Charsets_1.CHARSETS) {
2026 cs = Charsets_1.CHARSETS[ch];
2027 if (ch === '/') {
2028 this.skipNextChar();
2029 }
2030 }
2031 else {
2032 cs = Charsets_1.DEFAULT_CHARSET;
2033 }
2034 this._terminal.setgCharset(this._terminal.gcharset, cs);
2035 this._terminal.gcharset = null;
2036 this._state = ParserState.NORMAL;
2037 break;
2038 case ParserState.OSC:
2039 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
2040 if (ch === EscapeSequences_1.C0.ESC)
2041 this._position++;
2042 this._terminal.params.push(this._terminal.currentParam);
2043 switch (this._terminal.params[0]) {
2044 case 0:
2045 case 1:
2046 case 2:
2047 if (this._terminal.params[1]) {
2048 this._terminal.title = this._terminal.params[1];
2049 this._terminal.handleTitle(this._terminal.title);
2050 }
2051 break;
2052 case 3:
2053 break;
2054 case 4:
2055 case 5:
2056 break;
2057 case 10:
2058 case 11:
2059 case 12:
2060 case 13:
2061 case 14:
2062 case 15:
2063 case 16:
2064 case 17:
2065 case 18:
2066 case 19:
2067 break;
2068 case 46:
2069 break;
2070 case 50:
2071 break;
2072 case 51:
2073 break;
2074 case 52:
2075 break;
2076 case 104:
2077 case 105:
2078 case 110:
2079 case 111:
2080 case 112:
2081 case 113:
2082 case 114:
2083 case 115:
2084 case 116:
2085 case 117:
2086 case 118:
2087 break;
2088 }
2089 this._terminal.params = [];
2090 this._terminal.currentParam = 0;
2091 this._state = ParserState.NORMAL;
2092 }
2093 else {
2094 if (!this._terminal.params.length) {
2095 if (ch >= '0' && ch <= '9') {
2096 this._terminal.currentParam =
2097 this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
2098 }
2099 else if (ch === ';') {
2100 this._terminal.params.push(this._terminal.currentParam);
2101 this._terminal.currentParam = '';
2102 }
2103 }
2104 else {
2105 this._terminal.currentParam += ch;
2106 }
2107 }
2108 break;
2109 case ParserState.CSI_PARAM:
2110 if (ch in csiParamStateHandler) {
2111 csiParamStateHandler[ch](this);
2112 break;
2113 }
2114 this.finalizeParam();
2115 this._state = ParserState.CSI;
2116 case ParserState.CSI:
2117 if (ch in csiStateHandler) {
2118 if (this._terminal.debug) {
2119 this._terminal.log("CSI " + (this._terminal.prefix ? this._terminal.prefix : '') + " " + (this._terminal.params ? this._terminal.params.join(';') : '') + " " + (this._terminal.postfix ? this._terminal.postfix : '') + " " + ch);
2120 }
2121 csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
2122 }
2123 else {
2124 this._terminal.error('Unknown CSI code: %s.', ch);
2125 }
2126 this._state = ParserState.NORMAL;
2127 this._terminal.prefix = '';
2128 this._terminal.postfix = '';
2129 break;
2130 case ParserState.DCS:
2131 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
2132 if (ch === EscapeSequences_1.C0.ESC)
2133 this._position++;
2134 var pt = void 0;
2135 var valid = void 0;
2136 switch (this._terminal.prefix) {
2137 case '':
2138 break;
2139 case '$q':
2140 pt = this._terminal.currentParam;
2141 valid = false;
2142 switch (pt) {
2143 case '"q':
2144 pt = '0"q';
2145 break;
2146 case '"p':
2147 pt = '61"p';
2148 break;
2149 case 'r':
2150 pt = ''
2151 + (this._terminal.buffer.scrollTop + 1)
2152 + ';'
2153 + (this._terminal.buffer.scrollBottom + 1)
2154 + 'r';
2155 break;
2156 case 'm':
2157 pt = '0m';
2158 break;
2159 default:
2160 this._terminal.error('Unknown DCS Pt: %s.', pt);
2161 pt = '';
2162 break;
2163 }
2164 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '$r' + pt + EscapeSequences_1.C0.ESC + '\\');
2165 break;
2166 case '+p':
2167 break;
2168 case '+q':
2169 pt = this._terminal.currentParam;
2170 valid = false;
2171 this._terminal.send(EscapeSequences_1.C0.ESC + 'P' + +valid + '+r' + pt + EscapeSequences_1.C0.ESC + '\\');
2172 break;
2173 default:
2174 this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
2175 break;
2176 }
2177 this._terminal.currentParam = 0;
2178 this._terminal.prefix = '';
2179 this._state = ParserState.NORMAL;
2180 }
2181 else if (!this._terminal.currentParam) {
2182 if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
2183 this._terminal.currentParam = ch;
2184 }
2185 else if (this._terminal.prefix.length === 2) {
2186 this._terminal.currentParam = ch;
2187 }
2188 else {
2189 this._terminal.prefix += ch;
2190 }
2191 }
2192 else {
2193 this._terminal.currentParam += ch;
2194 }
2195 break;
2196 case ParserState.IGNORE:
2197 if (ch === EscapeSequences_1.C0.ESC || ch === EscapeSequences_1.C0.BEL) {
2198 if (ch === EscapeSequences_1.C0.ESC)
2199 this._position++;
2200 this._state = ParserState.NORMAL;
2201 }
2202 break;
2203 }
2204 }
2205 return this._state;
2206 };
2207 Parser.prototype.setState = function (state) {
2208 this._state = state;
2209 };
2210 Parser.prototype.setPrefix = function (prefix) {
2211 this._terminal.prefix = prefix;
2212 };
2213 Parser.prototype.setPostfix = function (postfix) {
2214 this._terminal.postfix = postfix;
2215 };
2216 Parser.prototype.setParam = function (param) {
2217 this._terminal.currentParam = param;
2218 };
2219 Parser.prototype.getParam = function () {
2220 return this._terminal.currentParam;
2221 };
2222 Parser.prototype.finalizeParam = function () {
2223 this._terminal.params.push(this._terminal.currentParam);
2224 this._terminal.currentParam = 0;
2225 };
2226 Parser.prototype.skipNextChar = function () {
2227 this._position++;
2228 };
2229 return Parser;
2230 }());
2231 exports.Parser = Parser;
2232
2233
2234
2235 },{"./Charsets":3,"./EscapeSequences":5}],10:[function(require,module,exports){
2236 "use strict";
2237 Object.defineProperty(exports, "__esModule", { value: true });
2238 var DomElementObjectPool_1 = require("./utils/DomElementObjectPool");
2239 var MAX_REFRESH_FRAME_SKIP = 5;
2240 var FLAGS;
2241 (function (FLAGS) {
2242 FLAGS[FLAGS["BOLD"] = 1] = "BOLD";
2243 FLAGS[FLAGS["UNDERLINE"] = 2] = "UNDERLINE";
2244 FLAGS[FLAGS["BLINK"] = 4] = "BLINK";
2245 FLAGS[FLAGS["INVERSE"] = 8] = "INVERSE";
2246 FLAGS[FLAGS["INVISIBLE"] = 16] = "INVISIBLE";
2247 })(FLAGS || (FLAGS = {}));
2248 ;
2249 var brokenBold = null;
2250 var Renderer = (function () {
2251 function Renderer(_terminal) {
2252 this._terminal = _terminal;
2253 this._refreshRowsQueue = [];
2254 this._refreshFramesSkipped = 0;
2255 this._refreshAnimationFrame = null;
2256 this._spanElementObjectPool = new DomElementObjectPool_1.DomElementObjectPool('span');
2257 if (brokenBold === null) {
2258 brokenBold = checkBoldBroken(this._terminal.element);
2259 }
2260 this._spanElementObjectPool = new DomElementObjectPool_1.DomElementObjectPool('span');
2261 }
2262 Renderer.prototype.queueRefresh = function (start, end) {
2263 this._refreshRowsQueue.push({ start: start, end: end });
2264 if (!this._refreshAnimationFrame) {
2265 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
2266 }
2267 };
2268 Renderer.prototype._refreshLoop = function () {
2269 var skipFrame = this._terminal.writeBuffer.length > 0 && this._refreshFramesSkipped++ <= MAX_REFRESH_FRAME_SKIP;
2270 if (skipFrame) {
2271 this._refreshAnimationFrame = window.requestAnimationFrame(this._refreshLoop.bind(this));
2272 return;
2273 }
2274 this._refreshFramesSkipped = 0;
2275 var start;
2276 var end;
2277 if (this._refreshRowsQueue.length > 4) {
2278 start = 0;
2279 end = this._terminal.rows - 1;
2280 }
2281 else {
2282 start = this._refreshRowsQueue[0].start;
2283 end = this._refreshRowsQueue[0].end;
2284 for (var i = 1; i < this._refreshRowsQueue.length; i++) {
2285 if (this._refreshRowsQueue[i].start < start) {
2286 start = this._refreshRowsQueue[i].start;
2287 }
2288 if (this._refreshRowsQueue[i].end > end) {
2289 end = this._refreshRowsQueue[i].end;
2290 }
2291 }
2292 }
2293 this._refreshRowsQueue = [];
2294 this._refreshAnimationFrame = null;
2295 this._refresh(start, end);
2296 };
2297 Renderer.prototype._refresh = function (start, end) {
2298 var parent;
2299 if (end - start >= this._terminal.rows / 2) {
2300 parent = this._terminal.element.parentNode;
2301 if (parent) {
2302 this._terminal.element.removeChild(this._terminal.rowContainer);
2303 }
2304 }
2305 var width = this._terminal.cols;
2306 var y = start;
2307 if (end >= this._terminal.rows) {
2308 this._terminal.log('`end` is too large. Most likely a bad CSR.');
2309 end = this._terminal.rows - 1;
2310 }
2311 for (; y <= end; y++) {
2312 var row = y + this._terminal.buffer.ydisp;
2313 var line = this._terminal.buffer.lines.get(row);
2314 var x = void 0;
2315 if (this._terminal.buffer.y === y - (this._terminal.buffer.ybase - this._terminal.buffer.ydisp) &&
2316 this._terminal.cursorState &&
2317 !this._terminal.cursorHidden) {
2318 x = this._terminal.buffer.x;
2319 }
2320 else {
2321 x = -1;
2322 }
2323 var attr = this._terminal.defAttr;
2324 var documentFragment = document.createDocumentFragment();
2325 var innerHTML = '';
2326 var currentElement = void 0;
2327 while (this._terminal.children[y].children.length) {
2328 var child = this._terminal.children[y].children[0];
2329 this._terminal.children[y].removeChild(child);
2330 this._spanElementObjectPool.release(child);
2331 }
2332 for (var i = 0; i < width; i++) {
2333 var data = line[i][0];
2334 var ch = line[i][1];
2335 var ch_width = line[i][2];
2336 var isCursor = i === x;
2337 if (!ch_width) {
2338 continue;
2339 }
2340 if (data !== attr || isCursor) {
2341 if (attr !== this._terminal.defAttr && !isCursor) {
2342 if (innerHTML) {
2343 currentElement.innerHTML = innerHTML;
2344 innerHTML = '';
2345 }
2346 documentFragment.appendChild(currentElement);
2347 currentElement = null;
2348 }
2349 if (data !== this._terminal.defAttr || isCursor) {
2350 if (innerHTML && !currentElement) {
2351 currentElement = this._spanElementObjectPool.acquire();
2352 }
2353 if (currentElement) {
2354 if (innerHTML) {
2355 currentElement.innerHTML = innerHTML;
2356 innerHTML = '';
2357 }
2358 documentFragment.appendChild(currentElement);
2359 }
2360 currentElement = this._spanElementObjectPool.acquire();
2361 var bg = data & 0x1ff;
2362 var fg = (data >> 9) & 0x1ff;
2363 var flags = data >> 18;
2364 if (isCursor) {
2365 currentElement.classList.add('reverse-video');
2366 currentElement.classList.add('terminal-cursor');
2367 }
2368 if (flags & FLAGS.BOLD) {
2369 if (!brokenBold) {
2370 currentElement.classList.add('xterm-bold');
2371 }
2372 if (fg < 8) {
2373 fg += 8;
2374 }
2375 }
2376 if (flags & FLAGS.UNDERLINE) {
2377 currentElement.classList.add('xterm-underline');
2378 }
2379 if (flags & FLAGS.BLINK) {
2380 currentElement.classList.add('xterm-blink');
2381 }
2382 if (flags & FLAGS.INVERSE) {
2383 var temp = bg;
2384 bg = fg;
2385 fg = temp;
2386 if ((flags & 1) && fg < 8) {
2387 fg += 8;
2388 }
2389 }
2390 if (flags & FLAGS.INVISIBLE && !isCursor) {
2391 currentElement.classList.add('xterm-hidden');
2392 }
2393 if (flags & FLAGS.INVERSE) {
2394 if (bg === 257) {
2395 bg = 15;
2396 }
2397 if (fg === 256) {
2398 fg = 0;
2399 }
2400 }
2401 if (bg < 256) {
2402 currentElement.classList.add("xterm-bg-color-" + bg);
2403 }
2404 if (fg < 256) {
2405 currentElement.classList.add("xterm-color-" + fg);
2406 }
2407 }
2408 }
2409 if (ch_width === 2) {
2410 innerHTML += "<span class=\"xterm-wide-char\">" + ch + "</span>";
2411 }
2412 else if (ch.charCodeAt(0) > 255) {
2413 innerHTML += "<span class=\"xterm-normal-char\">" + ch + "</span>";
2414 }
2415 else {
2416 switch (ch) {
2417 case '&':
2418 innerHTML += '&amp;';
2419 break;
2420 case '<':
2421 innerHTML += '&lt;';
2422 break;
2423 case '>':
2424 innerHTML += '&gt;';
2425 break;
2426 default:
2427 if (ch <= ' ') {
2428 innerHTML += '&nbsp;';
2429 }
2430 else {
2431 innerHTML += ch;
2432 }
2433 break;
2434 }
2435 }
2436 attr = isCursor ? -1 : data;
2437 }
2438 if (innerHTML && !currentElement) {
2439 currentElement = this._spanElementObjectPool.acquire();
2440 }
2441 if (currentElement) {
2442 if (innerHTML) {
2443 currentElement.innerHTML = innerHTML;
2444 innerHTML = '';
2445 }
2446 documentFragment.appendChild(currentElement);
2447 currentElement = null;
2448 }
2449 this._terminal.children[y].appendChild(documentFragment);
2450 }
2451 if (parent) {
2452 this._terminal.element.appendChild(this._terminal.rowContainer);
2453 }
2454 this._terminal.emit('refresh', { element: this._terminal.element, start: start, end: end });
2455 };
2456 ;
2457 Renderer.prototype.refreshSelection = function (start, end) {
2458 while (this._terminal.selectionContainer.children.length) {
2459 this._terminal.selectionContainer.removeChild(this._terminal.selectionContainer.children[0]);
2460 }
2461 if (!start || !end) {
2462 return;
2463 }
2464 var viewportStartRow = start[1] - this._terminal.buffer.ydisp;
2465 var viewportEndRow = end[1] - this._terminal.buffer.ydisp;
2466 var viewportCappedStartRow = Math.max(viewportStartRow, 0);
2467 var viewportCappedEndRow = Math.min(viewportEndRow, this._terminal.rows - 1);
2468 if (viewportCappedStartRow >= this._terminal.rows || viewportCappedEndRow < 0) {
2469 return;
2470 }
2471 var documentFragment = document.createDocumentFragment();
2472 var startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
2473 var endCol = viewportCappedStartRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
2474 documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow, startCol, endCol));
2475 var middleRowsCount = viewportCappedEndRow - viewportCappedStartRow - 1;
2476 documentFragment.appendChild(this._createSelectionElement(viewportCappedStartRow + 1, 0, this._terminal.cols, middleRowsCount));
2477 if (viewportCappedStartRow !== viewportCappedEndRow) {
2478 var endCol_1 = viewportEndRow === viewportCappedEndRow ? end[0] : this._terminal.cols;
2479 documentFragment.appendChild(this._createSelectionElement(viewportCappedEndRow, 0, endCol_1));
2480 }
2481 this._terminal.selectionContainer.appendChild(documentFragment);
2482 };
2483 Renderer.prototype._createSelectionElement = function (row, colStart, colEnd, rowCount) {
2484 if (rowCount === void 0) { rowCount = 1; }
2485 var element = document.createElement('div');
2486 element.style.height = rowCount * this._terminal.charMeasure.height + "px";
2487 element.style.top = row * this._terminal.charMeasure.height + "px";
2488 element.style.left = colStart * this._terminal.charMeasure.width + "px";
2489 element.style.width = this._terminal.charMeasure.width * (colEnd - colStart) + "px";
2490 return element;
2491 };
2492 return Renderer;
2493 }());
2494 exports.Renderer = Renderer;
2495 function checkBoldBroken(terminal) {
2496 var document = terminal.ownerDocument;
2497 var el = document.createElement('span');
2498 el.innerHTML = 'hello world';
2499 terminal.appendChild(el);
2500 var w1 = el.offsetWidth;
2501 var h1 = el.offsetHeight;
2502 el.style.fontWeight = 'bold';
2503 var w2 = el.offsetWidth;
2504 var h2 = el.offsetHeight;
2505 terminal.removeChild(el);
2506 return w1 !== w2 || h1 !== h2;
2507 }
2508
2509
2510
2511 },{"./utils/DomElementObjectPool":19}],11:[function(require,module,exports){
2512 "use strict";
2513 var __extends = (this && this.__extends) || (function () {
2514 var extendStatics = Object.setPrototypeOf ||
2515 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2516 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2517 return function (d, b) {
2518 extendStatics(d, b);
2519 function __() { this.constructor = d; }
2520 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2521 };
2522 })();
2523 Object.defineProperty(exports, "__esModule", { value: true });
2524 var Mouse = require("./utils/Mouse");
2525 var Browser = require("./utils/Browser");
2526 var EventEmitter_1 = require("./EventEmitter");
2527 var SelectionModel_1 = require("./SelectionModel");
2528 var BufferLine_1 = require("./utils/BufferLine");
2529 var DRAG_SCROLL_MAX_THRESHOLD = 50;
2530 var DRAG_SCROLL_MAX_SPEED = 15;
2531 var DRAG_SCROLL_INTERVAL = 50;
2532 var WORD_SEPARATORS = ' ()[]{}\'"';
2533 var LINE_DATA_CHAR_INDEX = 1;
2534 var LINE_DATA_WIDTH_INDEX = 2;
2535 var NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
2536 var ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
2537 var SelectionMode;
2538 (function (SelectionMode) {
2539 SelectionMode[SelectionMode["NORMAL"] = 0] = "NORMAL";
2540 SelectionMode[SelectionMode["WORD"] = 1] = "WORD";
2541 SelectionMode[SelectionMode["LINE"] = 2] = "LINE";
2542 })(SelectionMode || (SelectionMode = {}));
2543 var SelectionManager = (function (_super) {
2544 __extends(SelectionManager, _super);
2545 function SelectionManager(_terminal, _buffer, _rowContainer, _charMeasure) {
2546 var _this = _super.call(this) || this;
2547 _this._terminal = _terminal;
2548 _this._buffer = _buffer;
2549 _this._rowContainer = _rowContainer;
2550 _this._charMeasure = _charMeasure;
2551 _this._enabled = true;
2552 _this._initListeners();
2553 _this.enable();
2554 _this._model = new SelectionModel_1.SelectionModel(_terminal);
2555 _this._activeSelectionMode = SelectionMode.NORMAL;
2556 return _this;
2557 }
2558 SelectionManager.prototype._initListeners = function () {
2559 var _this = this;
2560 this._mouseMoveListener = function (event) { return _this._onMouseMove(event); };
2561 this._mouseUpListener = function (event) { return _this._onMouseUp(event); };
2562 this._rowContainer.addEventListener('mousedown', function (event) { return _this._onMouseDown(event); });
2563 this._buffer.on('trim', function (amount) { return _this._onTrim(amount); });
2564 };
2565 SelectionManager.prototype.disable = function () {
2566 this.clearSelection();
2567 this._enabled = false;
2568 };
2569 SelectionManager.prototype.enable = function () {
2570 this._enabled = true;
2571 };
2572 SelectionManager.prototype.setBuffer = function (buffer) {
2573 this._buffer = buffer;
2574 this.clearSelection();
2575 };
2576 Object.defineProperty(SelectionManager.prototype, "selectionStart", {
2577 get: function () { return this._model.finalSelectionStart; },
2578 enumerable: true,
2579 configurable: true
2580 });
2581 Object.defineProperty(SelectionManager.prototype, "selectionEnd", {
2582 get: function () { return this._model.finalSelectionEnd; },
2583 enumerable: true,
2584 configurable: true
2585 });
2586 Object.defineProperty(SelectionManager.prototype, "hasSelection", {
2587 get: function () {
2588 var start = this._model.finalSelectionStart;
2589 var end = this._model.finalSelectionEnd;
2590 if (!start || !end) {
2591 return false;
2592 }
2593 return start[0] !== end[0] || start[1] !== end[1];
2594 },
2595 enumerable: true,
2596 configurable: true
2597 });
2598 Object.defineProperty(SelectionManager.prototype, "selectionText", {
2599 get: function () {
2600 var start = this._model.finalSelectionStart;
2601 var end = this._model.finalSelectionEnd;
2602 if (!start || !end) {
2603 return '';
2604 }
2605 var startRowEndCol = start[1] === end[1] ? end[0] : null;
2606 var result = [];
2607 result.push(BufferLine_1.translateBufferLineToString(this._buffer.get(start[1]), true, start[0], startRowEndCol));
2608 for (var i = start[1] + 1; i <= end[1] - 1; i++) {
2609 var bufferLine = this._buffer.get(i);
2610 var lineText = BufferLine_1.translateBufferLineToString(bufferLine, true);
2611 if (bufferLine.isWrapped) {
2612 result[result.length - 1] += lineText;
2613 }
2614 else {
2615 result.push(lineText);
2616 }
2617 }
2618 if (start[1] !== end[1]) {
2619 var bufferLine = this._buffer.get(end[1]);
2620 var lineText = BufferLine_1.translateBufferLineToString(bufferLine, true, 0, end[0]);
2621 if (bufferLine.isWrapped) {
2622 result[result.length - 1] += lineText;
2623 }
2624 else {
2625 result.push(lineText);
2626 }
2627 }
2628 var formattedResult = result.map(function (line) {
2629 return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
2630 }).join(Browser.isMSWindows ? '\r\n' : '\n');
2631 return formattedResult;
2632 },
2633 enumerable: true,
2634 configurable: true
2635 });
2636 SelectionManager.prototype.clearSelection = function () {
2637 this._model.clearSelection();
2638 this._removeMouseDownListeners();
2639 this.refresh();
2640 };
2641 SelectionManager.prototype.refresh = function (isNewSelection) {
2642 var _this = this;
2643 if (!this._refreshAnimationFrame) {
2644 this._refreshAnimationFrame = window.requestAnimationFrame(function () { return _this._refresh(); });
2645 }
2646 if (Browser.isLinux && isNewSelection) {
2647 var selectionText = this.selectionText;
2648 if (selectionText.length) {
2649 this.emit('newselection', this.selectionText);
2650 }
2651 }
2652 };
2653 SelectionManager.prototype._refresh = function () {
2654 this._refreshAnimationFrame = null;
2655 this.emit('refresh', { start: this._model.finalSelectionStart, end: this._model.finalSelectionEnd });
2656 };
2657 SelectionManager.prototype.selectAll = function () {
2658 this._model.isSelectAllActive = true;
2659 this.refresh();
2660 };
2661 SelectionManager.prototype._onTrim = function (amount) {
2662 var needsRefresh = this._model.onTrim(amount);
2663 if (needsRefresh) {
2664 this.refresh();
2665 }
2666 };
2667 SelectionManager.prototype._getMouseBufferCoords = function (event) {
2668 var coords = Mouse.getCoords(event, this._rowContainer, this._charMeasure, this._terminal.cols, this._terminal.rows, true);
2669 if (!coords) {
2670 return null;
2671 }
2672 coords[0]--;
2673 coords[1]--;
2674 coords[1] += this._terminal.buffer.ydisp;
2675 return coords;
2676 };
2677 SelectionManager.prototype._getMouseEventScrollAmount = function (event) {
2678 var offset = Mouse.getCoordsRelativeToElement(event, this._rowContainer)[1];
2679 var terminalHeight = this._terminal.rows * this._charMeasure.height;
2680 if (offset >= 0 && offset <= terminalHeight) {
2681 return 0;
2682 }
2683 if (offset > terminalHeight) {
2684 offset -= terminalHeight;
2685 }
2686 offset = Math.min(Math.max(offset, -DRAG_SCROLL_MAX_THRESHOLD), DRAG_SCROLL_MAX_THRESHOLD);
2687 offset /= DRAG_SCROLL_MAX_THRESHOLD;
2688 return (offset / Math.abs(offset)) + Math.round(offset * (DRAG_SCROLL_MAX_SPEED - 1));
2689 };
2690 SelectionManager.prototype._onMouseDown = function (event) {
2691 if (event.button === 2 && this.hasSelection) {
2692 event.stopPropagation();
2693 return;
2694 }
2695 if (event.button !== 0) {
2696 return;
2697 }
2698 if (!this._enabled) {
2699 var shouldForceSelection = Browser.isMac && event.altKey;
2700 if (!shouldForceSelection) {
2701 return;
2702 }
2703 event.stopPropagation();
2704 }
2705 event.preventDefault();
2706 this._dragScrollAmount = 0;
2707 if (this._enabled && event.shiftKey) {
2708 this._onIncrementalClick(event);
2709 }
2710 else {
2711 if (event.detail === 1) {
2712 this._onSingleClick(event);
2713 }
2714 else if (event.detail === 2) {
2715 this._onDoubleClick(event);
2716 }
2717 else if (event.detail === 3) {
2718 this._onTripleClick(event);
2719 }
2720 }
2721 this._addMouseDownListeners();
2722 this.refresh(true);
2723 };
2724 SelectionManager.prototype._addMouseDownListeners = function () {
2725 var _this = this;
2726 this._rowContainer.ownerDocument.addEventListener('mousemove', this._mouseMoveListener);
2727 this._rowContainer.ownerDocument.addEventListener('mouseup', this._mouseUpListener);
2728 this._dragScrollIntervalTimer = setInterval(function () { return _this._dragScroll(); }, DRAG_SCROLL_INTERVAL);
2729 };
2730 SelectionManager.prototype._removeMouseDownListeners = function () {
2731 this._rowContainer.ownerDocument.removeEventListener('mousemove', this._mouseMoveListener);
2732 this._rowContainer.ownerDocument.removeEventListener('mouseup', this._mouseUpListener);
2733 clearInterval(this._dragScrollIntervalTimer);
2734 this._dragScrollIntervalTimer = null;
2735 };
2736 SelectionManager.prototype._onIncrementalClick = function (event) {
2737 if (this._model.selectionStart) {
2738 this._model.selectionEnd = this._getMouseBufferCoords(event);
2739 }
2740 };
2741 SelectionManager.prototype._onSingleClick = function (event) {
2742 this._model.selectionStartLength = 0;
2743 this._model.isSelectAllActive = false;
2744 this._activeSelectionMode = SelectionMode.NORMAL;
2745 this._model.selectionStart = this._getMouseBufferCoords(event);
2746 if (!this._model.selectionStart) {
2747 return;
2748 }
2749 this._model.selectionEnd = null;
2750 var line = this._buffer.get(this._model.selectionStart[1]);
2751 if (!line) {
2752 return;
2753 }
2754 var char = line[this._model.selectionStart[0]];
2755 if (char[LINE_DATA_WIDTH_INDEX] === 0) {
2756 this._model.selectionStart[0]++;
2757 }
2758 };
2759 SelectionManager.prototype._onDoubleClick = function (event) {
2760 var coords = this._getMouseBufferCoords(event);
2761 if (coords) {
2762 this._activeSelectionMode = SelectionMode.WORD;
2763 this._selectWordAt(coords);
2764 }
2765 };
2766 SelectionManager.prototype._onTripleClick = function (event) {
2767 var coords = this._getMouseBufferCoords(event);
2768 if (coords) {
2769 this._activeSelectionMode = SelectionMode.LINE;
2770 this._selectLineAt(coords[1]);
2771 }
2772 };
2773 SelectionManager.prototype._onMouseMove = function (event) {
2774 var previousSelectionEnd = this._model.selectionEnd ? [this._model.selectionEnd[0], this._model.selectionEnd[1]] : null;
2775 this._model.selectionEnd = this._getMouseBufferCoords(event);
2776 if (!this._model.selectionEnd) {
2777 this.refresh(true);
2778 return;
2779 }
2780 if (this._activeSelectionMode === SelectionMode.LINE) {
2781 if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
2782 this._model.selectionEnd[0] = 0;
2783 }
2784 else {
2785 this._model.selectionEnd[0] = this._terminal.cols;
2786 }
2787 }
2788 else if (this._activeSelectionMode === SelectionMode.WORD) {
2789 this._selectToWordAt(this._model.selectionEnd);
2790 }
2791 this._dragScrollAmount = this._getMouseEventScrollAmount(event);
2792 if (this._dragScrollAmount > 0) {
2793 this._model.selectionEnd[0] = this._terminal.cols - 1;
2794 }
2795 else if (this._dragScrollAmount < 0) {
2796 this._model.selectionEnd[0] = 0;
2797 }
2798 if (this._model.selectionEnd[1] < this._buffer.length) {
2799 var char = this._buffer.get(this._model.selectionEnd[1])[this._model.selectionEnd[0]];
2800 if (char && char[2] === 0) {
2801 this._model.selectionEnd[0]++;
2802 }
2803 }
2804 if (!previousSelectionEnd ||
2805 previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
2806 previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
2807 this.refresh(true);
2808 }
2809 };
2810 SelectionManager.prototype._dragScroll = function () {
2811 if (this._dragScrollAmount) {
2812 this._terminal.scrollDisp(this._dragScrollAmount, false);
2813 if (this._dragScrollAmount > 0) {
2814 this._model.selectionEnd = [this._terminal.cols - 1, this._terminal.buffer.ydisp + this._terminal.rows];
2815 }
2816 else {
2817 this._model.selectionEnd = [0, this._terminal.buffer.ydisp];
2818 }
2819 this.refresh();
2820 }
2821 };
2822 SelectionManager.prototype._onMouseUp = function (event) {
2823 this._removeMouseDownListeners();
2824 };
2825 SelectionManager.prototype._convertViewportColToCharacterIndex = function (bufferLine, coords) {
2826 var charIndex = coords[0];
2827 for (var i = 0; coords[0] >= i; i++) {
2828 var char = bufferLine[i];
2829 if (char[LINE_DATA_WIDTH_INDEX] === 0) {
2830 charIndex--;
2831 }
2832 }
2833 return charIndex;
2834 };
2835 SelectionManager.prototype.setSelection = function (col, row, length) {
2836 this._model.clearSelection();
2837 this._removeMouseDownListeners();
2838 this._model.selectionStart = [col, row];
2839 this._model.selectionStartLength = length;
2840 this.refresh();
2841 };
2842 SelectionManager.prototype._getWordAt = function (coords) {
2843 var bufferLine = this._buffer.get(coords[1]);
2844 if (!bufferLine) {
2845 return null;
2846 }
2847 var line = BufferLine_1.translateBufferLineToString(bufferLine, false);
2848 var endIndex = this._convertViewportColToCharacterIndex(bufferLine, coords);
2849 var startIndex = endIndex;
2850 var charOffset = coords[0] - startIndex;
2851 var leftWideCharCount = 0;
2852 var rightWideCharCount = 0;
2853 if (line.charAt(startIndex) === ' ') {
2854 while (startIndex > 0 && line.charAt(startIndex - 1) === ' ') {
2855 startIndex--;
2856 }
2857 while (endIndex < line.length && line.charAt(endIndex + 1) === ' ') {
2858 endIndex++;
2859 }
2860 }
2861 else {
2862 var startCol = coords[0];
2863 var endCol = coords[0];
2864 if (bufferLine[startCol][LINE_DATA_WIDTH_INDEX] === 0) {
2865 leftWideCharCount++;
2866 startCol--;
2867 }
2868 if (bufferLine[endCol][LINE_DATA_WIDTH_INDEX] === 2) {
2869 rightWideCharCount++;
2870 endCol++;
2871 }
2872 while (startIndex > 0 && !this._isCharWordSeparator(line.charAt(startIndex - 1))) {
2873 if (bufferLine[startCol - 1][LINE_DATA_WIDTH_INDEX] === 0) {
2874 leftWideCharCount++;
2875 startCol--;
2876 }
2877 startIndex--;
2878 startCol--;
2879 }
2880 while (endIndex + 1 < line.length && !this._isCharWordSeparator(line.charAt(endIndex + 1))) {
2881 if (bufferLine[endCol + 1][LINE_DATA_WIDTH_INDEX] === 2) {
2882 rightWideCharCount++;
2883 endCol++;
2884 }
2885 endIndex++;
2886 endCol++;
2887 }
2888 }
2889 var start = startIndex + charOffset - leftWideCharCount;
2890 var length = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1, this._terminal.cols);
2891 return { start: start, length: length };
2892 };
2893 SelectionManager.prototype._selectWordAt = function (coords) {
2894 var wordPosition = this._getWordAt(coords);
2895 if (wordPosition) {
2896 this._model.selectionStart = [wordPosition.start, coords[1]];
2897 this._model.selectionStartLength = wordPosition.length;
2898 }
2899 };
2900 SelectionManager.prototype._selectToWordAt = function (coords) {
2901 var wordPosition = this._getWordAt(coords);
2902 if (wordPosition) {
2903 this._model.selectionEnd = [this._model.areSelectionValuesReversed() ? wordPosition.start : (wordPosition.start + wordPosition.length), coords[1]];
2904 }
2905 };
2906 SelectionManager.prototype._isCharWordSeparator = function (char) {
2907 return WORD_SEPARATORS.indexOf(char) >= 0;
2908 };
2909 SelectionManager.prototype._selectLineAt = function (line) {
2910 this._model.selectionStart = [0, line];
2911 this._model.selectionStartLength = this._terminal.cols;
2912 };
2913 return SelectionManager;
2914 }(EventEmitter_1.EventEmitter));
2915 exports.SelectionManager = SelectionManager;
2916
2917
2918
2919 },{"./EventEmitter":6,"./SelectionModel":12,"./utils/Browser":15,"./utils/BufferLine":16,"./utils/Mouse":21}],12:[function(require,module,exports){
2920 "use strict";
2921 Object.defineProperty(exports, "__esModule", { value: true });
2922 var SelectionModel = (function () {
2923 function SelectionModel(_terminal) {
2924 this._terminal = _terminal;
2925 this.clearSelection();
2926 }
2927 SelectionModel.prototype.clearSelection = function () {
2928 this.selectionStart = null;
2929 this.selectionEnd = null;
2930 this.isSelectAllActive = false;
2931 this.selectionStartLength = 0;
2932 };
2933 Object.defineProperty(SelectionModel.prototype, "finalSelectionStart", {
2934 get: function () {
2935 if (this.isSelectAllActive) {
2936 return [0, 0];
2937 }
2938 if (!this.selectionEnd || !this.selectionStart) {
2939 return this.selectionStart;
2940 }
2941 return this.areSelectionValuesReversed() ? this.selectionEnd : this.selectionStart;
2942 },
2943 enumerable: true,
2944 configurable: true
2945 });
2946 Object.defineProperty(SelectionModel.prototype, "finalSelectionEnd", {
2947 get: function () {
2948 if (this.isSelectAllActive) {
2949 return [this._terminal.cols, this._terminal.buffer.ybase + this._terminal.rows - 1];
2950 }
2951 if (!this.selectionStart) {
2952 return null;
2953 }
2954 if (!this.selectionEnd || this.areSelectionValuesReversed()) {
2955 return [this.selectionStart[0] + this.selectionStartLength, this.selectionStart[1]];
2956 }
2957 if (this.selectionStartLength) {
2958 if (this.selectionEnd[1] === this.selectionStart[1]) {
2959 return [Math.max(this.selectionStart[0] + this.selectionStartLength, this.selectionEnd[0]), this.selectionEnd[1]];
2960 }
2961 }
2962 return this.selectionEnd;
2963 },
2964 enumerable: true,
2965 configurable: true
2966 });
2967 SelectionModel.prototype.areSelectionValuesReversed = function () {
2968 var start = this.selectionStart;
2969 var end = this.selectionEnd;
2970 return start[1] > end[1] || (start[1] === end[1] && start[0] > end[0]);
2971 };
2972 SelectionModel.prototype.onTrim = function (amount) {
2973 if (this.selectionStart) {
2974 this.selectionStart[1] -= amount;
2975 }
2976 if (this.selectionEnd) {
2977 this.selectionEnd[1] -= amount;
2978 }
2979 if (this.selectionEnd && this.selectionEnd[1] < 0) {
2980 this.clearSelection();
2981 return true;
2982 }
2983 if (this.selectionStart && this.selectionStart[1] < 0) {
2984 this.selectionStart[1] = 0;
2985 }
2986 return false;
2987 };
2988 return SelectionModel;
2989 }());
2990 exports.SelectionModel = SelectionModel;
2991
2992
2993
2994 },{}],13:[function(require,module,exports){
2995 "use strict";
2996 Object.defineProperty(exports, "__esModule", { value: true });
2997 var Viewport = (function () {
2998 function Viewport(terminal, viewportElement, scrollArea, charMeasure) {
2999 var _this = this;
3000 this.terminal = terminal;
3001 this.viewportElement = viewportElement;
3002 this.scrollArea = scrollArea;
3003 this.charMeasure = charMeasure;
3004 this.currentRowHeight = 0;
3005 this.lastRecordedBufferLength = 0;
3006 this.lastRecordedViewportHeight = 0;
3007 this.terminal.on('scroll', this.syncScrollArea.bind(this));
3008 this.terminal.on('resize', this.syncScrollArea.bind(this));
3009 this.viewportElement.addEventListener('scroll', this.onScroll.bind(this));
3010 setTimeout(function () { return _this.syncScrollArea(); }, 0);
3011 }
3012 Viewport.prototype.refresh = function () {
3013 if (this.charMeasure.height > 0) {
3014 var rowHeightChanged = this.charMeasure.height !== this.currentRowHeight;
3015 if (rowHeightChanged) {
3016 this.currentRowHeight = this.charMeasure.height;
3017 this.viewportElement.style.lineHeight = this.charMeasure.height + 'px';
3018 this.terminal.rowContainer.style.lineHeight = this.charMeasure.height + 'px';
3019 }
3020 var viewportHeightChanged = this.lastRecordedViewportHeight !== this.terminal.rows;
3021 if (rowHeightChanged || viewportHeightChanged) {
3022 this.lastRecordedViewportHeight = this.terminal.rows;
3023 this.viewportElement.style.height = this.charMeasure.height * this.terminal.rows + 'px';
3024 this.terminal.selectionContainer.style.height = this.viewportElement.style.height;
3025 }
3026 this.scrollArea.style.height = (this.charMeasure.height * this.lastRecordedBufferLength) + 'px';
3027 }
3028 };
3029 Viewport.prototype.syncScrollArea = function () {
3030 if (this.lastRecordedBufferLength !== this.terminal.buffer.lines.length) {
3031 this.lastRecordedBufferLength = this.terminal.buffer.lines.length;
3032 this.refresh();
3033 }
3034 else if (this.lastRecordedViewportHeight !== this.terminal.rows) {
3035 this.refresh();
3036 }
3037 else {
3038 if (this.charMeasure.height !== this.currentRowHeight) {
3039 this.refresh();
3040 }
3041 }
3042 var scrollTop = this.terminal.buffer.ydisp * this.currentRowHeight;
3043 if (this.viewportElement.scrollTop !== scrollTop) {
3044 this.viewportElement.scrollTop = scrollTop;
3045 }
3046 };
3047 Viewport.prototype.onScroll = function (ev) {
3048 var newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
3049 var diff = newRow - this.terminal.buffer.ydisp;
3050 this.terminal.scrollDisp(diff, true);
3051 };
3052 Viewport.prototype.onWheel = function (ev) {
3053 if (ev.deltaY === 0) {
3054 return;
3055 }
3056 var multiplier = 1;
3057 if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
3058 multiplier = this.currentRowHeight;
3059 }
3060 else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
3061 multiplier = this.currentRowHeight * this.terminal.rows;
3062 }
3063 this.viewportElement.scrollTop += ev.deltaY * multiplier;
3064 ev.preventDefault();
3065 };
3066 ;
3067 Viewport.prototype.onTouchStart = function (ev) {
3068 this.lastTouchY = ev.touches[0].pageY;
3069 };
3070 ;
3071 Viewport.prototype.onTouchMove = function (ev) {
3072 var deltaY = this.lastTouchY - ev.touches[0].pageY;
3073 this.lastTouchY = ev.touches[0].pageY;
3074 if (deltaY === 0) {
3075 return;
3076 }
3077 this.viewportElement.scrollTop += deltaY;
3078 ev.preventDefault();
3079 };
3080 ;
3081 return Viewport;
3082 }());
3083 exports.Viewport = Viewport;
3084
3085
3086
3087 },{}],14:[function(require,module,exports){
3088 "use strict";
3089 Object.defineProperty(exports, "__esModule", { value: true });
3090 function prepareTextForTerminal(text, isMSWindows) {
3091 if (isMSWindows) {
3092 return text.replace(/\r?\n/g, '\r');
3093 }
3094 return text;
3095 }
3096 exports.prepareTextForTerminal = prepareTextForTerminal;
3097 function copyHandler(ev, term, selectionManager) {
3098 if (term.browser.isMSIE) {
3099 window.clipboardData.setData('Text', selectionManager.selectionText);
3100 }
3101 else {
3102 ev.clipboardData.setData('text/plain', selectionManager.selectionText);
3103 }
3104 ev.preventDefault();
3105 }
3106 exports.copyHandler = copyHandler;
3107 function pasteHandler(ev, term) {
3108 ev.stopPropagation();
3109 var text;
3110 var dispatchPaste = function (text) {
3111 text = prepareTextForTerminal(text, term.browser.isMSWindows);
3112 term.handler(text);
3113 term.textarea.value = '';
3114 term.emit('paste', text);
3115 return term.cancel(ev);
3116 };
3117 if (term.browser.isMSIE) {
3118 if (window.clipboardData) {
3119 text = window.clipboardData.getData('Text');
3120 dispatchPaste(text);
3121 }
3122 }
3123 else {
3124 if (ev.clipboardData) {
3125 text = ev.clipboardData.getData('text/plain');
3126 dispatchPaste(text);
3127 }
3128 }
3129 }
3130 exports.pasteHandler = pasteHandler;
3131 function moveTextAreaUnderMouseCursor(ev, textarea) {
3132 textarea.style.position = 'fixed';
3133 textarea.style.width = '20px';
3134 textarea.style.height = '20px';
3135 textarea.style.left = (ev.clientX - 10) + 'px';
3136 textarea.style.top = (ev.clientY - 10) + 'px';
3137 textarea.style.zIndex = '1000';
3138 textarea.focus();
3139 setTimeout(function () {
3140 textarea.style.position = null;
3141 textarea.style.width = null;
3142 textarea.style.height = null;
3143 textarea.style.left = null;
3144 textarea.style.top = null;
3145 textarea.style.zIndex = null;
3146 }, 4);
3147 }
3148 exports.moveTextAreaUnderMouseCursor = moveTextAreaUnderMouseCursor;
3149 function rightClickHandler(ev, textarea, selectionManager) {
3150 moveTextAreaUnderMouseCursor(ev, textarea);
3151 textarea.value = selectionManager.selectionText;
3152 textarea.select();
3153 }
3154 exports.rightClickHandler = rightClickHandler;
3155
3156
3157
3158 },{}],15:[function(require,module,exports){
3159 "use strict";
3160 Object.defineProperty(exports, "__esModule", { value: true });
3161 var Generic_1 = require("./Generic");
3162 var isNode = (typeof navigator === 'undefined') ? true : false;
3163 var userAgent = (isNode) ? 'node' : navigator.userAgent;
3164 var platform = (isNode) ? 'node' : navigator.platform;
3165 exports.isFirefox = !!~userAgent.indexOf('Firefox');
3166 exports.isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
3167 exports.isMac = Generic_1.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform);
3168 exports.isIpad = platform === 'iPad';
3169 exports.isIphone = platform === 'iPhone';
3170 exports.isMSWindows = Generic_1.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform);
3171 exports.isLinux = platform.indexOf('Linux') >= 0;
3172
3173
3174
3175 },{"./Generic":20}],16:[function(require,module,exports){
3176 "use strict";
3177 Object.defineProperty(exports, "__esModule", { value: true });
3178 var LINE_DATA_CHAR_INDEX = 1;
3179 var LINE_DATA_WIDTH_INDEX = 2;
3180 function translateBufferLineToString(line, trimRight, startCol, endCol) {
3181 if (startCol === void 0) { startCol = 0; }
3182 if (endCol === void 0) { endCol = null; }
3183 var lineString = '';
3184 var widthAdjustedStartCol = startCol;
3185 var widthAdjustedEndCol = endCol;
3186 for (var i = 0; i < line.length; i++) {
3187 var char = line[i];
3188 lineString += char[LINE_DATA_CHAR_INDEX];
3189 if (char[LINE_DATA_WIDTH_INDEX] === 0) {
3190 if (startCol >= i) {
3191 widthAdjustedStartCol--;
3192 }
3193 if (endCol >= i) {
3194 widthAdjustedEndCol--;
3195 }
3196 }
3197 }
3198 var finalEndCol = widthAdjustedEndCol || line.length;
3199 if (trimRight) {
3200 var rightWhitespaceIndex = lineString.search(/\s+$/);
3201 if (rightWhitespaceIndex !== -1) {
3202 finalEndCol = Math.min(finalEndCol, rightWhitespaceIndex);
3203 }
3204 if (finalEndCol <= widthAdjustedStartCol) {
3205 return '';
3206 }
3207 }
3208 return lineString.substring(widthAdjustedStartCol, finalEndCol);
3209 }
3210 exports.translateBufferLineToString = translateBufferLineToString;
3211
3212
3213
3214 },{}],17:[function(require,module,exports){
3215 "use strict";
3216 var __extends = (this && this.__extends) || (function () {
3217 var extendStatics = Object.setPrototypeOf ||
3218 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
3219 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3220 return function (d, b) {
3221 extendStatics(d, b);
3222 function __() { this.constructor = d; }
3223 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3224 };
3225 })();
3226 Object.defineProperty(exports, "__esModule", { value: true });
3227 var EventEmitter_js_1 = require("../EventEmitter.js");
3228 var CharMeasure = (function (_super) {
3229 __extends(CharMeasure, _super);
3230 function CharMeasure(document, parentElement) {
3231 var _this = _super.call(this) || this;
3232 _this._document = document;
3233 _this._parentElement = parentElement;
3234 return _this;
3235 }
3236 Object.defineProperty(CharMeasure.prototype, "width", {
3237 get: function () {
3238 return this._width;
3239 },
3240 enumerable: true,
3241 configurable: true
3242 });
3243 Object.defineProperty(CharMeasure.prototype, "height", {
3244 get: function () {
3245 return this._height;
3246 },
3247 enumerable: true,
3248 configurable: true
3249 });
3250 CharMeasure.prototype.measure = function () {
3251 var _this = this;
3252 if (!this._measureElement) {
3253 this._measureElement = this._document.createElement('span');
3254 this._measureElement.style.position = 'absolute';
3255 this._measureElement.style.top = '0';
3256 this._measureElement.style.left = '-9999em';
3257 this._measureElement.textContent = 'W';
3258 this._measureElement.setAttribute('aria-hidden', 'true');
3259 this._parentElement.appendChild(this._measureElement);
3260 setTimeout(function () { return _this._doMeasure(); }, 0);
3261 }
3262 else {
3263 this._doMeasure();
3264 }
3265 };
3266 CharMeasure.prototype._doMeasure = function () {
3267 var geometry = this._measureElement.getBoundingClientRect();
3268 if (geometry.width === 0 || geometry.height === 0) {
3269 return;
3270 }
3271 if (this._width !== geometry.width || this._height !== geometry.height) {
3272 this._width = geometry.width;
3273 this._height = geometry.height;
3274 this.emit('charsizechanged');
3275 }
3276 };
3277 return CharMeasure;
3278 }(EventEmitter_js_1.EventEmitter));
3279 exports.CharMeasure = CharMeasure;
3280
3281
3282
3283 },{"../EventEmitter.js":6}],18:[function(require,module,exports){
3284 "use strict";
3285 var __extends = (this && this.__extends) || (function () {
3286 var extendStatics = Object.setPrototypeOf ||
3287 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
3288 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3289 return function (d, b) {
3290 extendStatics(d, b);
3291 function __() { this.constructor = d; }
3292 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3293 };
3294 })();
3295 Object.defineProperty(exports, "__esModule", { value: true });
3296 var EventEmitter_1 = require("../EventEmitter");
3297 var CircularList = (function (_super) {
3298 __extends(CircularList, _super);
3299 function CircularList(maxLength) {
3300 var _this = _super.call(this) || this;
3301 _this._array = new Array(maxLength);
3302 _this._startIndex = 0;
3303 _this._length = 0;
3304 return _this;
3305 }
3306 Object.defineProperty(CircularList.prototype, "maxLength", {
3307 get: function () {
3308 return this._array.length;
3309 },
3310 set: function (newMaxLength) {
3311 var newArray = new Array(newMaxLength);
3312 for (var i = 0; i < Math.min(newMaxLength, this.length); i++) {
3313 newArray[i] = this._array[this._getCyclicIndex(i)];
3314 }
3315 this._array = newArray;
3316 this._startIndex = 0;
3317 },
3318 enumerable: true,
3319 configurable: true
3320 });
3321 Object.defineProperty(CircularList.prototype, "length", {
3322 get: function () {
3323 return this._length;
3324 },
3325 set: function (newLength) {
3326 if (newLength > this._length) {
3327 for (var i = this._length; i < newLength; i++) {
3328 this._array[i] = undefined;
3329 }
3330 }
3331 this._length = newLength;
3332 },
3333 enumerable: true,
3334 configurable: true
3335 });
3336 Object.defineProperty(CircularList.prototype, "forEach", {
3337 get: function () {
3338 var _this = this;
3339 return function (callbackfn) {
3340 var i = 0;
3341 var length = _this.length;
3342 for (var i_1 = 0; i_1 < length; i_1++) {
3343 callbackfn(_this.get(i_1), i_1);
3344 }
3345 };
3346 },
3347 enumerable: true,
3348 configurable: true
3349 });
3350 CircularList.prototype.get = function (index) {
3351 return this._array[this._getCyclicIndex(index)];
3352 };
3353 CircularList.prototype.set = function (index, value) {
3354 this._array[this._getCyclicIndex(index)] = value;
3355 };
3356 CircularList.prototype.push = function (value) {
3357 this._array[this._getCyclicIndex(this._length)] = value;
3358 if (this._length === this.maxLength) {
3359 this._startIndex++;
3360 if (this._startIndex === this.maxLength) {
3361 this._startIndex = 0;
3362 }
3363 this.emit('trim', 1);
3364 }
3365 else {
3366 this._length++;
3367 }
3368 };
3369 CircularList.prototype.pop = function () {
3370 return this._array[this._getCyclicIndex(this._length-- - 1)];
3371 };
3372 CircularList.prototype.splice = function (start, deleteCount) {
3373 var items = [];
3374 for (var _i = 2; _i < arguments.length; _i++) {
3375 items[_i - 2] = arguments[_i];
3376 }
3377 if (deleteCount) {
3378 for (var i = start; i < this._length - deleteCount; i++) {
3379 this._array[this._getCyclicIndex(i)] = this._array[this._getCyclicIndex(i + deleteCount)];
3380 }
3381 this._length -= deleteCount;
3382 }
3383 if (items && items.length) {
3384 for (var i = this._length - 1; i >= start; i--) {
3385 this._array[this._getCyclicIndex(i + items.length)] = this._array[this._getCyclicIndex(i)];
3386 }
3387 for (var i = 0; i < items.length; i++) {
3388 this._array[this._getCyclicIndex(start + i)] = items[i];
3389 }
3390 if (this._length + items.length > this.maxLength) {
3391 var countToTrim = (this._length + items.length) - this.maxLength;
3392 this._startIndex += countToTrim;
3393 this._length = this.maxLength;
3394 this.emit('trim', countToTrim);
3395 }
3396 else {
3397 this._length += items.length;
3398 }
3399 }
3400 };
3401 CircularList.prototype.trimStart = function (count) {
3402 if (count > this._length) {
3403 count = this._length;
3404 }
3405 this._startIndex += count;
3406 this._length -= count;
3407 this.emit('trim', count);
3408 };
3409 CircularList.prototype.shiftElements = function (start, count, offset) {
3410 if (count <= 0) {
3411 return;
3412 }
3413 if (start < 0 || start >= this._length) {
3414 throw new Error('start argument out of range');
3415 }
3416 if (start + offset < 0) {
3417 throw new Error('Cannot shift elements in list beyond index 0');
3418 }
3419 if (offset > 0) {
3420 for (var i = count - 1; i >= 0; i--) {
3421 this.set(start + i + offset, this.get(start + i));
3422 }
3423 var expandListBy = (start + count + offset) - this._length;
3424 if (expandListBy > 0) {
3425 this._length += expandListBy;
3426 while (this._length > this.maxLength) {
3427 this._length--;
3428 this._startIndex++;
3429 this.emit('trim', 1);
3430 }
3431 }
3432 }
3433 else {
3434 for (var i = 0; i < count; i++) {
3435 this.set(start + i + offset, this.get(start + i));
3436 }
3437 }
3438 };
3439 CircularList.prototype._getCyclicIndex = function (index) {
3440 return (this._startIndex + index) % this.maxLength;
3441 };
3442 return CircularList;
3443 }(EventEmitter_1.EventEmitter));
3444 exports.CircularList = CircularList;
3445
3446
3447
3448 },{"../EventEmitter":6}],19:[function(require,module,exports){
3449 "use strict";
3450 Object.defineProperty(exports, "__esModule", { value: true });
3451 var DomElementObjectPool = (function () {
3452 function DomElementObjectPool(type) {
3453 this.type = type;
3454 this._type = type;
3455 this._pool = [];
3456 this._inUse = {};
3457 }
3458 DomElementObjectPool.prototype.acquire = function () {
3459 var element;
3460 if (this._pool.length === 0) {
3461 element = this._createNew();
3462 }
3463 else {
3464 element = this._pool.pop();
3465 }
3466 this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)] = element;
3467 return element;
3468 };
3469 DomElementObjectPool.prototype.release = function (element) {
3470 if (!this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)]) {
3471 throw new Error('Could not release an element not yet acquired');
3472 }
3473 delete this._inUse[element.getAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE)];
3474 this._cleanElement(element);
3475 this._pool.push(element);
3476 };
3477 DomElementObjectPool.prototype._createNew = function () {
3478 var element = document.createElement(this._type);
3479 var id = DomElementObjectPool._objectCount++;
3480 element.setAttribute(DomElementObjectPool.OBJECT_ID_ATTRIBUTE, id.toString(10));
3481 return element;
3482 };
3483 DomElementObjectPool.prototype._cleanElement = function (element) {
3484 element.className = '';
3485 element.innerHTML = '';
3486 };
3487 return DomElementObjectPool;
3488 }());
3489 DomElementObjectPool.OBJECT_ID_ATTRIBUTE = 'data-obj-id';
3490 DomElementObjectPool._objectCount = 0;
3491 exports.DomElementObjectPool = DomElementObjectPool;
3492
3493
3494
3495 },{}],20:[function(require,module,exports){
3496 "use strict";
3497 Object.defineProperty(exports, "__esModule", { value: true });
3498 function contains(arr, el) {
3499 return arr.indexOf(el) >= 0;
3500 }
3501 exports.contains = contains;
3502 ;
3503
3504
3505
3506 },{}],21:[function(require,module,exports){
3507 "use strict";
3508 Object.defineProperty(exports, "__esModule", { value: true });
3509 function getCoordsRelativeToElement(event, element) {
3510 if (event.pageX == null) {
3511 return null;
3512 }
3513 var x = event.pageX;
3514 var y = event.pageY;
3515 while (element && element !== self.document.documentElement) {
3516 x -= element.offsetLeft;
3517 y -= element.offsetTop;
3518 element = 'offsetParent' in element ? element.offsetParent : element.parentElement;
3519 }
3520 return [x, y];
3521 }
3522 exports.getCoordsRelativeToElement = getCoordsRelativeToElement;
3523 function getCoords(event, rowContainer, charMeasure, colCount, rowCount, isSelection) {
3524 if (!charMeasure.width || !charMeasure.height) {
3525 return null;
3526 }
3527 var coords = getCoordsRelativeToElement(event, rowContainer);
3528 if (!coords) {
3529 return null;
3530 }
3531 coords[0] = Math.ceil((coords[0] + (isSelection ? charMeasure.width / 2 : 0)) / charMeasure.width);
3532 coords[1] = Math.ceil(coords[1] / charMeasure.height);
3533 coords[0] = Math.min(Math.max(coords[0], 1), colCount + 1);
3534 coords[1] = Math.min(Math.max(coords[1], 1), rowCount + 1);
3535 return coords;
3536 }
3537 exports.getCoords = getCoords;
3538 function getRawByteCoords(event, rowContainer, charMeasure, colCount, rowCount) {
3539 var coords = getCoords(event, rowContainer, charMeasure, colCount, rowCount);
3540 var x = coords[0];
3541 var y = coords[1];
3542 x += 32;
3543 y += 32;
3544 return { x: x, y: y };
3545 }
3546 exports.getRawByteCoords = getRawByteCoords;
3547
3548
3549
3550 },{}],22:[function(require,module,exports){
3551 "use strict";
3552 Object.defineProperty(exports, "__esModule", { value: true });
3553 var BufferSet_1 = require("./BufferSet");
3554 var CompositionHelper_1 = require("./CompositionHelper");
3555 var EventEmitter_1 = require("./EventEmitter");
3556 var Viewport_1 = require("./Viewport");
3557 var Clipboard_1 = require("./handlers/Clipboard");
3558 var EscapeSequences_1 = require("./EscapeSequences");
3559 var InputHandler_1 = require("./InputHandler");
3560 var Parser_1 = require("./Parser");
3561 var Renderer_1 = require("./Renderer");
3562 var Linkifier_1 = require("./Linkifier");
3563 var SelectionManager_1 = require("./SelectionManager");
3564 var CharMeasure_1 = require("./utils/CharMeasure");
3565 var Browser = require("./utils/Browser");
3566 var Mouse_1 = require("./utils/Mouse");
3567 var BufferLine_1 = require("./utils/BufferLine");
3568 var document = (typeof window != 'undefined') ? window.document : null;
3569 var WRITE_BUFFER_PAUSE_THRESHOLD = 5;
3570 var WRITE_BATCH_SIZE = 300;
3571 var CURSOR_BLINK_INTERVAL = 600;
3572 function Terminal(options) {
3573 var self = this;
3574 if (!(this instanceof Terminal)) {
3575 return new Terminal(arguments[0], arguments[1], arguments[2]);
3576 }
3577 self.browser = Browser;
3578 self.cancel = Terminal.cancel;
3579 EventEmitter_1.EventEmitter.call(this);
3580 if (typeof options === 'number') {
3581 options = {
3582 cols: arguments[0],
3583 rows: arguments[1],
3584 handler: arguments[2]
3585 };
3586 }
3587 options = options || {};
3588 Object.keys(Terminal.defaults).forEach(function (key) {
3589 if (options[key] == null) {
3590 options[key] = Terminal.options[key];
3591 if (Terminal[key] !== Terminal.defaults[key]) {
3592 options[key] = Terminal[key];
3593 }
3594 }
3595 self[key] = options[key];
3596 });
3597 if (options.colors.length === 8) {
3598 options.colors = options.colors.concat(Terminal._colors.slice(8));
3599 }
3600 else if (options.colors.length === 16) {
3601 options.colors = options.colors.concat(Terminal._colors.slice(16));
3602 }
3603 else if (options.colors.length === 10) {
3604 options.colors = options.colors.slice(0, -2).concat(Terminal._colors.slice(8, -2), options.colors.slice(-2));
3605 }
3606 else if (options.colors.length === 18) {
3607 options.colors = options.colors.concat(Terminal._colors.slice(16, -2), options.colors.slice(-2));
3608 }
3609 this.colors = options.colors;
3610 this.options = options;
3611 this.parent = options.body || options.parent || (document ? document.getElementsByTagName('body')[0] : null);
3612 this.cols = options.cols || options.geometry[0];
3613 this.rows = options.rows || options.geometry[1];
3614 this.geometry = [this.cols, this.rows];
3615 if (options.handler) {
3616 this.on('data', options.handler);
3617 }
3618 this.cursorState = 0;
3619 this.cursorHidden = false;
3620 this.convertEol;
3621 this.queue = '';
3622 this.customKeyEventHandler = null;
3623 this.cursorBlinkInterval = null;
3624 this.applicationKeypad = false;
3625 this.applicationCursor = false;
3626 this.originMode = false;
3627 this.insertMode = false;
3628 this.wraparoundMode = true;
3629 this.charset = null;
3630 this.gcharset = null;
3631 this.glevel = 0;
3632 this.charsets = [null];
3633 this.decLocator;
3634 this.x10Mouse;
3635 this.vt200Mouse;
3636 this.vt300Mouse;
3637 this.normalMouse;
3638 this.mouseEvents;
3639 this.sendFocus;
3640 this.utfMouse;
3641 this.sgrMouse;
3642 this.urxvtMouse;
3643 this.element;
3644 this.children;
3645 this.refreshStart;
3646 this.refreshEnd;
3647 this.savedX;
3648 this.savedY;
3649 this.savedCols;
3650 this.readable = true;
3651 this.writable = true;
3652 this.defAttr = (0 << 18) | (257 << 9) | (256 << 0);
3653 this.curAttr = this.defAttr;
3654 this.params = [];
3655 this.currentParam = 0;
3656 this.prefix = '';
3657 this.postfix = '';
3658 this.inputHandler = new InputHandler_1.InputHandler(this);
3659 this.parser = new Parser_1.Parser(this.inputHandler, this);
3660 this.renderer = this.renderer || null;
3661 this.selectionManager = this.selectionManager || null;
3662 this.linkifier = this.linkifier || new Linkifier_1.Linkifier();
3663 this.writeBuffer = [];
3664 this.writeInProgress = false;
3665 this.xoffSentToCatchUp = false;
3666 this.writeStopped = false;
3667 this.surrogate_high = '';
3668 this.buffers = new BufferSet_1.BufferSet(this);
3669 this.buffer = this.buffers.active;
3670 this.buffers.on('activate', function (buffer) {
3671 this._terminal.buffer = buffer;
3672 });
3673 if (this.selectionManager) {
3674 this.selectionManager.setBuffer(this.buffer.lines);
3675 }
3676 this.setupStops();
3677 this.userScrolling = false;
3678 }
3679 inherits(Terminal, EventEmitter_1.EventEmitter);
3680 Terminal.prototype.eraseAttr = function () {
3681 return (this.defAttr & ~0x1ff) | (this.curAttr & 0x1ff);
3682 };
3683 Terminal.tangoColors = [
3684 '#2e3436',
3685 '#cc0000',
3686 '#4e9a06',
3687 '#c4a000',
3688 '#3465a4',
3689 '#75507b',
3690 '#06989a',
3691 '#d3d7cf',
3692 '#555753',
3693 '#ef2929',
3694 '#8ae234',
3695 '#fce94f',
3696 '#729fcf',
3697 '#ad7fa8',
3698 '#34e2e2',
3699 '#eeeeec'
3700 ];
3701 Terminal.colors = (function () {
3702 var colors = Terminal.tangoColors.slice(), r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i;
3703 i = 0;
3704 for (; i < 216; i++) {
3705 out(r[(i / 36) % 6 | 0], r[(i / 6) % 6 | 0], r[i % 6]);
3706 }
3707 i = 0;
3708 for (; i < 24; i++) {
3709 r = 8 + i * 10;
3710 out(r, r, r);
3711 }
3712 function out(r, g, b) {
3713 colors.push('#' + hex(r) + hex(g) + hex(b));
3714 }
3715 function hex(c) {
3716 c = c.toString(16);
3717 return c.length < 2 ? '0' + c : c;
3718 }
3719 return colors;
3720 })();
3721 Terminal._colors = Terminal.colors.slice();
3722 Terminal.vcolors = (function () {
3723 var out = [], colors = Terminal.colors, i = 0, color;
3724 for (; i < 256; i++) {
3725 color = parseInt(colors[i].substring(1), 16);
3726 out.push([
3727 (color >> 16) & 0xff,
3728 (color >> 8) & 0xff,
3729 color & 0xff
3730 ]);
3731 }
3732 return out;
3733 })();
3734 Terminal.defaults = {
3735 colors: Terminal.colors,
3736 theme: 'default',
3737 convertEol: false,
3738 termName: 'xterm',
3739 geometry: [80, 24],
3740 cursorBlink: false,
3741 cursorStyle: 'block',
3742 visualBell: false,
3743 popOnBell: false,
3744 scrollback: 1000,
3745 screenKeys: false,
3746 debug: false,
3747 cancelEvents: false,
3748 disableStdin: false,
3749 useFlowControl: false,
3750 tabStopWidth: 8
3751 };
3752 Terminal.options = {};
3753 Terminal.focus = null;
3754 each(keys(Terminal.defaults), function (key) {
3755 Terminal[key] = Terminal.defaults[key];
3756 Terminal.options[key] = Terminal.defaults[key];
3757 });
3758 Terminal.prototype.focus = function () {
3759 return this.textarea.focus();
3760 };
3761 Terminal.prototype.getOption = function (key) {
3762 if (!(key in Terminal.defaults)) {
3763 throw new Error('No option with key "' + key + '"');
3764 }
3765 if (typeof this.options[key] !== 'undefined') {
3766 return this.options[key];
3767 }
3768 return this[key];
3769 };
3770 Terminal.prototype.setOption = function (key, value) {
3771 if (!(key in Terminal.defaults)) {
3772 throw new Error('No option with key "' + key + '"');
3773 }
3774 switch (key) {
3775 case 'scrollback':
3776 if (value < this.rows) {
3777 var msg = 'Setting the scrollback value less than the number of rows ';
3778 msg += "(" + this.rows + ") is not allowed.";
3779 console.warn(msg);
3780 return false;
3781 }
3782 if (this.options[key] !== value) {
3783 if (this.buffer.lines.length > value) {
3784 var amountToTrim = this.buffer.lines.length - value;
3785 var needsRefresh = (this.buffer.ydisp - amountToTrim < 0);
3786 this.buffer.lines.trimStart(amountToTrim);
3787 this.buffer.ybase = Math.max(this.buffer.ybase - amountToTrim, 0);
3788 this.buffer.ydisp = Math.max(this.buffer.ydisp - amountToTrim, 0);
3789 if (needsRefresh) {
3790 this.refresh(0, this.rows - 1);
3791 }
3792 }
3793 this.buffer.lines.maxLength = value;
3794 this.viewport.syncScrollArea();
3795 }
3796 break;
3797 }
3798 this[key] = value;
3799 this.options[key] = value;
3800 switch (key) {
3801 case 'cursorBlink':
3802 this.setCursorBlinking(value);
3803 break;
3804 case 'cursorStyle':
3805 this.element.classList.toggle("xterm-cursor-style-block", value === 'block');
3806 this.element.classList.toggle("xterm-cursor-style-underline", value === 'underline');
3807 this.element.classList.toggle("xterm-cursor-style-bar", value === 'bar');
3808 break;
3809 case 'tabStopWidth':
3810 this.setupStops();
3811 break;
3812 }
3813 };
3814 Terminal.prototype.restartCursorBlinking = function () {
3815 this.setCursorBlinking(this.options.cursorBlink);
3816 };
3817 Terminal.prototype.setCursorBlinking = function (enabled) {
3818 this.element.classList.toggle('xterm-cursor-blink', enabled);
3819 this.clearCursorBlinkingInterval();
3820 if (enabled) {
3821 var self = this;
3822 this.cursorBlinkInterval = setInterval(function () {
3823 self.element.classList.toggle('xterm-cursor-blink-on');
3824 }, CURSOR_BLINK_INTERVAL);
3825 }
3826 };
3827 Terminal.prototype.clearCursorBlinkingInterval = function () {
3828 this.element.classList.remove('xterm-cursor-blink-on');
3829 if (this.cursorBlinkInterval) {
3830 clearInterval(this.cursorBlinkInterval);
3831 this.cursorBlinkInterval = null;
3832 }
3833 };
3834 Terminal.bindFocus = function (term) {
3835 on(term.textarea, 'focus', function (ev) {
3836 if (term.sendFocus) {
3837 term.send(EscapeSequences_1.C0.ESC + '[I');
3838 }
3839 term.element.classList.add('focus');
3840 term.showCursor();
3841 term.restartCursorBlinking.apply(term);
3842 Terminal.focus = term;
3843 term.emit('focus', { terminal: term });
3844 });
3845 };
3846 Terminal.prototype.blur = function () {
3847 return this.textarea.blur();
3848 };
3849 Terminal.bindBlur = function (term) {
3850 on(term.textarea, 'blur', function (ev) {
3851 term.refresh(term.buffer.y, term.buffer.y);
3852 if (term.sendFocus) {
3853 term.send(EscapeSequences_1.C0.ESC + '[O');
3854 }
3855 term.element.classList.remove('focus');
3856 term.clearCursorBlinkingInterval.apply(term);
3857 Terminal.focus = null;
3858 term.emit('blur', { terminal: term });
3859 });
3860 };
3861 Terminal.prototype.initGlobal = function () {
3862 var _this = this;
3863 var term = this;
3864 Terminal.bindKeys(this);
3865 Terminal.bindFocus(this);
3866 Terminal.bindBlur(this);
3867 on(this.element, 'copy', function (event) {
3868 if (!term.hasSelection()) {
3869 return;
3870 }
3871 Clipboard_1.copyHandler(event, term, _this.selectionManager);
3872 });
3873 var pasteHandlerWrapper = function (event) { return Clipboard_1.pasteHandler(event, term); };
3874 on(this.textarea, 'paste', pasteHandlerWrapper);
3875 on(this.element, 'paste', pasteHandlerWrapper);
3876 if (term.browser.isFirefox) {
3877 on(this.element, 'mousedown', function (event) {
3878 if (event.button == 2) {
3879 Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager);
3880 }
3881 });
3882 }
3883 else {
3884 on(this.element, 'contextmenu', function (event) {
3885 Clipboard_1.rightClickHandler(event, _this.textarea, _this.selectionManager);
3886 });
3887 }
3888 if (term.browser.isLinux) {
3889 on(this.element, 'auxclick', function (event) {
3890 if (event.button === 1) {
3891 Clipboard_1.moveTextAreaUnderMouseCursor(event, _this.textarea, _this.selectionManager);
3892 }
3893 });
3894 }
3895 };
3896 Terminal.bindKeys = function (term) {
3897 on(term.element, 'keydown', function (ev) {
3898 if (document.activeElement != this) {
3899 return;
3900 }
3901 term.keyDown(ev);
3902 }, true);
3903 on(term.element, 'keypress', function (ev) {
3904 if (document.activeElement != this) {
3905 return;
3906 }
3907 term.keyPress(ev);
3908 }, true);
3909 on(term.element, 'keyup', function (ev) {
3910 if (!wasMondifierKeyOnlyEvent(ev)) {
3911 term.focus(term);
3912 }
3913 }, true);
3914 on(term.textarea, 'keydown', function (ev) {
3915 term.keyDown(ev);
3916 }, true);
3917 on(term.textarea, 'keypress', function (ev) {
3918 term.keyPress(ev);
3919 this.value = '';
3920 }, true);
3921 on(term.textarea, 'compositionstart', term.compositionHelper.compositionstart.bind(term.compositionHelper));
3922 on(term.textarea, 'compositionupdate', term.compositionHelper.compositionupdate.bind(term.compositionHelper));
3923 on(term.textarea, 'compositionend', term.compositionHelper.compositionend.bind(term.compositionHelper));
3924 term.on('refresh', term.compositionHelper.updateCompositionElements.bind(term.compositionHelper));
3925 term.on('refresh', function (data) {
3926 term.queueLinkification(data.start, data.end);
3927 });
3928 };
3929 Terminal.prototype.insertRow = function (row) {
3930 if (typeof row != 'object') {
3931 row = document.createElement('div');
3932 }
3933 this.rowContainer.appendChild(row);
3934 this.children.push(row);
3935 return row;
3936 };
3937 Terminal.prototype.open = function (parent, focus) {
3938 var _this = this;
3939 var self = this, i = 0, div;
3940 this.parent = parent || this.parent;
3941 if (!this.parent) {
3942 throw new Error('Terminal requires a parent element.');
3943 }
3944 this.context = this.parent.ownerDocument.defaultView;
3945 this.document = this.parent.ownerDocument;
3946 this.body = this.document.getElementsByTagName('body')[0];
3947 this.element = this.document.createElement('div');
3948 this.element.classList.add('terminal');
3949 this.element.classList.add('xterm');
3950 this.element.classList.add('xterm-theme-' + this.theme);
3951 this.element.classList.add("xterm-cursor-style-" + this.options.cursorStyle);
3952 this.setCursorBlinking(this.options.cursorBlink);
3953 this.element.setAttribute('tabindex', 0);
3954 this.viewportElement = document.createElement('div');
3955 this.viewportElement.classList.add('xterm-viewport');
3956 this.element.appendChild(this.viewportElement);
3957 this.viewportScrollArea = document.createElement('div');
3958 this.viewportScrollArea.classList.add('xterm-scroll-area');
3959 this.viewportElement.appendChild(this.viewportScrollArea);
3960 this.selectionContainer = document.createElement('div');
3961 this.selectionContainer.classList.add('xterm-selection');
3962 this.element.appendChild(this.selectionContainer);
3963 this.rowContainer = document.createElement('div');
3964 this.rowContainer.classList.add('xterm-rows');
3965 this.element.appendChild(this.rowContainer);
3966 this.children = [];
3967 this.linkifier.attachToDom(document, this.children);
3968 this.helperContainer = document.createElement('div');
3969 this.helperContainer.classList.add('xterm-helpers');
3970 this.element.appendChild(this.helperContainer);
3971 this.textarea = document.createElement('textarea');
3972 this.textarea.classList.add('xterm-helper-textarea');
3973 this.textarea.setAttribute('autocorrect', 'off');
3974 this.textarea.setAttribute('autocapitalize', 'off');
3975 this.textarea.setAttribute('spellcheck', 'false');
3976 this.textarea.tabIndex = 0;
3977 this.textarea.addEventListener('focus', function () {
3978 self.emit('focus', { terminal: self });
3979 });
3980 this.textarea.addEventListener('blur', function () {
3981 self.emit('blur', { terminal: self });
3982 });
3983 this.helperContainer.appendChild(this.textarea);
3984 this.compositionView = document.createElement('div');
3985 this.compositionView.classList.add('composition-view');
3986 this.compositionHelper = new CompositionHelper_1.CompositionHelper(this.textarea, this.compositionView, this);
3987 this.helperContainer.appendChild(this.compositionView);
3988 this.charSizeStyleElement = document.createElement('style');
3989 this.helperContainer.appendChild(this.charSizeStyleElement);
3990 for (; i < this.rows; i++) {
3991 this.insertRow();
3992 }
3993 this.parent.appendChild(this.element);
3994 this.charMeasure = new CharMeasure_1.CharMeasure(document, this.helperContainer);
3995 this.charMeasure.on('charsizechanged', function () {
3996 self.updateCharSizeStyles();
3997 });
3998 this.charMeasure.measure();
3999 this.viewport = new Viewport_1.Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
4000 this.renderer = new Renderer_1.Renderer(this);
4001 this.selectionManager = new SelectionManager_1.SelectionManager(this, this.buffer.lines, this.rowContainer, this.charMeasure);
4002 this.selectionManager.on('refresh', function (data) {
4003 _this.renderer.refreshSelection(data.start, data.end);
4004 });
4005 this.selectionManager.on('newselection', function (text) {
4006 _this.textarea.value = text;
4007 _this.textarea.focus();
4008 _this.textarea.select();
4009 });
4010 this.on('scroll', function () { return _this.selectionManager.refresh(); });
4011 this.viewportElement.addEventListener('scroll', function () { return _this.selectionManager.refresh(); });
4012 this.refresh(0, this.rows - 1);
4013 this.initGlobal();
4014 if (typeof focus == 'undefined') {
4015 var message = 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
4016 message += 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
4017 message += 'it will default to `false`.';
4018 console.warn(message);
4019 focus = true;
4020 }
4021 if (focus) {
4022 this.focus();
4023 }
4024 this.bindMouse();
4025 this.emit('open');
4026 };
4027 Terminal.loadAddon = function (addon, callback) {
4028 if (typeof exports === 'object' && typeof module === 'object') {
4029 return require('./addons/' + addon + '/' + addon);
4030 }
4031 else if (typeof define == 'function') {
4032 return require(['./addons/' + addon + '/' + addon], callback);
4033 }
4034 else {
4035 console.error('Cannot load a module without a CommonJS or RequireJS environment.');
4036 return false;
4037 }
4038 };
4039 Terminal.prototype.updateCharSizeStyles = function () {
4040 this.charSizeStyleElement.textContent =
4041 ".xterm-wide-char{width:" + this.charMeasure.width * 2 + "px;}" +
4042 (".xterm-normal-char{width:" + this.charMeasure.width + "px;}") +
4043 (".xterm-rows > div{height:" + this.charMeasure.height + "px;}");
4044 };
4045 Terminal.prototype.bindMouse = function () {
4046 var el = this.element, self = this, pressed = 32;
4047 function sendButton(ev) {
4048 var button, pos;
4049 button = getButton(ev);
4050 pos = Mouse_1.getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
4051 if (!pos)
4052 return;
4053 sendEvent(button, pos);
4054 switch (ev.overrideType || ev.type) {
4055 case 'mousedown':
4056 pressed = button;
4057 break;
4058 case 'mouseup':
4059 pressed = 32;
4060 break;
4061 case 'wheel':
4062 break;
4063 }
4064 }
4065 function sendMove(ev) {
4066 var button = pressed, pos;
4067 pos = Mouse_1.getRawByteCoords(ev, self.rowContainer, self.charMeasure, self.cols, self.rows);
4068 if (!pos)
4069 return;
4070 button += 32;
4071 sendEvent(button, pos);
4072 }
4073 function encode(data, ch) {
4074 if (!self.utfMouse) {
4075 if (ch === 255)
4076 return data.push(0);
4077 if (ch > 127)
4078 ch = 127;
4079 data.push(ch);
4080 }
4081 else {
4082 if (ch === 2047)
4083 return data.push(0);
4084 if (ch < 127) {
4085 data.push(ch);
4086 }
4087 else {
4088 if (ch > 2047)
4089 ch = 2047;
4090 data.push(0xC0 | (ch >> 6));
4091 data.push(0x80 | (ch & 0x3F));
4092 }
4093 }
4094 }
4095 function sendEvent(button, pos) {
4096 if (self.vt300Mouse) {
4097 button &= 3;
4098 pos.x -= 32;
4099 pos.y -= 32;
4100 var data = EscapeSequences_1.C0.ESC + '[24';
4101 if (button === 0)
4102 data += '1';
4103 else if (button === 1)
4104 data += '3';
4105 else if (button === 2)
4106 data += '5';
4107 else if (button === 3)
4108 return;
4109 else
4110 data += '0';
4111 data += '~[' + pos.x + ',' + pos.y + ']\r';
4112 self.send(data);
4113 return;
4114 }
4115 if (self.decLocator) {
4116 button &= 3;
4117 pos.x -= 32;
4118 pos.y -= 32;
4119 if (button === 0)
4120 button = 2;
4121 else if (button === 1)
4122 button = 4;
4123 else if (button === 2)
4124 button = 6;
4125 else if (button === 3)
4126 button = 3;
4127 self.send(EscapeSequences_1.C0.ESC + '['
4128 + button
4129 + ';'
4130 + (button === 3 ? 4 : 0)
4131 + ';'
4132 + pos.y
4133 + ';'
4134 + pos.x
4135 + ';'
4136 + (pos.page || 0)
4137 + '&w');
4138 return;
4139 }
4140 if (self.urxvtMouse) {
4141 pos.x -= 32;
4142 pos.y -= 32;
4143 pos.x++;
4144 pos.y++;
4145 self.send(EscapeSequences_1.C0.ESC + '[' + button + ';' + pos.x + ';' + pos.y + 'M');
4146 return;
4147 }
4148 if (self.sgrMouse) {
4149 pos.x -= 32;
4150 pos.y -= 32;
4151 self.send(EscapeSequences_1.C0.ESC + '[<'
4152 + (((button & 3) === 3 ? button & ~3 : button) - 32)
4153 + ';'
4154 + pos.x
4155 + ';'
4156 + pos.y
4157 + ((button & 3) === 3 ? 'm' : 'M'));
4158 return;
4159 }
4160 var data = [];
4161 encode(data, button);
4162 encode(data, pos.x);
4163 encode(data, pos.y);
4164 self.send(EscapeSequences_1.C0.ESC + '[M' + String.fromCharCode.apply(String, data));
4165 }
4166 function getButton(ev) {
4167 var button, shift, meta, ctrl, mod;
4168 switch (ev.overrideType || ev.type) {
4169 case 'mousedown':
4170 button = ev.button != null
4171 ? +ev.button
4172 : ev.which != null
4173 ? ev.which - 1
4174 : null;
4175 if (self.browser.isMSIE) {
4176 button = button === 1 ? 0 : button === 4 ? 1 : button;
4177 }
4178 break;
4179 case 'mouseup':
4180 button = 3;
4181 break;
4182 case 'DOMMouseScroll':
4183 button = ev.detail < 0
4184 ? 64
4185 : 65;
4186 break;
4187 case 'wheel':
4188 button = ev.wheelDeltaY > 0
4189 ? 64
4190 : 65;
4191 break;
4192 }
4193 shift = ev.shiftKey ? 4 : 0;
4194 meta = ev.metaKey ? 8 : 0;
4195 ctrl = ev.ctrlKey ? 16 : 0;
4196 mod = shift | meta | ctrl;
4197 if (self.vt200Mouse) {
4198 mod &= ctrl;
4199 }
4200 else if (!self.normalMouse) {
4201 mod = 0;
4202 }
4203 button = (32 + (mod << 2)) + button;
4204 return button;
4205 }
4206 on(el, 'mousedown', function (ev) {
4207 ev.preventDefault();
4208 self.focus();
4209 if (!self.mouseEvents)
4210 return;
4211 sendButton(ev);
4212 if (self.vt200Mouse) {
4213 ev.overrideType = 'mouseup';
4214 sendButton(ev);
4215 return self.cancel(ev);
4216 }
4217 if (self.normalMouse)
4218 on(self.document, 'mousemove', sendMove);
4219 if (!self.x10Mouse) {
4220 on(self.document, 'mouseup', function up(ev) {
4221 sendButton(ev);
4222 if (self.normalMouse)
4223 off(self.document, 'mousemove', sendMove);
4224 off(self.document, 'mouseup', up);
4225 return self.cancel(ev);
4226 });
4227 }
4228 return self.cancel(ev);
4229 });
4230 on(el, 'wheel', function (ev) {
4231 if (!self.mouseEvents)
4232 return;
4233 if (self.x10Mouse
4234 || self.vt300Mouse
4235 || self.decLocator)
4236 return;
4237 sendButton(ev);
4238 return self.cancel(ev);
4239 });
4240 on(el, 'wheel', function (ev) {
4241 if (self.mouseEvents)
4242 return;
4243 self.viewport.onWheel(ev);
4244 return self.cancel(ev);
4245 });
4246 on(el, 'touchstart', function (ev) {
4247 if (self.mouseEvents)
4248 return;
4249 self.viewport.onTouchStart(ev);
4250 return self.cancel(ev);
4251 });
4252 on(el, 'touchmove', function (ev) {
4253 if (self.mouseEvents)
4254 return;
4255 self.viewport.onTouchMove(ev);
4256 return self.cancel(ev);
4257 });
4258 };
4259 Terminal.prototype.destroy = function () {
4260 this.readable = false;
4261 this.writable = false;
4262 this._events = {};
4263 this.handler = function () { };
4264 this.write = function () { };
4265 if (this.element && this.element.parentNode) {
4266 this.element.parentNode.removeChild(this.element);
4267 }
4268 };
4269 Terminal.prototype.refresh = function (start, end) {
4270 if (this.renderer) {
4271 this.renderer.queueRefresh(start, end);
4272 }
4273 };
4274 Terminal.prototype.queueLinkification = function (start, end) {
4275 if (this.linkifier) {
4276 for (var i = start; i <= end; i++) {
4277 this.linkifier.linkifyRow(i);
4278 }
4279 }
4280 };
4281 Terminal.prototype.showCursor = function () {
4282 if (!this.cursorState) {
4283 this.cursorState = 1;
4284 this.refresh(this.buffer.y, this.buffer.y);
4285 }
4286 };
4287 Terminal.prototype.scroll = function (isWrapped) {
4288 var row;
4289 if (this.buffer.lines.length === this.buffer.lines.maxLength) {
4290 this.buffer.lines.trimStart(1);
4291 this.buffer.ybase--;
4292 if (this.buffer.ydisp !== 0) {
4293 this.buffer.ydisp--;
4294 }
4295 }
4296 this.buffer.ybase++;
4297 if (!this.userScrolling) {
4298 this.buffer.ydisp = this.buffer.ybase;
4299 }
4300 row = this.buffer.ybase + this.rows - 1;
4301 row -= this.rows - 1 - this.buffer.scrollBottom;
4302 if (row === this.buffer.lines.length) {
4303 this.buffer.lines.push(this.blankLine(undefined, isWrapped));
4304 }
4305 else {
4306 this.buffer.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
4307 }
4308 if (this.buffer.scrollTop !== 0) {
4309 if (this.buffer.ybase !== 0) {
4310 this.buffer.ybase--;
4311 if (!this.userScrolling) {
4312 this.buffer.ydisp = this.buffer.ybase;
4313 }
4314 }
4315 this.buffer.lines.splice(this.buffer.ybase + this.buffer.scrollTop, 1);
4316 }
4317 this.updateRange(this.buffer.scrollTop);
4318 this.updateRange(this.buffer.scrollBottom);
4319 this.emit('scroll', this.buffer.ydisp);
4320 };
4321 Terminal.prototype.scrollDisp = function (disp, suppressScrollEvent) {
4322 if (disp < 0) {
4323 if (this.buffer.ydisp === 0) {
4324 return;
4325 }
4326 this.userScrolling = true;
4327 }
4328 else if (disp + this.buffer.ydisp >= this.buffer.ybase) {
4329 this.userScrolling = false;
4330 }
4331 var oldYdisp = this.buffer.ydisp;
4332 this.buffer.ydisp = Math.max(Math.min(this.buffer.ydisp + disp, this.buffer.ybase), 0);
4333 if (oldYdisp === this.buffer.ydisp) {
4334 return;
4335 }
4336 if (!suppressScrollEvent) {
4337 this.emit('scroll', this.buffer.ydisp);
4338 }
4339 this.refresh(0, this.rows - 1);
4340 };
4341 Terminal.prototype.scrollPages = function (pageCount) {
4342 this.scrollDisp(pageCount * (this.rows - 1));
4343 };
4344 Terminal.prototype.scrollToTop = function () {
4345 this.scrollDisp(-this.buffer.ydisp);
4346 };
4347 Terminal.prototype.scrollToBottom = function () {
4348 this.scrollDisp(this.buffer.ybase - this.buffer.ydisp);
4349 };
4350 Terminal.prototype.write = function (data) {
4351 this.writeBuffer.push(data);
4352 if (this.options.useFlowControl && !this.xoffSentToCatchUp && this.writeBuffer.length >= WRITE_BUFFER_PAUSE_THRESHOLD) {
4353 this.send(EscapeSequences_1.C0.DC3);
4354 this.xoffSentToCatchUp = true;
4355 }
4356 if (!this.writeInProgress && this.writeBuffer.length > 0) {
4357 this.writeInProgress = true;
4358 var self = this;
4359 setTimeout(function () {
4360 self.innerWrite();
4361 });
4362 }
4363 };
4364 Terminal.prototype.innerWrite = function () {
4365 var writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
4366 while (writeBatch.length > 0) {
4367 var data = writeBatch.shift();
4368 var l = data.length, i = 0, j, cs, ch, code, low, ch_width, row;
4369 if (this.xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
4370 this.send(EscapeSequences_1.C0.DC1);
4371 this.xoffSentToCatchUp = false;
4372 }
4373 this.refreshStart = this.buffer.y;
4374 this.refreshEnd = this.buffer.y;
4375 var state = this.parser.parse(data);
4376 this.parser.setState(state);
4377 this.updateRange(this.buffer.y);
4378 this.refresh(this.refreshStart, this.refreshEnd);
4379 }
4380 if (this.writeBuffer.length > 0) {
4381 var self = this;
4382 setTimeout(function () {
4383 self.innerWrite();
4384 }, 0);
4385 }
4386 else {
4387 this.writeInProgress = false;
4388 }
4389 };
4390 Terminal.prototype.writeln = function (data) {
4391 this.write(data + '\r\n');
4392 };
4393 Terminal.prototype.attachCustomKeydownHandler = function (customKeydownHandler) {
4394 var message = 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
4395 console.warn(message);
4396 this.attachCustomKeyEventHandler(customKeydownHandler);
4397 };
4398 Terminal.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler) {
4399 this.customKeyEventHandler = customKeyEventHandler;
4400 };
4401 Terminal.prototype.setHypertextLinkHandler = function (handler) {
4402 if (!this.linkifier) {
4403 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
4404 }
4405 this.linkifier.setHypertextLinkHandler(handler);
4406 this.refresh(0, this.rows - 1);
4407 };
4408 Terminal.prototype.setHypertextValidationCallback = function (callback) {
4409 if (!this.linkifier) {
4410 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
4411 }
4412 this.linkifier.setHypertextValidationCallback(callback);
4413 this.refresh(0, this.rows - 1);
4414 };
4415 Terminal.prototype.registerLinkMatcher = function (regex, handler, options) {
4416 if (this.linkifier) {
4417 var matcherId = this.linkifier.registerLinkMatcher(regex, handler, options);
4418 this.refresh(0, this.rows - 1);
4419 return matcherId;
4420 }
4421 };
4422 Terminal.prototype.deregisterLinkMatcher = function (matcherId) {
4423 if (this.linkifier) {
4424 if (this.linkifier.deregisterLinkMatcher(matcherId)) {
4425 this.refresh(0, this.rows - 1);
4426 }
4427 }
4428 };
4429 Terminal.prototype.hasSelection = function () {
4430 return this.selectionManager ? this.selectionManager.hasSelection : false;
4431 };
4432 Terminal.prototype.getSelection = function () {
4433 return this.selectionManager ? this.selectionManager.selectionText : '';
4434 };
4435 Terminal.prototype.clearSelection = function () {
4436 if (this.selectionManager) {
4437 this.selectionManager.clearSelection();
4438 }
4439 };
4440 Terminal.prototype.selectAll = function () {
4441 if (this.selectionManager) {
4442 this.selectionManager.selectAll();
4443 }
4444 };
4445 Terminal.prototype.keyDown = function (ev) {
4446 if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
4447 return false;
4448 }
4449 this.restartCursorBlinking();
4450 if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
4451 if (this.buffer.ybase !== this.buffer.ydisp) {
4452 this.scrollToBottom();
4453 }
4454 return false;
4455 }
4456 var self = this;
4457 var result = this.evaluateKeyEscapeSequence(ev);
4458 if (result.key === EscapeSequences_1.C0.DC3) {
4459 this.writeStopped = true;
4460 }
4461 else if (result.key === EscapeSequences_1.C0.DC1) {
4462 this.writeStopped = false;
4463 }
4464 if (result.scrollDisp) {
4465 this.scrollDisp(result.scrollDisp);
4466 return this.cancel(ev, true);
4467 }
4468 if (isThirdLevelShift(this, ev)) {
4469 return true;
4470 }
4471 if (result.cancel) {
4472 this.cancel(ev, true);
4473 }
4474 if (!result.key) {
4475 return true;
4476 }
4477 this.emit('keydown', ev);
4478 this.emit('key', result.key, ev);
4479 this.showCursor();
4480 this.handler(result.key);
4481 return this.cancel(ev, true);
4482 };
4483 Terminal.prototype.evaluateKeyEscapeSequence = function (ev) {
4484 var result = {
4485 cancel: false,
4486 key: undefined,
4487 scrollDisp: undefined
4488 };
4489 var modifiers = ev.shiftKey << 0 | ev.altKey << 1 | ev.ctrlKey << 2 | ev.metaKey << 3;
4490 switch (ev.keyCode) {
4491 case 8:
4492 if (ev.shiftKey) {
4493 result.key = EscapeSequences_1.C0.BS;
4494 break;
4495 }
4496 result.key = EscapeSequences_1.C0.DEL;
4497 break;
4498 case 9:
4499 if (ev.shiftKey) {
4500 result.key = EscapeSequences_1.C0.ESC + '[Z';
4501 break;
4502 }
4503 result.key = EscapeSequences_1.C0.HT;
4504 result.cancel = true;
4505 break;
4506 case 13:
4507 result.key = EscapeSequences_1.C0.CR;
4508 result.cancel = true;
4509 break;
4510 case 27:
4511 result.key = EscapeSequences_1.C0.ESC;
4512 result.cancel = true;
4513 break;
4514 case 37:
4515 if (modifiers) {
4516 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'D';
4517 if (result.key == EscapeSequences_1.C0.ESC + '[1;3D') {
4518 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'b' : EscapeSequences_1.C0.ESC + '[1;5D';
4519 }
4520 }
4521 else if (this.applicationCursor) {
4522 result.key = EscapeSequences_1.C0.ESC + 'OD';
4523 }
4524 else {
4525 result.key = EscapeSequences_1.C0.ESC + '[D';
4526 }
4527 break;
4528 case 39:
4529 if (modifiers) {
4530 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'C';
4531 if (result.key == EscapeSequences_1.C0.ESC + '[1;3C') {
4532 result.key = (this.browser.isMac) ? EscapeSequences_1.C0.ESC + 'f' : EscapeSequences_1.C0.ESC + '[1;5C';
4533 }
4534 }
4535 else if (this.applicationCursor) {
4536 result.key = EscapeSequences_1.C0.ESC + 'OC';
4537 }
4538 else {
4539 result.key = EscapeSequences_1.C0.ESC + '[C';
4540 }
4541 break;
4542 case 38:
4543 if (modifiers) {
4544 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'A';
4545 if (result.key == EscapeSequences_1.C0.ESC + '[1;3A') {
4546 result.key = EscapeSequences_1.C0.ESC + '[1;5A';
4547 }
4548 }
4549 else if (this.applicationCursor) {
4550 result.key = EscapeSequences_1.C0.ESC + 'OA';
4551 }
4552 else {
4553 result.key = EscapeSequences_1.C0.ESC + '[A';
4554 }
4555 break;
4556 case 40:
4557 if (modifiers) {
4558 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'B';
4559 if (result.key == EscapeSequences_1.C0.ESC + '[1;3B') {
4560 result.key = EscapeSequences_1.C0.ESC + '[1;5B';
4561 }
4562 }
4563 else if (this.applicationCursor) {
4564 result.key = EscapeSequences_1.C0.ESC + 'OB';
4565 }
4566 else {
4567 result.key = EscapeSequences_1.C0.ESC + '[B';
4568 }
4569 break;
4570 case 45:
4571 if (!ev.shiftKey && !ev.ctrlKey) {
4572 result.key = EscapeSequences_1.C0.ESC + '[2~';
4573 }
4574 break;
4575 case 46:
4576 if (modifiers) {
4577 result.key = EscapeSequences_1.C0.ESC + '[3;' + (modifiers + 1) + '~';
4578 }
4579 else {
4580 result.key = EscapeSequences_1.C0.ESC + '[3~';
4581 }
4582 break;
4583 case 36:
4584 if (modifiers)
4585 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'H';
4586 else if (this.applicationCursor)
4587 result.key = EscapeSequences_1.C0.ESC + 'OH';
4588 else
4589 result.key = EscapeSequences_1.C0.ESC + '[H';
4590 break;
4591 case 35:
4592 if (modifiers)
4593 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'F';
4594 else if (this.applicationCursor)
4595 result.key = EscapeSequences_1.C0.ESC + 'OF';
4596 else
4597 result.key = EscapeSequences_1.C0.ESC + '[F';
4598 break;
4599 case 33:
4600 if (ev.shiftKey) {
4601 result.scrollDisp = -(this.rows - 1);
4602 }
4603 else {
4604 result.key = EscapeSequences_1.C0.ESC + '[5~';
4605 }
4606 break;
4607 case 34:
4608 if (ev.shiftKey) {
4609 result.scrollDisp = this.rows - 1;
4610 }
4611 else {
4612 result.key = EscapeSequences_1.C0.ESC + '[6~';
4613 }
4614 break;
4615 case 112:
4616 if (modifiers) {
4617 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'P';
4618 }
4619 else {
4620 result.key = EscapeSequences_1.C0.ESC + 'OP';
4621 }
4622 break;
4623 case 113:
4624 if (modifiers) {
4625 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'Q';
4626 }
4627 else {
4628 result.key = EscapeSequences_1.C0.ESC + 'OQ';
4629 }
4630 break;
4631 case 114:
4632 if (modifiers) {
4633 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'R';
4634 }
4635 else {
4636 result.key = EscapeSequences_1.C0.ESC + 'OR';
4637 }
4638 break;
4639 case 115:
4640 if (modifiers) {
4641 result.key = EscapeSequences_1.C0.ESC + '[1;' + (modifiers + 1) + 'S';
4642 }
4643 else {
4644 result.key = EscapeSequences_1.C0.ESC + 'OS';
4645 }
4646 break;
4647 case 116:
4648 if (modifiers) {
4649 result.key = EscapeSequences_1.C0.ESC + '[15;' + (modifiers + 1) + '~';
4650 }
4651 else {
4652 result.key = EscapeSequences_1.C0.ESC + '[15~';
4653 }
4654 break;
4655 case 117:
4656 if (modifiers) {
4657 result.key = EscapeSequences_1.C0.ESC + '[17;' + (modifiers + 1) + '~';
4658 }
4659 else {
4660 result.key = EscapeSequences_1.C0.ESC + '[17~';
4661 }
4662 break;
4663 case 118:
4664 if (modifiers) {
4665 result.key = EscapeSequences_1.C0.ESC + '[18;' + (modifiers + 1) + '~';
4666 }
4667 else {
4668 result.key = EscapeSequences_1.C0.ESC + '[18~';
4669 }
4670 break;
4671 case 119:
4672 if (modifiers) {
4673 result.key = EscapeSequences_1.C0.ESC + '[19;' + (modifiers + 1) + '~';
4674 }
4675 else {
4676 result.key = EscapeSequences_1.C0.ESC + '[19~';
4677 }
4678 break;
4679 case 120:
4680 if (modifiers) {
4681 result.key = EscapeSequences_1.C0.ESC + '[20;' + (modifiers + 1) + '~';
4682 }
4683 else {
4684 result.key = EscapeSequences_1.C0.ESC + '[20~';
4685 }
4686 break;
4687 case 121:
4688 if (modifiers) {
4689 result.key = EscapeSequences_1.C0.ESC + '[21;' + (modifiers + 1) + '~';
4690 }
4691 else {
4692 result.key = EscapeSequences_1.C0.ESC + '[21~';
4693 }
4694 break;
4695 case 122:
4696 if (modifiers) {
4697 result.key = EscapeSequences_1.C0.ESC + '[23;' + (modifiers + 1) + '~';
4698 }
4699 else {
4700 result.key = EscapeSequences_1.C0.ESC + '[23~';
4701 }
4702 break;
4703 case 123:
4704 if (modifiers) {
4705 result.key = EscapeSequences_1.C0.ESC + '[24;' + (modifiers + 1) + '~';
4706 }
4707 else {
4708 result.key = EscapeSequences_1.C0.ESC + '[24~';
4709 }
4710 break;
4711 default:
4712 if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
4713 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
4714 result.key = String.fromCharCode(ev.keyCode - 64);
4715 }
4716 else if (ev.keyCode === 32) {
4717 result.key = String.fromCharCode(0);
4718 }
4719 else if (ev.keyCode >= 51 && ev.keyCode <= 55) {
4720 result.key = String.fromCharCode(ev.keyCode - 51 + 27);
4721 }
4722 else if (ev.keyCode === 56) {
4723 result.key = String.fromCharCode(127);
4724 }
4725 else if (ev.keyCode === 219) {
4726 result.key = String.fromCharCode(27);
4727 }
4728 else if (ev.keyCode === 220) {
4729 result.key = String.fromCharCode(28);
4730 }
4731 else if (ev.keyCode === 221) {
4732 result.key = String.fromCharCode(29);
4733 }
4734 }
4735 else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) {
4736 if (ev.keyCode >= 65 && ev.keyCode <= 90) {
4737 result.key = EscapeSequences_1.C0.ESC + String.fromCharCode(ev.keyCode + 32);
4738 }
4739 else if (ev.keyCode === 192) {
4740 result.key = EscapeSequences_1.C0.ESC + '`';
4741 }
4742 else if (ev.keyCode >= 48 && ev.keyCode <= 57) {
4743 result.key = EscapeSequences_1.C0.ESC + (ev.keyCode - 48);
4744 }
4745 }
4746 else if (this.browser.isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) {
4747 if (ev.keyCode === 65) {
4748 this.selectAll();
4749 }
4750 }
4751 break;
4752 }
4753 return result;
4754 };
4755 Terminal.prototype.setgLevel = function (g) {
4756 this.glevel = g;
4757 this.charset = this.charsets[g];
4758 };
4759 Terminal.prototype.setgCharset = function (g, charset) {
4760 this.charsets[g] = charset;
4761 if (this.glevel === g) {
4762 this.charset = charset;
4763 }
4764 };
4765 Terminal.prototype.keyPress = function (ev) {
4766 var key;
4767 if (this.customKeyEventHandler && this.customKeyEventHandler(ev) === false) {
4768 return false;
4769 }
4770 this.cancel(ev);
4771 if (ev.charCode) {
4772 key = ev.charCode;
4773 }
4774 else if (ev.which == null) {
4775 key = ev.keyCode;
4776 }
4777 else if (ev.which !== 0 && ev.charCode !== 0) {
4778 key = ev.which;
4779 }
4780 else {
4781 return false;
4782 }
4783 if (!key || ((ev.altKey || ev.ctrlKey || ev.metaKey) && !isThirdLevelShift(this, ev))) {
4784 return false;
4785 }
4786 key = String.fromCharCode(key);
4787 this.emit('keypress', key, ev);
4788 this.emit('key', key, ev);
4789 this.showCursor();
4790 this.handler(key);
4791 return true;
4792 };
4793 Terminal.prototype.send = function (data) {
4794 var self = this;
4795 if (!this.queue) {
4796 setTimeout(function () {
4797 self.handler(self.queue);
4798 self.queue = '';
4799 }, 1);
4800 }
4801 this.queue += data;
4802 };
4803 Terminal.prototype.bell = function () {
4804 if (!this.visualBell)
4805 return;
4806 var self = this;
4807 this.element.style.borderColor = 'white';
4808 setTimeout(function () {
4809 self.element.style.borderColor = '';
4810 }, 10);
4811 if (this.popOnBell)
4812 this.focus();
4813 };
4814 Terminal.prototype.log = function () {
4815 if (!this.debug)
4816 return;
4817 if (!this.context.console || !this.context.console.log)
4818 return;
4819 var args = Array.prototype.slice.call(arguments);
4820 this.context.console.log.apply(this.context.console, args);
4821 };
4822 Terminal.prototype.error = function () {
4823 if (!this.debug)
4824 return;
4825 if (!this.context.console || !this.context.console.error)
4826 return;
4827 var args = Array.prototype.slice.call(arguments);
4828 this.context.console.error.apply(this.context.console, args);
4829 };
4830 Terminal.prototype.resize = function (x, y) {
4831 if (isNaN(x) || isNaN(y)) {
4832 return;
4833 }
4834 if (y > this.getOption('scrollback')) {
4835 this.setOption('scrollback', y);
4836 }
4837 var line, el, i, j, ch, addToY;
4838 if (x === this.cols && y === this.rows) {
4839 if (!this.charMeasure.width || !this.charMeasure.height) {
4840 this.charMeasure.measure();
4841 }
4842 return;
4843 }
4844 if (x < 1)
4845 x = 1;
4846 if (y < 1)
4847 y = 1;
4848 this.buffers.resize(x, y);
4849 while (this.children.length < y) {
4850 this.insertRow();
4851 }
4852 while (this.children.length > y) {
4853 el = this.children.shift();
4854 if (!el)
4855 continue;
4856 el.parentNode.removeChild(el);
4857 }
4858 this.cols = x;
4859 this.rows = y;
4860 this.setupStops(this.cols);
4861 this.charMeasure.measure();
4862 this.refresh(0, this.rows - 1);
4863 this.geometry = [this.cols, this.rows];
4864 this.emit('resize', { terminal: this, cols: x, rows: y });
4865 };
4866 Terminal.prototype.updateRange = function (y) {
4867 if (y < this.refreshStart)
4868 this.refreshStart = y;
4869 if (y > this.refreshEnd)
4870 this.refreshEnd = y;
4871 };
4872 Terminal.prototype.maxRange = function () {
4873 this.refreshStart = 0;
4874 this.refreshEnd = this.rows - 1;
4875 };
4876 Terminal.prototype.setupStops = function (i) {
4877 if (i != null) {
4878 if (!this.buffer.tabs[i]) {
4879 i = this.prevStop(i);
4880 }
4881 }
4882 else {
4883 this.buffer.tabs = {};
4884 i = 0;
4885 }
4886 for (; i < this.cols; i += this.getOption('tabStopWidth')) {
4887 this.buffer.tabs[i] = true;
4888 }
4889 };
4890 Terminal.prototype.prevStop = function (x) {
4891 if (x == null)
4892 x = this.buffer.x;
4893 while (!this.buffer.tabs[--x] && x > 0)
4894 ;
4895 return x >= this.cols
4896 ? this.cols - 1
4897 : x < 0 ? 0 : x;
4898 };
4899 Terminal.prototype.nextStop = function (x) {
4900 if (x == null)
4901 x = this.buffer.x;
4902 while (!this.buffer.tabs[++x] && x < this.cols)
4903 ;
4904 return x >= this.cols
4905 ? this.cols - 1
4906 : x < 0 ? 0 : x;
4907 };
4908 Terminal.prototype.eraseRight = function (x, y) {
4909 var line = this.buffer.lines.get(this.buffer.ybase + y);
4910 if (!line) {
4911 return;
4912 }
4913 var ch = [this.eraseAttr(), ' ', 1];
4914 for (; x < this.cols; x++) {
4915 line[x] = ch;
4916 }
4917 this.updateRange(y);
4918 };
4919 Terminal.prototype.eraseLeft = function (x, y) {
4920 var line = this.buffer.lines.get(this.buffer.ybase + y);
4921 if (!line) {
4922 return;
4923 }
4924 var ch = [this.eraseAttr(), ' ', 1];
4925 x++;
4926 while (x--) {
4927 line[x] = ch;
4928 }
4929 this.updateRange(y);
4930 };
4931 Terminal.prototype.clear = function () {
4932 if (this.buffer.ybase === 0 && this.buffer.y === 0) {
4933 return;
4934 }
4935 this.buffer.lines.set(0, this.buffer.lines.get(this.buffer.ybase + this.buffer.y));
4936 this.buffer.lines.length = 1;
4937 this.buffer.ydisp = 0;
4938 this.buffer.ybase = 0;
4939 this.buffer.y = 0;
4940 for (var i = 1; i < this.rows; i++) {
4941 this.buffer.lines.push(this.blankLine());
4942 }
4943 this.refresh(0, this.rows - 1);
4944 this.emit('scroll', this.buffer.ydisp);
4945 };
4946 Terminal.prototype.eraseLine = function (y) {
4947 this.eraseRight(0, y);
4948 };
4949 Terminal.prototype.blankLine = function (cur, isWrapped, cols) {
4950 var attr = cur
4951 ? this.eraseAttr()
4952 : this.defAttr;
4953 var ch = [attr, ' ', 1], line = [], i = 0;
4954 if (isWrapped) {
4955 line.isWrapped = isWrapped;
4956 }
4957 cols = cols || this.cols;
4958 for (; i < cols; i++) {
4959 line[i] = ch;
4960 }
4961 return line;
4962 };
4963 Terminal.prototype.ch = function (cur) {
4964 return cur
4965 ? [this.eraseAttr(), ' ', 1]
4966 : [this.defAttr, ' ', 1];
4967 };
4968 Terminal.prototype.is = function (term) {
4969 var name = this.termName;
4970 return (name + '').indexOf(term) === 0;
4971 };
4972 Terminal.prototype.handler = function (data) {
4973 if (this.options.disableStdin) {
4974 return;
4975 }
4976 if (this.selectionManager && this.selectionManager.hasSelection) {
4977 this.selectionManager.clearSelection();
4978 }
4979 if (this.buffer.ybase !== this.buffer.ydisp) {
4980 this.scrollToBottom();
4981 }
4982 this.emit('data', data);
4983 };
4984 Terminal.prototype.handleTitle = function (title) {
4985 this.emit('title', title);
4986 };
4987 Terminal.prototype.index = function () {
4988 this.buffer.y++;
4989 if (this.buffer.y > this.buffer.scrollBottom) {
4990 this.buffer.y--;
4991 this.scroll();
4992 }
4993 if (this.buffer.x >= this.cols) {
4994 this.buffer.x--;
4995 }
4996 };
4997 Terminal.prototype.reverseIndex = function () {
4998 var j;
4999 if (this.buffer.y === this.buffer.scrollTop) {
5000 this.buffer.lines.shiftElements(this.buffer.y + this.buffer.ybase, this.rows - 1, 1);
5001 this.buffer.lines.set(this.buffer.y + this.buffer.ybase, this.blankLine(true));
5002 this.updateRange(this.buffer.scrollTop);
5003 this.updateRange(this.buffer.scrollBottom);
5004 }
5005 else {
5006 this.buffer.y--;
5007 }
5008 };
5009 Terminal.prototype.reset = function () {
5010 this.options.rows = this.rows;
5011 this.options.cols = this.cols;
5012 var customKeyEventHandler = this.customKeyEventHandler;
5013 var cursorBlinkInterval = this.cursorBlinkInterval;
5014 var inputHandler = this.inputHandler;
5015 Terminal.call(this, this.options);
5016 this.customKeyEventHandler = customKeyEventHandler;
5017 this.cursorBlinkInterval = cursorBlinkInterval;
5018 this.inputHandler = inputHandler;
5019 this.refresh(0, this.rows - 1);
5020 this.viewport.syncScrollArea();
5021 };
5022 Terminal.prototype.tabSet = function () {
5023 this.buffer.tabs[this.buffer.x] = true;
5024 };
5025 function on(el, type, handler, capture) {
5026 if (!Array.isArray(el)) {
5027 el = [el];
5028 }
5029 el.forEach(function (element) {
5030 element.addEventListener(type, handler, capture || false);
5031 });
5032 }
5033 function off(el, type, handler, capture) {
5034 el.removeEventListener(type, handler, capture || false);
5035 }
5036 function cancel(ev, force) {
5037 if (!this.cancelEvents && !force) {
5038 return;
5039 }
5040 ev.preventDefault();
5041 ev.stopPropagation();
5042 return false;
5043 }
5044 function inherits(child, parent) {
5045 function f() {
5046 this.constructor = child;
5047 }
5048 f.prototype = parent.prototype;
5049 child.prototype = new f;
5050 }
5051 function indexOf(obj, el) {
5052 var i = obj.length;
5053 while (i--) {
5054 if (obj[i] === el)
5055 return i;
5056 }
5057 return -1;
5058 }
5059 function isThirdLevelShift(term, ev) {
5060 var thirdLevelKey = (term.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
5061 (term.browser.isMSWindows && ev.altKey && ev.ctrlKey && !ev.metaKey);
5062 if (ev.type == 'keypress') {
5063 return thirdLevelKey;
5064 }
5065 return thirdLevelKey && (!ev.keyCode || ev.keyCode > 47);
5066 }
5067 Terminal.prototype.matchColor = matchColor;
5068 function matchColor(r1, g1, b1) {
5069 var hash = (r1 << 16) | (g1 << 8) | b1;
5070 if (matchColor._cache[hash] != null) {
5071 return matchColor._cache[hash];
5072 }
5073 var ldiff = Infinity, li = -1, i = 0, c, r2, g2, b2, diff;
5074 for (; i < Terminal.vcolors.length; i++) {
5075 c = Terminal.vcolors[i];
5076 r2 = c[0];
5077 g2 = c[1];
5078 b2 = c[2];
5079 diff = matchColor.distance(r1, g1, b1, r2, g2, b2);
5080 if (diff === 0) {
5081 li = i;
5082 break;
5083 }
5084 if (diff < ldiff) {
5085 ldiff = diff;
5086 li = i;
5087 }
5088 }
5089 return matchColor._cache[hash] = li;
5090 }
5091 matchColor._cache = {};
5092 matchColor.distance = function (r1, g1, b1, r2, g2, b2) {
5093 return Math.pow(30 * (r1 - r2), 2)
5094 + Math.pow(59 * (g1 - g2), 2)
5095 + Math.pow(11 * (b1 - b2), 2);
5096 };
5097 function each(obj, iter, con) {
5098 if (obj.forEach)
5099 return obj.forEach(iter, con);
5100 for (var i = 0; i < obj.length; i++) {
5101 iter.call(con, obj[i], i, obj);
5102 }
5103 }
5104 function wasMondifierKeyOnlyEvent(ev) {
5105 return ev.keyCode === 16 ||
5106 ev.keyCode === 17 ||
5107 ev.keyCode === 18;
5108 }
5109 function keys(obj) {
5110 if (Object.keys)
5111 return Object.keys(obj);
5112 var key, keys = [];
5113 for (key in obj) {
5114 if (Object.prototype.hasOwnProperty.call(obj, key)) {
5115 keys.push(key);
5116 }
5117 }
5118 return keys;
5119 }
5120 Terminal.translateBufferLineToString = BufferLine_1.translateBufferLineToString;
5121 Terminal.EventEmitter = EventEmitter_1.EventEmitter;
5122 Terminal.inherits = inherits;
5123 Terminal.on = on;
5124 Terminal.off = off;
5125 Terminal.cancel = cancel;
5126 module.exports = Terminal;
5127
5128
5129
5130 },{"./BufferSet":2,"./CompositionHelper":4,"./EscapeSequences":5,"./EventEmitter":6,"./InputHandler":7,"./Linkifier":8,"./Parser":9,"./Renderer":10,"./SelectionManager":11,"./Viewport":13,"./handlers/Clipboard":14,"./utils/Browser":15,"./utils/BufferLine":16,"./utils/CharMeasure":17,"./utils/Mouse":21}]},{},[22])(22)
5131 });
5132 //# sourceMappingURL=xterm.js.map