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
= false;
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 EscapeSequences_1
= require("./EscapeSequences");
1318 var Charsets_1
= require("./Charsets");
1319 var normalStateHandler
= {};
1320 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1321 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1322 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1323 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1324 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1325 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1326 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1327 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1328 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1329 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1330 var escapedStateHandler
= {};
1331 escapedStateHandler
['['] = function (parser
, terminal
) {
1332 terminal
.params
= [];
1333 terminal
.currentParam
= 0;
1334 parser
.setState(ParserState
.CSI_PARAM
);
1336 escapedStateHandler
[']'] = function (parser
, terminal
) {
1337 terminal
.params
= [];
1338 terminal
.currentParam
= 0;
1339 parser
.setState(ParserState
.OSC
);
1341 escapedStateHandler
['P'] = function (parser
, terminal
) {
1342 terminal
.params
= [];
1343 terminal
.currentParam
= 0;
1344 parser
.setState(ParserState
.DCS
);
1346 escapedStateHandler
['_'] = function (parser
, terminal
) {
1347 parser
.setState(ParserState
.IGNORE
);
1349 escapedStateHandler
['^'] = function (parser
, terminal
) {
1350 parser
.setState(ParserState
.IGNORE
);
1352 escapedStateHandler
['c'] = function (parser
, terminal
) {
1355 escapedStateHandler
['E'] = function (parser
, terminal
) {
1358 parser
.setState(ParserState
.NORMAL
);
1360 escapedStateHandler
['D'] = function (parser
, terminal
) {
1362 parser
.setState(ParserState
.NORMAL
);
1364 escapedStateHandler
['M'] = function (parser
, terminal
) {
1365 terminal
.reverseIndex();
1366 parser
.setState(ParserState
.NORMAL
);
1368 escapedStateHandler
['%'] = function (parser
, terminal
) {
1369 terminal
.setgLevel(0);
1370 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1371 parser
.setState(ParserState
.NORMAL
);
1372 parser
.skipNextChar();
1374 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1375 var csiParamStateHandler
= {};
1376 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1377 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1378 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1379 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1380 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1381 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1382 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1383 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1384 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1385 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1386 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1387 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1388 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1389 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1390 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1391 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1392 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1393 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1394 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1395 var csiStateHandler
= {};
1396 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1397 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1398 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1399 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1400 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1401 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1402 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1403 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1404 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1405 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1406 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1407 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1408 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1409 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1410 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1411 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1412 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1413 if (params
.length
< 2 && !prefix
) {
1414 handler
.scrollDown(params
);
1417 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1418 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1419 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1420 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1421 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1422 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1423 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1424 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1425 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1426 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1427 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1428 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1429 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1430 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1431 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1434 handler
.softReset(params
);
1438 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1439 if (postfix
=== ' ') {
1440 handler
.setCursorStyle(params
);
1443 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1444 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1445 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1446 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1448 (function (ParserState
) {
1449 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1450 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1451 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1452 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1453 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1454 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1455 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1456 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1457 })(ParserState
|| (ParserState
= {}));
1458 var Parser
= (function () {
1459 function Parser(_inputHandler
, _terminal
) {
1460 this._inputHandler
= _inputHandler
;
1461 this._terminal
= _terminal
;
1462 this._state
= ParserState
.NORMAL
;
1464 Parser
.prototype.parse = function (data
) {
1465 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1467 if (this._terminal
.surrogate_high
) {
1468 data
= this._terminal
.surrogate_high
+ data
;
1469 this._terminal
.surrogate_high
= '';
1471 for (; this._position
< l
; this._position
++) {
1472 ch
= data
[this._position
];
1473 code
= data
.charCodeAt(this._position
);
1474 if (0xD800 <= code
&& code
<= 0xDBFF) {
1475 low
= data
.charCodeAt(this._position
+ 1);
1477 this._terminal
.surrogate_high
= ch
;
1480 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1481 ch
+= data
.charAt(this._position
+ 1);
1483 if (0xDC00 <= code
&& code
<= 0xDFFF)
1485 switch (this._state
) {
1486 case ParserState
.NORMAL
:
1487 if (ch
in normalStateHandler
) {
1488 normalStateHandler
[ch
](this, this._inputHandler
);
1491 this._inputHandler
.addChar(ch
, code
);
1494 case ParserState
.ESCAPED
:
1495 if (ch
in escapedStateHandler
) {
1496 escapedStateHandler
[ch
](this, this._terminal
);
1508 this._terminal
.gcharset
= 0;
1511 this._terminal
.gcharset
= 1;
1514 this._terminal
.gcharset
= 2;
1517 this._terminal
.gcharset
= 3;
1520 this._terminal
.gcharset
= 1;
1523 this._terminal
.gcharset
= 2;
1526 this._state
= ParserState
.CHARSET
;
1529 this._terminal
.gcharset
= 3;
1530 this._state
= ParserState
.CHARSET
;
1538 this._terminal
.setgLevel(2);
1541 this._terminal
.setgLevel(3);
1544 this._terminal
.setgLevel(3);
1547 this._terminal
.setgLevel(2);
1550 this._terminal
.setgLevel(1);
1553 this._inputHandler
.saveCursor();
1554 this._state
= ParserState
.NORMAL
;
1557 this._inputHandler
.restoreCursor();
1558 this._state
= ParserState
.NORMAL
;
1561 this._state
= ParserState
.NORMAL
;
1565 this._terminal
.tabSet();
1566 this._state
= ParserState
.NORMAL
;
1569 this._terminal
.log('Serial port requested application keypad.');
1570 this._terminal
.applicationKeypad
= true;
1571 this._terminal
.viewport
.syncScrollArea();
1572 this._state
= ParserState
.NORMAL
;
1575 this._terminal
.log('Switching back to normal keypad.');
1576 this._terminal
.applicationKeypad
= false;
1577 this._terminal
.viewport
.syncScrollArea();
1578 this._state
= ParserState
.NORMAL
;
1581 this._state
= ParserState
.NORMAL
;
1582 this._terminal
.error('Unknown ESC control: %s.', ch
);
1586 case ParserState
.CHARSET
:
1587 if (ch
in Charsets_1
.CHARSETS
) {
1588 cs
= Charsets_1
.CHARSETS
[ch
];
1590 this.skipNextChar();
1594 cs
= Charsets_1
.DEFAULT_CHARSET
;
1596 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1597 this._terminal
.gcharset
= null;
1598 this._state
= ParserState
.NORMAL
;
1600 case ParserState
.OSC
:
1601 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1602 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1604 this._terminal
.params
.push(this._terminal
.currentParam
);
1605 switch (this._terminal
.params
[0]) {
1609 if (this._terminal
.params
[1]) {
1610 this._terminal
.title
= this._terminal
.params
[1];
1611 this._terminal
.handleTitle(this._terminal
.title
);
1651 this._terminal
.params
= [];
1652 this._terminal
.currentParam
= 0;
1653 this._state
= ParserState
.NORMAL
;
1656 if (!this._terminal
.params
.length
) {
1657 if (ch
>= '0' && ch
<= '9') {
1658 this._terminal
.currentParam
=
1659 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1661 else if (ch
=== ';') {
1662 this._terminal
.params
.push(this._terminal
.currentParam
);
1663 this._terminal
.currentParam
= '';
1667 this._terminal
.currentParam
+= ch
;
1671 case ParserState
.CSI_PARAM
:
1672 if (ch
in csiParamStateHandler
) {
1673 csiParamStateHandler
[ch
](this);
1676 this.finalizeParam();
1677 this._state
= ParserState
.CSI
;
1678 case ParserState
.CSI
:
1679 if (ch
in csiStateHandler
) {
1680 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1683 this._terminal
.error('Unknown CSI code: %s.', ch
);
1685 this._state
= ParserState
.NORMAL
;
1686 this._terminal
.prefix
= '';
1687 this._terminal
.postfix
= '';
1689 case ParserState
.DCS
:
1690 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1691 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1693 switch (this._terminal
.prefix
) {
1697 var pt
= this._terminal
.currentParam
, valid
= false;
1707 + (this._terminal
.scrollTop
+ 1)
1709 + (this._terminal
.scrollBottom
+ 1)
1716 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1720 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1725 pt
= this._terminal
.currentParam
1727 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1730 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1733 this._terminal
.currentParam
= 0;
1734 this._terminal
.prefix
= '';
1735 this._state
= ParserState
.NORMAL
;
1737 else if (!this._terminal
.currentParam
) {
1738 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1739 this._terminal
.currentParam
= ch
;
1741 else if (this._terminal
.prefix
.length
=== 2) {
1742 this._terminal
.currentParam
= ch
;
1745 this._terminal
.prefix
+= ch
;
1749 this._terminal
.currentParam
+= ch
;
1752 case ParserState
.IGNORE
:
1753 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1754 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1756 this._state
= ParserState
.NORMAL
;
1762 Parser
.prototype.setState = function (state
) {
1763 this._state
= state
;
1765 Parser
.prototype.setPrefix = function (prefix
) {
1766 this._terminal
.prefix
= prefix
;
1768 Parser
.prototype.setPostfix = function (postfix
) {
1769 this._terminal
.postfix
= postfix
;
1771 Parser
.prototype.setParam = function (param
) {
1772 this._terminal
.currentParam
= param
;
1774 Parser
.prototype.getParam = function () {
1775 return this._terminal
.currentParam
;
1777 Parser
.prototype.finalizeParam = function () {
1778 this._terminal
.params
.push(this._terminal
.currentParam
);
1779 this._terminal
.currentParam
= 0;
1781 Parser
.prototype.skipNextChar = function () {
1786 exports
.Parser
= Parser
;
1790 },{"./Charsets":1,"./EscapeSequences":3}],7:[function(require
,module
,exports
){
1792 var MAX_REFRESH_FRAME_SKIP
= 5;
1795 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
1796 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
1797 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
1798 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
1799 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
1800 })(FLAGS
|| (FLAGS
= {}));
1802 var brokenBold
= null;
1803 var Renderer
= (function () {
1804 function Renderer(_terminal
) {
1805 this._terminal
= _terminal
;
1806 this._refreshRowsQueue
= [];
1807 this._refreshFramesSkipped
= 0;
1808 this._refreshAnimationFrame
= null;
1809 if (brokenBold
=== null) {
1810 brokenBold
= checkBoldBroken(this._terminal
.document
);
1813 Renderer
.prototype.queueRefresh = function (start
, end
) {
1814 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
1815 if (!this._refreshAnimationFrame
) {
1816 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
1819 Renderer
.prototype._refreshLoop = function () {
1820 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
1822 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
1825 this._refreshFramesSkipped
= 0;
1828 if (this._refreshRowsQueue
.length
> 4) {
1830 end
= this._terminal
.rows
- 1;
1833 start
= this._refreshRowsQueue
[0].start
;
1834 end
= this._refreshRowsQueue
[0].end
;
1835 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
1836 if (this._refreshRowsQueue
[i
].start
< start
) {
1837 start
= this._refreshRowsQueue
[i
].start
;
1839 if (this._refreshRowsQueue
[i
].end
> end
) {
1840 end
= this._refreshRowsQueue
[i
].end
;
1844 this._refreshRowsQueue
= [];
1845 this._refreshAnimationFrame
= null;
1846 this._refresh(start
, end
);
1848 Renderer
.prototype._refresh = function (start
, end
) {
1849 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1850 if (end
- start
>= this._terminal
.rows
/ 2) {
1851 parent
= this._terminal
.element
.parentNode
;
1853 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
1856 width
= this._terminal
.cols
;
1858 if (end
>= this._terminal
.rows
) {
1859 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
1860 end
= this._terminal
.rows
- 1;
1862 for (; y
<= end
; y
++) {
1863 row
= y
+ this._terminal
.ydisp
;
1864 line
= this._terminal
.lines
.get(row
);
1865 if (!line
|| !this._terminal
.children
[y
]) {
1869 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
)
1870 && this._terminal
.cursorState
1871 && !this._terminal
.cursorHidden
) {
1872 x
= this._terminal
.x
;
1877 attr
= this._terminal
.defAttr
;
1879 for (; i
< width
; i
++) {
1885 ch_width
= line
[i
][2];
1890 if (data
!== attr
) {
1891 if (attr
!== this._terminal
.defAttr
) {
1894 if (data
!== this._terminal
.defAttr
) {
1896 out
+= '<span class="reverse-video terminal-cursor">';
1899 var classNames
= [];
1901 fg
= (data
>> 9) & 0x1ff;
1903 if (flags
& FLAGS
.BOLD
) {
1905 classNames
.push('xterm-bold');
1910 if (flags
& FLAGS
.UNDERLINE
) {
1911 classNames
.push('xterm-underline');
1913 if (flags
& FLAGS
.BLINK
) {
1914 classNames
.push('xterm-blink');
1916 if (flags
& FLAGS
.INVERSE
) {
1917 bg
= [fg
, fg
= bg
][0];
1918 if ((flags
& 1) && fg
< 8)
1921 if (flags
& FLAGS
.INVISIBLE
) {
1922 classNames
.push('xterm-hidden');
1924 if (flags
& FLAGS
.INVERSE
) {
1933 classNames
.push('xterm-bg-color-' + bg
);
1936 classNames
.push('xterm-color-' + fg
);
1939 if (classNames
.length
) {
1940 out
+= ' class="' + classNames
.join(' ') + '"';
1946 if (ch_width
=== 2) {
1947 out
+= '<span class="xterm-wide-char">';
1968 if (ch_width
=== 2) {
1973 if (attr
!== this._terminal
.defAttr
) {
1976 this._terminal
.children
[y
].innerHTML
= out
;
1979 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
1981 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
1986 exports
.Renderer
= Renderer
;
1987 function checkBoldBroken(document
) {
1988 var body
= document
.getElementsByTagName('body')[0];
1989 var el
= document
.createElement('span');
1990 el
.innerHTML
= 'hello world';
1991 body
.appendChild(el
);
1992 var w1
= el
.scrollWidth
;
1993 el
.style
.fontWeight
= 'bold';
1994 var w2
= el
.scrollWidth
;
1995 body
.removeChild(el
);
2001 },{}],8:[function(require
,module
,exports
){
2003 var Viewport
= (function () {
2004 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2006 this.terminal
= terminal
;
2007 this.viewportElement
= viewportElement
;
2008 this.scrollArea
= scrollArea
;
2009 this.charMeasure
= charMeasure
;
2010 this.currentRowHeight
= 0;
2011 this.lastRecordedBufferLength
= 0;
2012 this.lastRecordedViewportHeight
= 0;
2013 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2014 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2015 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2016 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2018 Viewport
.prototype.refresh = function () {
2019 if (this.charMeasure
.height
> 0) {
2020 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2021 if (rowHeightChanged
) {
2022 this.currentRowHeight
= this.charMeasure
.height
;
2023 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2024 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2026 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2027 if (rowHeightChanged
|| viewportHeightChanged
) {
2028 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2029 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2031 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2034 Viewport
.prototype.syncScrollArea = function () {
2035 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2036 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2039 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2043 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2047 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2048 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2049 this.viewportElement
.scrollTop
= scrollTop
;
2052 Viewport
.prototype.onScroll = function (ev
) {
2053 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2054 var diff
= newRow
- this.terminal
.ydisp
;
2055 this.terminal
.scrollDisp(diff
, true);
2057 Viewport
.prototype.onWheel = function (ev
) {
2058 if (ev
.deltaY
=== 0) {
2062 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2063 multiplier
= this.currentRowHeight
;
2065 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2066 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2068 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2069 ev
.preventDefault();
2074 exports
.Viewport
= Viewport
;
2078 },{}],9:[function(require
,module
,exports
){
2080 function prepareTextForClipboard(text
) {
2081 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
2082 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
2083 return processedLine
;
2085 return processedText
;
2087 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
2088 function copyHandler(ev
, term
) {
2089 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
2090 if (term
.browser
.isMSIE
) {
2091 window
.clipboardData
.setData('Text', text
);
2094 ev
.clipboardData
.setData('text/plain', text
);
2096 ev
.preventDefault();
2098 exports
.copyHandler
= copyHandler
;
2099 function pasteHandler(ev
, term
) {
2100 ev
.stopPropagation();
2102 var dispatchPaste = function (text
) {
2104 term
.textarea
.value
= '';
2105 return term
.cancel(ev
);
2107 if (term
.browser
.isMSIE
) {
2108 if (window
.clipboardData
) {
2109 text
= window
.clipboardData
.getData('Text');
2110 dispatchPaste(text
);
2114 if (ev
.clipboardData
) {
2115 text
= ev
.clipboardData
.getData('text/plain');
2116 dispatchPaste(text
);
2120 exports
.pasteHandler
= pasteHandler
;
2121 function rightClickHandler(ev
, term
) {
2122 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
2124 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
2125 for (var i
= 0; i
< cr
.length
; i
++) {
2127 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
2128 (y
> rect
.top
) && (y
< rect
.bottom
));
2129 if (clickIsOnSelection
) {
2133 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
2134 clickIsOnSelection
= false;
2137 if (!clickIsOnSelection
) {
2138 term
.textarea
.style
.position
= 'fixed';
2139 term
.textarea
.style
.width
= '20px';
2140 term
.textarea
.style
.height
= '20px';
2141 term
.textarea
.style
.left
= (x
- 10) + 'px';
2142 term
.textarea
.style
.top
= (y
- 10) + 'px';
2143 term
.textarea
.style
.zIndex
= '1000';
2144 term
.textarea
.focus();
2145 setTimeout(function () {
2146 term
.textarea
.style
.position
= null;
2147 term
.textarea
.style
.width
= null;
2148 term
.textarea
.style
.height
= null;
2149 term
.textarea
.style
.left
= null;
2150 term
.textarea
.style
.top
= null;
2151 term
.textarea
.style
.zIndex
= null;
2155 exports
.rightClickHandler
= rightClickHandler
;
2159 },{}],10:[function(require
,module
,exports
){
2161 var Generic_1
= require("./Generic");
2162 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2163 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2164 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2165 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2166 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2167 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2168 exports
.isIpad
= platform
=== 'iPad';
2169 exports
.isIphone
= platform
=== 'iPhone';
2170 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2174 },{"./Generic":13}],11:[function(require
,module
,exports
){
2176 var __extends
= (this && this.__extends
) || function (d
, b
) {
2177 for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
];
2178 function __() { this.constructor = d
; }
2179 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2181 var EventEmitter_js_1
= require("../EventEmitter.js");
2182 var CharMeasure
= (function (_super
) {
2183 __extends(CharMeasure
, _super
);
2184 function CharMeasure(parentElement
) {
2185 var _this
= _super
.call(this) || this;
2186 _this
._parentElement
= parentElement
;
2189 Object
.defineProperty(CharMeasure
.prototype, "width", {
2196 Object
.defineProperty(CharMeasure
.prototype, "height", {
2198 return this._height
;
2203 CharMeasure
.prototype.measure = function () {
2205 if (!this._measureElement
) {
2206 this._measureElement
= document
.createElement('span');
2207 this._measureElement
.style
.position
= 'absolute';
2208 this._measureElement
.style
.top
= '0';
2209 this._measureElement
.style
.left
= '-9999em';
2210 this._measureElement
.textContent
= 'W';
2211 this._parentElement
.appendChild(this._measureElement
);
2212 setTimeout(function () { return _this
._doMeasure(); }, 0);
2218 CharMeasure
.prototype._doMeasure = function () {
2219 var geometry
= this._measureElement
.getBoundingClientRect();
2220 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
2223 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
2224 this._width
= geometry
.width
;
2225 this._height
= geometry
.height
;
2226 this.emit('charsizechanged');
2230 }(EventEmitter_js_1
.EventEmitter
));
2231 exports
.CharMeasure
= CharMeasure
;
2235 },{"../EventEmitter.js":4}],12:[function(require
,module
,exports
){
2237 var CircularList
= (function () {
2238 function CircularList(maxLength
) {
2239 this._array
= new Array(maxLength
);
2240 this._startIndex
= 0;
2243 Object
.defineProperty(CircularList
.prototype, "maxLength", {
2245 return this._array
.length
;
2247 set: function (newMaxLength
) {
2248 var newArray
= new Array(newMaxLength
);
2249 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
2250 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
2252 this._array
= newArray
;
2253 this._startIndex
= 0;
2258 Object
.defineProperty(CircularList
.prototype, "length", {
2260 return this._length
;
2262 set: function (newLength
) {
2263 if (newLength
> this._length
) {
2264 for (var i
= this._length
; i
< newLength
; i
++) {
2265 this._array
[i
] = undefined;
2268 this._length
= newLength
;
2273 Object
.defineProperty(CircularList
.prototype, "forEach", {
2275 return this._array
.forEach
;
2280 CircularList
.prototype.get = function (index
) {
2281 return this._array
[this._getCyclicIndex(index
)];
2283 CircularList
.prototype.set = function (index
, value
) {
2284 this._array
[this._getCyclicIndex(index
)] = value
;
2286 CircularList
.prototype.push = function (value
) {
2287 this._array
[this._getCyclicIndex(this._length
)] = value
;
2288 if (this._length
=== this.maxLength
) {
2290 if (this._startIndex
=== this.maxLength
) {
2291 this._startIndex
= 0;
2298 CircularList
.prototype.pop = function () {
2299 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
2301 CircularList
.prototype.splice = function (start
, deleteCount
) {
2303 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
2304 items
[_i
- 2] = arguments
[_i
];
2307 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
2308 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
2310 this._length
-= deleteCount
;
2312 if (items
&& items
.length
) {
2313 for (var i
= this._length
- 1; i
>= start
; i
--) {
2314 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
2316 for (var i
= 0; i
< items
.length
; i
++) {
2317 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
2319 if (this._length
+ items
.length
> this.maxLength
) {
2320 this._startIndex
+= (this._length
+ items
.length
) - this.maxLength
;
2321 this._length
= this.maxLength
;
2324 this._length
+= items
.length
;
2328 CircularList
.prototype.trimStart = function (count
) {
2329 if (count
> this._length
) {
2330 count
= this._length
;
2332 this._startIndex
+= count
;
2333 this._length
-= count
;
2335 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
2339 if (start
< 0 || start
>= this._length
) {
2340 throw new Error('start argument out of range');
2342 if (start
+ offset
< 0) {
2343 throw new Error('Cannot shift elements in list beyond index 0');
2346 for (var i
= count
- 1; i
>= 0; i
--) {
2347 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2349 var expandListBy
= (start
+ count
+ offset
) - this._length
;
2350 if (expandListBy
> 0) {
2351 this._length
+= expandListBy
;
2352 while (this._length
> this.maxLength
) {
2359 for (var i
= 0; i
< count
; i
++) {
2360 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2364 CircularList
.prototype._getCyclicIndex = function (index
) {
2365 return (this._startIndex
+ index
) % this.maxLength
;
2367 return CircularList
;
2369 exports
.CircularList
= CircularList
;
2373 },{}],13:[function(require
,module
,exports
){
2375 function contains(arr
, el
) {
2376 return arr
.indexOf(el
) >= 0;
2378 exports
.contains
= contains
;
2383 },{}],14:[function(require
,module
,exports
){
2385 var CompositionHelper_1
= require("./CompositionHelper");
2386 var EventEmitter_1
= require("./EventEmitter");
2387 var Viewport_1
= require("./Viewport");
2388 var Clipboard_1
= require("./handlers/Clipboard");
2389 var CircularList_1
= require("./utils/CircularList");
2390 var EscapeSequences_1
= require("./EscapeSequences");
2391 var InputHandler_1
= require("./InputHandler");
2392 var Parser_1
= require("./Parser");
2393 var Renderer_1
= require("./Renderer");
2394 var CharMeasure_1
= require("./utils/CharMeasure");
2395 var Browser
= require("./utils/Browser");
2396 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
2397 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
2398 var WRITE_BATCH_SIZE
= 300;
2399 function Terminal(options
) {
2401 if (!(this instanceof Terminal
)) {
2402 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
2404 self
.browser
= Browser
;
2405 self
.cancel
= Terminal
.cancel
;
2406 EventEmitter_1
.EventEmitter
.call(this);
2407 if (typeof options
=== 'number') {
2411 handler
: arguments
[2]
2414 options
= options
|| {};
2415 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
2416 if (options
[key
] == null) {
2417 options
[key
] = Terminal
.options
[key
];
2418 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
2419 options
[key
] = Terminal
[key
];
2422 self
[key
] = options
[key
];
2424 if (options
.colors
.length
=== 8) {
2425 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
2427 else if (options
.colors
.length
=== 16) {
2428 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
2430 else if (options
.colors
.length
=== 10) {
2431 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
2433 else if (options
.colors
.length
=== 18) {
2434 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
2436 this.colors
= options
.colors
;
2437 this.options
= options
;
2438 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
2439 this.cols
= options
.cols
|| options
.geometry
[0];
2440 this.rows
= options
.rows
|| options
.geometry
[1];
2441 this.geometry
= [this.cols
, this.rows
];
2442 if (options
.handler
) {
2443 this.on('data', options
.handler
);
2449 this.cursorState
= 0;
2450 this.cursorHidden
= false;
2454 this.scrollBottom
= this.rows
- 1;
2455 this.customKeydownHandler
= null;
2456 this.applicationKeypad
= false;
2457 this.applicationCursor
= false;
2458 this.originMode
= false;
2459 this.insertMode
= false;
2460 this.wraparoundMode
= true;
2462 this.charset
= null;
2463 this.gcharset
= null;
2465 this.charsets
= [null];
2483 this.readable
= true;
2484 this.writable
= true;
2485 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
2486 this.curAttr
= this.defAttr
;
2488 this.currentParam
= 0;
2491 this.inputHandler
= new InputHandler_1
.InputHandler(this);
2492 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
2493 this.renderer
= this.renderer
|| null;
2494 this.writeBuffer
= [];
2495 this.writeInProgress
= false;
2496 this.xoffSentToCatchUp
= false;
2497 this.writeStopped
= false;
2498 this.surrogate_high
= '';
2499 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
2502 this.lines
.push(this.blankLine());
2506 this.userScrolling
= false;
2508 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
2509 Terminal
.prototype.eraseAttr = function () {
2510 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
2512 Terminal
.tangoColors
= [
2530 Terminal
.colors
= (function () {
2531 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
2533 for (; i
< 216; i
++) {
2534 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
2537 for (; i
< 24; i
++) {
2541 function out(r
, g
, b
) {
2542 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
2546 return c
.length
< 2 ? '0' + c
: c
;
2550 Terminal
._colors
= Terminal
.colors
.slice();
2551 Terminal
.vcolors
= (function () {
2552 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
2553 for (; i
< 256; i
++) {
2554 color
= parseInt(colors
[i
].substring(1), 16);
2556 (color
>> 16) & 0xff,
2557 (color
>> 8) & 0xff,
2563 Terminal
.defaults
= {
2564 colors
: Terminal
.colors
,
2570 cursorStyle
: 'block',
2576 cancelEvents
: false,
2577 disableStdin
: false,
2578 useFlowControl
: false,
2581 Terminal
.options
= {};
2582 Terminal
.focus
= null;
2583 each(keys(Terminal
.defaults
), function (key
) {
2584 Terminal
[key
] = Terminal
.defaults
[key
];
2585 Terminal
.options
[key
] = Terminal
.defaults
[key
];
2587 Terminal
.prototype.focus = function () {
2588 return this.textarea
.focus();
2590 Terminal
.prototype.getOption = function (key
, value
) {
2591 if (!(key
in Terminal
.defaults
)) {
2592 throw new Error('No option with key "' + key
+ '"');
2594 if (typeof this.options
[key
] !== 'undefined') {
2595 return this.options
[key
];
2599 Terminal
.prototype.setOption = function (key
, value
) {
2600 if (!(key
in Terminal
.defaults
)) {
2601 throw new Error('No option with key "' + key
+ '"');
2605 if (this.options
[key
] !== value
) {
2606 if (this.lines
.length
> value
) {
2607 var amountToTrim
= this.lines
.length
- value
;
2608 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
2609 this.lines
.trimStart(amountToTrim
);
2610 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
2611 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
2613 this.refresh(0, this.rows
- 1);
2616 this.lines
.maxLength
= value
;
2617 this.viewport
.syncScrollArea();
2622 this.options
[key
] = value
;
2625 this.element
.classList
.toggle('xterm-cursor-blink', value
);
2628 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
2629 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
2631 case 'tabStopWidth':
2636 Terminal
.bindFocus = function (term
) {
2637 on(term
.textarea
, 'focus', function (ev
) {
2638 if (term
.sendFocus
) {
2639 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
2641 term
.element
.classList
.add('focus');
2643 Terminal
.focus
= term
;
2644 term
.emit('focus', { terminal
: term
});
2647 Terminal
.prototype.blur = function () {
2648 return this.textarea
.blur();
2650 Terminal
.bindBlur = function (term
) {
2651 on(term
.textarea
, 'blur', function (ev
) {
2652 term
.refresh(term
.y
, term
.y
);
2653 if (term
.sendFocus
) {
2654 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
2656 term
.element
.classList
.remove('focus');
2657 Terminal
.focus
= null;
2658 term
.emit('blur', { terminal
: term
});
2661 Terminal
.prototype.initGlobal = function () {
2663 Terminal
.bindKeys(this);
2664 Terminal
.bindFocus(this);
2665 Terminal
.bindBlur(this);
2666 on(this.element
, 'copy', function (ev
) {
2667 Clipboard_1
.copyHandler
.call(this, ev
, term
);
2669 on(this.textarea
, 'paste', function (ev
) {
2670 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2672 on(this.element
, 'paste', function (ev
) {
2673 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2675 function rightClickHandlerWrapper(ev
) {
2676 Clipboard_1
.rightClickHandler
.call(this, ev
, term
);
2678 if (term
.browser
.isFirefox
) {
2679 on(this.element
, 'mousedown', function (ev
) {
2680 if (ev
.button
== 2) {
2681 rightClickHandlerWrapper(ev
);
2686 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
2689 Terminal
.bindKeys = function (term
) {
2690 on(term
.element
, 'keydown', function (ev
) {
2691 if (document
.activeElement
!= this) {
2696 on(term
.element
, 'keypress', function (ev
) {
2697 if (document
.activeElement
!= this) {
2702 on(term
.element
, 'keyup', function (ev
) {
2703 if (!wasMondifierKeyOnlyEvent(ev
)) {
2707 on(term
.textarea
, 'keydown', function (ev
) {
2710 on(term
.textarea
, 'keypress', function (ev
) {
2714 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
2715 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
2716 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
2717 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
2719 Terminal
.prototype.insertRow = function (row
) {
2720 if (typeof row
!= 'object') {
2721 row
= document
.createElement('div');
2723 this.rowContainer
.appendChild(row
);
2724 this.children
.push(row
);
2727 Terminal
.prototype.open = function (parent
) {
2728 var self
= this, i
= 0, div
;
2729 this.parent
= parent
|| this.parent
;
2731 throw new Error('Terminal requires a parent element.');
2733 this.context
= this.parent
.ownerDocument
.defaultView
;
2734 this.document
= this.parent
.ownerDocument
;
2735 this.body
= this.document
.getElementsByTagName('body')[0];
2736 this.element
= this.document
.createElement('div');
2737 this.element
.classList
.add('terminal');
2738 this.element
.classList
.add('xterm');
2739 this.element
.classList
.add('xterm-theme-' + this.theme
);
2740 this.element
.classList
.toggle('xterm-cursor-blink', this.options
.cursorBlink
);
2741 this.element
.style
.height
;
2742 this.element
.setAttribute('tabindex', 0);
2743 this.viewportElement
= document
.createElement('div');
2744 this.viewportElement
.classList
.add('xterm-viewport');
2745 this.element
.appendChild(this.viewportElement
);
2746 this.viewportScrollArea
= document
.createElement('div');
2747 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
2748 this.viewportElement
.appendChild(this.viewportScrollArea
);
2749 this.rowContainer
= document
.createElement('div');
2750 this.rowContainer
.classList
.add('xterm-rows');
2751 this.element
.appendChild(this.rowContainer
);
2753 this.helperContainer
= document
.createElement('div');
2754 this.helperContainer
.classList
.add('xterm-helpers');
2755 this.element
.appendChild(this.helperContainer
);
2756 this.textarea
= document
.createElement('textarea');
2757 this.textarea
.classList
.add('xterm-helper-textarea');
2758 this.textarea
.setAttribute('autocorrect', 'off');
2759 this.textarea
.setAttribute('autocapitalize', 'off');
2760 this.textarea
.setAttribute('spellcheck', 'false');
2761 this.textarea
.tabIndex
= 0;
2762 this.textarea
.addEventListener('focus', function () {
2763 self
.emit('focus', { terminal
: self
});
2765 this.textarea
.addEventListener('blur', function () {
2766 self
.emit('blur', { terminal
: self
});
2768 this.helperContainer
.appendChild(this.textarea
);
2769 this.compositionView
= document
.createElement('div');
2770 this.compositionView
.classList
.add('composition-view');
2771 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
2772 this.helperContainer
.appendChild(this.compositionView
);
2773 this.charSizeStyleElement
= document
.createElement('style');
2774 this.helperContainer
.appendChild(this.charSizeStyleElement
);
2775 for (; i
< this.rows
; i
++) {
2778 this.parent
.appendChild(this.element
);
2779 this.charMeasure
= new CharMeasure_1
.CharMeasure(this.helperContainer
);
2780 this.charMeasure
.on('charsizechanged', function () {
2781 self
.updateCharSizeCSS();
2783 this.charMeasure
.measure();
2784 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
2785 this.renderer
= new Renderer_1
.Renderer(this);
2786 this.refresh(0, this.rows
- 1);
2789 on(this.element
, 'click', function () {
2790 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
2798 Terminal
.loadAddon = function (addon
, callback
) {
2799 if (typeof exports
=== 'object' && typeof module
=== 'object') {
2800 return require('./addons/' + addon
+ '/' + addon
);
2802 else if (typeof define
== 'function') {
2803 return require(['./addons/' + addon
+ '/' + addon
], callback
);
2806 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
2810 Terminal
.prototype.updateCharSizeCSS = function () {
2811 this.charSizeStyleElement
.textContent
= '.xterm-wide-char{width:' + (this.charMeasure
.width
* 2) + 'px;}';
2813 Terminal
.prototype.bindMouse = function () {
2814 var el
= this.element
, self
= this, pressed
= 32;
2815 function sendButton(ev
) {
2817 button
= getButton(ev
);
2818 pos
= getCoords(ev
);
2821 sendEvent(button
, pos
);
2822 switch (ev
.overrideType
|| ev
.type
) {
2833 function sendMove(ev
) {
2834 var button
= pressed
, pos
;
2835 pos
= getCoords(ev
);
2839 sendEvent(button
, pos
);
2841 function encode(data
, ch
) {
2842 if (!self
.utfMouse
) {
2844 return data
.push(0);
2851 return data
.push(0);
2858 data
.push(0xC0 | (ch
>> 6));
2859 data
.push(0x80 | (ch
& 0x3F));
2863 function sendEvent(button
, pos
) {
2864 if (self
.vt300Mouse
) {
2868 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
2871 else if (button
=== 1)
2873 else if (button
=== 2)
2875 else if (button
=== 3)
2879 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
2883 if (self
.decLocator
) {
2889 else if (button
=== 1)
2891 else if (button
=== 2)
2893 else if (button
=== 3)
2895 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
2898 + (button
=== 3 ? 4 : 0)
2908 if (self
.urxvtMouse
) {
2913 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
2916 if (self
.sgrMouse
) {
2919 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
2920 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
2925 + ((button
& 3) === 3 ? 'm' : 'M'));
2929 encode(data
, button
);
2930 encode(data
, pos
.x
);
2931 encode(data
, pos
.y
);
2932 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
2934 function getButton(ev
) {
2935 var button
, shift
, meta
, ctrl
, mod
;
2936 switch (ev
.overrideType
|| ev
.type
) {
2938 button
= ev
.button
!= null
2943 if (self
.browser
.isMSIE
) {
2944 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
2950 case 'DOMMouseScroll':
2951 button
= ev
.detail
< 0
2956 button
= ev
.wheelDeltaY
> 0
2961 shift
= ev
.shiftKey
? 4 : 0;
2962 meta
= ev
.metaKey
? 8 : 0;
2963 ctrl
= ev
.ctrlKey
? 16 : 0;
2964 mod
= shift
| meta
| ctrl
;
2965 if (self
.vt200Mouse
) {
2968 else if (!self
.normalMouse
) {
2971 button
= (32 + (mod
<< 2)) + button
;
2974 function getCoords(ev
) {
2976 if (ev
.pageX
== null)
2981 while (el
&& el
!== self
.document
.documentElement
) {
2984 el
= 'offsetParent' in el
2988 w
= self
.element
.clientWidth
;
2989 h
= self
.element
.clientHeight
;
2990 x
= Math
.ceil((x
/ w
) * self
.cols
);
2991 y
= Math
.ceil((y
/ h
) * self
.rows
);
3008 on(el
, 'mousedown', function (ev
) {
3009 if (!self
.mouseEvents
)
3013 if (self
.vt200Mouse
) {
3014 ev
.overrideType
= 'mouseup';
3016 return self
.cancel(ev
);
3018 if (self
.normalMouse
)
3019 on(self
.document
, 'mousemove', sendMove
);
3020 if (!self
.x10Mouse
) {
3021 on(self
.document
, 'mouseup', function up(ev
) {
3023 if (self
.normalMouse
)
3024 off(self
.document
, 'mousemove', sendMove
);
3025 off(self
.document
, 'mouseup', up
);
3026 return self
.cancel(ev
);
3029 return self
.cancel(ev
);
3031 on(el
, 'wheel', function (ev
) {
3032 if (!self
.mouseEvents
)
3039 return self
.cancel(ev
);
3041 on(el
, 'wheel', function (ev
) {
3042 if (self
.mouseEvents
)
3044 self
.viewport
.onWheel(ev
);
3045 return self
.cancel(ev
);
3048 Terminal
.prototype.destroy = function () {
3049 this.readable
= false;
3050 this.writable
= false;
3052 this.handler = function () { };
3053 this.write = function () { };
3054 if (this.element
&& this.element
.parentNode
) {
3055 this.element
.parentNode
.removeChild(this.element
);
3058 Terminal
.prototype.refresh = function (start
, end
) {
3059 if (this.renderer
) {
3060 this.renderer
.queueRefresh(start
, end
);
3063 Terminal
.prototype.showCursor = function () {
3064 if (!this.cursorState
) {
3065 this.cursorState
= 1;
3066 this.refresh(this.y
, this.y
);
3069 Terminal
.prototype.scroll = function () {
3071 if (this.lines
.length
=== this.lines
.maxLength
) {
3072 this.lines
.trimStart(1);
3074 if (this.ydisp
!== 0) {
3079 if (!this.userScrolling
) {
3080 this.ydisp
= this.ybase
;
3082 row
= this.ybase
+ this.rows
- 1;
3083 row
-= this.rows
- 1 - this.scrollBottom
;
3084 if (row
=== this.lines
.length
) {
3085 this.lines
.push(this.blankLine());
3088 this.lines
.splice(row
, 0, this.blankLine());
3090 if (this.scrollTop
!== 0) {
3091 if (this.ybase
!== 0) {
3093 if (!this.userScrolling
) {
3094 this.ydisp
= this.ybase
;
3097 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
3099 this.updateRange(this.scrollTop
);
3100 this.updateRange(this.scrollBottom
);
3101 this.emit('scroll', this.ydisp
);
3103 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
3105 this.userScrolling
= true;
3107 else if (disp
+ this.ydisp
>= this.ybase
) {
3108 this.userScrolling
= false;
3111 if (this.ydisp
> this.ybase
) {
3112 this.ydisp
= this.ybase
;
3114 else if (this.ydisp
< 0) {
3117 if (!suppressScrollEvent
) {
3118 this.emit('scroll', this.ydisp
);
3120 this.refresh(0, this.rows
- 1);
3122 Terminal
.prototype.scrollPages = function (pageCount
) {
3123 this.scrollDisp(pageCount
* (this.rows
- 1));
3125 Terminal
.prototype.scrollToTop = function () {
3126 this.scrollDisp(-this.ydisp
);
3128 Terminal
.prototype.scrollToBottom = function () {
3129 this.scrollDisp(this.ybase
- this.ydisp
);
3131 Terminal
.prototype.write = function (data
) {
3132 this.writeBuffer
.push(data
);
3133 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
3134 this.send(EscapeSequences_1
.C0
.DC3
);
3135 this.xoffSentToCatchUp
= true;
3137 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
3138 this.writeInProgress
= true;
3140 setTimeout(function () {
3145 Terminal
.prototype.innerWrite = function () {
3146 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
3147 while (writeBatch
.length
> 0) {
3148 var data
= writeBatch
.shift();
3149 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
3150 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
3151 this.send(EscapeSequences_1
.C0
.DC1
);
3152 this.xoffSentToCatchUp
= false;
3154 this.refreshStart
= this.y
;
3155 this.refreshEnd
= this.y
;
3156 this.parser
.parse(data
);
3157 this.updateRange(this.y
);
3158 this.refresh(this.refreshStart
, this.refreshEnd
);
3160 if (this.writeBuffer
.length
> 0) {
3162 setTimeout(function () {
3167 this.writeInProgress
= false;
3170 Terminal
.prototype.writeln = function (data
) {
3171 this.write(data
+ '\r\n');
3173 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
3174 this.customKeydownHandler
= customKeydownHandler
;
3176 Terminal
.prototype.keyDown = function (ev
) {
3177 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
3180 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
3181 if (this.ybase
!== this.ydisp
) {
3182 this.scrollToBottom();
3187 var result
= this.evaluateKeyEscapeSequence(ev
);
3188 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
3189 this.writeStopped
= true;
3191 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
3192 this.writeStopped
= false;
3194 if (result
.scrollDisp
) {
3195 this.scrollDisp(result
.scrollDisp
);
3196 return this.cancel(ev
, true);
3198 if (isThirdLevelShift(this, ev
)) {
3201 if (result
.cancel
) {
3202 this.cancel(ev
, true);
3207 this.emit('keydown', ev
);
3208 this.emit('key', result
.key
, ev
);
3210 this.handler(result
.key
);
3211 return this.cancel(ev
, true);
3213 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
3217 scrollDisp
: undefined
3219 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
3220 switch (ev
.keyCode
) {
3223 result
.key
= EscapeSequences_1
.C0
.BS
;
3226 result
.key
= EscapeSequences_1
.C0
.DEL
;
3230 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
3233 result
.key
= EscapeSequences_1
.C0
.HT
;
3234 result
.cancel
= true;
3237 result
.key
= EscapeSequences_1
.C0
.CR
;
3238 result
.cancel
= true;
3241 result
.key
= EscapeSequences_1
.C0
.ESC
;
3242 result
.cancel
= true;
3246 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
3247 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
3248 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
3251 else if (this.applicationCursor
) {
3252 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
3255 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
3260 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
3261 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
3262 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
3265 else if (this.applicationCursor
) {
3266 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
3269 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
3274 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
3275 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
3276 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
3279 else if (this.applicationCursor
) {
3280 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
3283 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
3288 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
3289 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
3290 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
3293 else if (this.applicationCursor
) {
3294 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
3297 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
3301 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
3302 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
3307 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
3310 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
3315 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
3316 else if (this.applicationCursor
)
3317 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
3319 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
3323 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
3324 else if (this.applicationCursor
)
3325 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
3327 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
3331 result
.scrollDisp
= -(this.rows
- 1);
3334 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
3339 result
.scrollDisp
= this.rows
- 1;
3342 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
3347 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
3350 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
3355 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
3358 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
3363 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
3366 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
3371 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
3374 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
3379 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
3382 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
3387 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
3390 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
3395 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
3398 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
3403 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
3406 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
3411 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
3414 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
3419 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
3422 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
3427 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
3430 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
3435 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
3438 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
3442 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
3443 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3444 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
3446 else if (ev
.keyCode
=== 32) {
3447 result
.key
= String
.fromCharCode(0);
3449 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
3450 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
3452 else if (ev
.keyCode
=== 56) {
3453 result
.key
= String
.fromCharCode(127);
3455 else if (ev
.keyCode
=== 219) {
3456 result
.key
= String
.fromCharCode(27);
3458 else if (ev
.keyCode
=== 220) {
3459 result
.key
= String
.fromCharCode(28);
3461 else if (ev
.keyCode
=== 221) {
3462 result
.key
= String
.fromCharCode(29);
3465 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
3466 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3467 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
3469 else if (ev
.keyCode
=== 192) {
3470 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
3472 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
3473 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
3480 Terminal
.prototype.setgLevel = function (g
) {
3482 this.charset
= this.charsets
[g
];
3484 Terminal
.prototype.setgCharset = function (g
, charset
) {
3485 this.charsets
[g
] = charset
;
3486 if (this.glevel
=== g
) {
3487 this.charset
= charset
;
3490 Terminal
.prototype.keyPress = function (ev
) {
3496 else if (ev
.which
== null) {
3499 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3505 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3508 key
= String
.fromCharCode(key
);
3509 this.emit('keypress', key
, ev
);
3510 this.emit('key', key
, ev
);
3515 Terminal
.prototype.send = function (data
) {
3518 setTimeout(function () {
3519 self
.handler(self
.queue
);
3525 Terminal
.prototype.bell = function () {
3526 if (!this.visualBell
)
3529 this.element
.style
.borderColor
= 'white';
3530 setTimeout(function () {
3531 self
.element
.style
.borderColor
= '';
3536 Terminal
.prototype.log = function () {
3539 if (!this.context
.console
|| !this.context
.console
.log
)
3541 var args
= Array
.prototype.slice
.call(arguments
);
3542 this.context
.console
.log
.apply(this.context
.console
, args
);
3544 Terminal
.prototype.error = function () {
3547 if (!this.context
.console
|| !this.context
.console
.error
)
3549 var args
= Array
.prototype.slice
.call(arguments
);
3550 this.context
.console
.error
.apply(this.context
.console
, args
);
3552 Terminal
.prototype.resize = function (x
, y
) {
3553 if (isNaN(x
) || isNaN(y
)) {
3556 var line
, el
, i
, j
, ch
, addToY
;
3557 if (x
=== this.cols
&& y
=== this.rows
) {
3566 ch
= [this.defAttr
, ' ', 1];
3567 i
= this.lines
.length
;
3569 while (this.lines
.get(i
).length
< x
) {
3570 this.lines
.get(i
).push(ch
);
3575 i
= this.lines
.length
;
3577 while (this.lines
.get(i
).length
> x
) {
3578 this.lines
.get(i
).pop();
3583 this.setupStops(this.cols
);
3589 if (this.lines
.length
< y
+ this.ybase
) {
3590 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
3593 if (this.ydisp
> 0) {
3598 this.lines
.push(this.blankLine());
3601 if (this.children
.length
< y
) {
3608 if (this.lines
.length
> y
+ this.ybase
) {
3609 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
3617 if (this.children
.length
> y
) {
3618 el
= this.children
.shift();
3621 el
.parentNode
.removeChild(el
);
3636 this.scrollBottom
= y
- 1;
3637 this.charMeasure
.measure();
3638 this.refresh(0, this.rows
- 1);
3640 this.geometry
= [this.cols
, this.rows
];
3641 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
3643 Terminal
.prototype.updateRange = function (y
) {
3644 if (y
< this.refreshStart
)
3645 this.refreshStart
= y
;
3646 if (y
> this.refreshEnd
)
3647 this.refreshEnd
= y
;
3649 Terminal
.prototype.maxRange = function () {
3650 this.refreshStart
= 0;
3651 this.refreshEnd
= this.rows
- 1;
3653 Terminal
.prototype.setupStops = function (i
) {
3655 if (!this.tabs
[i
]) {
3656 i
= this.prevStop(i
);
3663 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
3664 this.tabs
[i
] = true;
3667 Terminal
.prototype.prevStop = function (x
) {
3670 while (!this.tabs
[--x
] && x
> 0)
3672 return x
>= this.cols
3676 Terminal
.prototype.nextStop = function (x
) {
3679 while (!this.tabs
[++x
] && x
< this.cols
)
3681 return x
>= this.cols
3685 Terminal
.prototype.eraseRight = function (x
, y
) {
3686 var line
= this.lines
.get(this.ybase
+ y
);
3690 var ch
= [this.eraseAttr(), ' ', 1];
3691 for (; x
< this.cols
; x
++) {
3694 this.updateRange(y
);
3696 Terminal
.prototype.eraseLeft = function (x
, y
) {
3697 var line
= this.lines
.get(this.ybase
+ y
);
3701 var ch
= [this.eraseAttr(), ' ', 1];
3706 this.updateRange(y
);
3708 Terminal
.prototype.clear = function () {
3709 if (this.ybase
=== 0 && this.y
=== 0) {
3712 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
3713 this.lines
.length
= 1;
3717 for (var i
= 1; i
< this.rows
; i
++) {
3718 this.lines
.push(this.blankLine());
3720 this.refresh(0, this.rows
- 1);
3721 this.emit('scroll', this.ydisp
);
3723 Terminal
.prototype.eraseLine = function (y
) {
3724 this.eraseRight(0, y
);
3726 Terminal
.prototype.blankLine = function (cur
) {
3730 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
3731 for (; i
< this.cols
; i
++) {
3736 Terminal
.prototype.ch = function (cur
) {
3738 ? [this.eraseAttr(), ' ', 1]
3739 : [this.defAttr
, ' ', 1];
3741 Terminal
.prototype.is = function (term
) {
3742 var name
= this.termName
;
3743 return (name
+ '').indexOf(term
) === 0;
3745 Terminal
.prototype.handler = function (data
) {
3746 if (this.options
.disableStdin
) {
3749 if (this.ybase
!== this.ydisp
) {
3750 this.scrollToBottom();
3752 this.emit('data', data
);
3754 Terminal
.prototype.handleTitle = function (title
) {
3755 this.emit('title', title
);
3757 Terminal
.prototype.index = function () {
3759 if (this.y
> this.scrollBottom
) {
3763 if (this.x
>= this.cols
) {
3767 Terminal
.prototype.reverseIndex = function () {
3769 if (this.y
=== this.scrollTop
) {
3770 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
3771 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
3772 this.updateRange(this.scrollTop
);
3773 this.updateRange(this.scrollBottom
);
3779 Terminal
.prototype.reset = function () {
3780 this.options
.rows
= this.rows
;
3781 this.options
.cols
= this.cols
;
3782 var customKeydownHandler
= this.customKeydownHandler
;
3783 Terminal
.call(this, this.options
);
3784 this.customKeydownHandler
= customKeydownHandler
;
3785 this.refresh(0, this.rows
- 1);
3786 this.viewport
.syncScrollArea();
3788 Terminal
.prototype.tabSet = function () {
3789 this.tabs
[this.x
] = true;
3791 function on(el
, type
, handler
, capture
) {
3792 if (!Array
.isArray(el
)) {
3795 el
.forEach(function (element
) {
3796 element
.addEventListener(type
, handler
, capture
|| false);
3799 function off(el
, type
, handler
, capture
) {
3800 el
.removeEventListener(type
, handler
, capture
|| false);
3802 function cancel(ev
, force
) {
3803 if (!this.cancelEvents
&& !force
) {
3806 ev
.preventDefault();
3807 ev
.stopPropagation();
3810 function inherits(child
, parent
) {
3812 this.constructor = child
;
3814 f
.prototype = parent
.prototype;
3815 child
.prototype = new f
;
3817 function indexOf(obj
, el
) {
3825 function isThirdLevelShift(term
, ev
) {
3826 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
3827 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
3828 if (ev
.type
== 'keypress') {
3829 return thirdLevelKey
;
3831 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
3833 Terminal
.prototype.matchColor
= matchColor
;
3834 function matchColor(r1
, g1
, b1
) {
3835 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
3836 if (matchColor
._cache
[hash
] != null) {
3837 return matchColor
._cache
[hash
];
3839 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
3840 for (; i
< Terminal
.vcolors
.length
; i
++) {
3841 c
= Terminal
.vcolors
[i
];
3845 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
3855 return matchColor
._cache
[hash
] = li
;
3857 matchColor
._cache
= {};
3858 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
3859 return Math
.pow(30 * (r1
- r2
), 2)
3860 + Math
.pow(59 * (g1
- g2
), 2)
3861 + Math
.pow(11 * (b1
- b2
), 2);
3863 function each(obj
, iter
, con
) {
3865 return obj
.forEach(iter
, con
);
3866 for (var i
= 0; i
< obj
.length
; i
++) {
3867 iter
.call(con
, obj
[i
], i
, obj
);
3870 function wasMondifierKeyOnlyEvent(ev
) {
3871 return ev
.keyCode
=== 16 ||
3872 ev
.keyCode
=== 17 ||
3875 function keys(obj
) {
3877 return Object
.keys(obj
);
3880 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
3886 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
3887 Terminal
.inherits
= inherits
;
3890 Terminal
.cancel
= cancel
;
3891 module
.exports
= Terminal
;
3895 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Parser":6,"./Renderer":7,"./Viewport":8,"./handlers/Clipboard":9,"./utils/Browser":10,"./utils/CharMeasure":11,"./utils/CircularList":12}]},{},[14])(14)
3897 //# sourceMappingURL=xterm.js.map