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