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