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
){
3 Object
.defineProperty(exports
, "__esModule", { value
: true });
5 exports
.DEFAULT_CHARSET
= exports
.CHARSETS
['B'];
6 exports
.CHARSETS
['0'] = {
39 exports
.CHARSETS
['A'] = {
42 exports
.CHARSETS
['B'] = null;
43 exports
.CHARSETS
['4'] = {
54 exports
.CHARSETS
['C'] =
55 exports
.CHARSETS
['5'] = {
66 exports
.CHARSETS
['R'] = {
77 exports
.CHARSETS
['Q'] = {
89 exports
.CHARSETS
['K'] = {
99 exports
.CHARSETS
['Y'] = {
111 exports
.CHARSETS
['E'] =
112 exports
.CHARSETS
['6'] = {
124 exports
.CHARSETS
['Z'] = {
134 exports
.CHARSETS
['H'] =
135 exports
.CHARSETS
['7'] = {
147 exports
.CHARSETS
['='] = {
164 },{}],2:[function(require
,module
,exports
){
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 };
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');
182 CompositionHelper
.prototype.compositionupdate = function (ev
) {
184 this.compositionView
.textContent
= ev
.data
;
185 this.updateCompositionElements();
186 setTimeout(function () {
187 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
190 CompositionHelper
.prototype.compositionend = function () {
191 this.finalizeComposition(true);
193 CompositionHelper
.prototype.keydown = function (ev
) {
194 if (this.isComposing
|| this.isSendingComposition
) {
195 if (ev
.keyCode
=== 229) {
198 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
202 this.finalizeComposition(false);
205 if (ev
.keyCode
=== 229) {
206 this.handleAnyTextareaChanges();
211 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
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
);
222 var currentCompositionPosition_1
= {
223 start
: this.compositionPosition
.start
,
224 end
: this.compositionPosition
.end
,
226 this.isSendingComposition
= true;
227 setTimeout(function () {
228 if (_this
.isSendingComposition
) {
229 _this
.isSendingComposition
= false;
231 if (_this
.isComposing
) {
232 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
235 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
237 _this
.terminal
.handler(input
);
242 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
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
);
255 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
257 if (!this.isComposing
) {
260 var cursor
= this.terminal
.element
.querySelector('.terminal-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';
276 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
280 CompositionHelper
.prototype.clearTextareaPosition = function () {
281 this.textarea
.style
.left
= '';
282 this.textarea
.style
.top
= '';
285 return CompositionHelper
;
287 exports
.CompositionHelper
= CompositionHelper
;
291 },{}],3:[function(require
,module
,exports
){
293 Object
.defineProperty(exports
, "__esModule", { value
: true });
330 })(C0
= exports
.C0
|| (exports
.C0
= {}));
335 },{}],4:[function(require
,module
,exports
){
337 Object
.defineProperty(exports
, "__esModule", { value
: true });
339 var EventEmitter
= (function () {
340 function EventEmitter() {
341 this._events
= this._events
|| {};
343 EventEmitter
.prototype.on = function (type
, listener
) {
344 this._events
[type
] = this._events
[type
] || [];
345 this._events
[type
].push(listener
);
347 EventEmitter
.prototype.off = function (type
, listener
) {
348 if (!this._events
[type
]) {
351 var obj
= this._events
[type
];
354 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
360 EventEmitter
.prototype.removeAllListeners = function (type
) {
361 if (this._events
[type
]) {
362 delete this._events
[type
];
365 EventEmitter
.prototype.once = function (type
, listener
) {
367 var args
= Array
.prototype.slice
.call(arguments
);
369 return listener
.apply(this, args
);
371 on
.listener
= listener
;
372 return this.on(type
, on
);
374 EventEmitter
.prototype.emit = function (type
) {
376 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
377 args
[_i
- 1] = arguments
[_i
];
379 if (!this._events
[type
]) {
382 var obj
= this._events
[type
];
383 for (var i
= 0; i
< obj
.length
; i
++) {
384 obj
[i
].apply(this, args
);
387 EventEmitter
.prototype.listeners = function (type
) {
388 return this._events
[type
] || [];
392 exports
.EventEmitter
= EventEmitter
;
396 },{}],5:[function(require
,module
,exports
){
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
;
405 InputHandler
.prototype.addChar = function (char, code
) {
407 var ch_width
= wcwidth(code
);
408 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
409 char = this._terminal
.charset
[char];
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;
419 this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][1] += char;
421 this._terminal
.updateRange(this._terminal
.y
);
425 if (this._terminal
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
426 if (this._terminal
.wraparoundMode
) {
427 this._terminal
.x
= 0;
429 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
431 this._terminal
.scroll(true);
434 this._terminal
.lines
.get(this._terminal
.y
).isWrapped
= true;
442 row
= this._terminal
.y
+ this._terminal
.ybase
;
443 if (this._terminal
.insertMode
) {
444 for (var moves
= 0; moves
< ch_width
; ++moves
) {
445 var removed
= this._terminal
.lines
.get(this._terminal
.y
+ this._terminal
.ybase
).pop();
447 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2]
448 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2) {
449 this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
451 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
454 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, char, ch_width
];
456 this._terminal
.updateRange(this._terminal
.y
);
457 if (ch_width
=== 2) {
458 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, '', 0];
463 InputHandler
.prototype.bell = function () {
465 if (!this._terminal
.visualBell
) {
468 this._terminal
.element
.style
.borderColor
= 'white';
469 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
470 if (this._terminal
.popOnBell
) {
471 this._terminal
.focus();
474 InputHandler
.prototype.lineFeed = function () {
475 if (this._terminal
.convertEol
) {
476 this._terminal
.x
= 0;
479 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
481 this._terminal
.scroll();
483 if (this._terminal
.x
>= this._terminal
.cols
) {
487 InputHandler
.prototype.carriageReturn = function () {
488 this._terminal
.x
= 0;
490 InputHandler
.prototype.backspace = function () {
491 if (this._terminal
.x
> 0) {
495 InputHandler
.prototype.tab = function () {
496 this._terminal
.x
= this._terminal
.nextStop();
498 InputHandler
.prototype.shiftOut = function () {
499 this._terminal
.setgLevel(1);
501 InputHandler
.prototype.shiftIn = function () {
502 this._terminal
.setgLevel(0);
504 InputHandler
.prototype.insertChars = function (params
) {
505 var param
, row
, j
, ch
;
509 row
= this._terminal
.y
+ this._terminal
.ybase
;
510 j
= this._terminal
.x
;
511 ch
= [this._terminal
.eraseAttr(), ' ', 1];
512 while (param
-- && j
< this._terminal
.cols
) {
513 this._terminal
.lines
.get(row
).splice(j
++, 0, ch
);
514 this._terminal
.lines
.get(row
).pop();
517 InputHandler
.prototype.cursorUp = function (params
) {
518 var param
= params
[0];
522 this._terminal
.y
-= param
;
523 if (this._terminal
.y
< 0) {
524 this._terminal
.y
= 0;
527 InputHandler
.prototype.cursorDown = function (params
) {
528 var param
= params
[0];
532 this._terminal
.y
+= param
;
533 if (this._terminal
.y
>= this._terminal
.rows
) {
534 this._terminal
.y
= this._terminal
.rows
- 1;
536 if (this._terminal
.x
>= this._terminal
.cols
) {
540 InputHandler
.prototype.cursorForward = function (params
) {
541 var param
= params
[0];
545 this._terminal
.x
+= param
;
546 if (this._terminal
.x
>= this._terminal
.cols
) {
547 this._terminal
.x
= this._terminal
.cols
- 1;
550 InputHandler
.prototype.cursorBackward = function (params
) {
551 var param
= params
[0];
555 if (this._terminal
.x
>= this._terminal
.cols
) {
558 this._terminal
.x
-= param
;
559 if (this._terminal
.x
< 0) {
560 this._terminal
.x
= 0;
563 InputHandler
.prototype.cursorNextLine = function (params
) {
564 var param
= params
[0];
568 this._terminal
.y
+= param
;
569 if (this._terminal
.y
>= this._terminal
.rows
) {
570 this._terminal
.y
= this._terminal
.rows
- 1;
572 this._terminal
.x
= 0;
575 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
576 var param
= params
[0];
580 this._terminal
.y
-= param
;
581 if (this._terminal
.y
< 0) {
582 this._terminal
.y
= 0;
584 this._terminal
.x
= 0;
587 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
588 var param
= params
[0];
592 this._terminal
.x
= param
- 1;
594 InputHandler
.prototype.cursorPosition = function (params
) {
597 if (params
.length
>= 2) {
606 else if (row
>= this._terminal
.rows
) {
607 row
= this._terminal
.rows
- 1;
612 else if (col
>= this._terminal
.cols
) {
613 col
= this._terminal
.cols
- 1;
615 this._terminal
.x
= col
;
616 this._terminal
.y
= row
;
618 InputHandler
.prototype.cursorForwardTab = function (params
) {
619 var param
= params
[0] || 1;
621 this._terminal
.x
= this._terminal
.nextStop();
624 InputHandler
.prototype.eraseInDisplay = function (params
) {
628 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
629 j
= this._terminal
.y
+ 1;
630 for (; j
< this._terminal
.rows
; j
++) {
631 this._terminal
.eraseLine(j
);
635 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
636 j
= this._terminal
.y
;
638 this._terminal
.eraseLine(j
);
642 j
= this._terminal
.rows
;
644 this._terminal
.eraseLine(j
);
647 var scrollBackSize
= this._terminal
.lines
.length
- this._terminal
.rows
;
648 if (scrollBackSize
> 0) {
649 this._terminal
.lines
.trimStart(scrollBackSize
);
650 this._terminal
.ybase
= Math
.max(this._terminal
.ybase
- scrollBackSize
, 0);
651 this._terminal
.ydisp
= Math
.max(this._terminal
.ydisp
- scrollBackSize
, 0);
656 InputHandler
.prototype.eraseInLine = function (params
) {
659 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
662 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
665 this._terminal
.eraseLine(this._terminal
.y
);
669 InputHandler
.prototype.insertLines = function (params
) {
675 row
= this._terminal
.y
+ this._terminal
.ybase
;
676 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
677 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
+ 1;
679 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
680 this._terminal
.lines
.trimStart(1);
681 this._terminal
.ybase
--;
682 this._terminal
.ydisp
--;
686 this._terminal
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
687 this._terminal
.lines
.splice(j
, 1);
689 this._terminal
.updateRange(this._terminal
.y
);
690 this._terminal
.updateRange(this._terminal
.scrollBottom
);
692 InputHandler
.prototype.deleteLines = function (params
) {
698 row
= this._terminal
.y
+ this._terminal
.ybase
;
699 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
700 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
;
702 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
703 this._terminal
.lines
.trimStart(1);
704 this._terminal
.ybase
-= 1;
705 this._terminal
.ydisp
-= 1;
707 this._terminal
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
708 this._terminal
.lines
.splice(row
, 1);
710 this._terminal
.updateRange(this._terminal
.y
);
711 this._terminal
.updateRange(this._terminal
.scrollBottom
);
713 InputHandler
.prototype.deleteChars = function (params
) {
719 row
= this._terminal
.y
+ this._terminal
.ybase
;
720 ch
= [this._terminal
.eraseAttr(), ' ', 1];
722 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 1);
723 this._terminal
.lines
.get(row
).push(ch
);
726 InputHandler
.prototype.scrollUp = function (params
) {
727 var param
= params
[0] || 1;
729 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 1);
730 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 0, this._terminal
.blankLine());
732 this._terminal
.updateRange(this._terminal
.scrollTop
);
733 this._terminal
.updateRange(this._terminal
.scrollBottom
);
735 InputHandler
.prototype.scrollDown = function (params
) {
736 var param
= params
[0] || 1;
738 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 1);
739 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 0, this._terminal
.blankLine());
741 this._terminal
.updateRange(this._terminal
.scrollTop
);
742 this._terminal
.updateRange(this._terminal
.scrollBottom
);
744 InputHandler
.prototype.eraseChars = function (params
) {
745 var param
, row
, j
, ch
;
750 row
= this._terminal
.y
+ this._terminal
.ybase
;
751 j
= this._terminal
.x
;
752 ch
= [this._terminal
.eraseAttr(), ' ', 1];
753 while (param
-- && j
< this._terminal
.cols
) {
754 this._terminal
.lines
.get(row
)[j
++] = ch
;
757 InputHandler
.prototype.cursorBackwardTab = function (params
) {
758 var param
= params
[0] || 1;
760 this._terminal
.x
= this._terminal
.prevStop();
763 InputHandler
.prototype.charPosAbsolute = function (params
) {
764 var param
= params
[0];
768 this._terminal
.x
= param
- 1;
769 if (this._terminal
.x
>= this._terminal
.cols
) {
770 this._terminal
.x
= this._terminal
.cols
- 1;
773 InputHandler
.prototype.HPositionRelative = function (params
) {
774 var param
= params
[0];
778 this._terminal
.x
+= param
;
779 if (this._terminal
.x
>= this._terminal
.cols
) {
780 this._terminal
.x
= this._terminal
.cols
- 1;
783 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
784 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];
786 line
[this._terminal
.x
++] = ch
;
789 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
793 if (!this._terminal
.prefix
) {
794 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
795 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
797 else if (this._terminal
.is('linux')) {
798 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
801 else if (this._terminal
.prefix
=== '>') {
802 if (this._terminal
.is('xterm')) {
803 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
805 else if (this._terminal
.is('rxvt-unicode')) {
806 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
808 else if (this._terminal
.is('linux')) {
809 this._terminal
.send(params
[0] + 'c');
811 else if (this._terminal
.is('screen')) {
812 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
816 InputHandler
.prototype.linePosAbsolute = function (params
) {
817 var param
= params
[0];
821 this._terminal
.y
= param
- 1;
822 if (this._terminal
.y
>= this._terminal
.rows
) {
823 this._terminal
.y
= this._terminal
.rows
- 1;
826 InputHandler
.prototype.VPositionRelative = function (params
) {
827 var param
= params
[0];
831 this._terminal
.y
+= param
;
832 if (this._terminal
.y
>= this._terminal
.rows
) {
833 this._terminal
.y
= this._terminal
.rows
- 1;
835 if (this._terminal
.x
>= this._terminal
.cols
) {
839 InputHandler
.prototype.HVPosition = function (params
) {
844 this._terminal
.y
= params
[0] - 1;
845 if (this._terminal
.y
>= this._terminal
.rows
) {
846 this._terminal
.y
= this._terminal
.rows
- 1;
848 this._terminal
.x
= params
[1] - 1;
849 if (this._terminal
.x
>= this._terminal
.cols
) {
850 this._terminal
.x
= this._terminal
.cols
- 1;
853 InputHandler
.prototype.tabClear = function (params
) {
854 var param
= params
[0];
856 delete this._terminal
.tabs
[this._terminal
.x
];
858 else if (param
=== 3) {
859 this._terminal
.tabs
= {};
862 InputHandler
.prototype.setMode = function (params
) {
863 if (params
.length
> 1) {
864 for (var i
= 0; i
< params
.length
; i
++) {
865 this.setMode([params
[i
]]);
869 if (!this._terminal
.prefix
) {
872 this._terminal
.insertMode
= true;
878 else if (this._terminal
.prefix
=== '?') {
881 this._terminal
.applicationCursor
= true;
884 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
885 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
886 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
887 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
890 this._terminal
.savedCols
= this._terminal
.cols
;
891 this._terminal
.resize(132, this._terminal
.rows
);
894 this._terminal
.originMode
= true;
897 this._terminal
.wraparoundMode
= true;
902 this._terminal
.log('Serial port requested application keypad.');
903 this._terminal
.applicationKeypad
= true;
904 this._terminal
.viewport
.syncScrollArea();
910 this._terminal
.x10Mouse
= params
[0] === 9;
911 this._terminal
.vt200Mouse
= params
[0] === 1000;
912 this._terminal
.normalMouse
= params
[0] > 1000;
913 this._terminal
.mouseEvents
= true;
914 this._terminal
.element
.classList
.add('enable-mouse-events');
915 this._terminal
.selectionManager
.disable();
916 this._terminal
.log('Binding to mouse events.');
919 this._terminal
.sendFocus
= true;
922 this._terminal
.utfMouse
= true;
925 this._terminal
.sgrMouse
= true;
928 this._terminal
.urxvtMouse
= true;
931 this._terminal
.cursorHidden
= false;
937 if (!this._terminal
.normal
) {
939 lines
: this._terminal
.lines
,
940 ybase
: this._terminal
.ybase
,
941 ydisp
: this._terminal
.ydisp
,
944 scrollTop
: this._terminal
.scrollTop
,
945 scrollBottom
: this._terminal
.scrollBottom
,
946 tabs
: this._terminal
.tabs
948 this._terminal
.reset();
949 this._terminal
.viewport
.syncScrollArea();
950 this._terminal
.normal
= normal
;
951 this._terminal
.showCursor();
957 InputHandler
.prototype.resetMode = function (params
) {
958 if (params
.length
> 1) {
959 for (var i
= 0; i
< params
.length
; i
++) {
960 this.resetMode([params
[i
]]);
964 if (!this._terminal
.prefix
) {
967 this._terminal
.insertMode
= false;
973 else if (this._terminal
.prefix
=== '?') {
976 this._terminal
.applicationCursor
= false;
979 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
980 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
982 delete this._terminal
.savedCols
;
985 this._terminal
.originMode
= false;
988 this._terminal
.wraparoundMode
= false;
993 this._terminal
.log('Switching back to normal keypad.');
994 this._terminal
.applicationKeypad
= false;
995 this._terminal
.viewport
.syncScrollArea();
1001 this._terminal
.x10Mouse
= false;
1002 this._terminal
.vt200Mouse
= false;
1003 this._terminal
.normalMouse
= false;
1004 this._terminal
.mouseEvents
= false;
1005 this._terminal
.element
.classList
.remove('enable-mouse-events');
1006 this._terminal
.selectionManager
.enable();
1009 this._terminal
.sendFocus
= false;
1012 this._terminal
.utfMouse
= false;
1015 this._terminal
.sgrMouse
= false;
1018 this._terminal
.urxvtMouse
= false;
1021 this._terminal
.cursorHidden
= true;
1027 if (this._terminal
.normal
) {
1028 this._terminal
.lines
= this._terminal
.normal
.lines
;
1029 this._terminal
.ybase
= this._terminal
.normal
.ybase
;
1030 this._terminal
.ydisp
= this._terminal
.normal
.ydisp
;
1031 this._terminal
.x
= this._terminal
.normal
.x
;
1032 this._terminal
.y
= this._terminal
.normal
.y
;
1033 this._terminal
.scrollTop
= this._terminal
.normal
.scrollTop
;
1034 this._terminal
.scrollBottom
= this._terminal
.normal
.scrollBottom
;
1035 this._terminal
.tabs
= this._terminal
.normal
.tabs
;
1036 this._terminal
.normal
= null;
1037 this._terminal
.selectionManager
.setBuffer(this._terminal
.lines
);
1038 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1039 this._terminal
.viewport
.syncScrollArea();
1040 this._terminal
.showCursor();
1046 InputHandler
.prototype.charAttributes = function (params
) {
1047 if (params
.length
=== 1 && params
[0] === 0) {
1048 this._terminal
.curAttr
= this._terminal
.defAttr
;
1051 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1052 for (; i
< l
; i
++) {
1054 if (p
>= 30 && p
<= 37) {
1057 else if (p
>= 40 && p
<= 47) {
1060 else if (p
>= 90 && p
<= 97) {
1064 else if (p
>= 100 && p
<= 107) {
1069 flags
= this._terminal
.defAttr
>> 18;
1070 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1071 bg
= this._terminal
.defAttr
& 0x1ff;
1088 else if (p
=== 22) {
1091 else if (p
=== 24) {
1094 else if (p
=== 25) {
1097 else if (p
=== 27) {
1100 else if (p
=== 28) {
1103 else if (p
=== 39) {
1104 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1106 else if (p
=== 49) {
1107 bg
= this._terminal
.defAttr
& 0x1ff;
1109 else if (p
=== 38) {
1110 if (params
[i
+ 1] === 2) {
1112 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1117 else if (params
[i
+ 1] === 5) {
1119 p
= params
[i
] & 0xff;
1123 else if (p
=== 48) {
1124 if (params
[i
+ 1] === 2) {
1126 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1131 else if (params
[i
+ 1] === 5) {
1133 p
= params
[i
] & 0xff;
1137 else if (p
=== 100) {
1138 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1139 bg
= this._terminal
.defAttr
& 0x1ff;
1142 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1145 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1147 InputHandler
.prototype.deviceStatus = function (params
) {
1148 if (!this._terminal
.prefix
) {
1149 switch (params
[0]) {
1151 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1154 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1155 + (this._terminal
.y
+ 1)
1157 + (this._terminal
.x
+ 1)
1162 else if (this._terminal
.prefix
=== '?') {
1163 switch (params
[0]) {
1165 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1166 + (this._terminal
.y
+ 1)
1168 + (this._terminal
.x
+ 1)
1182 InputHandler
.prototype.softReset = function (params
) {
1183 this._terminal
.cursorHidden
= false;
1184 this._terminal
.insertMode
= false;
1185 this._terminal
.originMode
= false;
1186 this._terminal
.wraparoundMode
= true;
1187 this._terminal
.applicationKeypad
= false;
1188 this._terminal
.viewport
.syncScrollArea();
1189 this._terminal
.applicationCursor
= false;
1190 this._terminal
.scrollTop
= 0;
1191 this._terminal
.scrollBottom
= this._terminal
.rows
- 1;
1192 this._terminal
.curAttr
= this._terminal
.defAttr
;
1193 this._terminal
.x
= this._terminal
.y
= 0;
1194 this._terminal
.charset
= null;
1195 this._terminal
.glevel
= 0;
1196 this._terminal
.charsets
= [null];
1198 InputHandler
.prototype.setCursorStyle = function (params
) {
1199 var param
= params
[0] < 1 ? 1 : params
[0];
1203 this._terminal
.setOption('cursorStyle', 'block');
1207 this._terminal
.setOption('cursorStyle', 'underline');
1211 this._terminal
.setOption('cursorStyle', 'bar');
1214 var isBlinking
= param
% 2 === 1;
1215 this._terminal
.setOption('cursorBlink', isBlinking
);
1217 InputHandler
.prototype.setScrollRegion = function (params
) {
1218 if (this._terminal
.prefix
)
1220 this._terminal
.scrollTop
= (params
[0] || 1) - 1;
1221 this._terminal
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1222 this._terminal
.x
= 0;
1223 this._terminal
.y
= 0;
1225 InputHandler
.prototype.saveCursor = function (params
) {
1226 this._terminal
.savedX
= this._terminal
.x
;
1227 this._terminal
.savedY
= this._terminal
.y
;
1229 InputHandler
.prototype.restoreCursor = function (params
) {
1230 this._terminal
.x
= this._terminal
.savedX
|| 0;
1231 this._terminal
.y
= this._terminal
.savedY
|| 0;
1233 return InputHandler
;
1235 exports
.InputHandler
= InputHandler
;
1236 var wcwidth
= (function (opts
) {
1238 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1239 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1240 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1241 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1242 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1243 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1244 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1245 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1246 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1247 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1248 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1249 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1250 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1251 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1252 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1253 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1254 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1255 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1256 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1257 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1258 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1259 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1260 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1261 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1262 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1263 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1264 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1265 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1266 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1267 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1268 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1269 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1270 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1271 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1272 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1273 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1274 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1275 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1276 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1277 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1278 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1279 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1280 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1281 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1282 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1283 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1284 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1287 function bisearch(ucs
) {
1289 var max
= COMBINING
.length
- 1;
1291 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
1293 while (max
>= min
) {
1294 mid
= Math
.floor((min
+ max
) / 2);
1295 if (ucs
> COMBINING
[mid
][1])
1297 else if (ucs
< COMBINING
[mid
][0])
1304 function wcwidth(ucs
) {
1307 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1308 return opts
.control
;
1316 function isWide(ucs
) {
1317 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1320 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1321 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1322 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1323 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1324 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1325 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1326 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
1327 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
1328 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
1331 })({ nul
: 0, control
: 0 });
1335 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require
,module
,exports
){
1337 Object
.defineProperty(exports
, "__esModule", { value
: true });
1338 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1339 var protocolClause
= '(https?:\\/\\/)';
1340 var domainCharacterSet
= '[\\da-z\\.-]+';
1341 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1342 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1343 var tldClause
= '([a-z\\.]{2,6})';
1344 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1345 var localHostClause
= '(localhost)';
1346 var portClause
= '(:\\d{1,5})';
1347 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1348 var pathClause
= '(\\/[\\/\\w\\.\\-%~]*)*';
1349 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1350 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1351 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1352 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1353 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1354 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1355 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1356 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1357 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1358 var Linkifier
= (function () {
1359 function Linkifier() {
1360 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1361 this._rowTimeoutIds
= [];
1362 this._linkMatchers
= [];
1363 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1365 Linkifier
.prototype.attachToDom = function (document
, rows
) {
1366 this._document
= document
;
1369 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1370 if (!this._document
) {
1373 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1375 clearTimeout(timeoutId
);
1377 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1379 Linkifier
.prototype.setHypertextLinkHandler = function (handler
) {
1380 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1382 Linkifier
.prototype.setHypertextValidationCallback = function (callback
) {
1383 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].validationCallback
= callback
;
1385 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1386 if (options
=== void 0) { options
= {}; }
1387 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1388 throw new Error('handler must be defined');
1391 id
: this._nextLinkMatcherId
++,
1394 matchIndex
: options
.matchIndex
,
1395 validationCallback
: options
.validationCallback
,
1396 priority
: options
.priority
|| 0
1398 this._addLinkMatcherToList(matcher
);
1401 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1402 if (this._linkMatchers
.length
=== 0) {
1403 this._linkMatchers
.push(matcher
);
1406 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1407 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1408 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1412 this._linkMatchers
.splice(0, 0, matcher
);
1414 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1415 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1416 if (this._linkMatchers
[i
].id
=== matcherId
) {
1417 this._linkMatchers
.splice(i
, 1);
1423 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1424 var row
= this._rows
[rowIndex
];
1428 var text
= row
.textContent
;
1429 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1430 var matcher
= this._linkMatchers
[i
];
1431 var linkElements
= this._doLinkifyRow(row
, matcher
);
1432 if (linkElements
.length
> 0) {
1433 if (matcher
.validationCallback
) {
1434 var _loop_1 = function (j
) {
1435 var element
= linkElements
[j
];
1436 matcher
.validationCallback(element
.textContent
, element
, function (isValid
) {
1438 element
.classList
.add(INVALID_LINK_CLASS
);
1442 for (var j
= 0; j
< linkElements
.length
; j
++) {
1450 Linkifier
.prototype._doLinkifyRow = function (row
, matcher
) {
1452 var isHttpLinkMatcher
= matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
;
1453 var nodes
= row
.childNodes
;
1454 var match
= row
.textContent
.match(matcher
.regex
);
1455 if (!match
|| match
.length
=== 0) {
1458 var uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1459 var rowStartIndex
= match
.index
+ uri
.length
;
1460 for (var i
= 0; i
< nodes
.length
; i
++) {
1461 var node
= nodes
[i
];
1462 var searchIndex
= node
.textContent
.indexOf(uri
);
1463 if (searchIndex
>= 0) {
1464 var linkElement
= this._createAnchorElement(uri
, matcher
.handler
, isHttpLinkMatcher
);
1465 if (node
.textContent
.length
=== uri
.length
) {
1466 if (node
.nodeType
=== 3) {
1467 this._replaceNode(node
, linkElement
);
1471 if (element
.nodeName
=== 'A') {
1474 element
.innerHTML
= '';
1475 element
.appendChild(linkElement
);
1478 else if (node
.childNodes
.length
> 1) {
1479 for (var j
= 0; j
< node
.childNodes
.length
; j
++) {
1480 var childNode
= node
.childNodes
[j
];
1481 var childSearchIndex
= childNode
.textContent
.indexOf(uri
);
1482 if (childSearchIndex
!== -1) {
1483 this._replaceNodeSubstringWithNode(childNode
, linkElement
, uri
, childSearchIndex
);
1489 var nodesAdded
= this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1492 result
.push(linkElement
);
1493 match
= row
.textContent
.substring(rowStartIndex
).match(matcher
.regex
);
1494 if (!match
|| match
.length
=== 0) {
1497 uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1498 rowStartIndex
+= match
.index
+ uri
.length
;
1503 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1504 var element
= this._document
.createElement('a');
1505 element
.textContent
= uri
;
1506 element
.draggable
= false;
1507 if (isHypertextLinkHandler
) {
1509 element
.target
= '_blank';
1510 element
.addEventListener('click', function (event
) {
1512 return handler(event
, uri
);
1517 element
.addEventListener('click', function (event
) {
1518 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1521 return handler(event
, uri
);
1526 Linkifier
.prototype._replaceNode = function (oldNode
) {
1528 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1529 newNodes
[_i
- 1] = arguments
[_i
];
1531 var parent
= oldNode
.parentNode
;
1532 for (var i
= 0; i
< newNodes
.length
; i
++) {
1533 parent
.insertBefore(newNodes
[i
], oldNode
);
1535 parent
.removeChild(oldNode
);
1537 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1538 if (targetNode
.childNodes
.length
=== 1) {
1539 targetNode
= targetNode
.childNodes
[0];
1541 if (targetNode
.nodeType
!== 3) {
1542 throw new Error('targetNode must be a text node or only contain a single text node');
1544 var fullText
= targetNode
.textContent
;
1545 if (substringIndex
=== 0) {
1546 var rightText_1
= fullText
.substring(substring
.length
);
1547 var rightTextNode_1
= this._document
.createTextNode(rightText_1
);
1548 this._replaceNode(targetNode
, newNode
, rightTextNode_1
);
1551 if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1552 var leftText_1
= fullText
.substring(0, substringIndex
);
1553 var leftTextNode_1
= this._document
.createTextNode(leftText_1
);
1554 this._replaceNode(targetNode
, leftTextNode_1
, newNode
);
1557 var leftText
= fullText
.substring(0, substringIndex
);
1558 var leftTextNode
= this._document
.createTextNode(leftText
);
1559 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1560 var rightTextNode
= this._document
.createTextNode(rightText
);
1561 this._replaceNode(targetNode
, leftTextNode
, newNode
, rightTextNode
);
1566 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1567 exports
.Linkifier
= Linkifier
;
1571 },{}],7:[function(require
,module
,exports
){
1573 Object
.defineProperty(exports
, "__esModule", { value
: true });
1574 var EscapeSequences_1
= require("./EscapeSequences");
1575 var Charsets_1
= require("./Charsets");
1576 var normalStateHandler
= {};
1577 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1578 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1579 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1580 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1581 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1582 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1583 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1584 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1585 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1586 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1587 var escapedStateHandler
= {};
1588 escapedStateHandler
['['] = function (parser
, terminal
) {
1589 terminal
.params
= [];
1590 terminal
.currentParam
= 0;
1591 parser
.setState(ParserState
.CSI_PARAM
);
1593 escapedStateHandler
[']'] = function (parser
, terminal
) {
1594 terminal
.params
= [];
1595 terminal
.currentParam
= 0;
1596 parser
.setState(ParserState
.OSC
);
1598 escapedStateHandler
['P'] = function (parser
, terminal
) {
1599 terminal
.params
= [];
1600 terminal
.currentParam
= 0;
1601 parser
.setState(ParserState
.DCS
);
1603 escapedStateHandler
['_'] = function (parser
, terminal
) {
1604 parser
.setState(ParserState
.IGNORE
);
1606 escapedStateHandler
['^'] = function (parser
, terminal
) {
1607 parser
.setState(ParserState
.IGNORE
);
1609 escapedStateHandler
['c'] = function (parser
, terminal
) {
1612 escapedStateHandler
['E'] = function (parser
, terminal
) {
1615 parser
.setState(ParserState
.NORMAL
);
1617 escapedStateHandler
['D'] = function (parser
, terminal
) {
1619 parser
.setState(ParserState
.NORMAL
);
1621 escapedStateHandler
['M'] = function (parser
, terminal
) {
1622 terminal
.reverseIndex();
1623 parser
.setState(ParserState
.NORMAL
);
1625 escapedStateHandler
['%'] = function (parser
, terminal
) {
1626 terminal
.setgLevel(0);
1627 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1628 parser
.setState(ParserState
.NORMAL
);
1629 parser
.skipNextChar();
1631 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1632 var csiParamStateHandler
= {};
1633 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1634 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1635 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1636 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1637 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1638 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1639 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1640 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1641 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1642 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1643 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1644 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1645 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1646 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1647 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1648 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1649 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1650 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1651 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1652 var csiStateHandler
= {};
1653 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1654 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1655 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1656 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1657 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1658 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1659 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1660 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1661 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1662 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1663 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1664 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1665 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1666 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1667 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1668 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1669 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1670 if (params
.length
< 2 && !prefix
) {
1671 handler
.scrollDown(params
);
1674 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1675 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1676 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1677 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1678 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1679 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1680 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1681 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1682 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1683 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1684 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1685 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1686 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1687 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1688 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1691 handler
.softReset(params
);
1695 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1696 if (postfix
=== ' ') {
1697 handler
.setCursorStyle(params
);
1700 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1701 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1702 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1703 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1705 (function (ParserState
) {
1706 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1707 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1708 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1709 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1710 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1711 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1712 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1713 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1714 })(ParserState
|| (ParserState
= {}));
1715 var Parser
= (function () {
1716 function Parser(_inputHandler
, _terminal
) {
1717 this._inputHandler
= _inputHandler
;
1718 this._terminal
= _terminal
;
1719 this._state
= ParserState
.NORMAL
;
1721 Parser
.prototype.parse = function (data
) {
1722 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1724 if (this._terminal
.surrogate_high
) {
1725 data
= this._terminal
.surrogate_high
+ data
;
1726 this._terminal
.surrogate_high
= '';
1728 for (; this._position
< l
; this._position
++) {
1729 ch
= data
[this._position
];
1730 code
= data
.charCodeAt(this._position
);
1731 if (0xD800 <= code
&& code
<= 0xDBFF) {
1732 low
= data
.charCodeAt(this._position
+ 1);
1734 this._terminal
.surrogate_high
= ch
;
1737 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1738 ch
+= data
.charAt(this._position
+ 1);
1740 if (0xDC00 <= code
&& code
<= 0xDFFF)
1742 switch (this._state
) {
1743 case ParserState
.NORMAL
:
1744 if (ch
in normalStateHandler
) {
1745 normalStateHandler
[ch
](this, this._inputHandler
);
1748 this._inputHandler
.addChar(ch
, code
);
1751 case ParserState
.ESCAPED
:
1752 if (ch
in escapedStateHandler
) {
1753 escapedStateHandler
[ch
](this, this._terminal
);
1765 this._terminal
.gcharset
= 0;
1768 this._terminal
.gcharset
= 1;
1771 this._terminal
.gcharset
= 2;
1774 this._terminal
.gcharset
= 3;
1777 this._terminal
.gcharset
= 1;
1780 this._terminal
.gcharset
= 2;
1783 this._state
= ParserState
.CHARSET
;
1786 this._terminal
.gcharset
= 3;
1787 this._state
= ParserState
.CHARSET
;
1795 this._terminal
.setgLevel(2);
1798 this._terminal
.setgLevel(3);
1801 this._terminal
.setgLevel(3);
1804 this._terminal
.setgLevel(2);
1807 this._terminal
.setgLevel(1);
1810 this._inputHandler
.saveCursor();
1811 this._state
= ParserState
.NORMAL
;
1814 this._inputHandler
.restoreCursor();
1815 this._state
= ParserState
.NORMAL
;
1818 this._state
= ParserState
.NORMAL
;
1822 this._terminal
.tabSet();
1823 this._state
= ParserState
.NORMAL
;
1826 this._terminal
.log('Serial port requested application keypad.');
1827 this._terminal
.applicationKeypad
= true;
1828 this._terminal
.viewport
.syncScrollArea();
1829 this._state
= ParserState
.NORMAL
;
1832 this._terminal
.log('Switching back to normal keypad.');
1833 this._terminal
.applicationKeypad
= false;
1834 this._terminal
.viewport
.syncScrollArea();
1835 this._state
= ParserState
.NORMAL
;
1838 this._state
= ParserState
.NORMAL
;
1839 this._terminal
.error('Unknown ESC control: %s.', ch
);
1843 case ParserState
.CHARSET
:
1844 if (ch
in Charsets_1
.CHARSETS
) {
1845 cs
= Charsets_1
.CHARSETS
[ch
];
1847 this.skipNextChar();
1851 cs
= Charsets_1
.DEFAULT_CHARSET
;
1853 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1854 this._terminal
.gcharset
= null;
1855 this._state
= ParserState
.NORMAL
;
1857 case ParserState
.OSC
:
1858 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1859 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1861 this._terminal
.params
.push(this._terminal
.currentParam
);
1862 switch (this._terminal
.params
[0]) {
1866 if (this._terminal
.params
[1]) {
1867 this._terminal
.title
= this._terminal
.params
[1];
1868 this._terminal
.handleTitle(this._terminal
.title
);
1908 this._terminal
.params
= [];
1909 this._terminal
.currentParam
= 0;
1910 this._state
= ParserState
.NORMAL
;
1913 if (!this._terminal
.params
.length
) {
1914 if (ch
>= '0' && ch
<= '9') {
1915 this._terminal
.currentParam
=
1916 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1918 else if (ch
=== ';') {
1919 this._terminal
.params
.push(this._terminal
.currentParam
);
1920 this._terminal
.currentParam
= '';
1924 this._terminal
.currentParam
+= ch
;
1928 case ParserState
.CSI_PARAM
:
1929 if (ch
in csiParamStateHandler
) {
1930 csiParamStateHandler
[ch
](this);
1933 this.finalizeParam();
1934 this._state
= ParserState
.CSI
;
1935 case ParserState
.CSI
:
1936 if (ch
in csiStateHandler
) {
1937 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1940 this._terminal
.error('Unknown CSI code: %s.', ch
);
1942 this._state
= ParserState
.NORMAL
;
1943 this._terminal
.prefix
= '';
1944 this._terminal
.postfix
= '';
1946 case ParserState
.DCS
:
1947 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1948 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1952 switch (this._terminal
.prefix
) {
1956 pt
= this._terminal
.currentParam
;
1967 + (this._terminal
.scrollTop
+ 1)
1969 + (this._terminal
.scrollBottom
+ 1)
1976 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1980 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1985 pt
= this._terminal
.currentParam
;
1987 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1990 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1993 this._terminal
.currentParam
= 0;
1994 this._terminal
.prefix
= '';
1995 this._state
= ParserState
.NORMAL
;
1997 else if (!this._terminal
.currentParam
) {
1998 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1999 this._terminal
.currentParam
= ch
;
2001 else if (this._terminal
.prefix
.length
=== 2) {
2002 this._terminal
.currentParam
= ch
;
2005 this._terminal
.prefix
+= ch
;
2009 this._terminal
.currentParam
+= ch
;
2012 case ParserState
.IGNORE
:
2013 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
2014 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2016 this._state
= ParserState
.NORMAL
;
2023 Parser
.prototype.setState = function (state
) {
2024 this._state
= state
;
2026 Parser
.prototype.setPrefix = function (prefix
) {
2027 this._terminal
.prefix
= prefix
;
2029 Parser
.prototype.setPostfix = function (postfix
) {
2030 this._terminal
.postfix
= postfix
;
2032 Parser
.prototype.setParam = function (param
) {
2033 this._terminal
.currentParam
= param
;
2035 Parser
.prototype.getParam = function () {
2036 return this._terminal
.currentParam
;
2038 Parser
.prototype.finalizeParam = function () {
2039 this._terminal
.params
.push(this._terminal
.currentParam
);
2040 this._terminal
.currentParam
= 0;
2042 Parser
.prototype.skipNextChar = function () {
2047 exports
.Parser
= Parser
;
2051 },{"./Charsets":1,"./EscapeSequences":3}],8:[function(require
,module
,exports
){
2053 Object
.defineProperty(exports
, "__esModule", { value
: true });
2054 var DomElementObjectPool_1
= require("./utils/DomElementObjectPool");
2055 var MAX_REFRESH_FRAME_SKIP
= 5;
2058 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2059 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2060 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2061 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2062 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2063 })(FLAGS
|| (FLAGS
= {}));
2065 var brokenBold
= null;
2066 var Renderer
= (function () {
2067 function Renderer(_terminal
) {
2068 this._terminal
= _terminal
;
2069 this._refreshRowsQueue
= [];
2070 this._refreshFramesSkipped
= 0;
2071 this._refreshAnimationFrame
= null;
2072 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2073 if (brokenBold
=== null) {
2074 brokenBold
= checkBoldBroken(this._terminal
.element
);
2076 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2078 Renderer
.prototype.queueRefresh = function (start
, end
) {
2079 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2080 if (!this._refreshAnimationFrame
) {
2081 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2084 Renderer
.prototype._refreshLoop = function () {
2085 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2087 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2090 this._refreshFramesSkipped
= 0;
2093 if (this._refreshRowsQueue
.length
> 4) {
2095 end
= this._terminal
.rows
- 1;
2098 start
= this._refreshRowsQueue
[0].start
;
2099 end
= this._refreshRowsQueue
[0].end
;
2100 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2101 if (this._refreshRowsQueue
[i
].start
< start
) {
2102 start
= this._refreshRowsQueue
[i
].start
;
2104 if (this._refreshRowsQueue
[i
].end
> end
) {
2105 end
= this._refreshRowsQueue
[i
].end
;
2109 this._refreshRowsQueue
= [];
2110 this._refreshAnimationFrame
= null;
2111 this._refresh(start
, end
);
2113 Renderer
.prototype._refresh = function (start
, end
) {
2115 if (end
- start
>= this._terminal
.rows
/ 2) {
2116 parent
= this._terminal
.element
.parentNode
;
2118 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2121 var width
= this._terminal
.cols
;
2123 if (end
>= this._terminal
.rows
) {
2124 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2125 end
= this._terminal
.rows
- 1;
2127 for (; y
<= end
; y
++) {
2128 var row
= y
+ this._terminal
.ydisp
;
2129 var line
= this._terminal
.lines
.get(row
);
2131 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
) &&
2132 this._terminal
.cursorState
&&
2133 !this._terminal
.cursorHidden
) {
2134 x
= this._terminal
.x
;
2139 var attr
= this._terminal
.defAttr
;
2140 var documentFragment
= document
.createDocumentFragment();
2142 var currentElement
= void 0;
2143 while (this._terminal
.children
[y
].children
.length
) {
2144 var child
= this._terminal
.children
[y
].children
[0];
2145 this._terminal
.children
[y
].removeChild(child
);
2146 this._spanElementObjectPool
.release(child
);
2148 for (var i
= 0; i
< width
; i
++) {
2149 var data
= line
[i
][0];
2150 var ch
= line
[i
][1];
2151 var ch_width
= line
[i
][2];
2158 if (data
!== attr
) {
2159 if (attr
!== this._terminal
.defAttr
) {
2161 currentElement
.innerHTML
= innerHTML
;
2164 documentFragment
.appendChild(currentElement
);
2165 currentElement
= null;
2167 if (data
!== this._terminal
.defAttr
) {
2168 if (innerHTML
&& !currentElement
) {
2169 currentElement
= this._spanElementObjectPool
.acquire();
2171 if (currentElement
) {
2173 currentElement
.innerHTML
= innerHTML
;
2176 documentFragment
.appendChild(currentElement
);
2178 currentElement
= this._spanElementObjectPool
.acquire();
2180 currentElement
.classList
.add('reverse-video');
2181 currentElement
.classList
.add('terminal-cursor');
2184 var bg
= data
& 0x1ff;
2185 var fg
= (data
>> 9) & 0x1ff;
2186 var flags
= data
>> 18;
2187 if (flags
& FLAGS
.BOLD
) {
2189 currentElement
.classList
.add('xterm-bold');
2195 if (flags
& FLAGS
.UNDERLINE
) {
2196 currentElement
.classList
.add('xterm-underline');
2198 if (flags
& FLAGS
.BLINK
) {
2199 currentElement
.classList
.add('xterm-blink');
2201 if (flags
& FLAGS
.INVERSE
) {
2205 if ((flags
& 1) && fg
< 8) {
2209 if (flags
& FLAGS
.INVISIBLE
) {
2210 currentElement
.classList
.add('xterm-hidden');
2212 if (flags
& FLAGS
.INVERSE
) {
2221 currentElement
.classList
.add("xterm-bg-color-" + bg
);
2224 currentElement
.classList
.add("xterm-color-" + fg
);
2229 if (ch_width
=== 2) {
2230 innerHTML
+= "<span class=\"xterm-wide-char\">" + ch
+ "</span>";
2232 else if (ch
.charCodeAt(0) > 255) {
2233 innerHTML
+= "<span class=\"xterm-normal-char\">" + ch
+ "</span>";
2238 innerHTML
+= '&';
2241 innerHTML
+= '<';
2244 innerHTML
+= '>';
2248 innerHTML
+= ' ';
2258 if (innerHTML
&& !currentElement
) {
2259 currentElement
= this._spanElementObjectPool
.acquire();
2261 if (currentElement
) {
2263 currentElement
.innerHTML
= innerHTML
;
2266 documentFragment
.appendChild(currentElement
);
2267 currentElement
= null;
2269 this._terminal
.children
[y
].appendChild(documentFragment
);
2272 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2274 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2277 Renderer
.prototype.refreshSelection = function (start
, end
) {
2278 while (this._terminal
.selectionContainer
.children
.length
) {
2279 this._terminal
.selectionContainer
.removeChild(this._terminal
.selectionContainer
.children
[0]);
2281 if (!start
|| !end
) {
2284 var viewportStartRow
= start
[1] - this._terminal
.ydisp
;
2285 var viewportEndRow
= end
[1] - this._terminal
.ydisp
;
2286 var viewportCappedStartRow
= Math
.max(viewportStartRow
, 0);
2287 var viewportCappedEndRow
= Math
.min(viewportEndRow
, this._terminal
.rows
- 1);
2288 if (viewportCappedStartRow
>= this._terminal
.rows
|| viewportCappedEndRow
< 0) {
2291 var documentFragment
= document
.createDocumentFragment();
2292 var startCol
= viewportStartRow
=== viewportCappedStartRow
? start
[0] : 0;
2293 var endCol
= viewportCappedStartRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2294 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
, startCol
, endCol
));
2295 var middleRowsCount
= viewportCappedEndRow
- viewportCappedStartRow
- 1;
2296 documentFragment
.appendChild(this._createSelectionElement(viewportCappedStartRow
+ 1, 0, this._terminal
.cols
, middleRowsCount
));
2297 if (viewportCappedStartRow
!== viewportCappedEndRow
) {
2298 var endCol_1
= viewportEndRow
=== viewportCappedEndRow
? end
[0] : this._terminal
.cols
;
2299 documentFragment
.appendChild(this._createSelectionElement(viewportCappedEndRow
, 0, endCol_1
));
2301 this._terminal
.selectionContainer
.appendChild(documentFragment
);
2303 Renderer
.prototype._createSelectionElement = function (row
, colStart
, colEnd
, rowCount
) {
2304 if (rowCount
=== void 0) { rowCount
= 1; }
2305 var element
= document
.createElement('div');
2306 element
.style
.height
= rowCount
* this._terminal
.charMeasure
.height
+ "px";
2307 element
.style
.top
= row
* this._terminal
.charMeasure
.height
+ "px";
2308 element
.style
.left
= colStart
* this._terminal
.charMeasure
.width
+ "px";
2309 element
.style
.width
= this._terminal
.charMeasure
.width
* (colEnd
- colStart
) + "px";
2314 exports
.Renderer
= Renderer
;
2315 function checkBoldBroken(terminal
) {
2316 var document
= terminal
.ownerDocument
;
2317 var el
= document
.createElement('span');
2318 el
.innerHTML
= 'hello world';
2319 terminal
.appendChild(el
);
2320 var w1
= el
.offsetWidth
;
2321 var h1
= el
.offsetHeight
;
2322 el
.style
.fontWeight
= 'bold';
2323 var w2
= el
.offsetWidth
;
2324 var h2
= el
.offsetHeight
;
2325 terminal
.removeChild(el
);
2326 return w1
!== w2
|| h1
!== h2
;
2331 },{"./utils/DomElementObjectPool":16}],9:[function(require
,module
,exports
){
2333 var __extends
= (this && this.__extends
) || (function () {
2334 var extendStatics
= Object
.setPrototypeOf
||
2335 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
2336 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
2337 return function (d
, b
) {
2338 extendStatics(d
, b
);
2339 function __() { this.constructor = d
; }
2340 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2343 Object
.defineProperty(exports
, "__esModule", { value
: true });
2344 var Mouse
= require("./utils/Mouse");
2345 var Browser
= require("./utils/Browser");
2346 var EventEmitter_1
= require("./EventEmitter");
2347 var SelectionModel_1
= require("./SelectionModel");
2348 var DRAG_SCROLL_MAX_THRESHOLD
= 50;
2349 var DRAG_SCROLL_MAX_SPEED
= 15;
2350 var DRAG_SCROLL_INTERVAL
= 50;
2351 var CLEAR_MOUSE_DOWN_TIME
= 400;
2352 var CLEAR_MOUSE_DISTANCE
= 10;
2353 var WORD_SEPARATORS
= ' ()[]{}\'"';
2354 var LINE_DATA_CHAR_INDEX
= 1;
2355 var LINE_DATA_WIDTH_INDEX
= 2;
2356 var NON_BREAKING_SPACE_CHAR
= String
.fromCharCode(160);
2357 var ALL_NON_BREAKING_SPACE_REGEX
= new RegExp(NON_BREAKING_SPACE_CHAR
, 'g');
2359 (function (SelectionMode
) {
2360 SelectionMode
[SelectionMode
["NORMAL"] = 0] = "NORMAL";
2361 SelectionMode
[SelectionMode
["WORD"] = 1] = "WORD";
2362 SelectionMode
[SelectionMode
["LINE"] = 2] = "LINE";
2363 })(SelectionMode
|| (SelectionMode
= {}));
2364 var SelectionManager
= (function (_super
) {
2365 __extends(SelectionManager
, _super
);
2366 function SelectionManager(_terminal
, _buffer
, _rowContainer
, _charMeasure
) {
2367 var _this
= _super
.call(this) || this;
2368 _this
._terminal
= _terminal
;
2369 _this
._buffer
= _buffer
;
2370 _this
._rowContainer
= _rowContainer
;
2371 _this
._charMeasure
= _charMeasure
;
2372 _this
._initListeners();
2374 _this
._model
= new SelectionModel_1
.SelectionModel(_terminal
);
2375 _this
._lastMouseDownTime
= 0;
2376 _this
._activeSelectionMode
= SelectionMode
.NORMAL
;
2379 SelectionManager
.prototype._initListeners = function () {
2381 this._bufferTrimListener = function (amount
) { return _this
._onTrim(amount
); };
2382 this._mouseMoveListener = function (event
) { return _this
._onMouseMove(event
); };
2383 this._mouseDownListener = function (event
) { return _this
._onMouseDown(event
); };
2384 this._mouseUpListener = function (event
) { return _this
._onMouseUp(event
); };
2386 SelectionManager
.prototype.disable = function () {
2387 this.clearSelection();
2388 this._buffer
.off('trim', this._bufferTrimListener
);
2389 this._rowContainer
.removeEventListener('mousedown', this._mouseDownListener
);
2391 SelectionManager
.prototype.enable = function () {
2392 this._buffer
.on('trim', this._bufferTrimListener
);
2393 this._rowContainer
.addEventListener('mousedown', this._mouseDownListener
);
2395 SelectionManager
.prototype.setBuffer = function (buffer
) {
2396 this._buffer
= buffer
;
2397 this.clearSelection();
2399 Object
.defineProperty(SelectionManager
.prototype, "hasSelection", {
2401 var start
= this._model
.finalSelectionStart
;
2402 var end
= this._model
.finalSelectionEnd
;
2403 if (!start
|| !end
) {
2406 return start
[0] !== end
[0] || start
[1] !== end
[1];
2411 Object
.defineProperty(SelectionManager
.prototype, "selectionText", {
2413 var start
= this._model
.finalSelectionStart
;
2414 var end
= this._model
.finalSelectionEnd
;
2415 if (!start
|| !end
) {
2418 var startRowEndCol
= start
[1] === end
[1] ? end
[0] : null;
2420 result
.push(this._translateBufferLineToString(this._buffer
.get(start
[1]), true, start
[0], startRowEndCol
));
2421 for (var i
= start
[1] + 1; i
<= end
[1] - 1; i
++) {
2422 var bufferLine
= this._buffer
.get(i
);
2423 var lineText
= this._translateBufferLineToString(bufferLine
, true);
2424 if (bufferLine
.isWrapped
) {
2425 result
[result
.length
- 1] += lineText
;
2428 result
.push(lineText
);
2431 if (start
[1] !== end
[1]) {
2432 var bufferLine
= this._buffer
.get(end
[1]);
2433 var lineText
= this._translateBufferLineToString(bufferLine
, true, 0, end
[0]);
2434 if (bufferLine
.isWrapped
) {
2435 result
[result
.length
- 1] += lineText
;
2438 result
.push(lineText
);
2441 var formattedResult
= result
.map(function (line
) {
2442 return line
.replace(ALL_NON_BREAKING_SPACE_REGEX
, ' ');
2443 }).join(Browser
.isMSWindows
? '\r\n' : '\n');
2444 return formattedResult
;
2449 SelectionManager
.prototype.clearSelection = function () {
2450 this._model
.clearSelection();
2451 this._removeMouseDownListeners();
2454 SelectionManager
.prototype._translateBufferLineToString = function (line
, trimRight
, startCol
, endCol
) {
2455 if (startCol
=== void 0) { startCol
= 0; }
2456 if (endCol
=== void 0) { endCol
= null; }
2457 var lineString
= '';
2458 var widthAdjustedStartCol
= startCol
;
2459 var widthAdjustedEndCol
= endCol
;
2460 for (var i
= 0; i
< line
.length
; i
++) {
2462 lineString
+= char[LINE_DATA_CHAR_INDEX
];
2463 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2464 if (startCol
>= i
) {
2465 widthAdjustedStartCol
--;
2468 widthAdjustedEndCol
--;
2472 var finalEndCol
= widthAdjustedEndCol
|| line
.length
;
2474 var rightWhitespaceIndex
= lineString
.search(/\s+$/);
2475 if (rightWhitespaceIndex
!== -1) {
2476 finalEndCol
= Math
.min(finalEndCol
, rightWhitespaceIndex
);
2478 if (finalEndCol
<= widthAdjustedStartCol
) {
2482 return lineString
.substring(widthAdjustedStartCol
, finalEndCol
);
2484 SelectionManager
.prototype.refresh = function (isNewSelection
) {
2486 if (!this._refreshAnimationFrame
) {
2487 this._refreshAnimationFrame
= window
.requestAnimationFrame(function () { return _this
._refresh(); });
2489 if (Browser
.isLinux
&& isNewSelection
) {
2490 var selectionText
= this.selectionText
;
2491 if (selectionText
.length
) {
2492 this.emit('newselection', this.selectionText
);
2496 SelectionManager
.prototype._refresh = function () {
2497 this._refreshAnimationFrame
= null;
2498 this.emit('refresh', { start
: this._model
.finalSelectionStart
, end
: this._model
.finalSelectionEnd
});
2500 SelectionManager
.prototype.selectAll = function () {
2501 this._model
.isSelectAllActive
= true;
2504 SelectionManager
.prototype._onTrim = function (amount
) {
2505 var needsRefresh
= this._model
.onTrim(amount
);
2510 SelectionManager
.prototype._getMouseBufferCoords = function (event
) {
2511 var coords
= Mouse
.getCoords(event
, this._rowContainer
, this._charMeasure
, this._terminal
.cols
, this._terminal
.rows
, true);
2514 coords
[1] += this._terminal
.ydisp
;
2517 SelectionManager
.prototype._getMouseEventScrollAmount = function (event
) {
2518 var offset
= Mouse
.getCoordsRelativeToElement(event
, this._rowContainer
)[1];
2519 var terminalHeight
= this._terminal
.rows
* this._charMeasure
.height
;
2520 if (offset
>= 0 && offset
<= terminalHeight
) {
2523 if (offset
> terminalHeight
) {
2524 offset
-= terminalHeight
;
2526 offset
= Math
.min(Math
.max(offset
, -DRAG_SCROLL_MAX_THRESHOLD
), DRAG_SCROLL_MAX_THRESHOLD
);
2527 offset
/= DRAG_SCROLL_MAX_THRESHOLD
;
2528 return (offset
/ Math
.abs(offset
)) + Math
.round(offset
* (DRAG_SCROLL_MAX_SPEED
- 1));
2530 SelectionManager
.prototype._onMouseDown = function (event
) {
2531 if (event
.button
!== 0) {
2534 event
.preventDefault();
2535 this._dragScrollAmount
= 0;
2536 this._setMouseClickCount(event
);
2537 if (event
.shiftKey
) {
2538 this._onShiftClick(event
);
2541 if (this._clickCount
=== 1) {
2542 this._onSingleClick(event
);
2544 else if (this._clickCount
=== 2) {
2545 this._onDoubleClick(event
);
2547 else if (this._clickCount
=== 3) {
2548 this._onTripleClick(event
);
2551 this._addMouseDownListeners();
2554 SelectionManager
.prototype._addMouseDownListeners = function () {
2556 this._rowContainer
.ownerDocument
.addEventListener('mousemove', this._mouseMoveListener
);
2557 this._rowContainer
.ownerDocument
.addEventListener('mouseup', this._mouseUpListener
);
2558 this._dragScrollIntervalTimer
= setInterval(function () { return _this
._dragScroll(); }, DRAG_SCROLL_INTERVAL
);
2560 SelectionManager
.prototype._removeMouseDownListeners = function () {
2561 this._rowContainer
.ownerDocument
.removeEventListener('mousemove', this._mouseMoveListener
);
2562 this._rowContainer
.ownerDocument
.removeEventListener('mouseup', this._mouseUpListener
);
2563 clearInterval(this._dragScrollIntervalTimer
);
2564 this._dragScrollIntervalTimer
= null;
2566 SelectionManager
.prototype._onShiftClick = function (event
) {
2567 if (this._model
.selectionStart
) {
2568 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2571 SelectionManager
.prototype._onSingleClick = function (event
) {
2572 this._model
.selectionStartLength
= 0;
2573 this._model
.isSelectAllActive
= false;
2574 this._activeSelectionMode
= SelectionMode
.NORMAL
;
2575 this._model
.selectionStart
= this._getMouseBufferCoords(event
);
2576 if (this._model
.selectionStart
) {
2577 this._model
.selectionEnd
= null;
2578 var char = this._buffer
.get(this._model
.selectionStart
[1])[this._model
.selectionStart
[0]];
2579 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2580 this._model
.selectionStart
[0]++;
2584 SelectionManager
.prototype._onDoubleClick = function (event
) {
2585 var coords
= this._getMouseBufferCoords(event
);
2587 this._activeSelectionMode
= SelectionMode
.WORD
;
2588 this._selectWordAt(coords
);
2591 SelectionManager
.prototype._onTripleClick = function (event
) {
2592 var coords
= this._getMouseBufferCoords(event
);
2594 this._activeSelectionMode
= SelectionMode
.LINE
;
2595 this._selectLineAt(coords
[1]);
2598 SelectionManager
.prototype._setMouseClickCount = function (event
) {
2599 var currentTime
= (new Date()).getTime();
2600 if (currentTime
- this._lastMouseDownTime
> CLEAR_MOUSE_DOWN_TIME
|| this._distanceFromLastMousePosition(event
) > CLEAR_MOUSE_DISTANCE
) {
2601 this._clickCount
= 0;
2603 this._lastMouseDownTime
= currentTime
;
2604 this._lastMousePosition
= [event
.pageX
, event
.pageY
];
2607 SelectionManager
.prototype._distanceFromLastMousePosition = function (event
) {
2608 var result
= Math
.max(Math
.abs(this._lastMousePosition
[0] - event
.pageX
), Math
.abs(this._lastMousePosition
[1] - event
.pageY
));
2611 SelectionManager
.prototype._onMouseMove = function (event
) {
2612 var previousSelectionEnd
= this._model
.selectionEnd
? [this._model
.selectionEnd
[0], this._model
.selectionEnd
[1]] : null;
2613 this._model
.selectionEnd
= this._getMouseBufferCoords(event
);
2614 if (this._activeSelectionMode
=== SelectionMode
.LINE
) {
2615 if (this._model
.selectionEnd
[1] < this._model
.selectionStart
[1]) {
2616 this._model
.selectionEnd
[0] = 0;
2619 this._model
.selectionEnd
[0] = this._terminal
.cols
;
2622 else if (this._activeSelectionMode
=== SelectionMode
.WORD
) {
2623 this._selectToWordAt(this._model
.selectionEnd
);
2625 this._dragScrollAmount
= this._getMouseEventScrollAmount(event
);
2626 if (this._dragScrollAmount
> 0) {
2627 this._model
.selectionEnd
[0] = this._terminal
.cols
- 1;
2629 else if (this._dragScrollAmount
< 0) {
2630 this._model
.selectionEnd
[0] = 0;
2632 if (this._model
.selectionEnd
[1] < this._buffer
.length
) {
2633 var char = this._buffer
.get(this._model
.selectionEnd
[1])[this._model
.selectionEnd
[0]];
2634 if (char && char[2] === 0) {
2635 this._model
.selectionEnd
[0]++;
2638 if (!previousSelectionEnd
||
2639 previousSelectionEnd
[0] !== this._model
.selectionEnd
[0] ||
2640 previousSelectionEnd
[1] !== this._model
.selectionEnd
[1]) {
2644 SelectionManager
.prototype._dragScroll = function () {
2645 if (this._dragScrollAmount
) {
2646 this._terminal
.scrollDisp(this._dragScrollAmount
, false);
2647 if (this._dragScrollAmount
> 0) {
2648 this._model
.selectionEnd
= [this._terminal
.cols
- 1, this._terminal
.ydisp
+ this._terminal
.rows
];
2651 this._model
.selectionEnd
= [0, this._terminal
.ydisp
];
2656 SelectionManager
.prototype._onMouseUp = function (event
) {
2657 this._removeMouseDownListeners();
2659 SelectionManager
.prototype._convertViewportColToCharacterIndex = function (bufferLine
, coords
) {
2660 var charIndex
= coords
[0];
2661 for (var i
= 0; coords
[0] >= i
; i
++) {
2662 var char = bufferLine
[i
];
2663 if (char[LINE_DATA_WIDTH_INDEX
] === 0) {
2669 SelectionManager
.prototype._getWordAt = function (coords
) {
2670 var bufferLine
= this._buffer
.get(coords
[1]);
2671 var line
= this._translateBufferLineToString(bufferLine
, false);
2672 var endIndex
= this._convertViewportColToCharacterIndex(bufferLine
, coords
);
2673 var startIndex
= endIndex
;
2674 var charOffset
= coords
[0] - startIndex
;
2675 var leftWideCharCount
= 0;
2676 var rightWideCharCount
= 0;
2677 if (line
.charAt(startIndex
) === ' ') {
2678 while (startIndex
> 0 && line
.charAt(startIndex
- 1) === ' ') {
2681 while (endIndex
< line
.length
&& line
.charAt(endIndex
+ 1) === ' ') {
2686 var startCol
= coords
[0];
2687 var endCol
= coords
[0];
2688 if (bufferLine
[startCol
][LINE_DATA_WIDTH_INDEX
] === 0) {
2689 leftWideCharCount
++;
2692 if (bufferLine
[endCol
][LINE_DATA_WIDTH_INDEX
] === 2) {
2693 rightWideCharCount
++;
2696 while (startIndex
> 0 && !this._isCharWordSeparator(line
.charAt(startIndex
- 1))) {
2697 if (bufferLine
[startCol
- 1][LINE_DATA_WIDTH_INDEX
] === 0) {
2698 leftWideCharCount
++;
2704 while (endIndex
+ 1 < line
.length
&& !this._isCharWordSeparator(line
.charAt(endIndex
+ 1))) {
2705 if (bufferLine
[endCol
+ 1][LINE_DATA_WIDTH_INDEX
] === 2) {
2706 rightWideCharCount
++;
2713 var start
= startIndex
+ charOffset
- leftWideCharCount
;
2714 var length
= Math
.min(endIndex
- startIndex
+ leftWideCharCount
+ rightWideCharCount
+ 1, this._terminal
.cols
);
2715 return { start
: start
, length
: length
};
2717 SelectionManager
.prototype._selectWordAt = function (coords
) {
2718 var wordPosition
= this._getWordAt(coords
);
2719 this._model
.selectionStart
= [wordPosition
.start
, coords
[1]];
2720 this._model
.selectionStartLength
= wordPosition
.length
;
2722 SelectionManager
.prototype._selectToWordAt = function (coords
) {
2723 var wordPosition
= this._getWordAt(coords
);
2724 this._model
.selectionEnd
= [this._model
.areSelectionValuesReversed() ? wordPosition
.start
: (wordPosition
.start
+ wordPosition
.length
), coords
[1]];
2726 SelectionManager
.prototype._isCharWordSeparator = function (char) {
2727 return WORD_SEPARATORS
.indexOf(char) >= 0;
2729 SelectionManager
.prototype._selectLineAt = function (line
) {
2730 this._model
.selectionStart
= [0, line
];
2731 this._model
.selectionStartLength
= this._terminal
.cols
;
2733 return SelectionManager
;
2734 }(EventEmitter_1
.EventEmitter
));
2735 exports
.SelectionManager
= SelectionManager
;
2739 },{"./EventEmitter":4,"./SelectionModel":10,"./utils/Browser":13,"./utils/Mouse":18}],10:[function(require
,module
,exports
){
2741 Object
.defineProperty(exports
, "__esModule", { value
: true });
2742 var SelectionModel
= (function () {
2743 function SelectionModel(_terminal
) {
2744 this._terminal
= _terminal
;
2745 this.clearSelection();
2747 SelectionModel
.prototype.clearSelection = function () {
2748 this.selectionStart
= null;
2749 this.selectionEnd
= null;
2750 this.isSelectAllActive
= false;
2751 this.selectionStartLength
= 0;
2753 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionStart", {
2755 if (this.isSelectAllActive
) {
2758 if (!this.selectionEnd
|| !this.selectionStart
) {
2759 return this.selectionStart
;
2761 return this.areSelectionValuesReversed() ? this.selectionEnd
: this.selectionStart
;
2766 Object
.defineProperty(SelectionModel
.prototype, "finalSelectionEnd", {
2768 if (this.isSelectAllActive
) {
2769 return [this._terminal
.cols
, this._terminal
.ybase
+ this._terminal
.rows
- 1];
2771 if (!this.selectionStart
) {
2774 if (!this.selectionEnd
|| this.areSelectionValuesReversed()) {
2775 return [this.selectionStart
[0] + this.selectionStartLength
, this.selectionStart
[1]];
2777 if (this.selectionStartLength
) {
2778 if (this.selectionEnd
[1] === this.selectionStart
[1]) {
2779 return [Math
.max(this.selectionStart
[0] + this.selectionStartLength
, this.selectionEnd
[0]), this.selectionEnd
[1]];
2782 return this.selectionEnd
;
2787 SelectionModel
.prototype.areSelectionValuesReversed = function () {
2788 var start
= this.selectionStart
;
2789 var end
= this.selectionEnd
;
2790 return start
[1] > end
[1] || (start
[1] === end
[1] && start
[0] > end
[0]);
2792 SelectionModel
.prototype.onTrim = function (amount
) {
2793 if (this.selectionStart
) {
2794 this.selectionStart
[1] -= amount
;
2796 if (this.selectionEnd
) {
2797 this.selectionEnd
[1] -= amount
;
2799 if (this.selectionEnd
&& this.selectionEnd
[1] < 0) {
2800 this.clearSelection();
2803 if (this.selectionStart
&& this.selectionStart
[1] < 0) {
2804 this.selectionStart
[1] = 0;
2808 return SelectionModel
;
2810 exports
.SelectionModel
= SelectionModel
;
2814 },{}],11:[function(require
,module
,exports
){
2816 Object
.defineProperty(exports
, "__esModule", { value
: true });
2817 var Viewport
= (function () {
2818 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2820 this.terminal
= terminal
;
2821 this.viewportElement
= viewportElement
;
2822 this.scrollArea
= scrollArea
;
2823 this.charMeasure
= charMeasure
;
2824 this.currentRowHeight
= 0;
2825 this.lastRecordedBufferLength
= 0;
2826 this.lastRecordedViewportHeight
= 0;
2827 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2828 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2829 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2830 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2832 Viewport
.prototype.refresh = function () {
2833 if (this.charMeasure
.height
> 0) {
2834 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2835 if (rowHeightChanged
) {
2836 this.currentRowHeight
= this.charMeasure
.height
;
2837 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2838 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2840 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2841 if (rowHeightChanged
|| viewportHeightChanged
) {
2842 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2843 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2844 this.terminal
.selectionContainer
.style
.height
= this.viewportElement
.style
.height
;
2846 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2849 Viewport
.prototype.syncScrollArea = function () {
2850 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2851 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2854 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2858 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2862 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2863 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2864 this.viewportElement
.scrollTop
= scrollTop
;
2867 Viewport
.prototype.onScroll = function (ev
) {
2868 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2869 var diff
= newRow
- this.terminal
.ydisp
;
2870 this.terminal
.scrollDisp(diff
, true);
2872 Viewport
.prototype.onWheel = function (ev
) {
2873 if (ev
.deltaY
=== 0) {
2877 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2878 multiplier
= this.currentRowHeight
;
2880 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2881 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2883 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2884 ev
.preventDefault();
2887 Viewport
.prototype.onTouchStart = function (ev
) {
2888 this.lastTouchY
= ev
.touches
[0].pageY
;
2891 Viewport
.prototype.onTouchMove = function (ev
) {
2892 var deltaY
= this.lastTouchY
- ev
.touches
[0].pageY
;
2893 this.lastTouchY
= ev
.touches
[0].pageY
;
2897 this.viewportElement
.scrollTop
+= deltaY
;
2898 ev
.preventDefault();
2903 exports
.Viewport
= Viewport
;
2907 },{}],12:[function(require
,module
,exports
){
2909 Object
.defineProperty(exports
, "__esModule", { value
: true });
2910 function prepareTextForTerminal(text
, isMSWindows
) {
2912 return text
.replace(/\r?\n/g, '\r');
2916 exports
.prepareTextForTerminal
= prepareTextForTerminal
;
2917 function copyHandler(ev
, term
, selectionManager
) {
2918 if (term
.browser
.isMSIE
) {
2919 window
.clipboardData
.setData('Text', selectionManager
.selectionText
);
2922 ev
.clipboardData
.setData('text/plain', selectionManager
.selectionText
);
2924 ev
.preventDefault();
2926 exports
.copyHandler
= copyHandler
;
2927 function pasteHandler(ev
, term
) {
2928 ev
.stopPropagation();
2930 var dispatchPaste = function (text
) {
2931 text
= prepareTextForTerminal(text
, term
.browser
.isMSWindows
);
2933 term
.textarea
.value
= '';
2934 term
.emit('paste', text
);
2935 return term
.cancel(ev
);
2937 if (term
.browser
.isMSIE
) {
2938 if (window
.clipboardData
) {
2939 text
= window
.clipboardData
.getData('Text');
2940 dispatchPaste(text
);
2944 if (ev
.clipboardData
) {
2945 text
= ev
.clipboardData
.getData('text/plain');
2946 dispatchPaste(text
);
2950 exports
.pasteHandler
= pasteHandler
;
2951 function moveTextAreaUnderMouseCursor(ev
, textarea
) {
2952 textarea
.style
.position
= 'fixed';
2953 textarea
.style
.width
= '20px';
2954 textarea
.style
.height
= '20px';
2955 textarea
.style
.left
= (ev
.clientX
- 10) + 'px';
2956 textarea
.style
.top
= (ev
.clientY
- 10) + 'px';
2957 textarea
.style
.zIndex
= '1000';
2959 setTimeout(function () {
2960 textarea
.style
.position
= null;
2961 textarea
.style
.width
= null;
2962 textarea
.style
.height
= null;
2963 textarea
.style
.left
= null;
2964 textarea
.style
.top
= null;
2965 textarea
.style
.zIndex
= null;
2968 exports
.moveTextAreaUnderMouseCursor
= moveTextAreaUnderMouseCursor
;
2969 function rightClickHandler(ev
, textarea
, selectionManager
) {
2970 moveTextAreaUnderMouseCursor(ev
, textarea
);
2971 textarea
.value
= selectionManager
.selectionText
;
2974 exports
.rightClickHandler
= rightClickHandler
;
2978 },{}],13:[function(require
,module
,exports
){
2980 Object
.defineProperty(exports
, "__esModule", { value
: true });
2981 var Generic_1
= require("./Generic");
2982 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2983 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2984 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2985 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2986 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2987 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2988 exports
.isIpad
= platform
=== 'iPad';
2989 exports
.isIphone
= platform
=== 'iPhone';
2990 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2991 exports
.isLinux
= platform
.indexOf('Linux') >= 0;
2995 },{"./Generic":17}],14:[function(require
,module
,exports
){
2997 var __extends
= (this && this.__extends
) || (function () {
2998 var extendStatics
= Object
.setPrototypeOf
||
2999 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3000 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3001 return function (d
, b
) {
3002 extendStatics(d
, b
);
3003 function __() { this.constructor = d
; }
3004 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3007 Object
.defineProperty(exports
, "__esModule", { value
: true });
3008 var EventEmitter_js_1
= require("../EventEmitter.js");
3009 var CharMeasure
= (function (_super
) {
3010 __extends(CharMeasure
, _super
);
3011 function CharMeasure(document
, parentElement
) {
3012 var _this
= _super
.call(this) || this;
3013 _this
._document
= document
;
3014 _this
._parentElement
= parentElement
;
3017 Object
.defineProperty(CharMeasure
.prototype, "width", {
3024 Object
.defineProperty(CharMeasure
.prototype, "height", {
3026 return this._height
;
3031 CharMeasure
.prototype.measure = function () {
3033 if (!this._measureElement
) {
3034 this._measureElement
= this._document
.createElement('span');
3035 this._measureElement
.style
.position
= 'absolute';
3036 this._measureElement
.style
.top
= '0';
3037 this._measureElement
.style
.left
= '-9999em';
3038 this._measureElement
.textContent
= 'W';
3039 this._measureElement
.setAttribute('aria-hidden', 'true');
3040 this._parentElement
.appendChild(this._measureElement
);
3041 setTimeout(function () { return _this
._doMeasure(); }, 0);
3047 CharMeasure
.prototype._doMeasure = function () {
3048 var geometry
= this._measureElement
.getBoundingClientRect();
3049 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
3052 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
3053 this._width
= geometry
.width
;
3054 this._height
= geometry
.height
;
3055 this.emit('charsizechanged');
3059 }(EventEmitter_js_1
.EventEmitter
));
3060 exports
.CharMeasure
= CharMeasure
;
3064 },{"../EventEmitter.js":4}],15:[function(require
,module
,exports
){
3066 var __extends
= (this && this.__extends
) || (function () {
3067 var extendStatics
= Object
.setPrototypeOf
||
3068 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
3069 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
3070 return function (d
, b
) {
3071 extendStatics(d
, b
);
3072 function __() { this.constructor = d
; }
3073 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
3076 Object
.defineProperty(exports
, "__esModule", { value
: true });
3077 var EventEmitter_1
= require("../EventEmitter");
3078 var CircularList
= (function (_super
) {
3079 __extends(CircularList
, _super
);
3080 function CircularList(maxLength
) {
3081 var _this
= _super
.call(this) || this;
3082 _this
._array
= new Array(maxLength
);
3083 _this
._startIndex
= 0;
3087 Object
.defineProperty(CircularList
.prototype, "maxLength", {
3089 return this._array
.length
;
3091 set: function (newMaxLength
) {
3092 var newArray
= new Array(newMaxLength
);
3093 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
3094 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
3096 this._array
= newArray
;
3097 this._startIndex
= 0;
3102 Object
.defineProperty(CircularList
.prototype, "length", {
3104 return this._length
;
3106 set: function (newLength
) {
3107 if (newLength
> this._length
) {
3108 for (var i
= this._length
; i
< newLength
; i
++) {
3109 this._array
[i
] = undefined;
3112 this._length
= newLength
;
3117 Object
.defineProperty(CircularList
.prototype, "forEach", {
3120 return function (callbackfn
) {
3122 var length
= _this
.length
;
3123 for (var i_1
= 0; i_1
< length
; i_1
++) {
3124 callbackfn(_this
.get(i_1
), i_1
);
3131 CircularList
.prototype.get = function (index
) {
3132 return this._array
[this._getCyclicIndex(index
)];
3134 CircularList
.prototype.set = function (index
, value
) {
3135 this._array
[this._getCyclicIndex(index
)] = value
;
3137 CircularList
.prototype.push = function (value
) {
3138 this._array
[this._getCyclicIndex(this._length
)] = value
;
3139 if (this._length
=== this.maxLength
) {
3141 if (this._startIndex
=== this.maxLength
) {
3142 this._startIndex
= 0;
3144 this.emit('trim', 1);
3150 CircularList
.prototype.pop = function () {
3151 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
3153 CircularList
.prototype.splice = function (start
, deleteCount
) {
3155 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
3156 items
[_i
- 2] = arguments
[_i
];
3159 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
3160 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
3162 this._length
-= deleteCount
;
3164 if (items
&& items
.length
) {
3165 for (var i
= this._length
- 1; i
>= start
; i
--) {
3166 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
3168 for (var i
= 0; i
< items
.length
; i
++) {
3169 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
3171 if (this._length
+ items
.length
> this.maxLength
) {
3172 var countToTrim
= (this._length
+ items
.length
) - this.maxLength
;
3173 this._startIndex
+= countToTrim
;
3174 this._length
= this.maxLength
;
3175 this.emit('trim', countToTrim
);
3178 this._length
+= items
.length
;
3182 CircularList
.prototype.trimStart = function (count
) {
3183 if (count
> this._length
) {
3184 count
= this._length
;
3186 this._startIndex
+= count
;
3187 this._length
-= count
;
3188 this.emit('trim', count
);
3190 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
3194 if (start
< 0 || start
>= this._length
) {
3195 throw new Error('start argument out of range');
3197 if (start
+ offset
< 0) {
3198 throw new Error('Cannot shift elements in list beyond index 0');
3201 for (var i
= count
- 1; i
>= 0; i
--) {
3202 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3204 var expandListBy
= (start
+ count
+ offset
) - this._length
;
3205 if (expandListBy
> 0) {
3206 this._length
+= expandListBy
;
3207 while (this._length
> this.maxLength
) {
3210 this.emit('trim', 1);
3215 for (var i
= 0; i
< count
; i
++) {
3216 this.set(start
+ i
+ offset
, this.get(start
+ i
));
3220 CircularList
.prototype._getCyclicIndex = function (index
) {
3221 return (this._startIndex
+ index
) % this.maxLength
;
3223 return CircularList
;
3224 }(EventEmitter_1
.EventEmitter
));
3225 exports
.CircularList
= CircularList
;
3229 },{"../EventEmitter":4}],16:[function(require
,module
,exports
){
3231 Object
.defineProperty(exports
, "__esModule", { value
: true });
3232 var DomElementObjectPool
= (function () {
3233 function DomElementObjectPool(type
) {
3239 DomElementObjectPool
.prototype.acquire = function () {
3241 if (this._pool
.length
=== 0) {
3242 element
= this._createNew();
3245 element
= this._pool
.pop();
3247 this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)] = element
;
3250 DomElementObjectPool
.prototype.release = function (element
) {
3251 if (!this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)]) {
3252 throw new Error('Could not release an element not yet acquired');
3254 delete this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)];
3255 this._cleanElement(element
);
3256 this._pool
.push(element
);
3258 DomElementObjectPool
.prototype._createNew = function () {
3259 var element
= document
.createElement(this._type
);
3260 var id
= DomElementObjectPool
._objectCount
++;
3261 element
.setAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
, id
.toString(10));
3264 DomElementObjectPool
.prototype._cleanElement = function (element
) {
3265 element
.className
= '';
3266 element
.innerHTML
= '';
3268 return DomElementObjectPool
;
3270 DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
= 'data-obj-id';
3271 DomElementObjectPool
._objectCount
= 0;
3272 exports
.DomElementObjectPool
= DomElementObjectPool
;
3276 },{}],17:[function(require
,module
,exports
){
3278 Object
.defineProperty(exports
, "__esModule", { value
: true });
3279 function contains(arr
, el
) {
3280 return arr
.indexOf(el
) >= 0;
3282 exports
.contains
= contains
;
3287 },{}],18:[function(require
,module
,exports
){
3289 Object
.defineProperty(exports
, "__esModule", { value
: true });
3290 function getCoordsRelativeToElement(event
, element
) {
3291 if (event
.pageX
== null) {
3294 var x
= event
.pageX
;
3295 var y
= event
.pageY
;
3296 while (element
&& element
!== self
.document
.documentElement
) {
3297 x
-= element
.offsetLeft
;
3298 y
-= element
.offsetTop
;
3299 element
= 'offsetParent' in element
? element
.offsetParent
: element
.parentElement
;
3303 exports
.getCoordsRelativeToElement
= getCoordsRelativeToElement
;
3304 function getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
, isSelection
) {
3305 var coords
= getCoordsRelativeToElement(event
, rowContainer
);
3306 coords
[0] = Math
.ceil((coords
[0] + (isSelection
? charMeasure
.width
/ 2 : 0)) / charMeasure
.width
);
3307 coords
[1] = Math
.ceil(coords
[1] / charMeasure
.height
);
3308 coords
[0] = Math
.min(Math
.max(coords
[0], 1), colCount
+ 1);
3309 coords
[1] = Math
.min(Math
.max(coords
[1], 1), rowCount
+ 1);
3312 exports
.getCoords
= getCoords
;
3313 function getRawByteCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
) {
3314 var coords
= getCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
);
3319 return { x
: x
, y
: y
};
3321 exports
.getRawByteCoords
= getRawByteCoords
;
3325 },{}],19:[function(require
,module
,exports
){
3327 Object
.defineProperty(exports
, "__esModule", { value
: true });
3328 var CompositionHelper_1
= require("./CompositionHelper");
3329 var EventEmitter_1
= require("./EventEmitter");
3330 var Viewport_1
= require("./Viewport");
3331 var Clipboard_1
= require("./handlers/Clipboard");
3332 var CircularList_1
= require("./utils/CircularList");
3333 var EscapeSequences_1
= require("./EscapeSequences");
3334 var InputHandler_1
= require("./InputHandler");
3335 var Parser_1
= require("./Parser");
3336 var Renderer_1
= require("./Renderer");
3337 var Linkifier_1
= require("./Linkifier");
3338 var SelectionManager_1
= require("./SelectionManager");
3339 var CharMeasure_1
= require("./utils/CharMeasure");
3340 var Browser
= require("./utils/Browser");
3341 var Mouse_1
= require("./utils/Mouse");
3342 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
3343 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
3344 var WRITE_BATCH_SIZE
= 300;
3345 var CURSOR_BLINK_INTERVAL
= 600;
3346 function Terminal(options
) {
3348 if (!(this instanceof Terminal
)) {
3349 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
3351 self
.browser
= Browser
;
3352 self
.cancel
= Terminal
.cancel
;
3353 EventEmitter_1
.EventEmitter
.call(this);
3354 if (typeof options
=== 'number') {
3358 handler
: arguments
[2]
3361 options
= options
|| {};
3362 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
3363 if (options
[key
] == null) {
3364 options
[key
] = Terminal
.options
[key
];
3365 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
3366 options
[key
] = Terminal
[key
];
3369 self
[key
] = options
[key
];
3371 if (options
.colors
.length
=== 8) {
3372 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
3374 else if (options
.colors
.length
=== 16) {
3375 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
3377 else if (options
.colors
.length
=== 10) {
3378 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
3380 else if (options
.colors
.length
=== 18) {
3381 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
3383 this.colors
= options
.colors
;
3384 this.options
= options
;
3385 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
3386 this.cols
= options
.cols
|| options
.geometry
[0];
3387 this.rows
= options
.rows
|| options
.geometry
[1];
3388 this.geometry
= [this.cols
, this.rows
];
3389 if (options
.handler
) {
3390 this.on('data', options
.handler
);
3396 this.cursorState
= 0;
3397 this.cursorHidden
= false;
3401 this.scrollBottom
= this.rows
- 1;
3402 this.customKeyEventHandler
= null;
3403 this.cursorBlinkInterval
= null;
3404 this.applicationKeypad
= false;
3405 this.applicationCursor
= false;
3406 this.originMode
= false;
3407 this.insertMode
= false;
3408 this.wraparoundMode
= true;
3410 this.charset
= null;
3411 this.gcharset
= null;
3413 this.charsets
= [null];
3431 this.readable
= true;
3432 this.writable
= true;
3433 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
3434 this.curAttr
= this.defAttr
;
3436 this.currentParam
= 0;
3439 this.inputHandler
= new InputHandler_1
.InputHandler(this);
3440 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
3441 this.renderer
= this.renderer
|| null;
3442 this.selectionManager
= this.selectionManager
|| null;
3443 this.linkifier
= this.linkifier
|| new Linkifier_1
.Linkifier();
3444 this.writeBuffer
= [];
3445 this.writeInProgress
= false;
3446 this.xoffSentToCatchUp
= false;
3447 this.writeStopped
= false;
3448 this.surrogate_high
= '';
3449 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
3452 this.lines
.push(this.blankLine());
3454 if (this.selectionManager
) {
3455 this.selectionManager
.setBuffer(this.lines
);
3459 this.userScrolling
= false;
3461 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
3462 Terminal
.prototype.eraseAttr = function () {
3463 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
3465 Terminal
.tangoColors
= [
3483 Terminal
.colors
= (function () {
3484 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
3486 for (; i
< 216; i
++) {
3487 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
3490 for (; i
< 24; i
++) {
3494 function out(r
, g
, b
) {
3495 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
3499 return c
.length
< 2 ? '0' + c
: c
;
3503 Terminal
._colors
= Terminal
.colors
.slice();
3504 Terminal
.vcolors
= (function () {
3505 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
3506 for (; i
< 256; i
++) {
3507 color
= parseInt(colors
[i
].substring(1), 16);
3509 (color
>> 16) & 0xff,
3510 (color
>> 8) & 0xff,
3516 Terminal
.defaults
= {
3517 colors
: Terminal
.colors
,
3523 cursorStyle
: 'block',
3529 cancelEvents
: false,
3530 disableStdin
: false,
3531 useFlowControl
: false,
3534 Terminal
.options
= {};
3535 Terminal
.focus
= null;
3536 each(keys(Terminal
.defaults
), function (key
) {
3537 Terminal
[key
] = Terminal
.defaults
[key
];
3538 Terminal
.options
[key
] = Terminal
.defaults
[key
];
3540 Terminal
.prototype.focus = function () {
3541 return this.textarea
.focus();
3543 Terminal
.prototype.getOption = function (key
, value
) {
3544 if (!(key
in Terminal
.defaults
)) {
3545 throw new Error('No option with key "' + key
+ '"');
3547 if (typeof this.options
[key
] !== 'undefined') {
3548 return this.options
[key
];
3552 Terminal
.prototype.setOption = function (key
, value
) {
3553 if (!(key
in Terminal
.defaults
)) {
3554 throw new Error('No option with key "' + key
+ '"');
3558 if (value
< this.rows
) {
3559 var msg
= 'Setting the scrollback value less than the number of rows ';
3560 msg
+= "(" + this.rows
+ ") is not allowed.";
3564 if (this.options
[key
] !== value
) {
3565 if (this.lines
.length
> value
) {
3566 var amountToTrim
= this.lines
.length
- value
;
3567 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
3568 this.lines
.trimStart(amountToTrim
);
3569 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
3570 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
3572 this.refresh(0, this.rows
- 1);
3575 this.lines
.maxLength
= value
;
3576 this.viewport
.syncScrollArea();
3581 this.options
[key
] = value
;
3584 this.setCursorBlinking(value
);
3587 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
3588 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
3590 case 'tabStopWidth':
3595 Terminal
.prototype.restartCursorBlinking = function () {
3596 this.setCursorBlinking(this.options
.cursorBlink
);
3598 Terminal
.prototype.setCursorBlinking = function (enabled
) {
3599 this.element
.classList
.toggle('xterm-cursor-blink', enabled
);
3600 this.clearCursorBlinkingInterval();
3603 this.cursorBlinkInterval
= setInterval(function () {
3604 self
.element
.classList
.toggle('xterm-cursor-blink-on');
3605 }, CURSOR_BLINK_INTERVAL
);
3608 Terminal
.prototype.clearCursorBlinkingInterval = function () {
3609 this.element
.classList
.remove('xterm-cursor-blink-on');
3610 if (this.cursorBlinkInterval
) {
3611 clearInterval(this.cursorBlinkInterval
);
3612 this.cursorBlinkInterval
= null;
3615 Terminal
.bindFocus = function (term
) {
3616 on(term
.textarea
, 'focus', function (ev
) {
3617 if (term
.sendFocus
) {
3618 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
3620 term
.element
.classList
.add('focus');
3622 term
.restartCursorBlinking
.apply(term
);
3623 Terminal
.focus
= term
;
3624 term
.emit('focus', { terminal
: term
});
3627 Terminal
.prototype.blur = function () {
3628 return this.textarea
.blur();
3630 Terminal
.bindBlur = function (term
) {
3631 on(term
.textarea
, 'blur', function (ev
) {
3632 term
.refresh(term
.y
, term
.y
);
3633 if (term
.sendFocus
) {
3634 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
3636 term
.element
.classList
.remove('focus');
3637 term
.clearCursorBlinkingInterval
.apply(term
);
3638 Terminal
.focus
= null;
3639 term
.emit('blur', { terminal
: term
});
3642 Terminal
.prototype.initGlobal = function () {
3645 Terminal
.bindKeys(this);
3646 Terminal
.bindFocus(this);
3647 Terminal
.bindBlur(this);
3648 on(this.element
, 'copy', function (event
) {
3649 if (_this
.mouseEvents
) {
3652 Clipboard_1
.copyHandler(event
, term
, _this
.selectionManager
);
3654 var pasteHandlerWrapper = function (event
) { return Clipboard_1
.pasteHandler(event
, term
); };
3655 on(this.textarea
, 'paste', pasteHandlerWrapper
);
3656 on(this.element
, 'paste', pasteHandlerWrapper
);
3657 if (term
.browser
.isFirefox
) {
3658 on(this.element
, 'mousedown', function (event
) {
3659 if (event
.button
== 2) {
3660 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3665 on(this.element
, 'contextmenu', function (event
) {
3666 Clipboard_1
.rightClickHandler(event
, _this
.textarea
, _this
.selectionManager
);
3669 if (term
.browser
.isLinux
) {
3670 on(this.element
, 'auxclick', function (event
) {
3671 if (event
.button
=== 1) {
3672 Clipboard_1
.moveTextAreaUnderMouseCursor(event
, _this
.textarea
, _this
.selectionManager
);
3677 Terminal
.bindKeys = function (term
) {
3678 on(term
.element
, 'keydown', function (ev
) {
3679 if (document
.activeElement
!= this) {
3684 on(term
.element
, 'keypress', function (ev
) {
3685 if (document
.activeElement
!= this) {
3690 on(term
.element
, 'keyup', function (ev
) {
3691 if (!wasMondifierKeyOnlyEvent(ev
)) {
3695 on(term
.textarea
, 'keydown', function (ev
) {
3698 on(term
.textarea
, 'keypress', function (ev
) {
3702 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
3703 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
3704 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
3705 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
3706 term
.on('refresh', function (data
) {
3707 term
.queueLinkification(data
.start
, data
.end
);
3710 Terminal
.prototype.insertRow = function (row
) {
3711 if (typeof row
!= 'object') {
3712 row
= document
.createElement('div');
3714 this.rowContainer
.appendChild(row
);
3715 this.children
.push(row
);
3718 Terminal
.prototype.open = function (parent
, focus
) {
3720 var self
= this, i
= 0, div
;
3721 this.parent
= parent
|| this.parent
;
3723 throw new Error('Terminal requires a parent element.');
3725 this.context
= this.parent
.ownerDocument
.defaultView
;
3726 this.document
= this.parent
.ownerDocument
;
3727 this.body
= this.document
.getElementsByTagName('body')[0];
3728 this.element
= this.document
.createElement('div');
3729 this.element
.classList
.add('terminal');
3730 this.element
.classList
.add('xterm');
3731 this.element
.classList
.add('xterm-theme-' + this.theme
);
3732 this.setCursorBlinking(this.options
.cursorBlink
);
3733 this.element
.setAttribute('tabindex', 0);
3734 this.viewportElement
= document
.createElement('div');
3735 this.viewportElement
.classList
.add('xterm-viewport');
3736 this.element
.appendChild(this.viewportElement
);
3737 this.viewportScrollArea
= document
.createElement('div');
3738 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
3739 this.viewportElement
.appendChild(this.viewportScrollArea
);
3740 this.selectionContainer
= document
.createElement('div');
3741 this.selectionContainer
.classList
.add('xterm-selection');
3742 this.element
.appendChild(this.selectionContainer
);
3743 this.rowContainer
= document
.createElement('div');
3744 this.rowContainer
.classList
.add('xterm-rows');
3745 this.element
.appendChild(this.rowContainer
);
3747 this.linkifier
.attachToDom(document
, this.children
);
3748 this.helperContainer
= document
.createElement('div');
3749 this.helperContainer
.classList
.add('xterm-helpers');
3750 this.element
.appendChild(this.helperContainer
);
3751 this.textarea
= document
.createElement('textarea');
3752 this.textarea
.classList
.add('xterm-helper-textarea');
3753 this.textarea
.setAttribute('autocorrect', 'off');
3754 this.textarea
.setAttribute('autocapitalize', 'off');
3755 this.textarea
.setAttribute('spellcheck', 'false');
3756 this.textarea
.tabIndex
= 0;
3757 this.textarea
.addEventListener('focus', function () {
3758 self
.emit('focus', { terminal
: self
});
3760 this.textarea
.addEventListener('blur', function () {
3761 self
.emit('blur', { terminal
: self
});
3763 this.helperContainer
.appendChild(this.textarea
);
3764 this.compositionView
= document
.createElement('div');
3765 this.compositionView
.classList
.add('composition-view');
3766 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
3767 this.helperContainer
.appendChild(this.compositionView
);
3768 this.charSizeStyleElement
= document
.createElement('style');
3769 this.helperContainer
.appendChild(this.charSizeStyleElement
);
3770 for (; i
< this.rows
; i
++) {
3773 this.parent
.appendChild(this.element
);
3774 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
3775 this.charMeasure
.on('charsizechanged', function () {
3776 self
.updateCharSizeStyles();
3778 this.charMeasure
.measure();
3779 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
3780 this.renderer
= new Renderer_1
.Renderer(this);
3781 this.selectionManager
= new SelectionManager_1
.SelectionManager(this, this.lines
, this.rowContainer
, this.charMeasure
);
3782 this.selectionManager
.on('refresh', function (data
) {
3783 _this
.renderer
.refreshSelection(data
.start
, data
.end
);
3785 this.selectionManager
.on('newselection', function (text
) {
3786 _this
.textarea
.value
= text
;
3787 _this
.textarea
.focus();
3788 _this
.textarea
.select();
3790 this.on('scroll', function () { return _this
.selectionManager
.refresh(); });
3791 this.viewportElement
.addEventListener('scroll', function () { return _this
.selectionManager
.refresh(); });
3792 this.refresh(0, this.rows
- 1);
3794 if (typeof focus
== 'undefined') {
3795 var message
= 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
3796 message
+= 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
3797 message
+= 'it will default to `false`.';
3798 console
.warn(message
);
3804 on(this.element
, 'click', function () {
3805 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
3813 Terminal
.loadAddon = function (addon
, callback
) {
3814 if (typeof exports
=== 'object' && typeof module
=== 'object') {
3815 return require('./addons/' + addon
+ '/' + addon
);
3817 else if (typeof define
== 'function') {
3818 return require(['./addons/' + addon
+ '/' + addon
], callback
);
3821 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
3825 Terminal
.prototype.updateCharSizeStyles = function () {
3826 this.charSizeStyleElement
.textContent
=
3827 ".xterm-wide-char{width:" + this.charMeasure
.width
* 2 + "px;}" +
3828 (".xterm-normal-char{width:" + this.charMeasure
.width
+ "px;}") +
3829 (".xterm-rows > div{height:" + this.charMeasure
.height
+ "px;}");
3831 Terminal
.prototype.bindMouse = function () {
3832 var el
= this.element
, self
= this, pressed
= 32;
3833 function sendButton(ev
) {
3835 button
= getButton(ev
);
3836 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
3839 sendEvent(button
, pos
);
3840 switch (ev
.overrideType
|| ev
.type
) {
3851 function sendMove(ev
) {
3852 var button
= pressed
, pos
;
3853 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
3857 sendEvent(button
, pos
);
3859 function encode(data
, ch
) {
3860 if (!self
.utfMouse
) {
3862 return data
.push(0);
3869 return data
.push(0);
3876 data
.push(0xC0 | (ch
>> 6));
3877 data
.push(0x80 | (ch
& 0x3F));
3881 function sendEvent(button
, pos
) {
3882 if (self
.vt300Mouse
) {
3886 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
3889 else if (button
=== 1)
3891 else if (button
=== 2)
3893 else if (button
=== 3)
3897 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
3901 if (self
.decLocator
) {
3907 else if (button
=== 1)
3909 else if (button
=== 2)
3911 else if (button
=== 3)
3913 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
3916 + (button
=== 3 ? 4 : 0)
3926 if (self
.urxvtMouse
) {
3931 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
3934 if (self
.sgrMouse
) {
3937 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
3938 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
3943 + ((button
& 3) === 3 ? 'm' : 'M'));
3947 encode(data
, button
);
3948 encode(data
, pos
.x
);
3949 encode(data
, pos
.y
);
3950 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
3952 function getButton(ev
) {
3953 var button
, shift
, meta
, ctrl
, mod
;
3954 switch (ev
.overrideType
|| ev
.type
) {
3956 button
= ev
.button
!= null
3961 if (self
.browser
.isMSIE
) {
3962 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
3968 case 'DOMMouseScroll':
3969 button
= ev
.detail
< 0
3974 button
= ev
.wheelDeltaY
> 0
3979 shift
= ev
.shiftKey
? 4 : 0;
3980 meta
= ev
.metaKey
? 8 : 0;
3981 ctrl
= ev
.ctrlKey
? 16 : 0;
3982 mod
= shift
| meta
| ctrl
;
3983 if (self
.vt200Mouse
) {
3986 else if (!self
.normalMouse
) {
3989 button
= (32 + (mod
<< 2)) + button
;
3992 on(el
, 'mousedown', function (ev
) {
3993 if (!self
.mouseEvents
)
3997 if (self
.vt200Mouse
) {
3998 ev
.overrideType
= 'mouseup';
4000 return self
.cancel(ev
);
4002 if (self
.normalMouse
)
4003 on(self
.document
, 'mousemove', sendMove
);
4004 if (!self
.x10Mouse
) {
4005 on(self
.document
, 'mouseup', function up(ev
) {
4007 if (self
.normalMouse
)
4008 off(self
.document
, 'mousemove', sendMove
);
4009 off(self
.document
, 'mouseup', up
);
4010 return self
.cancel(ev
);
4013 return self
.cancel(ev
);
4015 on(el
, 'wheel', function (ev
) {
4016 if (!self
.mouseEvents
)
4023 return self
.cancel(ev
);
4025 on(el
, 'wheel', function (ev
) {
4026 if (self
.mouseEvents
)
4028 self
.viewport
.onWheel(ev
);
4029 return self
.cancel(ev
);
4031 on(el
, 'touchstart', function (ev
) {
4032 if (self
.mouseEvents
)
4034 self
.viewport
.onTouchStart(ev
);
4035 return self
.cancel(ev
);
4037 on(el
, 'touchmove', function (ev
) {
4038 if (self
.mouseEvents
)
4040 self
.viewport
.onTouchMove(ev
);
4041 return self
.cancel(ev
);
4044 Terminal
.prototype.destroy = function () {
4045 this.readable
= false;
4046 this.writable
= false;
4048 this.handler = function () { };
4049 this.write = function () { };
4050 if (this.element
&& this.element
.parentNode
) {
4051 this.element
.parentNode
.removeChild(this.element
);
4054 Terminal
.prototype.refresh = function (start
, end
) {
4055 if (this.renderer
) {
4056 this.renderer
.queueRefresh(start
, end
);
4059 Terminal
.prototype.queueLinkification = function (start
, end
) {
4060 if (this.linkifier
) {
4061 for (var i
= start
; i
<= end
; i
++) {
4062 this.linkifier
.linkifyRow(i
);
4066 Terminal
.prototype.showCursor = function () {
4067 if (!this.cursorState
) {
4068 this.cursorState
= 1;
4069 this.refresh(this.y
, this.y
);
4072 Terminal
.prototype.scroll = function (isWrapped
) {
4074 if (this.lines
.length
=== this.lines
.maxLength
) {
4075 this.lines
.trimStart(1);
4077 if (this.ydisp
!== 0) {
4082 if (!this.userScrolling
) {
4083 this.ydisp
= this.ybase
;
4085 row
= this.ybase
+ this.rows
- 1;
4086 row
-= this.rows
- 1 - this.scrollBottom
;
4087 if (row
=== this.lines
.length
) {
4088 this.lines
.push(this.blankLine(undefined, isWrapped
));
4091 this.lines
.splice(row
, 0, this.blankLine(undefined, isWrapped
));
4093 if (this.scrollTop
!== 0) {
4094 if (this.ybase
!== 0) {
4096 if (!this.userScrolling
) {
4097 this.ydisp
= this.ybase
;
4100 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
4102 this.updateRange(this.scrollTop
);
4103 this.updateRange(this.scrollBottom
);
4104 this.emit('scroll', this.ydisp
);
4106 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
4108 if (this.ydisp
=== 0) {
4111 this.userScrolling
= true;
4113 else if (disp
+ this.ydisp
>= this.ybase
) {
4114 this.userScrolling
= false;
4117 if (this.ydisp
> this.ybase
) {
4118 this.ydisp
= this.ybase
;
4120 else if (this.ydisp
< 0) {
4123 if (!suppressScrollEvent
) {
4124 this.emit('scroll', this.ydisp
);
4126 this.refresh(0, this.rows
- 1);
4128 Terminal
.prototype.scrollPages = function (pageCount
) {
4129 this.scrollDisp(pageCount
* (this.rows
- 1));
4131 Terminal
.prototype.scrollToTop = function () {
4132 this.scrollDisp(-this.ydisp
);
4134 Terminal
.prototype.scrollToBottom = function () {
4135 this.scrollDisp(this.ybase
- this.ydisp
);
4137 Terminal
.prototype.write = function (data
) {
4138 this.writeBuffer
.push(data
);
4139 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
4140 this.send(EscapeSequences_1
.C0
.DC3
);
4141 this.xoffSentToCatchUp
= true;
4143 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
4144 this.writeInProgress
= true;
4146 setTimeout(function () {
4151 Terminal
.prototype.innerWrite = function () {
4152 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
4153 while (writeBatch
.length
> 0) {
4154 var data
= writeBatch
.shift();
4155 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
4156 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
4157 this.send(EscapeSequences_1
.C0
.DC1
);
4158 this.xoffSentToCatchUp
= false;
4160 this.refreshStart
= this.y
;
4161 this.refreshEnd
= this.y
;
4162 var state
= this.parser
.parse(data
);
4163 this.parser
.setState(state
);
4164 this.updateRange(this.y
);
4165 this.refresh(this.refreshStart
, this.refreshEnd
);
4167 if (this.writeBuffer
.length
> 0) {
4169 setTimeout(function () {
4174 this.writeInProgress
= false;
4177 Terminal
.prototype.writeln = function (data
) {
4178 this.write(data
+ '\r\n');
4180 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
4181 var message
= 'attachCustomKeydownHandler() is DEPRECATED and will be removed soon. Please use attachCustomKeyEventHandler() instead.';
4182 console
.warn(message
);
4183 this.attachCustomKeyEventHandler(customKeydownHandler
);
4185 Terminal
.prototype.attachCustomKeyEventHandler = function (customKeyEventHandler
) {
4186 this.customKeyEventHandler
= customKeyEventHandler
;
4188 Terminal
.prototype.setHypertextLinkHandler = function (handler
) {
4189 if (!this.linkifier
) {
4190 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
4192 this.linkifier
.setHypertextLinkHandler(handler
);
4193 this.refresh(0, this.rows
- 1);
4195 Terminal
.prototype.setHypertextValidationCallback = function (callback
) {
4196 if (!this.linkifier
) {
4197 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
4199 this.linkifier
.setHypertextValidationCallback(callback
);
4200 this.refresh(0, this.rows
- 1);
4202 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
4203 if (this.linkifier
) {
4204 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
4205 this.refresh(0, this.rows
- 1);
4209 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
4210 if (this.linkifier
) {
4211 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
4212 this.refresh(0, this.rows
- 1);
4216 Terminal
.prototype.hasSelection = function () {
4217 return this.selectionManager
.hasSelection
;
4219 Terminal
.prototype.getSelection = function () {
4220 return this.selectionManager
.selectionText
;
4222 Terminal
.prototype.clearSelection = function () {
4223 this.selectionManager
.clearSelection();
4225 Terminal
.prototype.selectAll = function () {
4226 this.selectionManager
.selectAll();
4228 Terminal
.prototype.keyDown = function (ev
) {
4229 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4232 this.restartCursorBlinking();
4233 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
4234 if (this.ybase
!== this.ydisp
) {
4235 this.scrollToBottom();
4240 var result
= this.evaluateKeyEscapeSequence(ev
);
4241 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
4242 this.writeStopped
= true;
4244 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
4245 this.writeStopped
= false;
4247 if (result
.scrollDisp
) {
4248 this.scrollDisp(result
.scrollDisp
);
4249 return this.cancel(ev
, true);
4251 if (isThirdLevelShift(this, ev
)) {
4254 if (result
.cancel
) {
4255 this.cancel(ev
, true);
4260 this.emit('keydown', ev
);
4261 this.emit('key', result
.key
, ev
);
4263 this.handler(result
.key
);
4264 return this.cancel(ev
, true);
4266 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
4270 scrollDisp
: undefined
4272 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
4273 switch (ev
.keyCode
) {
4276 result
.key
= EscapeSequences_1
.C0
.BS
;
4279 result
.key
= EscapeSequences_1
.C0
.DEL
;
4283 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
4286 result
.key
= EscapeSequences_1
.C0
.HT
;
4287 result
.cancel
= true;
4290 result
.key
= EscapeSequences_1
.C0
.CR
;
4291 result
.cancel
= true;
4294 result
.key
= EscapeSequences_1
.C0
.ESC
;
4295 result
.cancel
= true;
4299 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
4300 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
4301 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
4304 else if (this.applicationCursor
) {
4305 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
4308 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
4313 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
4314 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
4315 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
4318 else if (this.applicationCursor
) {
4319 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
4322 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
4327 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
4328 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
4329 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
4332 else if (this.applicationCursor
) {
4333 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
4336 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
4341 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
4342 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
4343 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
4346 else if (this.applicationCursor
) {
4347 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
4350 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
4354 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
4355 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
4360 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
4363 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
4368 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
4369 else if (this.applicationCursor
)
4370 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
4372 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
4376 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
4377 else if (this.applicationCursor
)
4378 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
4380 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
4384 result
.scrollDisp
= -(this.rows
- 1);
4387 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
4392 result
.scrollDisp
= this.rows
- 1;
4395 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
4400 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
4403 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
4408 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
4411 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
4416 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
4419 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
4424 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
4427 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
4432 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
4435 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
4440 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
4443 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
4448 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
4451 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
4456 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
4459 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
4464 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
4467 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
4472 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
4475 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
4480 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
4483 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
4488 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
4491 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
4495 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
4496 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4497 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
4499 else if (ev
.keyCode
=== 32) {
4500 result
.key
= String
.fromCharCode(0);
4502 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
4503 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
4505 else if (ev
.keyCode
=== 56) {
4506 result
.key
= String
.fromCharCode(127);
4508 else if (ev
.keyCode
=== 219) {
4509 result
.key
= String
.fromCharCode(27);
4511 else if (ev
.keyCode
=== 220) {
4512 result
.key
= String
.fromCharCode(28);
4514 else if (ev
.keyCode
=== 221) {
4515 result
.key
= String
.fromCharCode(29);
4518 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
4519 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
4520 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
4522 else if (ev
.keyCode
=== 192) {
4523 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
4525 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
4526 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
4529 else if (this.browser
.isMac
&& !ev
.altKey
&& !ev
.ctrlKey
&& ev
.metaKey
) {
4530 if (ev
.keyCode
=== 65) {
4538 Terminal
.prototype.setgLevel = function (g
) {
4540 this.charset
= this.charsets
[g
];
4542 Terminal
.prototype.setgCharset = function (g
, charset
) {
4543 this.charsets
[g
] = charset
;
4544 if (this.glevel
=== g
) {
4545 this.charset
= charset
;
4548 Terminal
.prototype.keyPress = function (ev
) {
4550 if (this.customKeyEventHandler
&& this.customKeyEventHandler(ev
) === false) {
4557 else if (ev
.which
== null) {
4560 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
4566 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
4569 key
= String
.fromCharCode(key
);
4570 this.emit('keypress', key
, ev
);
4571 this.emit('key', key
, ev
);
4576 Terminal
.prototype.send = function (data
) {
4579 setTimeout(function () {
4580 self
.handler(self
.queue
);
4586 Terminal
.prototype.bell = function () {
4587 if (!this.visualBell
)
4590 this.element
.style
.borderColor
= 'white';
4591 setTimeout(function () {
4592 self
.element
.style
.borderColor
= '';
4597 Terminal
.prototype.log = function () {
4600 if (!this.context
.console
|| !this.context
.console
.log
)
4602 var args
= Array
.prototype.slice
.call(arguments
);
4603 this.context
.console
.log
.apply(this.context
.console
, args
);
4605 Terminal
.prototype.error = function () {
4608 if (!this.context
.console
|| !this.context
.console
.error
)
4610 var args
= Array
.prototype.slice
.call(arguments
);
4611 this.context
.console
.error
.apply(this.context
.console
, args
);
4613 Terminal
.prototype.resize = function (x
, y
) {
4614 if (isNaN(x
) || isNaN(y
)) {
4617 if (y
> this.getOption('scrollback')) {
4618 this.setOption('scrollback', y
);
4620 var line
, el
, i
, j
, ch
, addToY
;
4621 if (x
=== this.cols
&& y
=== this.rows
) {
4630 ch
= [this.defAttr
, ' ', 1];
4631 i
= this.lines
.length
;
4633 while (this.lines
.get(i
).length
< x
) {
4634 this.lines
.get(i
).push(ch
);
4639 this.setupStops(this.cols
);
4645 if (this.lines
.length
< y
+ this.ybase
) {
4646 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
4649 if (this.ydisp
> 0) {
4654 this.lines
.push(this.blankLine());
4657 if (this.children
.length
< y
) {
4664 if (this.lines
.length
> y
+ this.ybase
) {
4665 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
4673 if (this.children
.length
> y
) {
4674 el
= this.children
.shift();
4677 el
.parentNode
.removeChild(el
);
4692 this.scrollBottom
= y
- 1;
4693 this.charMeasure
.measure();
4694 this.refresh(0, this.rows
- 1);
4696 this.geometry
= [this.cols
, this.rows
];
4697 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
4699 Terminal
.prototype.updateRange = function (y
) {
4700 if (y
< this.refreshStart
)
4701 this.refreshStart
= y
;
4702 if (y
> this.refreshEnd
)
4703 this.refreshEnd
= y
;
4705 Terminal
.prototype.maxRange = function () {
4706 this.refreshStart
= 0;
4707 this.refreshEnd
= this.rows
- 1;
4709 Terminal
.prototype.setupStops = function (i
) {
4711 if (!this.tabs
[i
]) {
4712 i
= this.prevStop(i
);
4719 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
4720 this.tabs
[i
] = true;
4723 Terminal
.prototype.prevStop = function (x
) {
4726 while (!this.tabs
[--x
] && x
> 0)
4728 return x
>= this.cols
4732 Terminal
.prototype.nextStop = function (x
) {
4735 while (!this.tabs
[++x
] && x
< this.cols
)
4737 return x
>= this.cols
4741 Terminal
.prototype.eraseRight = function (x
, y
) {
4742 var line
= this.lines
.get(this.ybase
+ y
);
4746 var ch
= [this.eraseAttr(), ' ', 1];
4747 for (; x
< this.cols
; x
++) {
4750 this.updateRange(y
);
4752 Terminal
.prototype.eraseLeft = function (x
, y
) {
4753 var line
= this.lines
.get(this.ybase
+ y
);
4757 var ch
= [this.eraseAttr(), ' ', 1];
4762 this.updateRange(y
);
4764 Terminal
.prototype.clear = function () {
4765 if (this.ybase
=== 0 && this.y
=== 0) {
4768 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
4769 this.lines
.length
= 1;
4773 for (var i
= 1; i
< this.rows
; i
++) {
4774 this.lines
.push(this.blankLine());
4776 this.refresh(0, this.rows
- 1);
4777 this.emit('scroll', this.ydisp
);
4779 Terminal
.prototype.eraseLine = function (y
) {
4780 this.eraseRight(0, y
);
4782 Terminal
.prototype.blankLine = function (cur
, isWrapped
) {
4786 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
4788 line
.isWrapped
= isWrapped
;
4790 for (; i
< this.cols
; i
++) {
4795 Terminal
.prototype.ch = function (cur
) {
4797 ? [this.eraseAttr(), ' ', 1]
4798 : [this.defAttr
, ' ', 1];
4800 Terminal
.prototype.is = function (term
) {
4801 var name
= this.termName
;
4802 return (name
+ '').indexOf(term
) === 0;
4804 Terminal
.prototype.handler = function (data
) {
4805 if (this.options
.disableStdin
) {
4808 if (this.ybase
!== this.ydisp
) {
4809 this.scrollToBottom();
4811 this.emit('data', data
);
4813 Terminal
.prototype.handleTitle = function (title
) {
4814 this.emit('title', title
);
4816 Terminal
.prototype.index = function () {
4818 if (this.y
> this.scrollBottom
) {
4822 if (this.x
>= this.cols
) {
4826 Terminal
.prototype.reverseIndex = function () {
4828 if (this.y
=== this.scrollTop
) {
4829 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
4830 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
4831 this.updateRange(this.scrollTop
);
4832 this.updateRange(this.scrollBottom
);
4838 Terminal
.prototype.reset = function () {
4839 this.options
.rows
= this.rows
;
4840 this.options
.cols
= this.cols
;
4841 var customKeyEventHandler
= this.customKeyEventHandler
;
4842 var cursorBlinkInterval
= this.cursorBlinkInterval
;
4843 Terminal
.call(this, this.options
);
4844 this.customKeyEventHandler
= customKeyEventHandler
;
4845 this.cursorBlinkInterval
= cursorBlinkInterval
;
4846 this.refresh(0, this.rows
- 1);
4847 this.viewport
.syncScrollArea();
4849 Terminal
.prototype.tabSet = function () {
4850 this.tabs
[this.x
] = true;
4852 function on(el
, type
, handler
, capture
) {
4853 if (!Array
.isArray(el
)) {
4856 el
.forEach(function (element
) {
4857 element
.addEventListener(type
, handler
, capture
|| false);
4860 function off(el
, type
, handler
, capture
) {
4861 el
.removeEventListener(type
, handler
, capture
|| false);
4863 function cancel(ev
, force
) {
4864 if (!this.cancelEvents
&& !force
) {
4867 ev
.preventDefault();
4868 ev
.stopPropagation();
4871 function inherits(child
, parent
) {
4873 this.constructor = child
;
4875 f
.prototype = parent
.prototype;
4876 child
.prototype = new f
;
4878 function indexOf(obj
, el
) {
4886 function isThirdLevelShift(term
, ev
) {
4887 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4888 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4889 if (ev
.type
== 'keypress') {
4890 return thirdLevelKey
;
4892 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4894 Terminal
.prototype.matchColor
= matchColor
;
4895 function matchColor(r1
, g1
, b1
) {
4896 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4897 if (matchColor
._cache
[hash
] != null) {
4898 return matchColor
._cache
[hash
];
4900 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
4901 for (; i
< Terminal
.vcolors
.length
; i
++) {
4902 c
= Terminal
.vcolors
[i
];
4906 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4916 return matchColor
._cache
[hash
] = li
;
4918 matchColor
._cache
= {};
4919 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
4920 return Math
.pow(30 * (r1
- r2
), 2)
4921 + Math
.pow(59 * (g1
- g2
), 2)
4922 + Math
.pow(11 * (b1
- b2
), 2);
4924 function each(obj
, iter
, con
) {
4926 return obj
.forEach(iter
, con
);
4927 for (var i
= 0; i
< obj
.length
; i
++) {
4928 iter
.call(con
, obj
[i
], i
, obj
);
4931 function wasMondifierKeyOnlyEvent(ev
) {
4932 return ev
.keyCode
=== 16 ||
4933 ev
.keyCode
=== 17 ||
4936 function keys(obj
) {
4938 return Object
.keys(obj
);
4941 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4947 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
4948 Terminal
.inherits
= inherits
;
4951 Terminal
.cancel
= cancel
;
4952 module
.exports
= Terminal
;
4956 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./SelectionManager":9,"./Viewport":11,"./handlers/Clipboard":12,"./utils/Browser":13,"./utils/CharMeasure":14,"./utils/CircularList":15,"./utils/Mouse":18}]},{},[19])(19)
4958 //# sourceMappingURL=xterm.js.map