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
['='] = {
161 },{}],2:[function(require
,module
,exports
){
163 var CompositionHelper
= (function () {
164 function CompositionHelper(textarea
, compositionView
, terminal
) {
165 this.textarea
= textarea
;
166 this.compositionView
= compositionView
;
167 this.terminal
= terminal
;
168 this.isComposing
= false;
169 this.isSendingComposition
= false;
170 this.compositionPosition
= { start
: null, end
: null };
172 CompositionHelper
.prototype.compositionstart = function () {
173 this.isComposing
= true;
174 this.compositionPosition
.start
= this.textarea
.value
.length
;
175 this.compositionView
.textContent
= '';
176 this.compositionView
.classList
.add('active');
178 CompositionHelper
.prototype.compositionupdate = function (ev
) {
180 this.compositionView
.textContent
= ev
.data
;
181 this.updateCompositionElements();
182 setTimeout(function () {
183 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
186 CompositionHelper
.prototype.compositionend = function () {
187 this.finalizeComposition(true);
189 CompositionHelper
.prototype.keydown = function (ev
) {
190 if (this.isComposing
|| this.isSendingComposition
) {
191 if (ev
.keyCode
=== 229) {
194 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
198 this.finalizeComposition(false);
201 if (ev
.keyCode
=== 229) {
202 this.handleAnyTextareaChanges();
207 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
209 this.compositionView
.classList
.remove('active');
210 this.isComposing
= false;
211 this.clearTextareaPosition();
212 if (!waitForPropogation
) {
213 this.isSendingComposition
= false;
214 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
215 this.terminal
.handler(input
);
218 var currentCompositionPosition_1
= {
219 start
: this.compositionPosition
.start
,
220 end
: this.compositionPosition
.end
,
222 this.isSendingComposition
= true;
223 setTimeout(function () {
224 if (_this
.isSendingComposition
) {
225 _this
.isSendingComposition
= false;
227 if (_this
.isComposing
) {
228 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
231 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
233 _this
.terminal
.handler(input
);
238 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
240 var oldValue
= this.textarea
.value
;
241 setTimeout(function () {
242 if (!_this
.isComposing
) {
243 var newValue
= _this
.textarea
.value
;
244 var diff
= newValue
.replace(oldValue
, '');
245 if (diff
.length
> 0) {
246 _this
.terminal
.handler(diff
);
251 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
253 if (!this.isComposing
) {
256 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
258 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
259 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
260 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
261 this.compositionView
.style
.top
= cursorTop
+ 'px';
262 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
263 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
264 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
265 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
266 this.textarea
.style
.top
= cursorTop
+ 'px';
267 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
268 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
269 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
272 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
276 CompositionHelper
.prototype.clearTextareaPosition = function () {
277 this.textarea
.style
.left
= '';
278 this.textarea
.style
.top
= '';
281 return CompositionHelper
;
283 exports
.CompositionHelper
= CompositionHelper
;
285 },{}],3:[function(require
,module
,exports
){
323 })(C0
= exports
.C0
|| (exports
.C0
= {}));
326 },{}],4:[function(require
,module
,exports
){
329 var EventEmitter
= (function () {
330 function EventEmitter() {
331 this._events
= this._events
|| {};
333 EventEmitter
.prototype.on = function (type
, listener
) {
334 this._events
[type
] = this._events
[type
] || [];
335 this._events
[type
].push(listener
);
337 EventEmitter
.prototype.off = function (type
, listener
) {
338 if (!this._events
[type
]) {
341 var obj
= this._events
[type
];
344 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
350 EventEmitter
.prototype.removeAllListeners = function (type
) {
351 if (this._events
[type
]) {
352 delete this._events
[type
];
355 EventEmitter
.prototype.once = function (type
, listener
) {
357 var args
= Array
.prototype.slice
.call(arguments
);
359 return listener
.apply(this, args
);
361 on
.listener
= listener
;
362 return this.on(type
, on
);
364 EventEmitter
.prototype.emit = function (type
) {
365 if (!this._events
[type
]) {
368 var args
= Array
.prototype.slice
.call(arguments
, 1);
369 var obj
= this._events
[type
];
370 for (var i
= 0; i
< obj
.length
; i
++) {
371 obj
[i
].apply(this, args
);
374 EventEmitter
.prototype.listeners = function (type
) {
375 return this._events
[type
] || [];
379 exports
.EventEmitter
= EventEmitter
;
381 },{}],5:[function(require
,module
,exports
){
383 var EscapeSequences_1
= require("./EscapeSequences");
384 var Charsets_1
= require("./Charsets");
385 var InputHandler
= (function () {
386 function InputHandler(_terminal
) {
387 this._terminal
= _terminal
;
389 InputHandler
.prototype.addChar = function (char, code
) {
391 var ch_width
= wcwidth(code
);
392 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
393 char = this._terminal
.charset
[char];
395 var row
= this._terminal
.y
+ this._terminal
.ybase
;
396 if (!ch_width
&& this._terminal
.x
) {
397 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 1]) {
398 if (!this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][2]) {
399 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 2])
400 this._terminal
.lines
.get(row
)[this._terminal
.x
- 2][1] += char;
403 this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][1] += char;
405 this._terminal
.updateRange(this._terminal
.y
);
409 if (this._terminal
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
410 if (this._terminal
.wraparoundMode
) {
411 this._terminal
.x
= 0;
413 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
415 this._terminal
.scroll();
423 row
= this._terminal
.y
+ this._terminal
.ybase
;
424 if (this._terminal
.insertMode
) {
425 for (var moves
= 0; moves
< ch_width
; ++moves
) {
426 var removed
= this._terminal
.lines
.get(this._terminal
.y
+ this._terminal
.ybase
).pop();
428 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2]
429 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2)
430 this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
431 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
434 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, char, ch_width
];
436 this._terminal
.updateRange(this._terminal
.y
);
437 if (ch_width
=== 2) {
438 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, '', 0];
443 InputHandler
.prototype.bell = function () {
445 if (!this._terminal
.visualBell
) {
448 this._terminal
.element
.style
.borderColor
= 'white';
449 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
450 if (this._terminal
.popOnBell
) {
451 this._terminal
.focus();
454 InputHandler
.prototype.lineFeed = function () {
455 if (this._terminal
.convertEol
) {
456 this._terminal
.x
= 0;
459 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
461 this._terminal
.scroll();
463 if (this._terminal
.x
>= this._terminal
.cols
) {
467 InputHandler
.prototype.carriageReturn = function () {
468 this._terminal
.x
= 0;
470 InputHandler
.prototype.backspace = function () {
471 if (this._terminal
.x
> 0) {
475 InputHandler
.prototype.tab = function () {
476 this._terminal
.x
= this._terminal
.nextStop();
478 InputHandler
.prototype.shiftOut = function () {
479 this._terminal
.setgLevel(1);
481 InputHandler
.prototype.shiftIn = function () {
482 this._terminal
.setgLevel(0);
484 InputHandler
.prototype.insertChars = function (params
) {
485 var param
, row
, j
, ch
;
489 row
= this._terminal
.y
+ this._terminal
.ybase
;
490 j
= this._terminal
.x
;
491 ch
= [this._terminal
.eraseAttr(), ' ', 1];
492 while (param
-- && j
< this._terminal
.cols
) {
493 this._terminal
.lines
.get(row
).splice(j
++, 0, ch
);
494 this._terminal
.lines
.get(row
).pop();
497 InputHandler
.prototype.cursorUp = function (params
) {
498 var param
= params
[0];
502 this._terminal
.y
-= param
;
503 if (this._terminal
.y
< 0) {
504 this._terminal
.y
= 0;
507 InputHandler
.prototype.cursorDown = function (params
) {
508 var param
= params
[0];
512 this._terminal
.y
+= param
;
513 if (this._terminal
.y
>= this._terminal
.rows
) {
514 this._terminal
.y
= this._terminal
.rows
- 1;
516 if (this._terminal
.x
>= this._terminal
.cols
) {
520 InputHandler
.prototype.cursorForward = function (params
) {
521 var param
= params
[0];
525 this._terminal
.x
+= param
;
526 if (this._terminal
.x
>= this._terminal
.cols
) {
527 this._terminal
.x
= this._terminal
.cols
- 1;
530 InputHandler
.prototype.cursorBackward = function (params
) {
531 var param
= params
[0];
535 if (this._terminal
.x
>= this._terminal
.cols
) {
538 this._terminal
.x
-= param
;
539 if (this._terminal
.x
< 0) {
540 this._terminal
.x
= 0;
543 InputHandler
.prototype.cursorNextLine = function (params
) {
544 var param
= params
[0];
548 this._terminal
.y
+= param
;
549 if (this._terminal
.y
>= this._terminal
.rows
) {
550 this._terminal
.y
= this._terminal
.rows
- 1;
552 this._terminal
.x
= 0;
555 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
556 var param
= params
[0];
560 this._terminal
.y
-= param
;
561 if (this._terminal
.y
< 0) {
562 this._terminal
.y
= 0;
564 this._terminal
.x
= 0;
567 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
568 var param
= params
[0];
572 this._terminal
.x
= param
- 1;
574 InputHandler
.prototype.cursorPosition = function (params
) {
577 if (params
.length
>= 2) {
586 else if (row
>= this._terminal
.rows
) {
587 row
= this._terminal
.rows
- 1;
592 else if (col
>= this._terminal
.cols
) {
593 col
= this._terminal
.cols
- 1;
595 this._terminal
.x
= col
;
596 this._terminal
.y
= row
;
598 InputHandler
.prototype.cursorForwardTab = function (params
) {
599 var param
= params
[0] || 1;
601 this._terminal
.x
= this._terminal
.nextStop();
604 InputHandler
.prototype.eraseInDisplay = function (params
) {
608 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
609 j
= this._terminal
.y
+ 1;
610 for (; j
< this._terminal
.rows
; j
++) {
611 this._terminal
.eraseLine(j
);
615 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
616 j
= this._terminal
.y
;
618 this._terminal
.eraseLine(j
);
622 j
= this._terminal
.rows
;
624 this._terminal
.eraseLine(j
);
631 InputHandler
.prototype.eraseInLine = function (params
) {
634 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
637 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
640 this._terminal
.eraseLine(this._terminal
.y
);
644 InputHandler
.prototype.insertLines = function (params
) {
650 row
= this._terminal
.y
+ this._terminal
.ybase
;
651 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
652 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
+ 1;
654 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
655 this._terminal
.lines
.trimStart(1);
656 this._terminal
.ybase
--;
657 this._terminal
.ydisp
--;
661 this._terminal
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
662 this._terminal
.lines
.splice(j
, 1);
664 this._terminal
.updateRange(this._terminal
.y
);
665 this._terminal
.updateRange(this._terminal
.scrollBottom
);
667 InputHandler
.prototype.deleteLines = function (params
) {
673 row
= this._terminal
.y
+ this._terminal
.ybase
;
674 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
675 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
;
677 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
678 this._terminal
.lines
.trimStart(1);
679 this._terminal
.ybase
-= 1;
680 this._terminal
.ydisp
-= 1;
682 this._terminal
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
683 this._terminal
.lines
.splice(row
, 1);
685 this._terminal
.updateRange(this._terminal
.y
);
686 this._terminal
.updateRange(this._terminal
.scrollBottom
);
688 InputHandler
.prototype.deleteChars = function (params
) {
694 row
= this._terminal
.y
+ this._terminal
.ybase
;
695 ch
= [this._terminal
.eraseAttr(), ' ', 1];
697 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 1);
698 this._terminal
.lines
.get(row
).push(ch
);
701 InputHandler
.prototype.scrollUp = function (params
) {
702 var param
= params
[0] || 1;
704 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 1);
705 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 0, this._terminal
.blankLine());
707 this._terminal
.updateRange(this._terminal
.scrollTop
);
708 this._terminal
.updateRange(this._terminal
.scrollBottom
);
710 InputHandler
.prototype.scrollDown = function (params
) {
711 var param
= params
[0] || 1;
713 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 1);
714 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 0, this._terminal
.blankLine());
716 this._terminal
.updateRange(this._terminal
.scrollTop
);
717 this._terminal
.updateRange(this._terminal
.scrollBottom
);
719 InputHandler
.prototype.eraseChars = function (params
) {
720 var param
, row
, j
, ch
;
725 row
= this._terminal
.y
+ this._terminal
.ybase
;
726 j
= this._terminal
.x
;
727 ch
= [this._terminal
.eraseAttr(), ' ', 1];
728 while (param
-- && j
< this._terminal
.cols
) {
729 this._terminal
.lines
.get(row
)[j
++] = ch
;
732 InputHandler
.prototype.cursorBackwardTab = function (params
) {
733 var param
= params
[0] || 1;
735 this._terminal
.x
= this._terminal
.prevStop();
738 InputHandler
.prototype.charPosAbsolute = function (params
) {
739 var param
= params
[0];
743 this._terminal
.x
= param
- 1;
744 if (this._terminal
.x
>= this._terminal
.cols
) {
745 this._terminal
.x
= this._terminal
.cols
- 1;
748 InputHandler
.prototype.HPositionRelative = function (params
) {
749 var param
= params
[0];
753 this._terminal
.x
+= param
;
754 if (this._terminal
.x
>= this._terminal
.cols
) {
755 this._terminal
.x
= this._terminal
.cols
- 1;
758 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
759 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];
761 line
[this._terminal
.x
++] = ch
;
764 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
768 if (!this._terminal
.prefix
) {
769 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
770 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
772 else if (this._terminal
.is('linux')) {
773 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
776 else if (this._terminal
.prefix
=== '>') {
777 if (this._terminal
.is('xterm')) {
778 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
780 else if (this._terminal
.is('rxvt-unicode')) {
781 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
783 else if (this._terminal
.is('linux')) {
784 this._terminal
.send(params
[0] + 'c');
786 else if (this._terminal
.is('screen')) {
787 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
791 InputHandler
.prototype.linePosAbsolute = function (params
) {
792 var param
= params
[0];
796 this._terminal
.y
= param
- 1;
797 if (this._terminal
.y
>= this._terminal
.rows
) {
798 this._terminal
.y
= this._terminal
.rows
- 1;
801 InputHandler
.prototype.VPositionRelative = function (params
) {
802 var param
= params
[0];
806 this._terminal
.y
+= param
;
807 if (this._terminal
.y
>= this._terminal
.rows
) {
808 this._terminal
.y
= this._terminal
.rows
- 1;
810 if (this._terminal
.x
>= this._terminal
.cols
) {
814 InputHandler
.prototype.HVPosition = function (params
) {
819 this._terminal
.y
= params
[0] - 1;
820 if (this._terminal
.y
>= this._terminal
.rows
) {
821 this._terminal
.y
= this._terminal
.rows
- 1;
823 this._terminal
.x
= params
[1] - 1;
824 if (this._terminal
.x
>= this._terminal
.cols
) {
825 this._terminal
.x
= this._terminal
.cols
- 1;
828 InputHandler
.prototype.tabClear = function (params
) {
829 var param
= params
[0];
831 delete this._terminal
.tabs
[this._terminal
.x
];
833 else if (param
=== 3) {
834 this._terminal
.tabs
= {};
837 InputHandler
.prototype.setMode = function (params
) {
838 if (params
.length
> 1) {
839 for (var i
= 0; i
< params
.length
; i
++) {
840 this.setMode([params
[i
]]);
844 if (!this._terminal
.prefix
) {
847 this._terminal
.insertMode
= true;
853 else if (this._terminal
.prefix
=== '?') {
856 this._terminal
.applicationCursor
= true;
859 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
860 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
861 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
862 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
865 this._terminal
.savedCols
= this._terminal
.cols
;
866 this._terminal
.resize(132, this._terminal
.rows
);
869 this._terminal
.originMode
= true;
872 this._terminal
.wraparoundMode
= true;
877 this._terminal
.log('Serial port requested application keypad.');
878 this._terminal
.applicationKeypad
= true;
879 this._terminal
.viewport
.syncScrollArea();
885 this._terminal
.x10Mouse
= params
[0] === 9;
886 this._terminal
.vt200Mouse
= params
[0] === 1000;
887 this._terminal
.normalMouse
= params
[0] > 1000;
888 this._terminal
.mouseEvents
= true;
889 this._terminal
.element
.style
.cursor
= 'default';
890 this._terminal
.log('Binding to mouse events.');
893 this._terminal
.sendFocus
= true;
896 this._terminal
.utfMouse
= true;
899 this._terminal
.sgrMouse
= true;
902 this._terminal
.urxvtMouse
= true;
905 this._terminal
.cursorHidden
= false;
911 if (!this._terminal
.normal
) {
913 lines
: this._terminal
.lines
,
914 ybase
: this._terminal
.ybase
,
915 ydisp
: this._terminal
.ydisp
,
918 scrollTop
: this._terminal
.scrollTop
,
919 scrollBottom
: this._terminal
.scrollBottom
,
920 tabs
: this._terminal
.tabs
922 this._terminal
.reset();
923 this._terminal
.viewport
.syncScrollArea();
924 this._terminal
.normal
= normal
;
925 this._terminal
.showCursor();
931 InputHandler
.prototype.resetMode = function (params
) {
932 if (params
.length
> 1) {
933 for (var i
= 0; i
< params
.length
; i
++) {
934 this.resetMode([params
[i
]]);
938 if (!this._terminal
.prefix
) {
941 this._terminal
.insertMode
= false;
947 else if (this._terminal
.prefix
=== '?') {
950 this._terminal
.applicationCursor
= false;
953 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
954 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
956 delete this._terminal
.savedCols
;
959 this._terminal
.originMode
= false;
962 this._terminal
.wraparoundMode
= false;
967 this._terminal
.log('Switching back to normal keypad.');
968 this._terminal
.applicationKeypad
= false;
969 this._terminal
.viewport
.syncScrollArea();
975 this._terminal
.x10Mouse
= false;
976 this._terminal
.vt200Mouse
= false;
977 this._terminal
.normalMouse
= false;
978 this._terminal
.mouseEvents
= false;
979 this._terminal
.element
.style
.cursor
= '';
982 this._terminal
.sendFocus
= false;
985 this._terminal
.utfMouse
= false;
988 this._terminal
.sgrMouse
= false;
991 this._terminal
.urxvtMouse
= false;
994 this._terminal
.cursorHidden
= true;
1000 if (this._terminal
.normal
) {
1001 this._terminal
.lines
= this._terminal
.normal
.lines
;
1002 this._terminal
.ybase
= this._terminal
.normal
.ybase
;
1003 this._terminal
.ydisp
= this._terminal
.normal
.ydisp
;
1004 this._terminal
.x
= this._terminal
.normal
.x
;
1005 this._terminal
.y
= this._terminal
.normal
.y
;
1006 this._terminal
.scrollTop
= this._terminal
.normal
.scrollTop
;
1007 this._terminal
.scrollBottom
= this._terminal
.normal
.scrollBottom
;
1008 this._terminal
.tabs
= this._terminal
.normal
.tabs
;
1009 this._terminal
.normal
= null;
1010 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1011 this._terminal
.viewport
.syncScrollArea();
1012 this._terminal
.showCursor();
1018 InputHandler
.prototype.charAttributes = function (params
) {
1019 if (params
.length
=== 1 && params
[0] === 0) {
1020 this._terminal
.curAttr
= this._terminal
.defAttr
;
1023 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1024 for (; i
< l
; i
++) {
1026 if (p
>= 30 && p
<= 37) {
1029 else if (p
>= 40 && p
<= 47) {
1032 else if (p
>= 90 && p
<= 97) {
1036 else if (p
>= 100 && p
<= 107) {
1041 flags
= this._terminal
.defAttr
>> 18;
1042 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1043 bg
= this._terminal
.defAttr
& 0x1ff;
1060 else if (p
=== 22) {
1063 else if (p
=== 24) {
1066 else if (p
=== 25) {
1069 else if (p
=== 27) {
1072 else if (p
=== 28) {
1075 else if (p
=== 39) {
1076 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1078 else if (p
=== 49) {
1079 bg
= this._terminal
.defAttr
& 0x1ff;
1081 else if (p
=== 38) {
1082 if (params
[i
+ 1] === 2) {
1084 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1089 else if (params
[i
+ 1] === 5) {
1091 p
= params
[i
] & 0xff;
1095 else if (p
=== 48) {
1096 if (params
[i
+ 1] === 2) {
1098 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1103 else if (params
[i
+ 1] === 5) {
1105 p
= params
[i
] & 0xff;
1109 else if (p
=== 100) {
1110 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1111 bg
= this._terminal
.defAttr
& 0x1ff;
1114 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1117 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1119 InputHandler
.prototype.deviceStatus = function (params
) {
1120 if (!this._terminal
.prefix
) {
1121 switch (params
[0]) {
1123 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1126 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1127 + (this._terminal
.y
+ 1)
1129 + (this._terminal
.x
+ 1)
1134 else if (this._terminal
.prefix
=== '?') {
1135 switch (params
[0]) {
1137 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1138 + (this._terminal
.y
+ 1)
1140 + (this._terminal
.x
+ 1)
1154 InputHandler
.prototype.softReset = function (params
) {
1155 this._terminal
.cursorHidden
= false;
1156 this._terminal
.insertMode
= false;
1157 this._terminal
.originMode
= false;
1158 this._terminal
.wraparoundMode
= false;
1159 this._terminal
.applicationKeypad
= false;
1160 this._terminal
.viewport
.syncScrollArea();
1161 this._terminal
.applicationCursor
= false;
1162 this._terminal
.scrollTop
= 0;
1163 this._terminal
.scrollBottom
= this._terminal
.rows
- 1;
1164 this._terminal
.curAttr
= this._terminal
.defAttr
;
1165 this._terminal
.x
= this._terminal
.y
= 0;
1166 this._terminal
.charset
= null;
1167 this._terminal
.glevel
= 0;
1168 this._terminal
.charsets
= [null];
1170 InputHandler
.prototype.setCursorStyle = function (params
) {
1171 var param
= params
[0] < 1 ? 1 : params
[0];
1175 this._terminal
.setOption('cursorStyle', 'block');
1179 this._terminal
.setOption('cursorStyle', 'underline');
1183 this._terminal
.setOption('cursorStyle', 'bar');
1186 var isBlinking
= param
% 2 === 1;
1187 this._terminal
.setOption('cursorBlink', isBlinking
);
1189 InputHandler
.prototype.setScrollRegion = function (params
) {
1190 if (this._terminal
.prefix
)
1192 this._terminal
.scrollTop
= (params
[0] || 1) - 1;
1193 this._terminal
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1194 this._terminal
.x
= 0;
1195 this._terminal
.y
= 0;
1197 InputHandler
.prototype.saveCursor = function (params
) {
1198 this._terminal
.savedX
= this._terminal
.x
;
1199 this._terminal
.savedY
= this._terminal
.y
;
1201 InputHandler
.prototype.restoreCursor = function (params
) {
1202 this._terminal
.x
= this._terminal
.savedX
|| 0;
1203 this._terminal
.y
= this._terminal
.savedY
|| 0;
1205 return InputHandler
;
1207 exports
.InputHandler
= InputHandler
;
1208 var wcwidth
= (function (opts
) {
1210 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1211 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1212 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1213 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1214 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1215 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1216 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1217 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1218 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1219 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1220 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1221 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1222 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1223 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1224 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1225 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1226 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1227 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1228 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1229 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1230 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1231 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1232 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1233 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1234 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1235 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1236 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1237 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1238 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1239 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1240 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1241 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1242 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1243 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1244 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1245 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1246 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1247 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1248 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1249 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1250 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1251 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1252 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1253 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1254 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1255 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1256 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1259 function bisearch(ucs
) {
1261 var max
= COMBINING
.length
- 1;
1263 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
1265 while (max
>= min
) {
1266 mid
= Math
.floor((min
+ max
) / 2);
1267 if (ucs
> COMBINING
[mid
][1])
1269 else if (ucs
< COMBINING
[mid
][0])
1276 function wcwidth(ucs
) {
1279 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1280 return opts
.control
;
1288 function isWide(ucs
) {
1289 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1292 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1293 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1294 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1295 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1296 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1297 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1298 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
1299 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
1300 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
1303 })({ nul
: 0, control
: 0 });
1305 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require
,module
,exports
){
1307 var EscapeSequences_1
= require("./EscapeSequences");
1308 var Charsets_1
= require("./Charsets");
1309 var normalStateHandler
= {};
1310 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1311 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1312 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1313 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1314 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1315 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1316 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1317 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1318 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1319 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1320 var escapedStateHandler
= {};
1321 escapedStateHandler
['['] = function (parser
, terminal
) {
1322 terminal
.params
= [];
1323 terminal
.currentParam
= 0;
1324 parser
.setState(ParserState
.CSI_PARAM
);
1326 escapedStateHandler
[']'] = function (parser
, terminal
) {
1327 terminal
.params
= [];
1328 terminal
.currentParam
= 0;
1329 parser
.setState(ParserState
.OSC
);
1331 escapedStateHandler
['P'] = function (parser
, terminal
) {
1332 terminal
.params
= [];
1333 terminal
.currentParam
= 0;
1334 parser
.setState(ParserState
.DCS
);
1336 escapedStateHandler
['_'] = function (parser
, terminal
) {
1337 parser
.setState(ParserState
.IGNORE
);
1339 escapedStateHandler
['^'] = function (parser
, terminal
) {
1340 parser
.setState(ParserState
.IGNORE
);
1342 escapedStateHandler
['c'] = function (parser
, terminal
) {
1345 escapedStateHandler
['E'] = function (parser
, terminal
) {
1348 parser
.setState(ParserState
.NORMAL
);
1350 escapedStateHandler
['D'] = function (parser
, terminal
) {
1352 parser
.setState(ParserState
.NORMAL
);
1354 escapedStateHandler
['M'] = function (parser
, terminal
) {
1355 terminal
.reverseIndex();
1356 parser
.setState(ParserState
.NORMAL
);
1358 escapedStateHandler
['%'] = function (parser
, terminal
) {
1359 terminal
.setgLevel(0);
1360 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1361 parser
.setState(ParserState
.NORMAL
);
1362 parser
.skipNextChar();
1364 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1365 var csiParamStateHandler
= {};
1366 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1367 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1368 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1369 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1370 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1371 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1372 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1373 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1374 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1375 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1376 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1377 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1378 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1379 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1380 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1381 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1382 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1383 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1384 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1385 var csiStateHandler
= {};
1386 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1387 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1388 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1389 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1390 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1391 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1392 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1393 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1394 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1395 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1396 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1397 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1398 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1399 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1400 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1401 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1402 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1403 if (params
.length
< 2 && !prefix
) {
1404 handler
.scrollDown(params
);
1407 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1408 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1409 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1410 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1411 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1412 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1413 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1414 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1415 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1416 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1417 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1418 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1419 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1420 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1421 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1424 handler
.softReset(params
);
1428 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1429 if (postfix
=== ' ') {
1430 handler
.setCursorStyle(params
);
1433 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1434 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1435 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1436 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1438 (function (ParserState
) {
1439 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1440 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1441 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1442 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1443 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1444 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1445 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1446 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1447 })(ParserState
|| (ParserState
= {}));
1448 var Parser
= (function () {
1449 function Parser(_inputHandler
, _terminal
) {
1450 this._inputHandler
= _inputHandler
;
1451 this._terminal
= _terminal
;
1452 this._state
= ParserState
.NORMAL
;
1454 Parser
.prototype.parse = function (data
) {
1455 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1457 if (this._terminal
.surrogate_high
) {
1458 data
= this._terminal
.surrogate_high
+ data
;
1459 this._terminal
.surrogate_high
= '';
1461 for (; this._position
< l
; this._position
++) {
1462 ch
= data
[this._position
];
1463 code
= data
.charCodeAt(this._position
);
1464 if (0xD800 <= code
&& code
<= 0xDBFF) {
1465 low
= data
.charCodeAt(this._position
+ 1);
1467 this._terminal
.surrogate_high
= ch
;
1470 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1471 ch
+= data
.charAt(this._position
+ 1);
1473 if (0xDC00 <= code
&& code
<= 0xDFFF)
1475 switch (this._state
) {
1476 case ParserState
.NORMAL
:
1477 if (ch
in normalStateHandler
) {
1478 normalStateHandler
[ch
](this, this._inputHandler
);
1481 this._inputHandler
.addChar(ch
, code
);
1484 case ParserState
.ESCAPED
:
1485 if (ch
in escapedStateHandler
) {
1486 escapedStateHandler
[ch
](this, this._terminal
);
1498 this._terminal
.gcharset
= 0;
1501 this._terminal
.gcharset
= 1;
1504 this._terminal
.gcharset
= 2;
1507 this._terminal
.gcharset
= 3;
1510 this._terminal
.gcharset
= 1;
1513 this._terminal
.gcharset
= 2;
1516 this._state
= ParserState
.CHARSET
;
1519 this._terminal
.gcharset
= 3;
1520 this._state
= ParserState
.CHARSET
;
1528 this._terminal
.setgLevel(2);
1531 this._terminal
.setgLevel(3);
1534 this._terminal
.setgLevel(3);
1537 this._terminal
.setgLevel(2);
1540 this._terminal
.setgLevel(1);
1543 this._inputHandler
.saveCursor();
1544 this._state
= ParserState
.NORMAL
;
1547 this._inputHandler
.restoreCursor();
1548 this._state
= ParserState
.NORMAL
;
1551 this._state
= ParserState
.NORMAL
;
1555 this._terminal
.tabSet();
1556 this._state
= ParserState
.NORMAL
;
1559 this._terminal
.log('Serial port requested application keypad.');
1560 this._terminal
.applicationKeypad
= true;
1561 this._terminal
.viewport
.syncScrollArea();
1562 this._state
= ParserState
.NORMAL
;
1565 this._terminal
.log('Switching back to normal keypad.');
1566 this._terminal
.applicationKeypad
= false;
1567 this._terminal
.viewport
.syncScrollArea();
1568 this._state
= ParserState
.NORMAL
;
1571 this._state
= ParserState
.NORMAL
;
1572 this._terminal
.error('Unknown ESC control: %s.', ch
);
1576 case ParserState
.CHARSET
:
1577 if (ch
in Charsets_1
.CHARSETS
) {
1578 cs
= Charsets_1
.CHARSETS
[ch
];
1580 this.skipNextChar();
1584 cs
= Charsets_1
.DEFAULT_CHARSET
;
1586 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1587 this._terminal
.gcharset
= null;
1588 this._state
= ParserState
.NORMAL
;
1590 case ParserState
.OSC
:
1591 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1592 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1594 this._terminal
.params
.push(this._terminal
.currentParam
);
1595 switch (this._terminal
.params
[0]) {
1599 if (this._terminal
.params
[1]) {
1600 this._terminal
.title
= this._terminal
.params
[1];
1601 this._terminal
.handleTitle(this._terminal
.title
);
1641 this._terminal
.params
= [];
1642 this._terminal
.currentParam
= 0;
1643 this._state
= ParserState
.NORMAL
;
1646 if (!this._terminal
.params
.length
) {
1647 if (ch
>= '0' && ch
<= '9') {
1648 this._terminal
.currentParam
=
1649 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1651 else if (ch
=== ';') {
1652 this._terminal
.params
.push(this._terminal
.currentParam
);
1653 this._terminal
.currentParam
= '';
1657 this._terminal
.currentParam
+= ch
;
1661 case ParserState
.CSI_PARAM
:
1662 if (ch
in csiParamStateHandler
) {
1663 csiParamStateHandler
[ch
](this);
1666 this.finalizeParam();
1667 this._state
= ParserState
.CSI
;
1668 case ParserState
.CSI
:
1669 if (ch
in csiStateHandler
) {
1670 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1673 this._terminal
.error('Unknown CSI code: %s.', ch
);
1675 this._state
= ParserState
.NORMAL
;
1676 this._terminal
.prefix
= '';
1677 this._terminal
.postfix
= '';
1679 case ParserState
.DCS
:
1680 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1681 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1683 switch (this._terminal
.prefix
) {
1687 var pt
= this._terminal
.currentParam
, valid
= false;
1697 + (this._terminal
.scrollTop
+ 1)
1699 + (this._terminal
.scrollBottom
+ 1)
1706 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1710 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1715 pt
= this._terminal
.currentParam
1717 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1720 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1723 this._terminal
.currentParam
= 0;
1724 this._terminal
.prefix
= '';
1725 this._state
= ParserState
.NORMAL
;
1727 else if (!this._terminal
.currentParam
) {
1728 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1729 this._terminal
.currentParam
= ch
;
1731 else if (this._terminal
.prefix
.length
=== 2) {
1732 this._terminal
.currentParam
= ch
;
1735 this._terminal
.prefix
+= ch
;
1739 this._terminal
.currentParam
+= ch
;
1742 case ParserState
.IGNORE
:
1743 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1744 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1746 this._state
= ParserState
.NORMAL
;
1752 Parser
.prototype.setState = function (state
) {
1753 this._state
= state
;
1755 Parser
.prototype.setPrefix = function (prefix
) {
1756 this._terminal
.prefix
= prefix
;
1758 Parser
.prototype.setPostfix = function (postfix
) {
1759 this._terminal
.postfix
= postfix
;
1761 Parser
.prototype.setParam = function (param
) {
1762 this._terminal
.currentParam
= param
;
1764 Parser
.prototype.getParam = function () {
1765 return this._terminal
.currentParam
;
1767 Parser
.prototype.finalizeParam = function () {
1768 this._terminal
.params
.push(this._terminal
.currentParam
);
1769 this._terminal
.currentParam
= 0;
1771 Parser
.prototype.skipNextChar = function () {
1776 exports
.Parser
= Parser
;
1778 },{"./Charsets":1,"./EscapeSequences":3}],7:[function(require
,module
,exports
){
1780 var MAX_REFRESH_FRAME_SKIP
= 5;
1783 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
1784 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
1785 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
1786 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
1787 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
1788 })(FLAGS
|| (FLAGS
= {}));
1790 var brokenBold
= null;
1791 var Renderer
= (function () {
1792 function Renderer(_terminal
) {
1793 this._terminal
= _terminal
;
1794 this._refreshRowsQueue
= [];
1795 this._refreshFramesSkipped
= 0;
1796 this._refreshAnimationFrame
= null;
1797 if (brokenBold
=== null) {
1798 brokenBold
= checkBoldBroken(this._terminal
.document
);
1801 Renderer
.prototype.queueRefresh = function (start
, end
) {
1802 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
1803 if (!this._refreshAnimationFrame
) {
1804 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
1807 Renderer
.prototype._refreshLoop = function () {
1808 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
1810 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
1813 this._refreshFramesSkipped
= 0;
1816 if (this._refreshRowsQueue
.length
> 4) {
1818 end
= this._terminal
.rows
- 1;
1821 start
= this._refreshRowsQueue
[0].start
;
1822 end
= this._refreshRowsQueue
[0].end
;
1823 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
1824 if (this._refreshRowsQueue
[i
].start
< start
) {
1825 start
= this._refreshRowsQueue
[i
].start
;
1827 if (this._refreshRowsQueue
[i
].end
> end
) {
1828 end
= this._refreshRowsQueue
[i
].end
;
1832 this._refreshRowsQueue
= [];
1833 this._refreshAnimationFrame
= null;
1834 this._refresh(start
, end
);
1836 Renderer
.prototype._refresh = function (start
, end
) {
1837 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
1838 if (end
- start
>= this._terminal
.rows
/ 2) {
1839 parent
= this._terminal
.element
.parentNode
;
1841 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
1844 width
= this._terminal
.cols
;
1846 if (end
>= this._terminal
.rows
) {
1847 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
1848 end
= this._terminal
.rows
- 1;
1850 for (; y
<= end
; y
++) {
1851 row
= y
+ this._terminal
.ydisp
;
1852 line
= this._terminal
.lines
.get(row
);
1853 if (!line
|| !this._terminal
.children
[y
]) {
1857 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
)
1858 && this._terminal
.cursorState
1859 && !this._terminal
.cursorHidden
) {
1860 x
= this._terminal
.x
;
1865 attr
= this._terminal
.defAttr
;
1867 for (; i
< width
; i
++) {
1873 ch_width
= line
[i
][2];
1878 if (data
!== attr
) {
1879 if (attr
!== this._terminal
.defAttr
) {
1882 if (data
!== this._terminal
.defAttr
) {
1884 out
+= '<span class="reverse-video terminal-cursor">';
1887 var classNames
= [];
1889 fg
= (data
>> 9) & 0x1ff;
1891 if (flags
& FLAGS
.BOLD
) {
1893 classNames
.push('xterm-bold');
1898 if (flags
& FLAGS
.UNDERLINE
) {
1899 classNames
.push('xterm-underline');
1901 if (flags
& FLAGS
.BLINK
) {
1902 classNames
.push('xterm-blink');
1904 if (flags
& FLAGS
.INVERSE
) {
1905 bg
= [fg
, fg
= bg
][0];
1906 if ((flags
& 1) && fg
< 8)
1909 if (flags
& FLAGS
.INVISIBLE
) {
1910 classNames
.push('xterm-hidden');
1912 if (flags
& FLAGS
.INVERSE
) {
1921 classNames
.push('xterm-bg-color-' + bg
);
1924 classNames
.push('xterm-color-' + fg
);
1927 if (classNames
.length
) {
1928 out
+= ' class="' + classNames
.join(' ') + '"';
1934 if (ch_width
=== 2) {
1935 out
+= '<span class="xterm-wide-char">';
1956 if (ch_width
=== 2) {
1961 if (attr
!== this._terminal
.defAttr
) {
1964 this._terminal
.children
[y
].innerHTML
= out
;
1967 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
1969 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
1974 exports
.Renderer
= Renderer
;
1975 function checkBoldBroken(document
) {
1976 var body
= document
.getElementsByTagName('body')[0];
1977 var el
= document
.createElement('span');
1978 el
.innerHTML
= 'hello world';
1979 body
.appendChild(el
);
1980 var w1
= el
.scrollWidth
;
1981 el
.style
.fontWeight
= 'bold';
1982 var w2
= el
.scrollWidth
;
1983 body
.removeChild(el
);
1987 },{}],8:[function(require
,module
,exports
){
1989 var Viewport
= (function () {
1990 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
1991 this.terminal
= terminal
;
1992 this.viewportElement
= viewportElement
;
1993 this.scrollArea
= scrollArea
;
1994 this.charMeasure
= charMeasure
;
1995 this.currentRowHeight
= 0;
1996 this.lastRecordedBufferLength
= 0;
1997 this.lastRecordedViewportHeight
= 0;
1998 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
1999 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2000 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2001 this.syncScrollArea();
2003 Viewport
.prototype.refresh = function () {
2004 if (this.charMeasure
.height
> 0) {
2005 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2006 if (rowHeightChanged
) {
2007 this.currentRowHeight
= this.charMeasure
.height
;
2008 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2009 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2011 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2012 if (rowHeightChanged
|| viewportHeightChanged
) {
2013 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2014 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2016 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2019 Viewport
.prototype.syncScrollArea = function () {
2020 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2021 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2024 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2028 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2032 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2033 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2034 this.viewportElement
.scrollTop
= scrollTop
;
2037 Viewport
.prototype.onScroll = function (ev
) {
2038 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2039 var diff
= newRow
- this.terminal
.ydisp
;
2040 this.terminal
.scrollDisp(diff
, true);
2042 Viewport
.prototype.onWheel = function (ev
) {
2043 if (ev
.deltaY
=== 0) {
2047 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2048 multiplier
= this.currentRowHeight
;
2050 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2051 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2053 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2054 ev
.preventDefault();
2059 exports
.Viewport
= Viewport
;
2061 },{}],9:[function(require
,module
,exports
){
2063 function prepareTextForClipboard(text
) {
2064 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
2065 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
2066 return processedLine
;
2068 return processedText
;
2070 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
2071 function copyHandler(ev
, term
) {
2072 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
2073 if (term
.browser
.isMSIE
) {
2074 window
.clipboardData
.setData('Text', text
);
2077 ev
.clipboardData
.setData('text/plain', text
);
2079 ev
.preventDefault();
2081 exports
.copyHandler
= copyHandler
;
2082 function pasteHandler(ev
, term
) {
2083 ev
.stopPropagation();
2085 var dispatchPaste = function (text
) {
2087 term
.textarea
.value
= '';
2088 return term
.cancel(ev
);
2090 if (term
.browser
.isMSIE
) {
2091 if (window
.clipboardData
) {
2092 text
= window
.clipboardData
.getData('Text');
2093 dispatchPaste(text
);
2097 if (ev
.clipboardData
) {
2098 text
= ev
.clipboardData
.getData('text/plain');
2099 dispatchPaste(text
);
2103 exports
.pasteHandler
= pasteHandler
;
2104 function rightClickHandler(ev
, term
) {
2105 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
2107 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
2108 for (var i
= 0; i
< cr
.length
; i
++) {
2110 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
2111 (y
> rect
.top
) && (y
< rect
.bottom
));
2112 if (clickIsOnSelection
) {
2116 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
2117 clickIsOnSelection
= false;
2120 if (!clickIsOnSelection
) {
2121 term
.textarea
.style
.position
= 'fixed';
2122 term
.textarea
.style
.width
= '20px';
2123 term
.textarea
.style
.height
= '20px';
2124 term
.textarea
.style
.left
= (x
- 10) + 'px';
2125 term
.textarea
.style
.top
= (y
- 10) + 'px';
2126 term
.textarea
.style
.zIndex
= '1000';
2127 term
.textarea
.focus();
2128 setTimeout(function () {
2129 term
.textarea
.style
.position
= null;
2130 term
.textarea
.style
.width
= null;
2131 term
.textarea
.style
.height
= null;
2132 term
.textarea
.style
.left
= null;
2133 term
.textarea
.style
.top
= null;
2134 term
.textarea
.style
.zIndex
= null;
2138 exports
.rightClickHandler
= rightClickHandler
;
2140 },{}],10:[function(require
,module
,exports
){
2142 var Generic_1
= require("./Generic");
2143 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2144 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2145 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2146 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2147 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2148 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2149 exports
.isIpad
= platform
=== 'iPad';
2150 exports
.isIphone
= platform
=== 'iPhone';
2151 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2153 },{"./Generic":13}],11:[function(require
,module
,exports
){
2155 var __extends
= (this && this.__extends
) || function (d
, b
) {
2157 if (b
.hasOwnProperty(p
))
2159 function __() { this.constructor = d
; }
2160 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2162 var EventEmitter_js_1
= require("../EventEmitter.js");
2163 var CharMeasure
= (function (_super
) {
2164 __extends(CharMeasure
, _super
);
2165 function CharMeasure(parentElement
) {
2166 var _this
= _super
.call(this) || this;
2167 _this
._parentElement
= parentElement
;
2170 Object
.defineProperty(CharMeasure
.prototype, "width", {
2177 Object
.defineProperty(CharMeasure
.prototype, "height", {
2179 return this._height
;
2184 CharMeasure
.prototype.measure = function () {
2186 if (!this._measureElement
) {
2187 this._measureElement
= document
.createElement('span');
2188 this._measureElement
.style
.position
= 'absolute';
2189 this._measureElement
.style
.top
= '0';
2190 this._measureElement
.style
.left
= '-9999em';
2191 this._measureElement
.textContent
= 'W';
2192 this._parentElement
.appendChild(this._measureElement
);
2193 setTimeout(function () { return _this
._doMeasure(); }, 0);
2199 CharMeasure
.prototype._doMeasure = function () {
2200 var geometry
= this._measureElement
.getBoundingClientRect();
2201 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
2204 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
2205 this._width
= geometry
.width
;
2206 this._height
= geometry
.height
;
2207 this.emit('charsizechanged');
2211 }(EventEmitter_js_1
.EventEmitter
));
2212 exports
.CharMeasure
= CharMeasure
;
2214 },{"../EventEmitter.js":4}],12:[function(require
,module
,exports
){
2216 var CircularList
= (function () {
2217 function CircularList(maxLength
) {
2218 this._array
= new Array(maxLength
);
2219 this._startIndex
= 0;
2222 Object
.defineProperty(CircularList
.prototype, "maxLength", {
2224 return this._array
.length
;
2226 set: function (newMaxLength
) {
2227 var newArray
= new Array(newMaxLength
);
2228 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
2229 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
2231 this._array
= newArray
;
2232 this._startIndex
= 0;
2237 Object
.defineProperty(CircularList
.prototype, "length", {
2239 return this._length
;
2241 set: function (newLength
) {
2242 if (newLength
> this._length
) {
2243 for (var i
= this._length
; i
< newLength
; i
++) {
2244 this._array
[i
] = undefined;
2247 this._length
= newLength
;
2252 Object
.defineProperty(CircularList
.prototype, "forEach", {
2254 return this._array
.forEach
;
2259 CircularList
.prototype.get = function (index
) {
2260 return this._array
[this._getCyclicIndex(index
)];
2262 CircularList
.prototype.set = function (index
, value
) {
2263 this._array
[this._getCyclicIndex(index
)] = value
;
2265 CircularList
.prototype.push = function (value
) {
2266 this._array
[this._getCyclicIndex(this._length
)] = value
;
2267 if (this._length
=== this.maxLength
) {
2269 if (this._startIndex
=== this.maxLength
) {
2270 this._startIndex
= 0;
2277 CircularList
.prototype.pop = function () {
2278 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
2280 CircularList
.prototype.splice = function (start
, deleteCount
) {
2282 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
2283 items
[_i
- 2] = arguments
[_i
];
2286 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
2287 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
2289 this._length
-= deleteCount
;
2291 if (items
&& items
.length
) {
2292 for (var i
= this._length
- 1; i
>= start
; i
--) {
2293 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
2295 for (var i
= 0; i
< items
.length
; i
++) {
2296 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
2298 if (this._length
+ items
.length
> this.maxLength
) {
2299 this._startIndex
+= (this._length
+ items
.length
) - this.maxLength
;
2300 this._length
= this.maxLength
;
2303 this._length
+= items
.length
;
2307 CircularList
.prototype.trimStart = function (count
) {
2308 if (count
> this._length
) {
2309 count
= this._length
;
2311 this._startIndex
+= count
;
2312 this._length
-= count
;
2314 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
2318 if (start
< 0 || start
>= this._length
) {
2319 throw new Error('start argument out of range');
2321 if (start
+ offset
< 0) {
2322 throw new Error('Cannot shift elements in list beyond index 0');
2325 for (var i
= count
- 1; i
>= 0; i
--) {
2326 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2328 var expandListBy
= (start
+ count
+ offset
) - this._length
;
2329 if (expandListBy
> 0) {
2330 this._length
+= expandListBy
;
2331 while (this._length
> this.maxLength
) {
2338 for (var i
= 0; i
< count
; i
++) {
2339 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2343 CircularList
.prototype._getCyclicIndex = function (index
) {
2344 return (this._startIndex
+ index
) % this.maxLength
;
2346 return CircularList
;
2348 exports
.CircularList
= CircularList
;
2350 },{}],13:[function(require
,module
,exports
){
2352 function contains(arr
, el
) {
2353 return arr
.indexOf(el
) >= 0;
2355 exports
.contains
= contains
;
2358 },{}],14:[function(require
,module
,exports
){
2360 var CompositionHelper_1
= require("./CompositionHelper");
2361 var EventEmitter_1
= require("./EventEmitter");
2362 var Viewport_1
= require("./Viewport");
2363 var Clipboard_1
= require("./handlers/Clipboard");
2364 var CircularList_1
= require("./utils/CircularList");
2365 var EscapeSequences_1
= require("./EscapeSequences");
2366 var InputHandler_1
= require("./InputHandler");
2367 var Parser_1
= require("./Parser");
2368 var Renderer_1
= require("./Renderer");
2369 var CharMeasure_1
= require("./utils/CharMeasure");
2370 var Browser
= require("./utils/Browser");
2371 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
2372 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
2373 var WRITE_BATCH_SIZE
= 300;
2374 function Terminal(options
) {
2376 if (!(this instanceof Terminal
)) {
2377 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
2379 self
.browser
= Browser
;
2380 self
.cancel
= Terminal
.cancel
;
2381 EventEmitter_1
.EventEmitter
.call(this);
2382 if (typeof options
=== 'number') {
2386 handler
: arguments
[2]
2389 options
= options
|| {};
2390 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
2391 if (options
[key
] == null) {
2392 options
[key
] = Terminal
.options
[key
];
2393 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
2394 options
[key
] = Terminal
[key
];
2397 self
[key
] = options
[key
];
2399 if (options
.colors
.length
=== 8) {
2400 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
2402 else if (options
.colors
.length
=== 16) {
2403 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
2405 else if (options
.colors
.length
=== 10) {
2406 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
2408 else if (options
.colors
.length
=== 18) {
2409 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
2411 this.colors
= options
.colors
;
2412 this.options
= options
;
2413 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
2414 this.cols
= options
.cols
|| options
.geometry
[0];
2415 this.rows
= options
.rows
|| options
.geometry
[1];
2416 this.geometry
= [this.cols
, this.rows
];
2417 if (options
.handler
) {
2418 this.on('data', options
.handler
);
2424 this.cursorState
= 0;
2425 this.cursorHidden
= false;
2429 this.scrollBottom
= this.rows
- 1;
2430 this.customKeydownHandler
= null;
2431 this.applicationKeypad
= false;
2432 this.applicationCursor
= false;
2433 this.originMode
= false;
2434 this.insertMode
= false;
2435 this.wraparoundMode
= true;
2437 this.charset
= null;
2438 this.gcharset
= null;
2440 this.charsets
= [null];
2458 this.readable
= true;
2459 this.writable
= true;
2460 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
2461 this.curAttr
= this.defAttr
;
2463 this.currentParam
= 0;
2466 this.inputHandler
= new InputHandler_1
.InputHandler(this);
2467 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
2468 this.renderer
= this.renderer
|| null;
2469 this.writeBuffer
= [];
2470 this.writeInProgress
= false;
2471 this.xoffSentToCatchUp
= false;
2472 this.writeStopped
= false;
2473 this.surrogate_high
= '';
2474 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
2477 this.lines
.push(this.blankLine());
2481 this.userScrolling
= false;
2483 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
2484 Terminal
.prototype.eraseAttr = function () {
2485 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
2487 Terminal
.tangoColors
= [
2505 Terminal
.colors
= (function () {
2506 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
2508 for (; i
< 216; i
++) {
2509 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
2512 for (; i
< 24; i
++) {
2516 function out(r
, g
, b
) {
2517 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
2521 return c
.length
< 2 ? '0' + c
: c
;
2525 Terminal
._colors
= Terminal
.colors
.slice();
2526 Terminal
.vcolors
= (function () {
2527 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
2528 for (; i
< 256; i
++) {
2529 color
= parseInt(colors
[i
].substring(1), 16);
2531 (color
>> 16) & 0xff,
2532 (color
>> 8) & 0xff,
2538 Terminal
.defaults
= {
2539 colors
: Terminal
.colors
,
2545 cursorStyle
: 'block',
2551 cancelEvents
: false,
2552 disableStdin
: false,
2553 useFlowControl
: false,
2556 Terminal
.options
= {};
2557 Terminal
.focus
= null;
2558 each(keys(Terminal
.defaults
), function (key
) {
2559 Terminal
[key
] = Terminal
.defaults
[key
];
2560 Terminal
.options
[key
] = Terminal
.defaults
[key
];
2562 Terminal
.prototype.focus = function () {
2563 return this.textarea
.focus();
2565 Terminal
.prototype.getOption = function (key
, value
) {
2566 if (!(key
in Terminal
.defaults
)) {
2567 throw new Error('No option with key "' + key
+ '"');
2569 if (typeof this.options
[key
] !== 'undefined') {
2570 return this.options
[key
];
2574 Terminal
.prototype.setOption = function (key
, value
) {
2575 if (!(key
in Terminal
.defaults
)) {
2576 throw new Error('No option with key "' + key
+ '"');
2580 if (this.options
[key
] !== value
) {
2581 if (this.lines
.length
> value
) {
2582 var amountToTrim
= this.lines
.length
- value
;
2583 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
2584 this.lines
.trimStart(amountToTrim
);
2585 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
2586 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
2588 this.refresh(0, this.rows
- 1);
2591 this.lines
.maxLength
= value
;
2592 this.viewport
.syncScrollArea();
2597 this.options
[key
] = value
;
2600 this.element
.classList
.toggle('xterm-cursor-blink', value
);
2603 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
2604 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
2606 case 'tabStopWidth':
2611 Terminal
.bindFocus = function (term
) {
2612 on(term
.textarea
, 'focus', function (ev
) {
2613 if (term
.sendFocus
) {
2614 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
2616 term
.element
.classList
.add('focus');
2618 Terminal
.focus
= term
;
2619 term
.emit('focus', { terminal
: term
});
2622 Terminal
.prototype.blur = function () {
2623 return this.textarea
.blur();
2625 Terminal
.bindBlur = function (term
) {
2626 on(term
.textarea
, 'blur', function (ev
) {
2627 term
.refresh(term
.y
, term
.y
);
2628 if (term
.sendFocus
) {
2629 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
2631 term
.element
.classList
.remove('focus');
2632 Terminal
.focus
= null;
2633 term
.emit('blur', { terminal
: term
});
2636 Terminal
.prototype.initGlobal = function () {
2638 Terminal
.bindKeys(this);
2639 Terminal
.bindFocus(this);
2640 Terminal
.bindBlur(this);
2641 on(this.element
, 'copy', function (ev
) {
2642 Clipboard_1
.copyHandler
.call(this, ev
, term
);
2644 on(this.textarea
, 'paste', function (ev
) {
2645 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2647 on(this.element
, 'paste', function (ev
) {
2648 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2650 function rightClickHandlerWrapper(ev
) {
2651 Clipboard_1
.rightClickHandler
.call(this, ev
, term
);
2653 if (term
.browser
.isFirefox
) {
2654 on(this.element
, 'mousedown', function (ev
) {
2655 if (ev
.button
== 2) {
2656 rightClickHandlerWrapper(ev
);
2661 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
2664 Terminal
.bindKeys = function (term
) {
2665 on(term
.element
, 'keydown', function (ev
) {
2666 if (document
.activeElement
!= this) {
2671 on(term
.element
, 'keypress', function (ev
) {
2672 if (document
.activeElement
!= this) {
2677 on(term
.element
, 'keyup', function (ev
) {
2678 if (!wasMondifierKeyOnlyEvent(ev
)) {
2682 on(term
.textarea
, 'keydown', function (ev
) {
2685 on(term
.textarea
, 'keypress', function (ev
) {
2689 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
2690 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
2691 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
2692 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
2694 Terminal
.prototype.insertRow = function (row
) {
2695 if (typeof row
!= 'object') {
2696 row
= document
.createElement('div');
2698 this.rowContainer
.appendChild(row
);
2699 this.children
.push(row
);
2702 Terminal
.prototype.open = function (parent
) {
2703 var self
= this, i
= 0, div
;
2704 this.parent
= parent
|| this.parent
;
2706 throw new Error('Terminal requires a parent element.');
2708 this.context
= this.parent
.ownerDocument
.defaultView
;
2709 this.document
= this.parent
.ownerDocument
;
2710 this.body
= this.document
.getElementsByTagName('body')[0];
2711 this.element
= this.document
.createElement('div');
2712 this.element
.classList
.add('terminal');
2713 this.element
.classList
.add('xterm');
2714 this.element
.classList
.add('xterm-theme-' + this.theme
);
2715 this.element
.classList
.toggle('xterm-cursor-blink', this.options
.cursorBlink
);
2716 this.element
.style
.height
;
2717 this.element
.setAttribute('tabindex', 0);
2718 this.viewportElement
= document
.createElement('div');
2719 this.viewportElement
.classList
.add('xterm-viewport');
2720 this.element
.appendChild(this.viewportElement
);
2721 this.viewportScrollArea
= document
.createElement('div');
2722 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
2723 this.viewportElement
.appendChild(this.viewportScrollArea
);
2724 this.rowContainer
= document
.createElement('div');
2725 this.rowContainer
.classList
.add('xterm-rows');
2726 this.element
.appendChild(this.rowContainer
);
2728 this.helperContainer
= document
.createElement('div');
2729 this.helperContainer
.classList
.add('xterm-helpers');
2730 this.element
.appendChild(this.helperContainer
);
2731 this.textarea
= document
.createElement('textarea');
2732 this.textarea
.classList
.add('xterm-helper-textarea');
2733 this.textarea
.setAttribute('autocorrect', 'off');
2734 this.textarea
.setAttribute('autocapitalize', 'off');
2735 this.textarea
.setAttribute('spellcheck', 'false');
2736 this.textarea
.tabIndex
= 0;
2737 this.textarea
.addEventListener('focus', function () {
2738 self
.emit('focus', { terminal
: self
});
2740 this.textarea
.addEventListener('blur', function () {
2741 self
.emit('blur', { terminal
: self
});
2743 this.helperContainer
.appendChild(this.textarea
);
2744 this.compositionView
= document
.createElement('div');
2745 this.compositionView
.classList
.add('composition-view');
2746 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
2747 this.helperContainer
.appendChild(this.compositionView
);
2748 this.charSizeStyleElement
= document
.createElement('style');
2749 this.helperContainer
.appendChild(this.charSizeStyleElement
);
2750 for (; i
< this.rows
; i
++) {
2753 this.parent
.appendChild(this.element
);
2754 this.charMeasure
= new CharMeasure_1
.CharMeasure(this.helperContainer
);
2755 this.charMeasure
.on('charsizechanged', function () {
2756 self
.updateCharSizeCSS();
2758 this.charMeasure
.measure();
2759 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
2760 this.renderer
= new Renderer_1
.Renderer(this);
2761 this.refresh(0, this.rows
- 1);
2764 on(this.element
, 'click', function () {
2765 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
2773 Terminal
.loadAddon = function (addon
, callback
) {
2774 if (typeof exports
=== 'object' && typeof module
=== 'object') {
2775 return require('./addons/' + addon
+ '/' + addon
);
2777 else if (typeof define
== 'function') {
2778 return require(['./addons/' + addon
+ '/' + addon
], callback
);
2781 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
2785 Terminal
.prototype.updateCharSizeCSS = function () {
2786 this.charSizeStyleElement
.textContent
= '.xterm-wide-char{width:' + (this.charMeasure
.width
* 2) + 'px;}';
2788 Terminal
.prototype.bindMouse = function () {
2789 var el
= this.element
, self
= this, pressed
= 32;
2790 function sendButton(ev
) {
2792 button
= getButton(ev
);
2793 pos
= getCoords(ev
);
2796 sendEvent(button
, pos
);
2797 switch (ev
.overrideType
|| ev
.type
) {
2808 function sendMove(ev
) {
2809 var button
= pressed
, pos
;
2810 pos
= getCoords(ev
);
2814 sendEvent(button
, pos
);
2816 function encode(data
, ch
) {
2817 if (!self
.utfMouse
) {
2819 return data
.push(0);
2826 return data
.push(0);
2833 data
.push(0xC0 | (ch
>> 6));
2834 data
.push(0x80 | (ch
& 0x3F));
2838 function sendEvent(button
, pos
) {
2839 if (self
.vt300Mouse
) {
2843 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
2846 else if (button
=== 1)
2848 else if (button
=== 2)
2850 else if (button
=== 3)
2854 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
2858 if (self
.decLocator
) {
2864 else if (button
=== 1)
2866 else if (button
=== 2)
2868 else if (button
=== 3)
2870 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
2873 + (button
=== 3 ? 4 : 0)
2883 if (self
.urxvtMouse
) {
2888 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
2891 if (self
.sgrMouse
) {
2894 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
2895 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
2900 + ((button
& 3) === 3 ? 'm' : 'M'));
2904 encode(data
, button
);
2905 encode(data
, pos
.x
);
2906 encode(data
, pos
.y
);
2907 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
2909 function getButton(ev
) {
2910 var button
, shift
, meta
, ctrl
, mod
;
2911 switch (ev
.overrideType
|| ev
.type
) {
2913 button
= ev
.button
!= null
2918 if (self
.browser
.isMSIE
) {
2919 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
2925 case 'DOMMouseScroll':
2926 button
= ev
.detail
< 0
2931 button
= ev
.wheelDeltaY
> 0
2936 shift
= ev
.shiftKey
? 4 : 0;
2937 meta
= ev
.metaKey
? 8 : 0;
2938 ctrl
= ev
.ctrlKey
? 16 : 0;
2939 mod
= shift
| meta
| ctrl
;
2940 if (self
.vt200Mouse
) {
2943 else if (!self
.normalMouse
) {
2946 button
= (32 + (mod
<< 2)) + button
;
2949 function getCoords(ev
) {
2951 if (ev
.pageX
== null)
2956 while (el
&& el
!== self
.document
.documentElement
) {
2959 el
= 'offsetParent' in el
2963 w
= self
.element
.clientWidth
;
2964 h
= self
.element
.clientHeight
;
2965 x
= Math
.ceil((x
/ w
) * self
.cols
);
2966 y
= Math
.ceil((y
/ h
) * self
.rows
);
2983 on(el
, 'mousedown', function (ev
) {
2984 if (!self
.mouseEvents
)
2988 if (self
.vt200Mouse
) {
2989 ev
.overrideType
= 'mouseup';
2991 return self
.cancel(ev
);
2993 if (self
.normalMouse
)
2994 on(self
.document
, 'mousemove', sendMove
);
2995 if (!self
.x10Mouse
) {
2996 on(self
.document
, 'mouseup', function up(ev
) {
2998 if (self
.normalMouse
)
2999 off(self
.document
, 'mousemove', sendMove
);
3000 off(self
.document
, 'mouseup', up
);
3001 return self
.cancel(ev
);
3004 return self
.cancel(ev
);
3006 on(el
, 'wheel', function (ev
) {
3007 if (!self
.mouseEvents
)
3014 return self
.cancel(ev
);
3016 on(el
, 'wheel', function (ev
) {
3017 if (self
.mouseEvents
)
3019 self
.viewport
.onWheel(ev
);
3020 return self
.cancel(ev
);
3023 Terminal
.prototype.destroy = function () {
3024 this.readable
= false;
3025 this.writable
= false;
3027 this.handler = function () { };
3028 this.write = function () { };
3029 if (this.element
&& this.element
.parentNode
) {
3030 this.element
.parentNode
.removeChild(this.element
);
3033 Terminal
.prototype.refresh = function (start
, end
) {
3034 if (this.renderer
) {
3035 this.renderer
.queueRefresh(start
, end
);
3038 Terminal
.prototype.showCursor = function () {
3039 if (!this.cursorState
) {
3040 this.cursorState
= 1;
3041 this.refresh(this.y
, this.y
);
3044 Terminal
.prototype.scroll = function () {
3046 if (this.lines
.length
=== this.lines
.maxLength
) {
3047 this.lines
.trimStart(1);
3049 if (this.ydisp
!== 0) {
3054 if (!this.userScrolling
) {
3055 this.ydisp
= this.ybase
;
3057 row
= this.ybase
+ this.rows
- 1;
3058 row
-= this.rows
- 1 - this.scrollBottom
;
3059 if (row
=== this.lines
.length
) {
3060 this.lines
.push(this.blankLine());
3063 this.lines
.splice(row
, 0, this.blankLine());
3065 if (this.scrollTop
!== 0) {
3066 if (this.ybase
!== 0) {
3068 if (!this.userScrolling
) {
3069 this.ydisp
= this.ybase
;
3072 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
3074 this.updateRange(this.scrollTop
);
3075 this.updateRange(this.scrollBottom
);
3076 this.emit('scroll', this.ydisp
);
3078 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
3080 this.userScrolling
= true;
3082 else if (disp
+ this.ydisp
>= this.ybase
) {
3083 this.userScrolling
= false;
3086 if (this.ydisp
> this.ybase
) {
3087 this.ydisp
= this.ybase
;
3089 else if (this.ydisp
< 0) {
3092 if (!suppressScrollEvent
) {
3093 this.emit('scroll', this.ydisp
);
3095 this.refresh(0, this.rows
- 1);
3097 Terminal
.prototype.scrollPages = function (pageCount
) {
3098 this.scrollDisp(pageCount
* (this.rows
- 1));
3100 Terminal
.prototype.scrollToTop = function () {
3101 this.scrollDisp(-this.ydisp
);
3103 Terminal
.prototype.scrollToBottom = function () {
3104 this.scrollDisp(this.ybase
- this.ydisp
);
3106 Terminal
.prototype.write = function (data
) {
3107 this.writeBuffer
.push(data
);
3108 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
3109 this.send(EscapeSequences_1
.C0
.DC3
);
3110 this.xoffSentToCatchUp
= true;
3112 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
3113 this.writeInProgress
= true;
3115 setTimeout(function () {
3120 Terminal
.prototype.innerWrite = function () {
3121 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
3122 while (writeBatch
.length
> 0) {
3123 var data
= writeBatch
.shift();
3124 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
3125 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
3126 this.send(EscapeSequences_1
.C0
.DC1
);
3127 this.xoffSentToCatchUp
= false;
3129 this.refreshStart
= this.y
;
3130 this.refreshEnd
= this.y
;
3131 this.parser
.parse(data
);
3132 this.updateRange(this.y
);
3133 this.refresh(this.refreshStart
, this.refreshEnd
);
3135 if (this.writeBuffer
.length
> 0) {
3137 setTimeout(function () {
3142 this.writeInProgress
= false;
3145 Terminal
.prototype.writeln = function (data
) {
3146 this.write(data
+ '\r\n');
3148 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
3149 this.customKeydownHandler
= customKeydownHandler
;
3151 Terminal
.prototype.keyDown = function (ev
) {
3152 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
3155 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
3156 if (this.ybase
!== this.ydisp
) {
3157 this.scrollToBottom();
3162 var result
= this.evaluateKeyEscapeSequence(ev
);
3163 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
3164 this.writeStopped
= true;
3166 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
3167 this.writeStopped
= false;
3169 if (result
.scrollDisp
) {
3170 this.scrollDisp(result
.scrollDisp
);
3171 return this.cancel(ev
, true);
3173 if (isThirdLevelShift(this, ev
)) {
3176 if (result
.cancel
) {
3177 this.cancel(ev
, true);
3182 this.emit('keydown', ev
);
3183 this.emit('key', result
.key
, ev
);
3185 this.handler(result
.key
);
3186 return this.cancel(ev
, true);
3188 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
3192 scrollDisp
: undefined
3194 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
3195 switch (ev
.keyCode
) {
3198 result
.key
= EscapeSequences_1
.C0
.BS
;
3201 result
.key
= EscapeSequences_1
.C0
.DEL
;
3205 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
3208 result
.key
= EscapeSequences_1
.C0
.HT
;
3209 result
.cancel
= true;
3212 result
.key
= EscapeSequences_1
.C0
.CR
;
3213 result
.cancel
= true;
3216 result
.key
= EscapeSequences_1
.C0
.ESC
;
3217 result
.cancel
= true;
3221 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
3222 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
3223 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
3226 else if (this.applicationCursor
) {
3227 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
3230 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
3235 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
3236 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
3237 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
3240 else if (this.applicationCursor
) {
3241 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
3244 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
3249 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
3250 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
3251 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
3254 else if (this.applicationCursor
) {
3255 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
3258 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
3263 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
3264 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
3265 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
3268 else if (this.applicationCursor
) {
3269 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
3272 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
3276 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
3277 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
3282 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
3285 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
3290 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
3291 else if (this.applicationCursor
)
3292 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
3294 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
3298 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
3299 else if (this.applicationCursor
)
3300 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
3302 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
3306 result
.scrollDisp
= -(this.rows
- 1);
3309 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
3314 result
.scrollDisp
= this.rows
- 1;
3317 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
3322 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
3325 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
3330 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
3333 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
3338 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
3341 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
3346 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
3349 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
3354 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
3357 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
3362 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
3365 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
3370 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
3373 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
3378 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
3381 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
3386 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
3389 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
3394 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
3397 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
3402 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
3405 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
3410 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
3413 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
3417 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
3418 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3419 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
3421 else if (ev
.keyCode
=== 32) {
3422 result
.key
= String
.fromCharCode(0);
3424 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
3425 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
3427 else if (ev
.keyCode
=== 56) {
3428 result
.key
= String
.fromCharCode(127);
3430 else if (ev
.keyCode
=== 219) {
3431 result
.key
= String
.fromCharCode(27);
3433 else if (ev
.keyCode
=== 220) {
3434 result
.key
= String
.fromCharCode(28);
3436 else if (ev
.keyCode
=== 221) {
3437 result
.key
= String
.fromCharCode(29);
3440 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
3441 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3442 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
3444 else if (ev
.keyCode
=== 192) {
3445 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
3447 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
3448 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
3455 Terminal
.prototype.setgLevel = function (g
) {
3457 this.charset
= this.charsets
[g
];
3459 Terminal
.prototype.setgCharset = function (g
, charset
) {
3460 this.charsets
[g
] = charset
;
3461 if (this.glevel
=== g
) {
3462 this.charset
= charset
;
3465 Terminal
.prototype.keyPress = function (ev
) {
3471 else if (ev
.which
== null) {
3474 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3480 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3483 key
= String
.fromCharCode(key
);
3484 this.emit('keypress', key
, ev
);
3485 this.emit('key', key
, ev
);
3490 Terminal
.prototype.send = function (data
) {
3493 setTimeout(function () {
3494 self
.handler(self
.queue
);
3500 Terminal
.prototype.bell = function () {
3501 if (!this.visualBell
)
3504 this.element
.style
.borderColor
= 'white';
3505 setTimeout(function () {
3506 self
.element
.style
.borderColor
= '';
3511 Terminal
.prototype.log = function () {
3514 if (!this.context
.console
|| !this.context
.console
.log
)
3516 var args
= Array
.prototype.slice
.call(arguments
);
3517 this.context
.console
.log
.apply(this.context
.console
, args
);
3519 Terminal
.prototype.error = function () {
3522 if (!this.context
.console
|| !this.context
.console
.error
)
3524 var args
= Array
.prototype.slice
.call(arguments
);
3525 this.context
.console
.error
.apply(this.context
.console
, args
);
3527 Terminal
.prototype.resize = function (x
, y
) {
3528 if (isNaN(x
) || isNaN(y
)) {
3531 var line
, el
, i
, j
, ch
, addToY
;
3532 if (x
=== this.cols
&& y
=== this.rows
) {
3541 ch
= [this.defAttr
, ' ', 1];
3542 i
= this.lines
.length
;
3544 while (this.lines
.get(i
).length
< x
) {
3545 this.lines
.get(i
).push(ch
);
3550 i
= this.lines
.length
;
3552 while (this.lines
.get(i
).length
> x
) {
3553 this.lines
.get(i
).pop();
3558 this.setupStops(this.cols
);
3564 if (this.lines
.length
< y
+ this.ybase
) {
3565 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
3568 if (this.ydisp
> 0) {
3573 this.lines
.push(this.blankLine());
3576 if (this.children
.length
< y
) {
3583 if (this.lines
.length
> y
+ this.ybase
) {
3584 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
3592 if (this.children
.length
> y
) {
3593 el
= this.children
.shift();
3596 el
.parentNode
.removeChild(el
);
3611 this.scrollBottom
= y
- 1;
3612 this.charMeasure
.measure();
3613 this.refresh(0, this.rows
- 1);
3615 this.geometry
= [this.cols
, this.rows
];
3616 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
3618 Terminal
.prototype.updateRange = function (y
) {
3619 if (y
< this.refreshStart
)
3620 this.refreshStart
= y
;
3621 if (y
> this.refreshEnd
)
3622 this.refreshEnd
= y
;
3624 Terminal
.prototype.maxRange = function () {
3625 this.refreshStart
= 0;
3626 this.refreshEnd
= this.rows
- 1;
3628 Terminal
.prototype.setupStops = function (i
) {
3630 if (!this.tabs
[i
]) {
3631 i
= this.prevStop(i
);
3638 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
3639 this.tabs
[i
] = true;
3642 Terminal
.prototype.prevStop = function (x
) {
3645 while (!this.tabs
[--x
] && x
> 0)
3647 return x
>= this.cols
3651 Terminal
.prototype.nextStop = function (x
) {
3654 while (!this.tabs
[++x
] && x
< this.cols
)
3656 return x
>= this.cols
3660 Terminal
.prototype.eraseRight = function (x
, y
) {
3661 var line
= this.lines
.get(this.ybase
+ y
);
3665 var ch
= [this.eraseAttr(), ' ', 1];
3666 for (; x
< this.cols
; x
++) {
3669 this.updateRange(y
);
3671 Terminal
.prototype.eraseLeft = function (x
, y
) {
3672 var line
= this.lines
.get(this.ybase
+ y
);
3676 var ch
= [this.eraseAttr(), ' ', 1];
3681 this.updateRange(y
);
3683 Terminal
.prototype.clear = function () {
3684 if (this.ybase
=== 0 && this.y
=== 0) {
3687 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
3688 this.lines
.length
= 1;
3692 for (var i
= 1; i
< this.rows
; i
++) {
3693 this.lines
.push(this.blankLine());
3695 this.refresh(0, this.rows
- 1);
3696 this.emit('scroll', this.ydisp
);
3698 Terminal
.prototype.eraseLine = function (y
) {
3699 this.eraseRight(0, y
);
3701 Terminal
.prototype.blankLine = function (cur
) {
3705 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
3706 for (; i
< this.cols
; i
++) {
3711 Terminal
.prototype.ch = function (cur
) {
3713 ? [this.eraseAttr(), ' ', 1]
3714 : [this.defAttr
, ' ', 1];
3716 Terminal
.prototype.is = function (term
) {
3717 var name
= this.termName
;
3718 return (name
+ '').indexOf(term
) === 0;
3720 Terminal
.prototype.handler = function (data
) {
3721 if (this.options
.disableStdin
) {
3724 if (this.ybase
!== this.ydisp
) {
3725 this.scrollToBottom();
3727 this.emit('data', data
);
3729 Terminal
.prototype.handleTitle = function (title
) {
3730 this.emit('title', title
);
3732 Terminal
.prototype.index = function () {
3734 if (this.y
> this.scrollBottom
) {
3738 if (this.x
>= this.cols
) {
3742 Terminal
.prototype.reverseIndex = function () {
3744 if (this.y
=== this.scrollTop
) {
3745 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
3746 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
3747 this.updateRange(this.scrollTop
);
3748 this.updateRange(this.scrollBottom
);
3754 Terminal
.prototype.reset = function () {
3755 this.options
.rows
= this.rows
;
3756 this.options
.cols
= this.cols
;
3757 var customKeydownHandler
= this.customKeydownHandler
;
3758 Terminal
.call(this, this.options
);
3759 this.customKeydownHandler
= customKeydownHandler
;
3760 this.refresh(0, this.rows
- 1);
3761 this.viewport
.syncScrollArea();
3763 Terminal
.prototype.tabSet = function () {
3764 this.tabs
[this.x
] = true;
3766 function on(el
, type
, handler
, capture
) {
3767 if (!Array
.isArray(el
)) {
3770 el
.forEach(function (element
) {
3771 element
.addEventListener(type
, handler
, capture
|| false);
3774 function off(el
, type
, handler
, capture
) {
3775 el
.removeEventListener(type
, handler
, capture
|| false);
3777 function cancel(ev
, force
) {
3778 if (!this.cancelEvents
&& !force
) {
3781 ev
.preventDefault();
3782 ev
.stopPropagation();
3785 function inherits(child
, parent
) {
3787 this.constructor = child
;
3789 f
.prototype = parent
.prototype;
3790 child
.prototype = new f
;
3792 function indexOf(obj
, el
) {
3800 function isThirdLevelShift(term
, ev
) {
3801 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
3802 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
3803 if (ev
.type
== 'keypress') {
3804 return thirdLevelKey
;
3806 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
3808 Terminal
.prototype.matchColor
= matchColor
;
3809 function matchColor(r1
, g1
, b1
) {
3810 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
3811 if (matchColor
._cache
[hash
] != null) {
3812 return matchColor
._cache
[hash
];
3814 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
3815 for (; i
< Terminal
.vcolors
.length
; i
++) {
3816 c
= Terminal
.vcolors
[i
];
3820 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
3830 return matchColor
._cache
[hash
] = li
;
3832 matchColor
._cache
= {};
3833 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
3834 return Math
.pow(30 * (r1
- r2
), 2)
3835 + Math
.pow(59 * (g1
- g2
), 2)
3836 + Math
.pow(11 * (b1
- b2
), 2);
3838 function each(obj
, iter
, con
) {
3840 return obj
.forEach(iter
, con
);
3841 for (var i
= 0; i
< obj
.length
; i
++) {
3842 iter
.call(con
, obj
[i
], i
, obj
);
3845 function wasMondifierKeyOnlyEvent(ev
) {
3846 return ev
.keyCode
=== 16 ||
3847 ev
.keyCode
=== 17 ||
3850 function keys(obj
) {
3852 return Object
.keys(obj
);
3855 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
3861 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
3862 Terminal
.inherits
= inherits
;
3865 Terminal
.cancel
= cancel
;
3866 module
.exports
= Terminal
;
3868 },{"./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)
3870 //# sourceMappingURL=xterm.js.map