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
){
4 exports
.DEFAULT_CHARSET
= exports
.CHARSETS
['B'];
5 exports
.CHARSETS
['0'] = {
38 exports
.CHARSETS
['A'] = {
41 exports
.CHARSETS
['B'] = null;
42 exports
.CHARSETS
['4'] = {
53 exports
.CHARSETS
['C'] =
54 exports
.CHARSETS
['5'] = {
65 exports
.CHARSETS
['R'] = {
76 exports
.CHARSETS
['Q'] = {
88 exports
.CHARSETS
['K'] = {
98 exports
.CHARSETS
['Y'] = {
110 exports
.CHARSETS
['E'] =
111 exports
.CHARSETS
['6'] = {
123 exports
.CHARSETS
['Z'] = {
133 exports
.CHARSETS
['H'] =
134 exports
.CHARSETS
['7'] = {
146 exports
.CHARSETS
['='] = {
163 },{}],2:[function(require
,module
,exports
){
165 var CompositionHelper
= (function () {
166 function CompositionHelper(textarea
, compositionView
, terminal
) {
167 this.textarea
= textarea
;
168 this.compositionView
= compositionView
;
169 this.terminal
= terminal
;
170 this.isComposing
= false;
171 this.isSendingComposition
= false;
172 this.compositionPosition
= { start
: null, end
: null };
174 CompositionHelper
.prototype.compositionstart = function () {
175 this.isComposing
= true;
176 this.compositionPosition
.start
= this.textarea
.value
.length
;
177 this.compositionView
.textContent
= '';
178 this.compositionView
.classList
.add('active');
180 CompositionHelper
.prototype.compositionupdate = function (ev
) {
182 this.compositionView
.textContent
= ev
.data
;
183 this.updateCompositionElements();
184 setTimeout(function () {
185 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
188 CompositionHelper
.prototype.compositionend = function () {
189 this.finalizeComposition(true);
191 CompositionHelper
.prototype.keydown = function (ev
) {
192 if (this.isComposing
|| this.isSendingComposition
) {
193 if (ev
.keyCode
=== 229) {
196 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
200 this.finalizeComposition(false);
203 if (ev
.keyCode
=== 229) {
204 this.handleAnyTextareaChanges();
209 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
211 this.compositionView
.classList
.remove('active');
212 this.isComposing
= false;
213 this.clearTextareaPosition();
214 if (!waitForPropogation
) {
215 this.isSendingComposition
= false;
216 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
217 this.terminal
.handler(input
);
220 var currentCompositionPosition_1
= {
221 start
: this.compositionPosition
.start
,
222 end
: this.compositionPosition
.end
,
224 this.isSendingComposition
= true;
225 setTimeout(function () {
226 if (_this
.isSendingComposition
) {
227 _this
.isSendingComposition
= false;
229 if (_this
.isComposing
) {
230 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
233 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
235 _this
.terminal
.handler(input
);
240 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
242 var oldValue
= this.textarea
.value
;
243 setTimeout(function () {
244 if (!_this
.isComposing
) {
245 var newValue
= _this
.textarea
.value
;
246 var diff
= newValue
.replace(oldValue
, '');
247 if (diff
.length
> 0) {
248 _this
.terminal
.handler(diff
);
253 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
255 if (!this.isComposing
) {
258 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
260 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
261 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
262 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
263 this.compositionView
.style
.top
= cursorTop
+ 'px';
264 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
265 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
266 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
267 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
268 this.textarea
.style
.top
= cursorTop
+ 'px';
269 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
270 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
271 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
274 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
278 CompositionHelper
.prototype.clearTextareaPosition = function () {
279 this.textarea
.style
.left
= '';
280 this.textarea
.style
.top
= '';
283 return CompositionHelper
;
285 exports
.CompositionHelper
= CompositionHelper
;
289 },{}],3:[function(require
,module
,exports
){
327 })(C0
= exports
.C0
|| (exports
.C0
= {}));
332 },{}],4:[function(require
,module
,exports
){
335 var EventEmitter
= (function () {
336 function EventEmitter() {
337 this._events
= this._events
|| {};
339 EventEmitter
.prototype.on = function (type
, listener
) {
340 this._events
[type
] = this._events
[type
] || [];
341 this._events
[type
].push(listener
);
343 EventEmitter
.prototype.off = function (type
, listener
) {
344 if (!this._events
[type
]) {
347 var obj
= this._events
[type
];
350 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
356 EventEmitter
.prototype.removeAllListeners = function (type
) {
357 if (this._events
[type
]) {
358 delete this._events
[type
];
361 EventEmitter
.prototype.once = function (type
, listener
) {
363 var args
= Array
.prototype.slice
.call(arguments
);
365 return listener
.apply(this, args
);
367 on
.listener
= listener
;
368 return this.on(type
, on
);
370 EventEmitter
.prototype.emit = function (type
) {
371 if (!this._events
[type
]) {
374 var args
= Array
.prototype.slice
.call(arguments
, 1);
375 var obj
= this._events
[type
];
376 for (var i
= 0; i
< obj
.length
; i
++) {
377 obj
[i
].apply(this, args
);
380 EventEmitter
.prototype.listeners = function (type
) {
381 return this._events
[type
] || [];
385 exports
.EventEmitter
= EventEmitter
;
389 },{}],5:[function(require
,module
,exports
){
391 var EscapeSequences_1
= require("./EscapeSequences");
392 var Charsets_1
= require("./Charsets");
393 var InputHandler
= (function () {
394 function InputHandler(_terminal
) {
395 this._terminal
= _terminal
;
397 InputHandler
.prototype.addChar = function (char, code
) {
399 var ch_width
= wcwidth(code
);
400 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
401 char = this._terminal
.charset
[char];
403 var row
= this._terminal
.y
+ this._terminal
.ybase
;
404 if (!ch_width
&& this._terminal
.x
) {
405 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 1]) {
406 if (!this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][2]) {
407 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 2])
408 this._terminal
.lines
.get(row
)[this._terminal
.x
- 2][1] += char;
411 this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][1] += char;
413 this._terminal
.updateRange(this._terminal
.y
);
417 if (this._terminal
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
418 if (this._terminal
.wraparoundMode
) {
419 this._terminal
.x
= 0;
421 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
423 this._terminal
.scroll();
431 row
= this._terminal
.y
+ this._terminal
.ybase
;
432 if (this._terminal
.insertMode
) {
433 for (var moves
= 0; moves
< ch_width
; ++moves
) {
434 var removed
= this._terminal
.lines
.get(this._terminal
.y
+ this._terminal
.ybase
).pop();
436 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2]
437 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2)
438 this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
439 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
442 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, char, ch_width
];
444 this._terminal
.updateRange(this._terminal
.y
);
445 if (ch_width
=== 2) {
446 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, '', 0];
451 InputHandler
.prototype.bell = function () {
453 if (!this._terminal
.visualBell
) {
456 this._terminal
.element
.style
.borderColor
= 'white';
457 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
458 if (this._terminal
.popOnBell
) {
459 this._terminal
.focus();
462 InputHandler
.prototype.lineFeed = function () {
463 if (this._terminal
.convertEol
) {
464 this._terminal
.x
= 0;
467 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
469 this._terminal
.scroll();
471 if (this._terminal
.x
>= this._terminal
.cols
) {
475 InputHandler
.prototype.carriageReturn = function () {
476 this._terminal
.x
= 0;
478 InputHandler
.prototype.backspace = function () {
479 if (this._terminal
.x
> 0) {
483 InputHandler
.prototype.tab = function () {
484 this._terminal
.x
= this._terminal
.nextStop();
486 InputHandler
.prototype.shiftOut = function () {
487 this._terminal
.setgLevel(1);
489 InputHandler
.prototype.shiftIn = function () {
490 this._terminal
.setgLevel(0);
492 InputHandler
.prototype.insertChars = function (params
) {
493 var param
, row
, j
, ch
;
497 row
= this._terminal
.y
+ this._terminal
.ybase
;
498 j
= this._terminal
.x
;
499 ch
= [this._terminal
.eraseAttr(), ' ', 1];
500 while (param
-- && j
< this._terminal
.cols
) {
501 this._terminal
.lines
.get(row
).splice(j
++, 0, ch
);
502 this._terminal
.lines
.get(row
).pop();
505 InputHandler
.prototype.cursorUp = function (params
) {
506 var param
= params
[0];
510 this._terminal
.y
-= param
;
511 if (this._terminal
.y
< 0) {
512 this._terminal
.y
= 0;
515 InputHandler
.prototype.cursorDown = function (params
) {
516 var param
= params
[0];
520 this._terminal
.y
+= param
;
521 if (this._terminal
.y
>= this._terminal
.rows
) {
522 this._terminal
.y
= this._terminal
.rows
- 1;
524 if (this._terminal
.x
>= this._terminal
.cols
) {
528 InputHandler
.prototype.cursorForward = function (params
) {
529 var param
= params
[0];
533 this._terminal
.x
+= param
;
534 if (this._terminal
.x
>= this._terminal
.cols
) {
535 this._terminal
.x
= this._terminal
.cols
- 1;
538 InputHandler
.prototype.cursorBackward = function (params
) {
539 var param
= params
[0];
543 if (this._terminal
.x
>= this._terminal
.cols
) {
546 this._terminal
.x
-= param
;
547 if (this._terminal
.x
< 0) {
548 this._terminal
.x
= 0;
551 InputHandler
.prototype.cursorNextLine = function (params
) {
552 var param
= params
[0];
556 this._terminal
.y
+= param
;
557 if (this._terminal
.y
>= this._terminal
.rows
) {
558 this._terminal
.y
= this._terminal
.rows
- 1;
560 this._terminal
.x
= 0;
563 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
564 var param
= params
[0];
568 this._terminal
.y
-= param
;
569 if (this._terminal
.y
< 0) {
570 this._terminal
.y
= 0;
572 this._terminal
.x
= 0;
575 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
576 var param
= params
[0];
580 this._terminal
.x
= param
- 1;
582 InputHandler
.prototype.cursorPosition = function (params
) {
585 if (params
.length
>= 2) {
594 else if (row
>= this._terminal
.rows
) {
595 row
= this._terminal
.rows
- 1;
600 else if (col
>= this._terminal
.cols
) {
601 col
= this._terminal
.cols
- 1;
603 this._terminal
.x
= col
;
604 this._terminal
.y
= row
;
606 InputHandler
.prototype.cursorForwardTab = function (params
) {
607 var param
= params
[0] || 1;
609 this._terminal
.x
= this._terminal
.nextStop();
612 InputHandler
.prototype.eraseInDisplay = function (params
) {
616 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
617 j
= this._terminal
.y
+ 1;
618 for (; j
< this._terminal
.rows
; j
++) {
619 this._terminal
.eraseLine(j
);
623 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
624 j
= this._terminal
.y
;
626 this._terminal
.eraseLine(j
);
630 j
= this._terminal
.rows
;
632 this._terminal
.eraseLine(j
);
639 InputHandler
.prototype.eraseInLine = function (params
) {
642 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
645 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
648 this._terminal
.eraseLine(this._terminal
.y
);
652 InputHandler
.prototype.insertLines = function (params
) {
658 row
= this._terminal
.y
+ this._terminal
.ybase
;
659 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
660 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
+ 1;
662 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
663 this._terminal
.lines
.trimStart(1);
664 this._terminal
.ybase
--;
665 this._terminal
.ydisp
--;
669 this._terminal
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
670 this._terminal
.lines
.splice(j
, 1);
672 this._terminal
.updateRange(this._terminal
.y
);
673 this._terminal
.updateRange(this._terminal
.scrollBottom
);
675 InputHandler
.prototype.deleteLines = function (params
) {
681 row
= this._terminal
.y
+ this._terminal
.ybase
;
682 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
683 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
;
685 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
686 this._terminal
.lines
.trimStart(1);
687 this._terminal
.ybase
-= 1;
688 this._terminal
.ydisp
-= 1;
690 this._terminal
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
691 this._terminal
.lines
.splice(row
, 1);
693 this._terminal
.updateRange(this._terminal
.y
);
694 this._terminal
.updateRange(this._terminal
.scrollBottom
);
696 InputHandler
.prototype.deleteChars = function (params
) {
702 row
= this._terminal
.y
+ this._terminal
.ybase
;
703 ch
= [this._terminal
.eraseAttr(), ' ', 1];
705 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 1);
706 this._terminal
.lines
.get(row
).push(ch
);
709 InputHandler
.prototype.scrollUp = function (params
) {
710 var param
= params
[0] || 1;
712 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 1);
713 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 0, this._terminal
.blankLine());
715 this._terminal
.updateRange(this._terminal
.scrollTop
);
716 this._terminal
.updateRange(this._terminal
.scrollBottom
);
718 InputHandler
.prototype.scrollDown = function (params
) {
719 var param
= params
[0] || 1;
721 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 1);
722 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 0, this._terminal
.blankLine());
724 this._terminal
.updateRange(this._terminal
.scrollTop
);
725 this._terminal
.updateRange(this._terminal
.scrollBottom
);
727 InputHandler
.prototype.eraseChars = function (params
) {
728 var param
, row
, j
, ch
;
733 row
= this._terminal
.y
+ this._terminal
.ybase
;
734 j
= this._terminal
.x
;
735 ch
= [this._terminal
.eraseAttr(), ' ', 1];
736 while (param
-- && j
< this._terminal
.cols
) {
737 this._terminal
.lines
.get(row
)[j
++] = ch
;
740 InputHandler
.prototype.cursorBackwardTab = function (params
) {
741 var param
= params
[0] || 1;
743 this._terminal
.x
= this._terminal
.prevStop();
746 InputHandler
.prototype.charPosAbsolute = function (params
) {
747 var param
= params
[0];
751 this._terminal
.x
= param
- 1;
752 if (this._terminal
.x
>= this._terminal
.cols
) {
753 this._terminal
.x
= this._terminal
.cols
- 1;
756 InputHandler
.prototype.HPositionRelative = function (params
) {
757 var param
= params
[0];
761 this._terminal
.x
+= param
;
762 if (this._terminal
.x
>= this._terminal
.cols
) {
763 this._terminal
.x
= this._terminal
.cols
- 1;
766 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
767 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];
769 line
[this._terminal
.x
++] = ch
;
772 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
776 if (!this._terminal
.prefix
) {
777 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
778 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
780 else if (this._terminal
.is('linux')) {
781 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
784 else if (this._terminal
.prefix
=== '>') {
785 if (this._terminal
.is('xterm')) {
786 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
788 else if (this._terminal
.is('rxvt-unicode')) {
789 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
791 else if (this._terminal
.is('linux')) {
792 this._terminal
.send(params
[0] + 'c');
794 else if (this._terminal
.is('screen')) {
795 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
799 InputHandler
.prototype.linePosAbsolute = function (params
) {
800 var param
= params
[0];
804 this._terminal
.y
= param
- 1;
805 if (this._terminal
.y
>= this._terminal
.rows
) {
806 this._terminal
.y
= this._terminal
.rows
- 1;
809 InputHandler
.prototype.VPositionRelative = function (params
) {
810 var param
= params
[0];
814 this._terminal
.y
+= param
;
815 if (this._terminal
.y
>= this._terminal
.rows
) {
816 this._terminal
.y
= this._terminal
.rows
- 1;
818 if (this._terminal
.x
>= this._terminal
.cols
) {
822 InputHandler
.prototype.HVPosition = function (params
) {
827 this._terminal
.y
= params
[0] - 1;
828 if (this._terminal
.y
>= this._terminal
.rows
) {
829 this._terminal
.y
= this._terminal
.rows
- 1;
831 this._terminal
.x
= params
[1] - 1;
832 if (this._terminal
.x
>= this._terminal
.cols
) {
833 this._terminal
.x
= this._terminal
.cols
- 1;
836 InputHandler
.prototype.tabClear = function (params
) {
837 var param
= params
[0];
839 delete this._terminal
.tabs
[this._terminal
.x
];
841 else if (param
=== 3) {
842 this._terminal
.tabs
= {};
845 InputHandler
.prototype.setMode = function (params
) {
846 if (params
.length
> 1) {
847 for (var i
= 0; i
< params
.length
; i
++) {
848 this.setMode([params
[i
]]);
852 if (!this._terminal
.prefix
) {
855 this._terminal
.insertMode
= true;
861 else if (this._terminal
.prefix
=== '?') {
864 this._terminal
.applicationCursor
= true;
867 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
868 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
869 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
870 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
873 this._terminal
.savedCols
= this._terminal
.cols
;
874 this._terminal
.resize(132, this._terminal
.rows
);
877 this._terminal
.originMode
= true;
880 this._terminal
.wraparoundMode
= true;
885 this._terminal
.log('Serial port requested application keypad.');
886 this._terminal
.applicationKeypad
= true;
887 this._terminal
.viewport
.syncScrollArea();
893 this._terminal
.x10Mouse
= params
[0] === 9;
894 this._terminal
.vt200Mouse
= params
[0] === 1000;
895 this._terminal
.normalMouse
= params
[0] > 1000;
896 this._terminal
.mouseEvents
= true;
897 this._terminal
.element
.style
.cursor
= 'default';
898 this._terminal
.log('Binding to mouse events.');
901 this._terminal
.sendFocus
= true;
904 this._terminal
.utfMouse
= true;
907 this._terminal
.sgrMouse
= true;
910 this._terminal
.urxvtMouse
= true;
913 this._terminal
.cursorHidden
= false;
919 if (!this._terminal
.normal
) {
921 lines
: this._terminal
.lines
,
922 ybase
: this._terminal
.ybase
,
923 ydisp
: this._terminal
.ydisp
,
926 scrollTop
: this._terminal
.scrollTop
,
927 scrollBottom
: this._terminal
.scrollBottom
,
928 tabs
: this._terminal
.tabs
930 this._terminal
.reset();
931 this._terminal
.viewport
.syncScrollArea();
932 this._terminal
.normal
= normal
;
933 this._terminal
.showCursor();
939 InputHandler
.prototype.resetMode = function (params
) {
940 if (params
.length
> 1) {
941 for (var i
= 0; i
< params
.length
; i
++) {
942 this.resetMode([params
[i
]]);
946 if (!this._terminal
.prefix
) {
949 this._terminal
.insertMode
= false;
955 else if (this._terminal
.prefix
=== '?') {
958 this._terminal
.applicationCursor
= false;
961 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
962 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
964 delete this._terminal
.savedCols
;
967 this._terminal
.originMode
= false;
970 this._terminal
.wraparoundMode
= false;
975 this._terminal
.log('Switching back to normal keypad.');
976 this._terminal
.applicationKeypad
= false;
977 this._terminal
.viewport
.syncScrollArea();
983 this._terminal
.x10Mouse
= false;
984 this._terminal
.vt200Mouse
= false;
985 this._terminal
.normalMouse
= false;
986 this._terminal
.mouseEvents
= false;
987 this._terminal
.element
.style
.cursor
= '';
990 this._terminal
.sendFocus
= false;
993 this._terminal
.utfMouse
= false;
996 this._terminal
.sgrMouse
= false;
999 this._terminal
.urxvtMouse
= false;
1002 this._terminal
.cursorHidden
= true;
1008 if (this._terminal
.normal
) {
1009 this._terminal
.lines
= this._terminal
.normal
.lines
;
1010 this._terminal
.ybase
= this._terminal
.normal
.ybase
;
1011 this._terminal
.ydisp
= this._terminal
.normal
.ydisp
;
1012 this._terminal
.x
= this._terminal
.normal
.x
;
1013 this._terminal
.y
= this._terminal
.normal
.y
;
1014 this._terminal
.scrollTop
= this._terminal
.normal
.scrollTop
;
1015 this._terminal
.scrollBottom
= this._terminal
.normal
.scrollBottom
;
1016 this._terminal
.tabs
= this._terminal
.normal
.tabs
;
1017 this._terminal
.normal
= null;
1018 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1019 this._terminal
.viewport
.syncScrollArea();
1020 this._terminal
.showCursor();
1026 InputHandler
.prototype.charAttributes = function (params
) {
1027 if (params
.length
=== 1 && params
[0] === 0) {
1028 this._terminal
.curAttr
= this._terminal
.defAttr
;
1031 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1032 for (; i
< l
; i
++) {
1034 if (p
>= 30 && p
<= 37) {
1037 else if (p
>= 40 && p
<= 47) {
1040 else if (p
>= 90 && p
<= 97) {
1044 else if (p
>= 100 && p
<= 107) {
1049 flags
= this._terminal
.defAttr
>> 18;
1050 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1051 bg
= this._terminal
.defAttr
& 0x1ff;
1068 else if (p
=== 22) {
1071 else if (p
=== 24) {
1074 else if (p
=== 25) {
1077 else if (p
=== 27) {
1080 else if (p
=== 28) {
1083 else if (p
=== 39) {
1084 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1086 else if (p
=== 49) {
1087 bg
= this._terminal
.defAttr
& 0x1ff;
1089 else if (p
=== 38) {
1090 if (params
[i
+ 1] === 2) {
1092 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1097 else if (params
[i
+ 1] === 5) {
1099 p
= params
[i
] & 0xff;
1103 else if (p
=== 48) {
1104 if (params
[i
+ 1] === 2) {
1106 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1111 else if (params
[i
+ 1] === 5) {
1113 p
= params
[i
] & 0xff;
1117 else if (p
=== 100) {
1118 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1119 bg
= this._terminal
.defAttr
& 0x1ff;
1122 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1125 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1127 InputHandler
.prototype.deviceStatus = function (params
) {
1128 if (!this._terminal
.prefix
) {
1129 switch (params
[0]) {
1131 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1134 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1135 + (this._terminal
.y
+ 1)
1137 + (this._terminal
.x
+ 1)
1142 else if (this._terminal
.prefix
=== '?') {
1143 switch (params
[0]) {
1145 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1146 + (this._terminal
.y
+ 1)
1148 + (this._terminal
.x
+ 1)
1162 InputHandler
.prototype.softReset = function (params
) {
1163 this._terminal
.cursorHidden
= false;
1164 this._terminal
.insertMode
= false;
1165 this._terminal
.originMode
= false;
1166 this._terminal
.wraparoundMode
= true;
1167 this._terminal
.applicationKeypad
= false;
1168 this._terminal
.viewport
.syncScrollArea();
1169 this._terminal
.applicationCursor
= false;
1170 this._terminal
.scrollTop
= 0;
1171 this._terminal
.scrollBottom
= this._terminal
.rows
- 1;
1172 this._terminal
.curAttr
= this._terminal
.defAttr
;
1173 this._terminal
.x
= this._terminal
.y
= 0;
1174 this._terminal
.charset
= null;
1175 this._terminal
.glevel
= 0;
1176 this._terminal
.charsets
= [null];
1178 InputHandler
.prototype.setCursorStyle = function (params
) {
1179 var param
= params
[0] < 1 ? 1 : params
[0];
1183 this._terminal
.setOption('cursorStyle', 'block');
1187 this._terminal
.setOption('cursorStyle', 'underline');
1191 this._terminal
.setOption('cursorStyle', 'bar');
1194 var isBlinking
= param
% 2 === 1;
1195 this._terminal
.setOption('cursorBlink', isBlinking
);
1197 InputHandler
.prototype.setScrollRegion = function (params
) {
1198 if (this._terminal
.prefix
)
1200 this._terminal
.scrollTop
= (params
[0] || 1) - 1;
1201 this._terminal
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1202 this._terminal
.x
= 0;
1203 this._terminal
.y
= 0;
1205 InputHandler
.prototype.saveCursor = function (params
) {
1206 this._terminal
.savedX
= this._terminal
.x
;
1207 this._terminal
.savedY
= this._terminal
.y
;
1209 InputHandler
.prototype.restoreCursor = function (params
) {
1210 this._terminal
.x
= this._terminal
.savedX
|| 0;
1211 this._terminal
.y
= this._terminal
.savedY
|| 0;
1213 return InputHandler
;
1215 exports
.InputHandler
= InputHandler
;
1216 var wcwidth
= (function (opts
) {
1218 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1219 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1220 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1221 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1222 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1223 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1224 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1225 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1226 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1227 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1228 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1229 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1230 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1231 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1232 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1233 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1234 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1235 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1236 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1237 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1238 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1239 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1240 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1241 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1242 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1243 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1244 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1245 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1246 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1247 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1248 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1249 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1250 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1251 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1252 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1253 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1254 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1255 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1256 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1257 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1258 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1259 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1260 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1261 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1262 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1263 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1264 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1267 function bisearch(ucs
) {
1269 var max
= COMBINING
.length
- 1;
1271 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
1273 while (max
>= min
) {
1274 mid
= Math
.floor((min
+ max
) / 2);
1275 if (ucs
> COMBINING
[mid
][1])
1277 else if (ucs
< COMBINING
[mid
][0])
1284 function wcwidth(ucs
) {
1287 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1288 return opts
.control
;
1296 function isWide(ucs
) {
1297 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1300 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1301 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1302 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1303 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1304 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1305 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1306 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
1307 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
1308 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
1311 })({ nul
: 0, control
: 0 });
1315 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require
,module
,exports
){
1317 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1318 var protocolClause
= '(https?:\\/\\/)';
1319 var domainCharacterSet
= '[\\da-z\\.-]+';
1320 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1321 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1322 var tldClause
= '([a-z\\.]{2,6})';
1323 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1324 var localHostClause
= '(localhost)';
1325 var portClause
= '(:\\d{1,5})';
1326 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1327 var pathClause
= '(\\/[\\/\\w\\.\\-%]*)*';
1328 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;\\=\\.\\-]*';
1329 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1330 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1331 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1332 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1333 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1334 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1335 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1336 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1337 var Linkifier
= (function () {
1338 function Linkifier(document
, rows
) {
1339 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1340 this._document
= document
;
1342 this._rowTimeoutIds
= [];
1343 this._linkMatchers
= [];
1344 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1346 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1347 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1349 clearTimeout(timeoutId
);
1351 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1353 Linkifier
.prototype.attachHypertextLinkHandler = function (handler
) {
1354 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1356 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1357 if (options
=== void 0) { options
= {}; }
1358 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1359 throw new Error('handler must be defined');
1362 id
: this._nextLinkMatcherId
++,
1365 matchIndex
: options
.matchIndex
,
1366 validationCallback
: options
.validationCallback
,
1367 priority
: options
.priority
|| 0
1369 this._addLinkMatcherToList(matcher
);
1372 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1373 if (this._linkMatchers
.length
=== 0) {
1374 this._linkMatchers
.push(matcher
);
1377 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1378 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1379 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1383 this._linkMatchers
.splice(0, 0, matcher
);
1385 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1386 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1387 if (this._linkMatchers
[i
].id
=== matcherId
) {
1388 this._linkMatchers
.splice(i
, 1);
1394 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1395 var row
= this._rows
[rowIndex
];
1399 var text
= row
.textContent
;
1400 var _loop_1 = function (i
) {
1401 var matcher
= this_1
._linkMatchers
[i
];
1402 var uri
= this_1
._findLinkMatch(text
, matcher
.regex
, matcher
.matchIndex
);
1404 var linkElement_1
= this_1
._doLinkifyRow(rowIndex
, uri
, matcher
.handler
, matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
);
1405 if (linkElement_1
&& matcher
.validationCallback
) {
1406 matcher
.validationCallback(uri
, function (isValid
) {
1408 linkElement_1
.classList
.add(INVALID_LINK_CLASS
);
1412 return { value
: void 0 };
1416 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1417 var state_1
= _loop_1(i
);
1418 if (typeof state_1
=== "object")
1419 return state_1
.value
;
1422 Linkifier
.prototype._doLinkifyRow = function (rowIndex
, uri
, handler
, isHttpLinkMatcher
) {
1423 var nodes
= this._rows
[rowIndex
].childNodes
;
1424 for (var i
= 0; i
< nodes
.length
; i
++) {
1425 var node
= nodes
[i
];
1426 var searchIndex
= node
.textContent
.indexOf(uri
);
1427 if (searchIndex
>= 0) {
1428 var linkElement
= this._createAnchorElement(uri
, handler
, isHttpLinkMatcher
);
1429 if (node
.textContent
.length
=== uri
.length
) {
1430 if (node
.nodeType
=== 3) {
1431 this._replaceNode(node
, linkElement
);
1435 if (element
.nodeName
=== 'A') {
1438 element
.innerHTML
= '';
1439 element
.appendChild(linkElement
);
1443 this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1449 Linkifier
.prototype._findLinkMatch = function (text
, regex
, matchIndex
) {
1450 var match
= text
.match(regex
);
1451 if (!match
|| match
.length
=== 0) {
1454 return match
[typeof matchIndex
!== 'number' ? 0 : matchIndex
];
1456 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1457 var element
= this._document
.createElement('a');
1458 element
.textContent
= uri
;
1459 if (isHypertextLinkHandler
) {
1461 element
.target
= '_blank';
1462 element
.addEventListener('click', function (event
) {
1464 return handler(event
, uri
);
1469 element
.addEventListener('click', function (event
) {
1470 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1473 return handler(event
, uri
);
1478 Linkifier
.prototype._replaceNode = function (oldNode
) {
1480 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1481 newNodes
[_i
- 1] = arguments
[_i
];
1483 var parent
= oldNode
.parentNode
;
1484 for (var i
= 0; i
< newNodes
.length
; i
++) {
1485 parent
.insertBefore(newNodes
[i
], oldNode
);
1487 parent
.removeChild(oldNode
);
1489 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1490 var node
= targetNode
;
1491 if (node
.nodeType
!== 3) {
1492 node
= node
.childNodes
[0];
1494 if (node
.childNodes
.length
=== 0 && node
.nodeType
!== Node
.TEXT_NODE
) {
1495 throw new Error('targetNode must be a text node or only contain a single text node');
1497 var fullText
= node
.textContent
;
1498 if (substringIndex
=== 0) {
1499 var rightText
= fullText
.substring(substring
.length
);
1500 var rightTextNode
= this._document
.createTextNode(rightText
);
1501 this._replaceNode(node
, newNode
, rightTextNode
);
1503 else if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1504 var leftText
= fullText
.substring(0, substringIndex
);
1505 var leftTextNode
= this._document
.createTextNode(leftText
);
1506 this._replaceNode(node
, leftTextNode
, newNode
);
1509 var leftText
= fullText
.substring(0, substringIndex
);
1510 var leftTextNode
= this._document
.createTextNode(leftText
);
1511 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1512 var rightTextNode
= this._document
.createTextNode(rightText
);
1513 this._replaceNode(node
, leftTextNode
, newNode
, rightTextNode
);
1518 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1519 exports
.Linkifier
= Linkifier
;
1523 },{}],7:[function(require
,module
,exports
){
1525 var EscapeSequences_1
= require("./EscapeSequences");
1526 var Charsets_1
= require("./Charsets");
1527 var normalStateHandler
= {};
1528 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1529 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1530 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1531 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1532 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1533 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1534 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1535 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1536 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1537 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1538 var escapedStateHandler
= {};
1539 escapedStateHandler
['['] = function (parser
, terminal
) {
1540 terminal
.params
= [];
1541 terminal
.currentParam
= 0;
1542 parser
.setState(ParserState
.CSI_PARAM
);
1544 escapedStateHandler
[']'] = function (parser
, terminal
) {
1545 terminal
.params
= [];
1546 terminal
.currentParam
= 0;
1547 parser
.setState(ParserState
.OSC
);
1549 escapedStateHandler
['P'] = function (parser
, terminal
) {
1550 terminal
.params
= [];
1551 terminal
.currentParam
= 0;
1552 parser
.setState(ParserState
.DCS
);
1554 escapedStateHandler
['_'] = function (parser
, terminal
) {
1555 parser
.setState(ParserState
.IGNORE
);
1557 escapedStateHandler
['^'] = function (parser
, terminal
) {
1558 parser
.setState(ParserState
.IGNORE
);
1560 escapedStateHandler
['c'] = function (parser
, terminal
) {
1563 escapedStateHandler
['E'] = function (parser
, terminal
) {
1566 parser
.setState(ParserState
.NORMAL
);
1568 escapedStateHandler
['D'] = function (parser
, terminal
) {
1570 parser
.setState(ParserState
.NORMAL
);
1572 escapedStateHandler
['M'] = function (parser
, terminal
) {
1573 terminal
.reverseIndex();
1574 parser
.setState(ParserState
.NORMAL
);
1576 escapedStateHandler
['%'] = function (parser
, terminal
) {
1577 terminal
.setgLevel(0);
1578 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1579 parser
.setState(ParserState
.NORMAL
);
1580 parser
.skipNextChar();
1582 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1583 var csiParamStateHandler
= {};
1584 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1585 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1586 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1587 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1588 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1589 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1590 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1591 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1592 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1593 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1594 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1595 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1596 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1597 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1598 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1599 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1600 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1601 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1602 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1603 var csiStateHandler
= {};
1604 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1605 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1606 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1607 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1608 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1609 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1610 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1611 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1612 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1613 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1614 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1615 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1616 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1617 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1618 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1619 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1620 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1621 if (params
.length
< 2 && !prefix
) {
1622 handler
.scrollDown(params
);
1625 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1626 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1627 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1628 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1629 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1630 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1631 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1632 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1633 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1634 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1635 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1636 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1637 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1638 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1639 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1642 handler
.softReset(params
);
1646 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1647 if (postfix
=== ' ') {
1648 handler
.setCursorStyle(params
);
1651 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1652 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1653 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1654 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1656 (function (ParserState
) {
1657 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1658 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1659 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1660 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1661 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1662 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1663 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1664 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1665 })(ParserState
|| (ParserState
= {}));
1666 var Parser
= (function () {
1667 function Parser(_inputHandler
, _terminal
) {
1668 this._inputHandler
= _inputHandler
;
1669 this._terminal
= _terminal
;
1670 this._state
= ParserState
.NORMAL
;
1672 Parser
.prototype.parse = function (data
) {
1673 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1675 if (this._terminal
.surrogate_high
) {
1676 data
= this._terminal
.surrogate_high
+ data
;
1677 this._terminal
.surrogate_high
= '';
1679 for (; this._position
< l
; this._position
++) {
1680 ch
= data
[this._position
];
1681 code
= data
.charCodeAt(this._position
);
1682 if (0xD800 <= code
&& code
<= 0xDBFF) {
1683 low
= data
.charCodeAt(this._position
+ 1);
1685 this._terminal
.surrogate_high
= ch
;
1688 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1689 ch
+= data
.charAt(this._position
+ 1);
1691 if (0xDC00 <= code
&& code
<= 0xDFFF)
1693 switch (this._state
) {
1694 case ParserState
.NORMAL
:
1695 if (ch
in normalStateHandler
) {
1696 normalStateHandler
[ch
](this, this._inputHandler
);
1699 this._inputHandler
.addChar(ch
, code
);
1702 case ParserState
.ESCAPED
:
1703 if (ch
in escapedStateHandler
) {
1704 escapedStateHandler
[ch
](this, this._terminal
);
1716 this._terminal
.gcharset
= 0;
1719 this._terminal
.gcharset
= 1;
1722 this._terminal
.gcharset
= 2;
1725 this._terminal
.gcharset
= 3;
1728 this._terminal
.gcharset
= 1;
1731 this._terminal
.gcharset
= 2;
1734 this._state
= ParserState
.CHARSET
;
1737 this._terminal
.gcharset
= 3;
1738 this._state
= ParserState
.CHARSET
;
1746 this._terminal
.setgLevel(2);
1749 this._terminal
.setgLevel(3);
1752 this._terminal
.setgLevel(3);
1755 this._terminal
.setgLevel(2);
1758 this._terminal
.setgLevel(1);
1761 this._inputHandler
.saveCursor();
1762 this._state
= ParserState
.NORMAL
;
1765 this._inputHandler
.restoreCursor();
1766 this._state
= ParserState
.NORMAL
;
1769 this._state
= ParserState
.NORMAL
;
1773 this._terminal
.tabSet();
1774 this._state
= ParserState
.NORMAL
;
1777 this._terminal
.log('Serial port requested application keypad.');
1778 this._terminal
.applicationKeypad
= true;
1779 this._terminal
.viewport
.syncScrollArea();
1780 this._state
= ParserState
.NORMAL
;
1783 this._terminal
.log('Switching back to normal keypad.');
1784 this._terminal
.applicationKeypad
= false;
1785 this._terminal
.viewport
.syncScrollArea();
1786 this._state
= ParserState
.NORMAL
;
1789 this._state
= ParserState
.NORMAL
;
1790 this._terminal
.error('Unknown ESC control: %s.', ch
);
1794 case ParserState
.CHARSET
:
1795 if (ch
in Charsets_1
.CHARSETS
) {
1796 cs
= Charsets_1
.CHARSETS
[ch
];
1798 this.skipNextChar();
1802 cs
= Charsets_1
.DEFAULT_CHARSET
;
1804 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1805 this._terminal
.gcharset
= null;
1806 this._state
= ParserState
.NORMAL
;
1808 case ParserState
.OSC
:
1809 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1810 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1812 this._terminal
.params
.push(this._terminal
.currentParam
);
1813 switch (this._terminal
.params
[0]) {
1817 if (this._terminal
.params
[1]) {
1818 this._terminal
.title
= this._terminal
.params
[1];
1819 this._terminal
.handleTitle(this._terminal
.title
);
1859 this._terminal
.params
= [];
1860 this._terminal
.currentParam
= 0;
1861 this._state
= ParserState
.NORMAL
;
1864 if (!this._terminal
.params
.length
) {
1865 if (ch
>= '0' && ch
<= '9') {
1866 this._terminal
.currentParam
=
1867 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1869 else if (ch
=== ';') {
1870 this._terminal
.params
.push(this._terminal
.currentParam
);
1871 this._terminal
.currentParam
= '';
1875 this._terminal
.currentParam
+= ch
;
1879 case ParserState
.CSI_PARAM
:
1880 if (ch
in csiParamStateHandler
) {
1881 csiParamStateHandler
[ch
](this);
1884 this.finalizeParam();
1885 this._state
= ParserState
.CSI
;
1886 case ParserState
.CSI
:
1887 if (ch
in csiStateHandler
) {
1888 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1891 this._terminal
.error('Unknown CSI code: %s.', ch
);
1893 this._state
= ParserState
.NORMAL
;
1894 this._terminal
.prefix
= '';
1895 this._terminal
.postfix
= '';
1897 case ParserState
.DCS
:
1898 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1899 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1901 switch (this._terminal
.prefix
) {
1905 var pt
= this._terminal
.currentParam
, valid
= false;
1915 + (this._terminal
.scrollTop
+ 1)
1917 + (this._terminal
.scrollBottom
+ 1)
1924 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1928 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1933 pt
= this._terminal
.currentParam
1935 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1938 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1941 this._terminal
.currentParam
= 0;
1942 this._terminal
.prefix
= '';
1943 this._state
= ParserState
.NORMAL
;
1945 else if (!this._terminal
.currentParam
) {
1946 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1947 this._terminal
.currentParam
= ch
;
1949 else if (this._terminal
.prefix
.length
=== 2) {
1950 this._terminal
.currentParam
= ch
;
1953 this._terminal
.prefix
+= ch
;
1957 this._terminal
.currentParam
+= ch
;
1960 case ParserState
.IGNORE
:
1961 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1962 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1964 this._state
= ParserState
.NORMAL
;
1970 Parser
.prototype.setState = function (state
) {
1971 this._state
= state
;
1973 Parser
.prototype.setPrefix = function (prefix
) {
1974 this._terminal
.prefix
= prefix
;
1976 Parser
.prototype.setPostfix = function (postfix
) {
1977 this._terminal
.postfix
= postfix
;
1979 Parser
.prototype.setParam = function (param
) {
1980 this._terminal
.currentParam
= param
;
1982 Parser
.prototype.getParam = function () {
1983 return this._terminal
.currentParam
;
1985 Parser
.prototype.finalizeParam = function () {
1986 this._terminal
.params
.push(this._terminal
.currentParam
);
1987 this._terminal
.currentParam
= 0;
1989 Parser
.prototype.skipNextChar = function () {
1994 exports
.Parser
= Parser
;
1998 },{"./Charsets":1,"./EscapeSequences":3}],8:[function(require
,module
,exports
){
2000 var MAX_REFRESH_FRAME_SKIP
= 5;
2003 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2004 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2005 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2006 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2007 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2008 })(FLAGS
|| (FLAGS
= {}));
2010 var brokenBold
= null;
2011 var Renderer
= (function () {
2012 function Renderer(_terminal
) {
2013 this._terminal
= _terminal
;
2014 this._refreshRowsQueue
= [];
2015 this._refreshFramesSkipped
= 0;
2016 this._refreshAnimationFrame
= null;
2017 if (brokenBold
=== null) {
2018 brokenBold
= checkBoldBroken(this._terminal
.document
);
2021 Renderer
.prototype.queueRefresh = function (start
, end
) {
2022 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2023 if (!this._refreshAnimationFrame
) {
2024 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2027 Renderer
.prototype._refreshLoop = function () {
2028 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2030 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2033 this._refreshFramesSkipped
= 0;
2036 if (this._refreshRowsQueue
.length
> 4) {
2038 end
= this._terminal
.rows
- 1;
2041 start
= this._refreshRowsQueue
[0].start
;
2042 end
= this._refreshRowsQueue
[0].end
;
2043 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2044 if (this._refreshRowsQueue
[i
].start
< start
) {
2045 start
= this._refreshRowsQueue
[i
].start
;
2047 if (this._refreshRowsQueue
[i
].end
> end
) {
2048 end
= this._refreshRowsQueue
[i
].end
;
2052 this._refreshRowsQueue
= [];
2053 this._refreshAnimationFrame
= null;
2054 this._refresh(start
, end
);
2056 Renderer
.prototype._refresh = function (start
, end
) {
2057 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
2058 if (end
- start
>= this._terminal
.rows
/ 2) {
2059 parent
= this._terminal
.element
.parentNode
;
2061 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2064 width
= this._terminal
.cols
;
2066 if (end
>= this._terminal
.rows
) {
2067 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2068 end
= this._terminal
.rows
- 1;
2070 for (; y
<= end
; y
++) {
2071 row
= y
+ this._terminal
.ydisp
;
2072 line
= this._terminal
.lines
.get(row
);
2073 if (!line
|| !this._terminal
.children
[y
]) {
2077 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
)
2078 && this._terminal
.cursorState
2079 && !this._terminal
.cursorHidden
) {
2080 x
= this._terminal
.x
;
2085 attr
= this._terminal
.defAttr
;
2087 for (; i
< width
; i
++) {
2093 ch_width
= line
[i
][2];
2098 if (data
!== attr
) {
2099 if (attr
!== this._terminal
.defAttr
) {
2102 if (data
!== this._terminal
.defAttr
) {
2104 out
+= '<span class="reverse-video terminal-cursor">';
2107 var classNames
= [];
2109 fg
= (data
>> 9) & 0x1ff;
2111 if (flags
& FLAGS
.BOLD
) {
2113 classNames
.push('xterm-bold');
2118 if (flags
& FLAGS
.UNDERLINE
) {
2119 classNames
.push('xterm-underline');
2121 if (flags
& FLAGS
.BLINK
) {
2122 classNames
.push('xterm-blink');
2124 if (flags
& FLAGS
.INVERSE
) {
2125 bg
= [fg
, fg
= bg
][0];
2126 if ((flags
& 1) && fg
< 8)
2129 if (flags
& FLAGS
.INVISIBLE
) {
2130 classNames
.push('xterm-hidden');
2132 if (flags
& FLAGS
.INVERSE
) {
2141 classNames
.push('xterm-bg-color-' + bg
);
2144 classNames
.push('xterm-color-' + fg
);
2147 if (classNames
.length
) {
2148 out
+= ' class="' + classNames
.join(' ') + '"';
2154 if (ch_width
=== 2) {
2155 out
+= '<span class="xterm-wide-char">';
2176 if (ch_width
=== 2) {
2181 if (attr
!== this._terminal
.defAttr
) {
2184 this._terminal
.children
[y
].innerHTML
= out
;
2187 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2189 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2194 exports
.Renderer
= Renderer
;
2195 function checkBoldBroken(document
) {
2196 var body
= document
.getElementsByTagName('body')[0];
2197 var el
= document
.createElement('span');
2198 el
.innerHTML
= 'hello world';
2199 body
.appendChild(el
);
2200 var w1
= el
.scrollWidth
;
2201 el
.style
.fontWeight
= 'bold';
2202 var w2
= el
.scrollWidth
;
2203 body
.removeChild(el
);
2209 },{}],9:[function(require
,module
,exports
){
2211 var Viewport
= (function () {
2212 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2214 this.terminal
= terminal
;
2215 this.viewportElement
= viewportElement
;
2216 this.scrollArea
= scrollArea
;
2217 this.charMeasure
= charMeasure
;
2218 this.currentRowHeight
= 0;
2219 this.lastRecordedBufferLength
= 0;
2220 this.lastRecordedViewportHeight
= 0;
2221 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2222 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2223 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2224 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2226 Viewport
.prototype.refresh = function () {
2227 if (this.charMeasure
.height
> 0) {
2228 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2229 if (rowHeightChanged
) {
2230 this.currentRowHeight
= this.charMeasure
.height
;
2231 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2232 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2234 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2235 if (rowHeightChanged
|| viewportHeightChanged
) {
2236 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2237 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2239 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2242 Viewport
.prototype.syncScrollArea = function () {
2243 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2244 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2247 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2251 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2255 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2256 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2257 this.viewportElement
.scrollTop
= scrollTop
;
2260 Viewport
.prototype.onScroll = function (ev
) {
2261 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2262 var diff
= newRow
- this.terminal
.ydisp
;
2263 this.terminal
.scrollDisp(diff
, true);
2265 Viewport
.prototype.onWheel = function (ev
) {
2266 if (ev
.deltaY
=== 0) {
2270 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2271 multiplier
= this.currentRowHeight
;
2273 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2274 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2276 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2277 ev
.preventDefault();
2282 exports
.Viewport
= Viewport
;
2286 },{}],10:[function(require
,module
,exports
){
2288 function prepareTextForClipboard(text
) {
2289 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
2290 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
2291 return processedLine
;
2293 return processedText
;
2295 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
2296 function copyHandler(ev
, term
) {
2297 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
2298 if (term
.browser
.isMSIE
) {
2299 window
.clipboardData
.setData('Text', text
);
2302 ev
.clipboardData
.setData('text/plain', text
);
2304 ev
.preventDefault();
2306 exports
.copyHandler
= copyHandler
;
2307 function pasteHandler(ev
, term
) {
2308 ev
.stopPropagation();
2310 var dispatchPaste = function (text
) {
2312 term
.textarea
.value
= '';
2313 return term
.cancel(ev
);
2315 if (term
.browser
.isMSIE
) {
2316 if (window
.clipboardData
) {
2317 text
= window
.clipboardData
.getData('Text');
2318 dispatchPaste(text
);
2322 if (ev
.clipboardData
) {
2323 text
= ev
.clipboardData
.getData('text/plain');
2324 dispatchPaste(text
);
2328 exports
.pasteHandler
= pasteHandler
;
2329 function rightClickHandler(ev
, term
) {
2330 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
2332 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
2333 for (var i
= 0; i
< cr
.length
; i
++) {
2335 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
2336 (y
> rect
.top
) && (y
< rect
.bottom
));
2337 if (clickIsOnSelection
) {
2341 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
2342 clickIsOnSelection
= false;
2345 if (!clickIsOnSelection
) {
2346 term
.textarea
.style
.position
= 'fixed';
2347 term
.textarea
.style
.width
= '20px';
2348 term
.textarea
.style
.height
= '20px';
2349 term
.textarea
.style
.left
= (x
- 10) + 'px';
2350 term
.textarea
.style
.top
= (y
- 10) + 'px';
2351 term
.textarea
.style
.zIndex
= '1000';
2352 term
.textarea
.focus();
2353 setTimeout(function () {
2354 term
.textarea
.style
.position
= null;
2355 term
.textarea
.style
.width
= null;
2356 term
.textarea
.style
.height
= null;
2357 term
.textarea
.style
.left
= null;
2358 term
.textarea
.style
.top
= null;
2359 term
.textarea
.style
.zIndex
= null;
2363 exports
.rightClickHandler
= rightClickHandler
;
2367 },{}],11:[function(require
,module
,exports
){
2369 var Generic_1
= require("./Generic");
2370 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2371 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2372 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2373 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2374 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2375 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2376 exports
.isIpad
= platform
=== 'iPad';
2377 exports
.isIphone
= platform
=== 'iPhone';
2378 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2382 },{"./Generic":14}],12:[function(require
,module
,exports
){
2384 var __extends
= (this && this.__extends
) || function (d
, b
) {
2385 for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
];
2386 function __() { this.constructor = d
; }
2387 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2389 var EventEmitter_js_1
= require("../EventEmitter.js");
2390 var CharMeasure
= (function (_super
) {
2391 __extends(CharMeasure
, _super
);
2392 function CharMeasure(document
, parentElement
) {
2393 var _this
= _super
.call(this) || this;
2394 _this
._document
= document
;
2395 _this
._parentElement
= parentElement
;
2398 Object
.defineProperty(CharMeasure
.prototype, "width", {
2405 Object
.defineProperty(CharMeasure
.prototype, "height", {
2407 return this._height
;
2412 CharMeasure
.prototype.measure = function () {
2414 if (!this._measureElement
) {
2415 this._measureElement
= this._document
.createElement('span');
2416 this._measureElement
.style
.position
= 'absolute';
2417 this._measureElement
.style
.top
= '0';
2418 this._measureElement
.style
.left
= '-9999em';
2419 this._measureElement
.textContent
= 'W';
2420 this._measureElement
.setAttribute('aria-hidden', 'true');
2421 this._parentElement
.appendChild(this._measureElement
);
2422 setTimeout(function () { return _this
._doMeasure(); }, 0);
2428 CharMeasure
.prototype._doMeasure = function () {
2429 var geometry
= this._measureElement
.getBoundingClientRect();
2430 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
2433 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
2434 this._width
= geometry
.width
;
2435 this._height
= geometry
.height
;
2436 this.emit('charsizechanged');
2440 }(EventEmitter_js_1
.EventEmitter
));
2441 exports
.CharMeasure
= CharMeasure
;
2445 },{"../EventEmitter.js":4}],13:[function(require
,module
,exports
){
2447 var CircularList
= (function () {
2448 function CircularList(maxLength
) {
2449 this._array
= new Array(maxLength
);
2450 this._startIndex
= 0;
2453 Object
.defineProperty(CircularList
.prototype, "maxLength", {
2455 return this._array
.length
;
2457 set: function (newMaxLength
) {
2458 var newArray
= new Array(newMaxLength
);
2459 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
2460 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
2462 this._array
= newArray
;
2463 this._startIndex
= 0;
2468 Object
.defineProperty(CircularList
.prototype, "length", {
2470 return this._length
;
2472 set: function (newLength
) {
2473 if (newLength
> this._length
) {
2474 for (var i
= this._length
; i
< newLength
; i
++) {
2475 this._array
[i
] = undefined;
2478 this._length
= newLength
;
2483 Object
.defineProperty(CircularList
.prototype, "forEach", {
2485 return this._array
.forEach
;
2490 CircularList
.prototype.get = function (index
) {
2491 return this._array
[this._getCyclicIndex(index
)];
2493 CircularList
.prototype.set = function (index
, value
) {
2494 this._array
[this._getCyclicIndex(index
)] = value
;
2496 CircularList
.prototype.push = function (value
) {
2497 this._array
[this._getCyclicIndex(this._length
)] = value
;
2498 if (this._length
=== this.maxLength
) {
2500 if (this._startIndex
=== this.maxLength
) {
2501 this._startIndex
= 0;
2508 CircularList
.prototype.pop = function () {
2509 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
2511 CircularList
.prototype.splice = function (start
, deleteCount
) {
2513 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
2514 items
[_i
- 2] = arguments
[_i
];
2517 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
2518 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
2520 this._length
-= deleteCount
;
2522 if (items
&& items
.length
) {
2523 for (var i
= this._length
- 1; i
>= start
; i
--) {
2524 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
2526 for (var i
= 0; i
< items
.length
; i
++) {
2527 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
2529 if (this._length
+ items
.length
> this.maxLength
) {
2530 this._startIndex
+= (this._length
+ items
.length
) - this.maxLength
;
2531 this._length
= this.maxLength
;
2534 this._length
+= items
.length
;
2538 CircularList
.prototype.trimStart = function (count
) {
2539 if (count
> this._length
) {
2540 count
= this._length
;
2542 this._startIndex
+= count
;
2543 this._length
-= count
;
2545 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
2549 if (start
< 0 || start
>= this._length
) {
2550 throw new Error('start argument out of range');
2552 if (start
+ offset
< 0) {
2553 throw new Error('Cannot shift elements in list beyond index 0');
2556 for (var i
= count
- 1; i
>= 0; i
--) {
2557 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2559 var expandListBy
= (start
+ count
+ offset
) - this._length
;
2560 if (expandListBy
> 0) {
2561 this._length
+= expandListBy
;
2562 while (this._length
> this.maxLength
) {
2569 for (var i
= 0; i
< count
; i
++) {
2570 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2574 CircularList
.prototype._getCyclicIndex = function (index
) {
2575 return (this._startIndex
+ index
) % this.maxLength
;
2577 return CircularList
;
2579 exports
.CircularList
= CircularList
;
2583 },{}],14:[function(require
,module
,exports
){
2585 function contains(arr
, el
) {
2586 return arr
.indexOf(el
) >= 0;
2588 exports
.contains
= contains
;
2593 },{}],15:[function(require
,module
,exports
){
2595 var CompositionHelper_1
= require("./CompositionHelper");
2596 var EventEmitter_1
= require("./EventEmitter");
2597 var Viewport_1
= require("./Viewport");
2598 var Clipboard_1
= require("./handlers/Clipboard");
2599 var CircularList_1
= require("./utils/CircularList");
2600 var EscapeSequences_1
= require("./EscapeSequences");
2601 var InputHandler_1
= require("./InputHandler");
2602 var Parser_1
= require("./Parser");
2603 var Renderer_1
= require("./Renderer");
2604 var Linkifier_1
= require("./Linkifier");
2605 var CharMeasure_1
= require("./utils/CharMeasure");
2606 var Browser
= require("./utils/Browser");
2607 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
2608 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
2609 var WRITE_BATCH_SIZE
= 300;
2610 function Terminal(options
) {
2612 if (!(this instanceof Terminal
)) {
2613 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
2615 self
.browser
= Browser
;
2616 self
.cancel
= Terminal
.cancel
;
2617 EventEmitter_1
.EventEmitter
.call(this);
2618 if (typeof options
=== 'number') {
2622 handler
: arguments
[2]
2625 options
= options
|| {};
2626 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
2627 if (options
[key
] == null) {
2628 options
[key
] = Terminal
.options
[key
];
2629 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
2630 options
[key
] = Terminal
[key
];
2633 self
[key
] = options
[key
];
2635 if (options
.colors
.length
=== 8) {
2636 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
2638 else if (options
.colors
.length
=== 16) {
2639 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
2641 else if (options
.colors
.length
=== 10) {
2642 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
2644 else if (options
.colors
.length
=== 18) {
2645 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
2647 this.colors
= options
.colors
;
2648 this.options
= options
;
2649 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
2650 this.cols
= options
.cols
|| options
.geometry
[0];
2651 this.rows
= options
.rows
|| options
.geometry
[1];
2652 this.geometry
= [this.cols
, this.rows
];
2653 if (options
.handler
) {
2654 this.on('data', options
.handler
);
2660 this.cursorState
= 0;
2661 this.cursorHidden
= false;
2665 this.scrollBottom
= this.rows
- 1;
2666 this.customKeydownHandler
= null;
2667 this.applicationKeypad
= false;
2668 this.applicationCursor
= false;
2669 this.originMode
= false;
2670 this.insertMode
= false;
2671 this.wraparoundMode
= true;
2673 this.charset
= null;
2674 this.gcharset
= null;
2676 this.charsets
= [null];
2694 this.readable
= true;
2695 this.writable
= true;
2696 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
2697 this.curAttr
= this.defAttr
;
2699 this.currentParam
= 0;
2702 this.inputHandler
= new InputHandler_1
.InputHandler(this);
2703 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
2704 this.renderer
= this.renderer
|| null;
2705 this.linkifier
= this.linkifier
|| null;
2707 this.writeBuffer
= [];
2708 this.writeInProgress
= false;
2709 this.xoffSentToCatchUp
= false;
2710 this.writeStopped
= false;
2711 this.surrogate_high
= '';
2712 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
2715 this.lines
.push(this.blankLine());
2719 this.userScrolling
= false;
2721 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
2722 Terminal
.prototype.eraseAttr = function () {
2723 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
2725 Terminal
.tangoColors
= [
2743 Terminal
.colors
= (function () {
2744 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
2746 for (; i
< 216; i
++) {
2747 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
2750 for (; i
< 24; i
++) {
2754 function out(r
, g
, b
) {
2755 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
2759 return c
.length
< 2 ? '0' + c
: c
;
2763 Terminal
._colors
= Terminal
.colors
.slice();
2764 Terminal
.vcolors
= (function () {
2765 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
2766 for (; i
< 256; i
++) {
2767 color
= parseInt(colors
[i
].substring(1), 16);
2769 (color
>> 16) & 0xff,
2770 (color
>> 8) & 0xff,
2776 Terminal
.defaults
= {
2777 colors
: Terminal
.colors
,
2783 cursorStyle
: 'block',
2789 cancelEvents
: false,
2790 disableStdin
: false,
2791 useFlowControl
: false,
2794 Terminal
.options
= {};
2795 Terminal
.focus
= null;
2796 each(keys(Terminal
.defaults
), function (key
) {
2797 Terminal
[key
] = Terminal
.defaults
[key
];
2798 Terminal
.options
[key
] = Terminal
.defaults
[key
];
2800 Terminal
.prototype.focus = function () {
2801 return this.textarea
.focus();
2803 Terminal
.prototype.getOption = function (key
, value
) {
2804 if (!(key
in Terminal
.defaults
)) {
2805 throw new Error('No option with key "' + key
+ '"');
2807 if (typeof this.options
[key
] !== 'undefined') {
2808 return this.options
[key
];
2812 Terminal
.prototype.setOption = function (key
, value
) {
2813 if (!(key
in Terminal
.defaults
)) {
2814 throw new Error('No option with key "' + key
+ '"');
2818 if (this.options
[key
] !== value
) {
2819 if (this.lines
.length
> value
) {
2820 var amountToTrim
= this.lines
.length
- value
;
2821 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
2822 this.lines
.trimStart(amountToTrim
);
2823 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
2824 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
2826 this.refresh(0, this.rows
- 1);
2829 this.lines
.maxLength
= value
;
2830 this.viewport
.syncScrollArea();
2835 this.options
[key
] = value
;
2838 this.element
.classList
.toggle('xterm-cursor-blink', value
);
2841 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
2842 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
2844 case 'tabStopWidth':
2849 Terminal
.bindFocus = function (term
) {
2850 on(term
.textarea
, 'focus', function (ev
) {
2851 if (term
.sendFocus
) {
2852 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
2854 term
.element
.classList
.add('focus');
2856 Terminal
.focus
= term
;
2857 term
.emit('focus', { terminal
: term
});
2860 Terminal
.prototype.blur = function () {
2861 return this.textarea
.blur();
2863 Terminal
.bindBlur = function (term
) {
2864 on(term
.textarea
, 'blur', function (ev
) {
2865 term
.refresh(term
.y
, term
.y
);
2866 if (term
.sendFocus
) {
2867 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
2869 term
.element
.classList
.remove('focus');
2870 Terminal
.focus
= null;
2871 term
.emit('blur', { terminal
: term
});
2874 Terminal
.prototype.initGlobal = function () {
2876 Terminal
.bindKeys(this);
2877 Terminal
.bindFocus(this);
2878 Terminal
.bindBlur(this);
2879 on(this.element
, 'copy', function (ev
) {
2880 Clipboard_1
.copyHandler
.call(this, ev
, term
);
2882 on(this.textarea
, 'paste', function (ev
) {
2883 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2885 on(this.element
, 'paste', function (ev
) {
2886 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2888 function rightClickHandlerWrapper(ev
) {
2889 Clipboard_1
.rightClickHandler
.call(this, ev
, term
);
2891 if (term
.browser
.isFirefox
) {
2892 on(this.element
, 'mousedown', function (ev
) {
2893 if (ev
.button
== 2) {
2894 rightClickHandlerWrapper(ev
);
2899 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
2902 Terminal
.bindKeys = function (term
) {
2903 on(term
.element
, 'keydown', function (ev
) {
2904 if (document
.activeElement
!= this) {
2909 on(term
.element
, 'keypress', function (ev
) {
2910 if (document
.activeElement
!= this) {
2915 on(term
.element
, 'keyup', function (ev
) {
2916 if (!wasMondifierKeyOnlyEvent(ev
)) {
2920 on(term
.textarea
, 'keydown', function (ev
) {
2923 on(term
.textarea
, 'keypress', function (ev
) {
2927 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
2928 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
2929 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
2930 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
2931 term
.on('refresh', function (data
) {
2932 term
.queueLinkification(data
.start
, data
.end
);
2935 Terminal
.prototype.insertRow = function (row
) {
2936 if (typeof row
!= 'object') {
2937 row
= document
.createElement('div');
2939 this.rowContainer
.appendChild(row
);
2940 this.children
.push(row
);
2943 Terminal
.prototype.open = function (parent
) {
2944 var self
= this, i
= 0, div
;
2945 this.parent
= parent
|| this.parent
;
2947 throw new Error('Terminal requires a parent element.');
2949 this.context
= this.parent
.ownerDocument
.defaultView
;
2950 this.document
= this.parent
.ownerDocument
;
2951 this.body
= this.document
.getElementsByTagName('body')[0];
2952 this.element
= this.document
.createElement('div');
2953 this.element
.classList
.add('terminal');
2954 this.element
.classList
.add('xterm');
2955 this.element
.classList
.add('xterm-theme-' + this.theme
);
2956 this.element
.classList
.toggle('xterm-cursor-blink', this.options
.cursorBlink
);
2957 this.element
.style
.height
;
2958 this.element
.setAttribute('tabindex', 0);
2959 this.viewportElement
= document
.createElement('div');
2960 this.viewportElement
.classList
.add('xterm-viewport');
2961 this.element
.appendChild(this.viewportElement
);
2962 this.viewportScrollArea
= document
.createElement('div');
2963 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
2964 this.viewportElement
.appendChild(this.viewportScrollArea
);
2965 this.rowContainer
= document
.createElement('div');
2966 this.rowContainer
.classList
.add('xterm-rows');
2967 this.element
.appendChild(this.rowContainer
);
2969 this.linkifier
= new Linkifier_1
.Linkifier(document
, this.children
);
2970 this.helperContainer
= document
.createElement('div');
2971 this.helperContainer
.classList
.add('xterm-helpers');
2972 this.element
.appendChild(this.helperContainer
);
2973 this.textarea
= document
.createElement('textarea');
2974 this.textarea
.classList
.add('xterm-helper-textarea');
2975 this.textarea
.setAttribute('autocorrect', 'off');
2976 this.textarea
.setAttribute('autocapitalize', 'off');
2977 this.textarea
.setAttribute('spellcheck', 'false');
2978 this.textarea
.tabIndex
= 0;
2979 this.textarea
.addEventListener('focus', function () {
2980 self
.emit('focus', { terminal
: self
});
2982 this.textarea
.addEventListener('blur', function () {
2983 self
.emit('blur', { terminal
: self
});
2985 this.helperContainer
.appendChild(this.textarea
);
2986 this.compositionView
= document
.createElement('div');
2987 this.compositionView
.classList
.add('composition-view');
2988 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
2989 this.helperContainer
.appendChild(this.compositionView
);
2990 this.charSizeStyleElement
= document
.createElement('style');
2991 this.helperContainer
.appendChild(this.charSizeStyleElement
);
2992 for (; i
< this.rows
; i
++) {
2995 this.parent
.appendChild(this.element
);
2996 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
2997 this.charMeasure
.on('charsizechanged', function () {
2998 self
.updateCharSizeCSS();
3000 this.charMeasure
.measure();
3001 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
3002 this.renderer
= new Renderer_1
.Renderer(this);
3003 this.refresh(0, this.rows
- 1);
3006 on(this.element
, 'click', function () {
3007 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
3015 Terminal
.loadAddon = function (addon
, callback
) {
3016 if (typeof exports
=== 'object' && typeof module
=== 'object') {
3017 return require('./addons/' + addon
+ '/' + addon
);
3019 else if (typeof define
== 'function') {
3020 return require(['./addons/' + addon
+ '/' + addon
], callback
);
3023 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
3027 Terminal
.prototype.updateCharSizeCSS = function () {
3028 this.charSizeStyleElement
.textContent
= '.xterm-wide-char{width:' + (this.charMeasure
.width
* 2) + 'px;}';
3030 Terminal
.prototype.bindMouse = function () {
3031 var el
= this.element
, self
= this, pressed
= 32;
3032 function sendButton(ev
) {
3034 button
= getButton(ev
);
3035 pos
= getCoords(ev
);
3038 sendEvent(button
, pos
);
3039 switch (ev
.overrideType
|| ev
.type
) {
3050 function sendMove(ev
) {
3051 var button
= pressed
, pos
;
3052 pos
= getCoords(ev
);
3056 sendEvent(button
, pos
);
3058 function encode(data
, ch
) {
3059 if (!self
.utfMouse
) {
3061 return data
.push(0);
3068 return data
.push(0);
3075 data
.push(0xC0 | (ch
>> 6));
3076 data
.push(0x80 | (ch
& 0x3F));
3080 function sendEvent(button
, pos
) {
3081 if (self
.vt300Mouse
) {
3085 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
3088 else if (button
=== 1)
3090 else if (button
=== 2)
3092 else if (button
=== 3)
3096 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
3100 if (self
.decLocator
) {
3106 else if (button
=== 1)
3108 else if (button
=== 2)
3110 else if (button
=== 3)
3112 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
3115 + (button
=== 3 ? 4 : 0)
3125 if (self
.urxvtMouse
) {
3130 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
3133 if (self
.sgrMouse
) {
3136 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
3137 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
3142 + ((button
& 3) === 3 ? 'm' : 'M'));
3146 encode(data
, button
);
3147 encode(data
, pos
.x
);
3148 encode(data
, pos
.y
);
3149 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
3151 function getButton(ev
) {
3152 var button
, shift
, meta
, ctrl
, mod
;
3153 switch (ev
.overrideType
|| ev
.type
) {
3155 button
= ev
.button
!= null
3160 if (self
.browser
.isMSIE
) {
3161 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
3167 case 'DOMMouseScroll':
3168 button
= ev
.detail
< 0
3173 button
= ev
.wheelDeltaY
> 0
3178 shift
= ev
.shiftKey
? 4 : 0;
3179 meta
= ev
.metaKey
? 8 : 0;
3180 ctrl
= ev
.ctrlKey
? 16 : 0;
3181 mod
= shift
| meta
| ctrl
;
3182 if (self
.vt200Mouse
) {
3185 else if (!self
.normalMouse
) {
3188 button
= (32 + (mod
<< 2)) + button
;
3191 function getCoords(ev
) {
3193 if (ev
.pageX
== null)
3198 while (el
&& el
!== self
.document
.documentElement
) {
3201 el
= 'offsetParent' in el
3205 x
= Math
.ceil(x
/ self
.charMeasure
.width
);
3206 y
= Math
.ceil(y
/ self
.charMeasure
.height
);
3223 on(el
, 'mousedown', function (ev
) {
3224 if (!self
.mouseEvents
)
3228 if (self
.vt200Mouse
) {
3229 ev
.overrideType
= 'mouseup';
3231 return self
.cancel(ev
);
3233 if (self
.normalMouse
)
3234 on(self
.document
, 'mousemove', sendMove
);
3235 if (!self
.x10Mouse
) {
3236 on(self
.document
, 'mouseup', function up(ev
) {
3238 if (self
.normalMouse
)
3239 off(self
.document
, 'mousemove', sendMove
);
3240 off(self
.document
, 'mouseup', up
);
3241 return self
.cancel(ev
);
3244 return self
.cancel(ev
);
3246 on(el
, 'wheel', function (ev
) {
3247 if (!self
.mouseEvents
)
3254 return self
.cancel(ev
);
3256 on(el
, 'wheel', function (ev
) {
3257 if (self
.mouseEvents
)
3259 self
.viewport
.onWheel(ev
);
3260 return self
.cancel(ev
);
3263 Terminal
.prototype.destroy = function () {
3264 this.readable
= false;
3265 this.writable
= false;
3267 this.handler = function () { };
3268 this.write = function () { };
3269 if (this.element
&& this.element
.parentNode
) {
3270 this.element
.parentNode
.removeChild(this.element
);
3273 Terminal
.prototype.refresh = function (start
, end
) {
3274 if (this.renderer
) {
3275 this.renderer
.queueRefresh(start
, end
);
3278 Terminal
.prototype.queueLinkification = function (start
, end
) {
3279 if (this.linkifier
) {
3280 for (var i
= start
; i
<= end
; i
++) {
3281 this.linkifier
.linkifyRow(i
);
3285 Terminal
.prototype.showCursor = function () {
3286 if (!this.cursorState
) {
3287 this.cursorState
= 1;
3288 this.refresh(this.y
, this.y
);
3291 Terminal
.prototype.scroll = function () {
3293 if (this.lines
.length
=== this.lines
.maxLength
) {
3294 this.lines
.trimStart(1);
3296 if (this.ydisp
!== 0) {
3301 if (!this.userScrolling
) {
3302 this.ydisp
= this.ybase
;
3304 row
= this.ybase
+ this.rows
- 1;
3305 row
-= this.rows
- 1 - this.scrollBottom
;
3306 if (row
=== this.lines
.length
) {
3307 this.lines
.push(this.blankLine());
3310 this.lines
.splice(row
, 0, this.blankLine());
3312 if (this.scrollTop
!== 0) {
3313 if (this.ybase
!== 0) {
3315 if (!this.userScrolling
) {
3316 this.ydisp
= this.ybase
;
3319 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
3321 this.updateRange(this.scrollTop
);
3322 this.updateRange(this.scrollBottom
);
3323 this.emit('scroll', this.ydisp
);
3325 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
3327 this.userScrolling
= true;
3329 else if (disp
+ this.ydisp
>= this.ybase
) {
3330 this.userScrolling
= false;
3333 if (this.ydisp
> this.ybase
) {
3334 this.ydisp
= this.ybase
;
3336 else if (this.ydisp
< 0) {
3339 if (!suppressScrollEvent
) {
3340 this.emit('scroll', this.ydisp
);
3342 this.refresh(0, this.rows
- 1);
3344 Terminal
.prototype.scrollPages = function (pageCount
) {
3345 this.scrollDisp(pageCount
* (this.rows
- 1));
3347 Terminal
.prototype.scrollToTop = function () {
3348 this.scrollDisp(-this.ydisp
);
3350 Terminal
.prototype.scrollToBottom = function () {
3351 this.scrollDisp(this.ybase
- this.ydisp
);
3353 Terminal
.prototype.write = function (data
) {
3354 this.writeBuffer
.push(data
);
3355 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
3356 this.send(EscapeSequences_1
.C0
.DC3
);
3357 this.xoffSentToCatchUp
= true;
3359 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
3360 this.writeInProgress
= true;
3362 setTimeout(function () {
3367 Terminal
.prototype.innerWrite = function () {
3368 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
3369 while (writeBatch
.length
> 0) {
3370 var data
= writeBatch
.shift();
3371 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
3372 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
3373 this.send(EscapeSequences_1
.C0
.DC1
);
3374 this.xoffSentToCatchUp
= false;
3376 this.refreshStart
= this.y
;
3377 this.refreshEnd
= this.y
;
3378 this.parser
.parse(data
);
3379 this.updateRange(this.y
);
3380 this.refresh(this.refreshStart
, this.refreshEnd
);
3382 if (this.writeBuffer
.length
> 0) {
3384 setTimeout(function () {
3389 this.writeInProgress
= false;
3392 Terminal
.prototype.writeln = function (data
) {
3393 this.write(data
+ '\r\n');
3395 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
3396 this.customKeydownHandler
= customKeydownHandler
;
3398 Terminal
.prototype.attachHypertextLinkHandler = function (handler
) {
3399 if (!this.linkifier
) {
3400 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
3402 this.linkifier
.attachHypertextLinkHandler(handler
);
3403 this.refresh(0, this.rows
- 1);
3405 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
3406 if (this.linkifier
) {
3407 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
3408 this.refresh(0, this.rows
- 1);
3412 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
3413 if (this.linkifier
) {
3414 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
3415 this.refresh(0, this.rows
- 1);
3419 Terminal
.prototype.keyDown = function (ev
) {
3420 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
3423 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
3424 if (this.ybase
!== this.ydisp
) {
3425 this.scrollToBottom();
3430 var result
= this.evaluateKeyEscapeSequence(ev
);
3431 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
3432 this.writeStopped
= true;
3434 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
3435 this.writeStopped
= false;
3437 if (result
.scrollDisp
) {
3438 this.scrollDisp(result
.scrollDisp
);
3439 return this.cancel(ev
, true);
3441 if (isThirdLevelShift(this, ev
)) {
3444 if (result
.cancel
) {
3445 this.cancel(ev
, true);
3450 this.emit('keydown', ev
);
3451 this.emit('key', result
.key
, ev
);
3453 this.handler(result
.key
);
3454 return this.cancel(ev
, true);
3456 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
3460 scrollDisp
: undefined
3462 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
3463 switch (ev
.keyCode
) {
3466 result
.key
= EscapeSequences_1
.C0
.BS
;
3469 result
.key
= EscapeSequences_1
.C0
.DEL
;
3473 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
3476 result
.key
= EscapeSequences_1
.C0
.HT
;
3477 result
.cancel
= true;
3480 result
.key
= EscapeSequences_1
.C0
.CR
;
3481 result
.cancel
= true;
3484 result
.key
= EscapeSequences_1
.C0
.ESC
;
3485 result
.cancel
= true;
3489 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
3490 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
3491 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
3494 else if (this.applicationCursor
) {
3495 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
3498 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
3503 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
3504 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
3505 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
3508 else if (this.applicationCursor
) {
3509 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
3512 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
3517 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
3518 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
3519 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
3522 else if (this.applicationCursor
) {
3523 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
3526 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
3531 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
3532 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
3533 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
3536 else if (this.applicationCursor
) {
3537 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
3540 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
3544 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
3545 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
3550 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
3553 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
3558 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
3559 else if (this.applicationCursor
)
3560 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
3562 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
3566 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
3567 else if (this.applicationCursor
)
3568 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
3570 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
3574 result
.scrollDisp
= -(this.rows
- 1);
3577 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
3582 result
.scrollDisp
= this.rows
- 1;
3585 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
3590 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
3593 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
3598 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
3601 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
3606 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
3609 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
3614 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
3617 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
3622 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
3625 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
3630 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
3633 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
3638 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
3641 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
3646 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
3649 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
3654 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
3657 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
3662 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
3665 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
3670 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
3673 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
3678 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
3681 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
3685 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
3686 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3687 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
3689 else if (ev
.keyCode
=== 32) {
3690 result
.key
= String
.fromCharCode(0);
3692 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
3693 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
3695 else if (ev
.keyCode
=== 56) {
3696 result
.key
= String
.fromCharCode(127);
3698 else if (ev
.keyCode
=== 219) {
3699 result
.key
= String
.fromCharCode(27);
3701 else if (ev
.keyCode
=== 220) {
3702 result
.key
= String
.fromCharCode(28);
3704 else if (ev
.keyCode
=== 221) {
3705 result
.key
= String
.fromCharCode(29);
3708 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
3709 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3710 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
3712 else if (ev
.keyCode
=== 192) {
3713 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
3715 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
3716 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
3723 Terminal
.prototype.setgLevel = function (g
) {
3725 this.charset
= this.charsets
[g
];
3727 Terminal
.prototype.setgCharset = function (g
, charset
) {
3728 this.charsets
[g
] = charset
;
3729 if (this.glevel
=== g
) {
3730 this.charset
= charset
;
3733 Terminal
.prototype.keyPress = function (ev
) {
3739 else if (ev
.which
== null) {
3742 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3748 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3751 key
= String
.fromCharCode(key
);
3752 this.emit('keypress', key
, ev
);
3753 this.emit('key', key
, ev
);
3758 Terminal
.prototype.send = function (data
) {
3761 setTimeout(function () {
3762 self
.handler(self
.queue
);
3768 Terminal
.prototype.bell = function () {
3769 if (!this.visualBell
)
3772 this.element
.style
.borderColor
= 'white';
3773 setTimeout(function () {
3774 self
.element
.style
.borderColor
= '';
3779 Terminal
.prototype.log = function () {
3782 if (!this.context
.console
|| !this.context
.console
.log
)
3784 var args
= Array
.prototype.slice
.call(arguments
);
3785 this.context
.console
.log
.apply(this.context
.console
, args
);
3787 Terminal
.prototype.error = function () {
3790 if (!this.context
.console
|| !this.context
.console
.error
)
3792 var args
= Array
.prototype.slice
.call(arguments
);
3793 this.context
.console
.error
.apply(this.context
.console
, args
);
3795 Terminal
.prototype.resize = function (x
, y
) {
3796 if (isNaN(x
) || isNaN(y
)) {
3799 var line
, el
, i
, j
, ch
, addToY
;
3800 if (x
=== this.cols
&& y
=== this.rows
) {
3809 ch
= [this.defAttr
, ' ', 1];
3810 i
= this.lines
.length
;
3812 while (this.lines
.get(i
).length
< x
) {
3813 this.lines
.get(i
).push(ch
);
3818 i
= this.lines
.length
;
3820 while (this.lines
.get(i
).length
> x
) {
3821 this.lines
.get(i
).pop();
3826 this.setupStops(this.cols
);
3832 if (this.lines
.length
< y
+ this.ybase
) {
3833 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
3836 if (this.ydisp
> 0) {
3841 this.lines
.push(this.blankLine());
3844 if (this.children
.length
< y
) {
3851 if (this.lines
.length
> y
+ this.ybase
) {
3852 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
3860 if (this.children
.length
> y
) {
3861 el
= this.children
.shift();
3864 el
.parentNode
.removeChild(el
);
3879 this.scrollBottom
= y
- 1;
3880 this.charMeasure
.measure();
3881 this.refresh(0, this.rows
- 1);
3883 this.geometry
= [this.cols
, this.rows
];
3884 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
3886 Terminal
.prototype.updateRange = function (y
) {
3887 if (y
< this.refreshStart
)
3888 this.refreshStart
= y
;
3889 if (y
> this.refreshEnd
)
3890 this.refreshEnd
= y
;
3892 Terminal
.prototype.maxRange = function () {
3893 this.refreshStart
= 0;
3894 this.refreshEnd
= this.rows
- 1;
3896 Terminal
.prototype.setupStops = function (i
) {
3898 if (!this.tabs
[i
]) {
3899 i
= this.prevStop(i
);
3906 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
3907 this.tabs
[i
] = true;
3910 Terminal
.prototype.prevStop = function (x
) {
3913 while (!this.tabs
[--x
] && x
> 0)
3915 return x
>= this.cols
3919 Terminal
.prototype.nextStop = function (x
) {
3922 while (!this.tabs
[++x
] && x
< this.cols
)
3924 return x
>= this.cols
3928 Terminal
.prototype.eraseRight = function (x
, y
) {
3929 var line
= this.lines
.get(this.ybase
+ y
);
3933 var ch
= [this.eraseAttr(), ' ', 1];
3934 for (; x
< this.cols
; x
++) {
3937 this.updateRange(y
);
3939 Terminal
.prototype.eraseLeft = function (x
, y
) {
3940 var line
= this.lines
.get(this.ybase
+ y
);
3944 var ch
= [this.eraseAttr(), ' ', 1];
3949 this.updateRange(y
);
3951 Terminal
.prototype.clear = function () {
3952 if (this.ybase
=== 0 && this.y
=== 0) {
3955 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
3956 this.lines
.length
= 1;
3960 for (var i
= 1; i
< this.rows
; i
++) {
3961 this.lines
.push(this.blankLine());
3963 this.refresh(0, this.rows
- 1);
3964 this.emit('scroll', this.ydisp
);
3966 Terminal
.prototype.eraseLine = function (y
) {
3967 this.eraseRight(0, y
);
3969 Terminal
.prototype.blankLine = function (cur
) {
3973 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
3974 for (; i
< this.cols
; i
++) {
3979 Terminal
.prototype.ch = function (cur
) {
3981 ? [this.eraseAttr(), ' ', 1]
3982 : [this.defAttr
, ' ', 1];
3984 Terminal
.prototype.is = function (term
) {
3985 var name
= this.termName
;
3986 return (name
+ '').indexOf(term
) === 0;
3988 Terminal
.prototype.handler = function (data
) {
3989 if (this.options
.disableStdin
) {
3992 if (this.ybase
!== this.ydisp
) {
3993 this.scrollToBottom();
3995 this.emit('data', data
);
3997 Terminal
.prototype.handleTitle = function (title
) {
3998 this.emit('title', title
);
4000 Terminal
.prototype.index = function () {
4002 if (this.y
> this.scrollBottom
) {
4006 if (this.x
>= this.cols
) {
4010 Terminal
.prototype.reverseIndex = function () {
4012 if (this.y
=== this.scrollTop
) {
4013 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
4014 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
4015 this.updateRange(this.scrollTop
);
4016 this.updateRange(this.scrollBottom
);
4022 Terminal
.prototype.reset = function () {
4023 this.options
.rows
= this.rows
;
4024 this.options
.cols
= this.cols
;
4025 var customKeydownHandler
= this.customKeydownHandler
;
4026 Terminal
.call(this, this.options
);
4027 this.customKeydownHandler
= customKeydownHandler
;
4028 this.refresh(0, this.rows
- 1);
4029 this.viewport
.syncScrollArea();
4031 Terminal
.prototype.tabSet = function () {
4032 this.tabs
[this.x
] = true;
4034 function on(el
, type
, handler
, capture
) {
4035 if (!Array
.isArray(el
)) {
4038 el
.forEach(function (element
) {
4039 element
.addEventListener(type
, handler
, capture
|| false);
4042 function off(el
, type
, handler
, capture
) {
4043 el
.removeEventListener(type
, handler
, capture
|| false);
4045 function cancel(ev
, force
) {
4046 if (!this.cancelEvents
&& !force
) {
4049 ev
.preventDefault();
4050 ev
.stopPropagation();
4053 function inherits(child
, parent
) {
4055 this.constructor = child
;
4057 f
.prototype = parent
.prototype;
4058 child
.prototype = new f
;
4060 function indexOf(obj
, el
) {
4068 function isThirdLevelShift(term
, ev
) {
4069 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4070 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4071 if (ev
.type
== 'keypress') {
4072 return thirdLevelKey
;
4074 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4076 Terminal
.prototype.matchColor
= matchColor
;
4077 function matchColor(r1
, g1
, b1
) {
4078 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4079 if (matchColor
._cache
[hash
] != null) {
4080 return matchColor
._cache
[hash
];
4082 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
4083 for (; i
< Terminal
.vcolors
.length
; i
++) {
4084 c
= Terminal
.vcolors
[i
];
4088 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4098 return matchColor
._cache
[hash
] = li
;
4100 matchColor
._cache
= {};
4101 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
4102 return Math
.pow(30 * (r1
- r2
), 2)
4103 + Math
.pow(59 * (g1
- g2
), 2)
4104 + Math
.pow(11 * (b1
- b2
), 2);
4106 function each(obj
, iter
, con
) {
4108 return obj
.forEach(iter
, con
);
4109 for (var i
= 0; i
< obj
.length
; i
++) {
4110 iter
.call(con
, obj
[i
], i
, obj
);
4113 function wasMondifierKeyOnlyEvent(ev
) {
4114 return ev
.keyCode
=== 16 ||
4115 ev
.keyCode
=== 17 ||
4118 function keys(obj
) {
4120 return Object
.keys(obj
);
4123 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4129 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
4130 Terminal
.inherits
= inherits
;
4133 Terminal
.cancel
= cancel
;
4134 module
.exports
= Terminal
;
4138 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./Viewport":9,"./handlers/Clipboard":10,"./utils/Browser":11,"./utils/CharMeasure":12,"./utils/CircularList":13}]},{},[15])(15)
4140 //# sourceMappingURL=xterm.js.map