1 (function(f
){if(typeof exports
==="object"&&typeof module
!=="undefined"){module
.exports
=f()}else if(typeof define
==="function"&&define
.amd
){define([],f
)}else{var g
;if(typeof window
!=="undefined"){g
=window
}else if(typeof global
!=="undefined"){g
=global
}else if(typeof self
!=="undefined"){g
=self
}else{g
=this}g
.Terminal
= f()}})(function(){var define
,module
,exports
;return (function e(t
,n
,r
){function s(o
,u
){if(!n
[o
]){if(!t
[o
]){var a
=typeof require
=="function"&&require
;if(!u
&&a
)return a(o
,!0);if(i
)return i(o
,!0);var f
=new Error("Cannot find module '"+o
+"'");throw f
.code
="MODULE_NOT_FOUND",f
}var l
=n
[o
]={exports
:{}};t
[o
][0].call(l
.exports
,function(e
){var n
=t
[o
][1][e
];return s(n
?n
:e
)},l
,l
.exports
,e
,t
,n
,r
)}return n
[o
].exports
}var i
=typeof require
=="function"&&require
;for(var o
=0;o
<r
.length
;o
++)s(r
[o
]);return s
})({1:[function(require
,module
,exports
){
3 Object
.defineProperty(exports
, "__esModule", { value
: true });
5 exports
.DEFAULT_CHARSET
= exports
.CHARSETS
['B'];
6 exports
.CHARSETS
['0'] = {
39 exports
.CHARSETS
['A'] = {
42 exports
.CHARSETS
['B'] = null;
43 exports
.CHARSETS
['4'] = {
54 exports
.CHARSETS
['C'] =
55 exports
.CHARSETS
['5'] = {
66 exports
.CHARSETS
['R'] = {
77 exports
.CHARSETS
['Q'] = {
89 exports
.CHARSETS
['K'] = {
99 exports
.CHARSETS
['Y'] = {
111 exports
.CHARSETS
['E'] =
112 exports
.CHARSETS
['6'] = {
124 exports
.CHARSETS
['Z'] = {
134 exports
.CHARSETS
['H'] =
135 exports
.CHARSETS
['7'] = {
147 exports
.CHARSETS
['='] = {
164 },{}],2:[function(require
,module
,exports
){
166 Object
.defineProperty(exports
, "__esModule", { value
: true });
167 var CompositionHelper
= (function () {
168 function CompositionHelper(textarea
, compositionView
, terminal
) {
169 this.textarea
= textarea
;
170 this.compositionView
= compositionView
;
171 this.terminal
= terminal
;
172 this.isComposing
= false;
173 this.isSendingComposition
= false;
174 this.compositionPosition
= { start
: null, end
: null };
176 CompositionHelper
.prototype.compositionstart = function () {
177 this.isComposing
= true;
178 this.compositionPosition
.start
= this.textarea
.value
.length
;
179 this.compositionView
.textContent
= '';
180 this.compositionView
.classList
.add('active');
182 CompositionHelper
.prototype.compositionupdate = function (ev
) {
184 this.compositionView
.textContent
= ev
.data
;
185 this.updateCompositionElements();
186 setTimeout(function () {
187 _this
.compositionPosition
.end
= _this
.textarea
.value
.length
;
190 CompositionHelper
.prototype.compositionend = function () {
191 this.finalizeComposition(true);
193 CompositionHelper
.prototype.keydown = function (ev
) {
194 if (this.isComposing
|| this.isSendingComposition
) {
195 if (ev
.keyCode
=== 229) {
198 else if (ev
.keyCode
=== 16 || ev
.keyCode
=== 17 || ev
.keyCode
=== 18) {
202 this.finalizeComposition(false);
205 if (ev
.keyCode
=== 229) {
206 this.handleAnyTextareaChanges();
211 CompositionHelper
.prototype.finalizeComposition = function (waitForPropogation
) {
213 this.compositionView
.classList
.remove('active');
214 this.isComposing
= false;
215 this.clearTextareaPosition();
216 if (!waitForPropogation
) {
217 this.isSendingComposition
= false;
218 var input
= this.textarea
.value
.substring(this.compositionPosition
.start
, this.compositionPosition
.end
);
219 this.terminal
.handler(input
);
222 var currentCompositionPosition_1
= {
223 start
: this.compositionPosition
.start
,
224 end
: this.compositionPosition
.end
,
226 this.isSendingComposition
= true;
227 setTimeout(function () {
228 if (_this
.isSendingComposition
) {
229 _this
.isSendingComposition
= false;
231 if (_this
.isComposing
) {
232 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
, currentCompositionPosition_1
.end
);
235 input
= _this
.textarea
.value
.substring(currentCompositionPosition_1
.start
);
237 _this
.terminal
.handler(input
);
242 CompositionHelper
.prototype.handleAnyTextareaChanges = function () {
244 var oldValue
= this.textarea
.value
;
245 setTimeout(function () {
246 if (!_this
.isComposing
) {
247 var newValue
= _this
.textarea
.value
;
248 var diff
= newValue
.replace(oldValue
, '');
249 if (diff
.length
> 0) {
250 _this
.terminal
.handler(diff
);
255 CompositionHelper
.prototype.updateCompositionElements = function (dontRecurse
) {
257 if (!this.isComposing
) {
260 var cursor
= this.terminal
.element
.querySelector('.terminal-cursor');
262 var xtermRows
= this.terminal
.element
.querySelector('.xterm-rows');
263 var cursorTop
= xtermRows
.offsetTop
+ cursor
.offsetTop
;
264 this.compositionView
.style
.left
= cursor
.offsetLeft
+ 'px';
265 this.compositionView
.style
.top
= cursorTop
+ 'px';
266 this.compositionView
.style
.height
= cursor
.offsetHeight
+ 'px';
267 this.compositionView
.style
.lineHeight
= cursor
.offsetHeight
+ 'px';
268 var compositionViewBounds
= this.compositionView
.getBoundingClientRect();
269 this.textarea
.style
.left
= cursor
.offsetLeft
+ 'px';
270 this.textarea
.style
.top
= cursorTop
+ 'px';
271 this.textarea
.style
.width
= compositionViewBounds
.width
+ 'px';
272 this.textarea
.style
.height
= compositionViewBounds
.height
+ 'px';
273 this.textarea
.style
.lineHeight
= compositionViewBounds
.height
+ 'px';
276 setTimeout(function () { return _this
.updateCompositionElements(true); }, 0);
280 CompositionHelper
.prototype.clearTextareaPosition = function () {
281 this.textarea
.style
.left
= '';
282 this.textarea
.style
.top
= '';
285 return CompositionHelper
;
287 exports
.CompositionHelper
= CompositionHelper
;
291 },{}],3:[function(require
,module
,exports
){
293 Object
.defineProperty(exports
, "__esModule", { value
: true });
330 })(C0
= exports
.C0
|| (exports
.C0
= {}));
335 },{}],4:[function(require
,module
,exports
){
337 Object
.defineProperty(exports
, "__esModule", { value
: true });
339 var EventEmitter
= (function () {
340 function EventEmitter() {
341 this._events
= this._events
|| {};
343 EventEmitter
.prototype.on = function (type
, listener
) {
344 this._events
[type
] = this._events
[type
] || [];
345 this._events
[type
].push(listener
);
347 EventEmitter
.prototype.off = function (type
, listener
) {
348 if (!this._events
[type
]) {
351 var obj
= this._events
[type
];
354 if (obj
[i
] === listener
|| obj
[i
].listener
=== listener
) {
360 EventEmitter
.prototype.removeAllListeners = function (type
) {
361 if (this._events
[type
]) {
362 delete this._events
[type
];
365 EventEmitter
.prototype.once = function (type
, listener
) {
367 var args
= Array
.prototype.slice
.call(arguments
);
369 return listener
.apply(this, args
);
371 on
.listener
= listener
;
372 return this.on(type
, on
);
374 EventEmitter
.prototype.emit = function (type
) {
376 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
377 args
[_i
- 1] = arguments
[_i
];
379 if (!this._events
[type
]) {
382 var obj
= this._events
[type
];
383 for (var i
= 0; i
< obj
.length
; i
++) {
384 obj
[i
].apply(this, args
);
387 EventEmitter
.prototype.listeners = function (type
) {
388 return this._events
[type
] || [];
392 exports
.EventEmitter
= EventEmitter
;
396 },{}],5:[function(require
,module
,exports
){
398 Object
.defineProperty(exports
, "__esModule", { value
: true });
399 var EscapeSequences_1
= require("./EscapeSequences");
400 var Charsets_1
= require("./Charsets");
401 var InputHandler
= (function () {
402 function InputHandler(_terminal
) {
403 this._terminal
= _terminal
;
405 InputHandler
.prototype.addChar = function (char, code
) {
407 var ch_width
= wcwidth(code
);
408 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
409 char = this._terminal
.charset
[char];
411 var row
= this._terminal
.y
+ this._terminal
.ybase
;
412 if (!ch_width
&& this._terminal
.x
) {
413 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 1]) {
414 if (!this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][2]) {
415 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 2])
416 this._terminal
.lines
.get(row
)[this._terminal
.x
- 2][1] += char;
419 this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][1] += char;
421 this._terminal
.updateRange(this._terminal
.y
);
425 if (this._terminal
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
426 if (this._terminal
.wraparoundMode
) {
427 this._terminal
.x
= 0;
429 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
431 this._terminal
.scroll();
439 row
= this._terminal
.y
+ this._terminal
.ybase
;
440 if (this._terminal
.insertMode
) {
441 for (var moves
= 0; moves
< ch_width
; ++moves
) {
442 var removed
= this._terminal
.lines
.get(this._terminal
.y
+ this._terminal
.ybase
).pop();
444 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2]
445 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2)
446 this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
447 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
450 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, char, ch_width
];
452 this._terminal
.updateRange(this._terminal
.y
);
453 if (ch_width
=== 2) {
454 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, '', 0];
459 InputHandler
.prototype.bell = function () {
461 if (!this._terminal
.visualBell
) {
464 this._terminal
.element
.style
.borderColor
= 'white';
465 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
466 if (this._terminal
.popOnBell
) {
467 this._terminal
.focus();
470 InputHandler
.prototype.lineFeed = function () {
471 if (this._terminal
.convertEol
) {
472 this._terminal
.x
= 0;
475 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
477 this._terminal
.scroll();
479 if (this._terminal
.x
>= this._terminal
.cols
) {
483 InputHandler
.prototype.carriageReturn = function () {
484 this._terminal
.x
= 0;
486 InputHandler
.prototype.backspace = function () {
487 if (this._terminal
.x
> 0) {
491 InputHandler
.prototype.tab = function () {
492 this._terminal
.x
= this._terminal
.nextStop();
494 InputHandler
.prototype.shiftOut = function () {
495 this._terminal
.setgLevel(1);
497 InputHandler
.prototype.shiftIn = function () {
498 this._terminal
.setgLevel(0);
500 InputHandler
.prototype.insertChars = function (params
) {
501 var param
, row
, j
, ch
;
505 row
= this._terminal
.y
+ this._terminal
.ybase
;
506 j
= this._terminal
.x
;
507 ch
= [this._terminal
.eraseAttr(), ' ', 1];
508 while (param
-- && j
< this._terminal
.cols
) {
509 this._terminal
.lines
.get(row
).splice(j
++, 0, ch
);
510 this._terminal
.lines
.get(row
).pop();
513 InputHandler
.prototype.cursorUp = function (params
) {
514 var param
= params
[0];
518 this._terminal
.y
-= param
;
519 if (this._terminal
.y
< 0) {
520 this._terminal
.y
= 0;
523 InputHandler
.prototype.cursorDown = function (params
) {
524 var param
= params
[0];
528 this._terminal
.y
+= param
;
529 if (this._terminal
.y
>= this._terminal
.rows
) {
530 this._terminal
.y
= this._terminal
.rows
- 1;
532 if (this._terminal
.x
>= this._terminal
.cols
) {
536 InputHandler
.prototype.cursorForward = function (params
) {
537 var param
= params
[0];
541 this._terminal
.x
+= param
;
542 if (this._terminal
.x
>= this._terminal
.cols
) {
543 this._terminal
.x
= this._terminal
.cols
- 1;
546 InputHandler
.prototype.cursorBackward = function (params
) {
547 var param
= params
[0];
551 if (this._terminal
.x
>= this._terminal
.cols
) {
554 this._terminal
.x
-= param
;
555 if (this._terminal
.x
< 0) {
556 this._terminal
.x
= 0;
559 InputHandler
.prototype.cursorNextLine = function (params
) {
560 var param
= params
[0];
564 this._terminal
.y
+= param
;
565 if (this._terminal
.y
>= this._terminal
.rows
) {
566 this._terminal
.y
= this._terminal
.rows
- 1;
568 this._terminal
.x
= 0;
571 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
572 var param
= params
[0];
576 this._terminal
.y
-= param
;
577 if (this._terminal
.y
< 0) {
578 this._terminal
.y
= 0;
580 this._terminal
.x
= 0;
583 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
584 var param
= params
[0];
588 this._terminal
.x
= param
- 1;
590 InputHandler
.prototype.cursorPosition = function (params
) {
593 if (params
.length
>= 2) {
602 else if (row
>= this._terminal
.rows
) {
603 row
= this._terminal
.rows
- 1;
608 else if (col
>= this._terminal
.cols
) {
609 col
= this._terminal
.cols
- 1;
611 this._terminal
.x
= col
;
612 this._terminal
.y
= row
;
614 InputHandler
.prototype.cursorForwardTab = function (params
) {
615 var param
= params
[0] || 1;
617 this._terminal
.x
= this._terminal
.nextStop();
620 InputHandler
.prototype.eraseInDisplay = function (params
) {
624 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
625 j
= this._terminal
.y
+ 1;
626 for (; j
< this._terminal
.rows
; j
++) {
627 this._terminal
.eraseLine(j
);
631 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
632 j
= this._terminal
.y
;
634 this._terminal
.eraseLine(j
);
638 j
= this._terminal
.rows
;
640 this._terminal
.eraseLine(j
);
643 var scrollBackSize
= this._terminal
.lines
.length
- this._terminal
.rows
;
644 if (scrollBackSize
> 0) {
645 this._terminal
.lines
.trimStart(scrollBackSize
);
646 this._terminal
.ybase
= Math
.max(this._terminal
.ybase
- scrollBackSize
, 0);
647 this._terminal
.ydisp
= Math
.max(this._terminal
.ydisp
- scrollBackSize
, 0);
652 InputHandler
.prototype.eraseInLine = function (params
) {
655 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
658 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
661 this._terminal
.eraseLine(this._terminal
.y
);
665 InputHandler
.prototype.insertLines = function (params
) {
671 row
= this._terminal
.y
+ this._terminal
.ybase
;
672 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
673 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
+ 1;
675 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
676 this._terminal
.lines
.trimStart(1);
677 this._terminal
.ybase
--;
678 this._terminal
.ydisp
--;
682 this._terminal
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
683 this._terminal
.lines
.splice(j
, 1);
685 this._terminal
.updateRange(this._terminal
.y
);
686 this._terminal
.updateRange(this._terminal
.scrollBottom
);
688 InputHandler
.prototype.deleteLines = function (params
) {
694 row
= this._terminal
.y
+ this._terminal
.ybase
;
695 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
696 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
;
698 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
699 this._terminal
.lines
.trimStart(1);
700 this._terminal
.ybase
-= 1;
701 this._terminal
.ydisp
-= 1;
703 this._terminal
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
704 this._terminal
.lines
.splice(row
, 1);
706 this._terminal
.updateRange(this._terminal
.y
);
707 this._terminal
.updateRange(this._terminal
.scrollBottom
);
709 InputHandler
.prototype.deleteChars = function (params
) {
715 row
= this._terminal
.y
+ this._terminal
.ybase
;
716 ch
= [this._terminal
.eraseAttr(), ' ', 1];
718 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 1);
719 this._terminal
.lines
.get(row
).push(ch
);
722 InputHandler
.prototype.scrollUp = function (params
) {
723 var param
= params
[0] || 1;
725 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 1);
726 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 0, this._terminal
.blankLine());
728 this._terminal
.updateRange(this._terminal
.scrollTop
);
729 this._terminal
.updateRange(this._terminal
.scrollBottom
);
731 InputHandler
.prototype.scrollDown = function (params
) {
732 var param
= params
[0] || 1;
734 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 1);
735 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 0, this._terminal
.blankLine());
737 this._terminal
.updateRange(this._terminal
.scrollTop
);
738 this._terminal
.updateRange(this._terminal
.scrollBottom
);
740 InputHandler
.prototype.eraseChars = function (params
) {
741 var param
, row
, j
, ch
;
746 row
= this._terminal
.y
+ this._terminal
.ybase
;
747 j
= this._terminal
.x
;
748 ch
= [this._terminal
.eraseAttr(), ' ', 1];
749 while (param
-- && j
< this._terminal
.cols
) {
750 this._terminal
.lines
.get(row
)[j
++] = ch
;
753 InputHandler
.prototype.cursorBackwardTab = function (params
) {
754 var param
= params
[0] || 1;
756 this._terminal
.x
= this._terminal
.prevStop();
759 InputHandler
.prototype.charPosAbsolute = function (params
) {
760 var param
= params
[0];
764 this._terminal
.x
= param
- 1;
765 if (this._terminal
.x
>= this._terminal
.cols
) {
766 this._terminal
.x
= this._terminal
.cols
- 1;
769 InputHandler
.prototype.HPositionRelative = function (params
) {
770 var param
= params
[0];
774 this._terminal
.x
+= param
;
775 if (this._terminal
.x
>= this._terminal
.cols
) {
776 this._terminal
.x
= this._terminal
.cols
- 1;
779 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
780 var param
= params
[0] || 1, line
= this._terminal
.lines
.get(this._terminal
.ybase
+ this._terminal
.y
), ch
= line
[this._terminal
.x
- 1] || [this._terminal
.defAttr
, ' ', 1];
782 line
[this._terminal
.x
++] = ch
;
785 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
789 if (!this._terminal
.prefix
) {
790 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
791 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
793 else if (this._terminal
.is('linux')) {
794 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
797 else if (this._terminal
.prefix
=== '>') {
798 if (this._terminal
.is('xterm')) {
799 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
801 else if (this._terminal
.is('rxvt-unicode')) {
802 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
804 else if (this._terminal
.is('linux')) {
805 this._terminal
.send(params
[0] + 'c');
807 else if (this._terminal
.is('screen')) {
808 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
812 InputHandler
.prototype.linePosAbsolute = function (params
) {
813 var param
= params
[0];
817 this._terminal
.y
= param
- 1;
818 if (this._terminal
.y
>= this._terminal
.rows
) {
819 this._terminal
.y
= this._terminal
.rows
- 1;
822 InputHandler
.prototype.VPositionRelative = function (params
) {
823 var param
= params
[0];
827 this._terminal
.y
+= param
;
828 if (this._terminal
.y
>= this._terminal
.rows
) {
829 this._terminal
.y
= this._terminal
.rows
- 1;
831 if (this._terminal
.x
>= this._terminal
.cols
) {
835 InputHandler
.prototype.HVPosition = function (params
) {
840 this._terminal
.y
= params
[0] - 1;
841 if (this._terminal
.y
>= this._terminal
.rows
) {
842 this._terminal
.y
= this._terminal
.rows
- 1;
844 this._terminal
.x
= params
[1] - 1;
845 if (this._terminal
.x
>= this._terminal
.cols
) {
846 this._terminal
.x
= this._terminal
.cols
- 1;
849 InputHandler
.prototype.tabClear = function (params
) {
850 var param
= params
[0];
852 delete this._terminal
.tabs
[this._terminal
.x
];
854 else if (param
=== 3) {
855 this._terminal
.tabs
= {};
858 InputHandler
.prototype.setMode = function (params
) {
859 if (params
.length
> 1) {
860 for (var i
= 0; i
< params
.length
; i
++) {
861 this.setMode([params
[i
]]);
865 if (!this._terminal
.prefix
) {
868 this._terminal
.insertMode
= true;
874 else if (this._terminal
.prefix
=== '?') {
877 this._terminal
.applicationCursor
= true;
880 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
881 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
882 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
883 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
886 this._terminal
.savedCols
= this._terminal
.cols
;
887 this._terminal
.resize(132, this._terminal
.rows
);
890 this._terminal
.originMode
= true;
893 this._terminal
.wraparoundMode
= true;
898 this._terminal
.log('Serial port requested application keypad.');
899 this._terminal
.applicationKeypad
= true;
900 this._terminal
.viewport
.syncScrollArea();
906 this._terminal
.x10Mouse
= params
[0] === 9;
907 this._terminal
.vt200Mouse
= params
[0] === 1000;
908 this._terminal
.normalMouse
= params
[0] > 1000;
909 this._terminal
.mouseEvents
= true;
910 this._terminal
.element
.style
.cursor
= 'default';
911 this._terminal
.log('Binding to mouse events.');
914 this._terminal
.sendFocus
= true;
917 this._terminal
.utfMouse
= true;
920 this._terminal
.sgrMouse
= true;
923 this._terminal
.urxvtMouse
= true;
926 this._terminal
.cursorHidden
= false;
932 if (!this._terminal
.normal
) {
934 lines
: this._terminal
.lines
,
935 ybase
: this._terminal
.ybase
,
936 ydisp
: this._terminal
.ydisp
,
939 scrollTop
: this._terminal
.scrollTop
,
940 scrollBottom
: this._terminal
.scrollBottom
,
941 tabs
: this._terminal
.tabs
943 this._terminal
.reset();
944 this._terminal
.viewport
.syncScrollArea();
945 this._terminal
.normal
= normal
;
946 this._terminal
.showCursor();
952 InputHandler
.prototype.resetMode = function (params
) {
953 if (params
.length
> 1) {
954 for (var i
= 0; i
< params
.length
; i
++) {
955 this.resetMode([params
[i
]]);
959 if (!this._terminal
.prefix
) {
962 this._terminal
.insertMode
= false;
968 else if (this._terminal
.prefix
=== '?') {
971 this._terminal
.applicationCursor
= false;
974 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
975 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
977 delete this._terminal
.savedCols
;
980 this._terminal
.originMode
= false;
983 this._terminal
.wraparoundMode
= false;
988 this._terminal
.log('Switching back to normal keypad.');
989 this._terminal
.applicationKeypad
= false;
990 this._terminal
.viewport
.syncScrollArea();
996 this._terminal
.x10Mouse
= false;
997 this._terminal
.vt200Mouse
= false;
998 this._terminal
.normalMouse
= false;
999 this._terminal
.mouseEvents
= false;
1000 this._terminal
.element
.style
.cursor
= '';
1003 this._terminal
.sendFocus
= false;
1006 this._terminal
.utfMouse
= false;
1009 this._terminal
.sgrMouse
= false;
1012 this._terminal
.urxvtMouse
= false;
1015 this._terminal
.cursorHidden
= true;
1021 if (this._terminal
.normal
) {
1022 this._terminal
.lines
= this._terminal
.normal
.lines
;
1023 this._terminal
.ybase
= this._terminal
.normal
.ybase
;
1024 this._terminal
.ydisp
= this._terminal
.normal
.ydisp
;
1025 this._terminal
.x
= this._terminal
.normal
.x
;
1026 this._terminal
.y
= this._terminal
.normal
.y
;
1027 this._terminal
.scrollTop
= this._terminal
.normal
.scrollTop
;
1028 this._terminal
.scrollBottom
= this._terminal
.normal
.scrollBottom
;
1029 this._terminal
.tabs
= this._terminal
.normal
.tabs
;
1030 this._terminal
.normal
= null;
1031 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1032 this._terminal
.viewport
.syncScrollArea();
1033 this._terminal
.showCursor();
1039 InputHandler
.prototype.charAttributes = function (params
) {
1040 if (params
.length
=== 1 && params
[0] === 0) {
1041 this._terminal
.curAttr
= this._terminal
.defAttr
;
1044 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1045 for (; i
< l
; i
++) {
1047 if (p
>= 30 && p
<= 37) {
1050 else if (p
>= 40 && p
<= 47) {
1053 else if (p
>= 90 && p
<= 97) {
1057 else if (p
>= 100 && p
<= 107) {
1062 flags
= this._terminal
.defAttr
>> 18;
1063 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1064 bg
= this._terminal
.defAttr
& 0x1ff;
1081 else if (p
=== 22) {
1084 else if (p
=== 24) {
1087 else if (p
=== 25) {
1090 else if (p
=== 27) {
1093 else if (p
=== 28) {
1096 else if (p
=== 39) {
1097 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1099 else if (p
=== 49) {
1100 bg
= this._terminal
.defAttr
& 0x1ff;
1102 else if (p
=== 38) {
1103 if (params
[i
+ 1] === 2) {
1105 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1110 else if (params
[i
+ 1] === 5) {
1112 p
= params
[i
] & 0xff;
1116 else if (p
=== 48) {
1117 if (params
[i
+ 1] === 2) {
1119 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1124 else if (params
[i
+ 1] === 5) {
1126 p
= params
[i
] & 0xff;
1130 else if (p
=== 100) {
1131 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1132 bg
= this._terminal
.defAttr
& 0x1ff;
1135 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1138 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1140 InputHandler
.prototype.deviceStatus = function (params
) {
1141 if (!this._terminal
.prefix
) {
1142 switch (params
[0]) {
1144 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1147 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1148 + (this._terminal
.y
+ 1)
1150 + (this._terminal
.x
+ 1)
1155 else if (this._terminal
.prefix
=== '?') {
1156 switch (params
[0]) {
1158 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1159 + (this._terminal
.y
+ 1)
1161 + (this._terminal
.x
+ 1)
1175 InputHandler
.prototype.softReset = function (params
) {
1176 this._terminal
.cursorHidden
= false;
1177 this._terminal
.insertMode
= false;
1178 this._terminal
.originMode
= false;
1179 this._terminal
.wraparoundMode
= true;
1180 this._terminal
.applicationKeypad
= false;
1181 this._terminal
.viewport
.syncScrollArea();
1182 this._terminal
.applicationCursor
= false;
1183 this._terminal
.scrollTop
= 0;
1184 this._terminal
.scrollBottom
= this._terminal
.rows
- 1;
1185 this._terminal
.curAttr
= this._terminal
.defAttr
;
1186 this._terminal
.x
= this._terminal
.y
= 0;
1187 this._terminal
.charset
= null;
1188 this._terminal
.glevel
= 0;
1189 this._terminal
.charsets
= [null];
1191 InputHandler
.prototype.setCursorStyle = function (params
) {
1192 var param
= params
[0] < 1 ? 1 : params
[0];
1196 this._terminal
.setOption('cursorStyle', 'block');
1200 this._terminal
.setOption('cursorStyle', 'underline');
1204 this._terminal
.setOption('cursorStyle', 'bar');
1207 var isBlinking
= param
% 2 === 1;
1208 this._terminal
.setOption('cursorBlink', isBlinking
);
1210 InputHandler
.prototype.setScrollRegion = function (params
) {
1211 if (this._terminal
.prefix
)
1213 this._terminal
.scrollTop
= (params
[0] || 1) - 1;
1214 this._terminal
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1215 this._terminal
.x
= 0;
1216 this._terminal
.y
= 0;
1218 InputHandler
.prototype.saveCursor = function (params
) {
1219 this._terminal
.savedX
= this._terminal
.x
;
1220 this._terminal
.savedY
= this._terminal
.y
;
1222 InputHandler
.prototype.restoreCursor = function (params
) {
1223 this._terminal
.x
= this._terminal
.savedX
|| 0;
1224 this._terminal
.y
= this._terminal
.savedY
|| 0;
1226 return InputHandler
;
1228 exports
.InputHandler
= InputHandler
;
1229 var wcwidth
= (function (opts
) {
1231 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1232 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1233 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1234 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1235 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1236 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1237 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1238 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1239 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1240 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1241 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1242 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1243 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1244 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1245 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1246 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1247 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1248 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1249 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1250 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1251 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1252 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1253 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1254 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1255 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1256 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1257 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1258 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1259 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1260 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1261 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1262 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1263 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1264 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1265 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1266 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1267 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1268 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1269 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1270 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1271 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1272 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1273 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1274 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1275 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1276 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1277 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1280 function bisearch(ucs
) {
1282 var max
= COMBINING
.length
- 1;
1284 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
1286 while (max
>= min
) {
1287 mid
= Math
.floor((min
+ max
) / 2);
1288 if (ucs
> COMBINING
[mid
][1])
1290 else if (ucs
< COMBINING
[mid
][0])
1297 function wcwidth(ucs
) {
1300 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1301 return opts
.control
;
1309 function isWide(ucs
) {
1310 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1313 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1314 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1315 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1316 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1317 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1318 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1319 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
1320 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
1321 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
1324 })({ nul
: 0, control
: 0 });
1328 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require
,module
,exports
){
1330 Object
.defineProperty(exports
, "__esModule", { value
: true });
1331 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1332 var protocolClause
= '(https?:\\/\\/)';
1333 var domainCharacterSet
= '[\\da-z\\.-]+';
1334 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1335 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1336 var tldClause
= '([a-z\\.]{2,6})';
1337 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1338 var localHostClause
= '(localhost)';
1339 var portClause
= '(:\\d{1,5})';
1340 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1341 var pathClause
= '(\\/[\\/\\w\\.\\-%~]*)*';
1342 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1343 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1344 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1345 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1346 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1347 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1348 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1349 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1350 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1351 var Linkifier
= (function () {
1352 function Linkifier() {
1353 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1354 this._rowTimeoutIds
= [];
1355 this._linkMatchers
= [];
1356 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1358 Linkifier
.prototype.attachToDom = function (document
, rows
) {
1359 this._document
= document
;
1362 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1363 if (!this._document
) {
1366 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1368 clearTimeout(timeoutId
);
1370 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1372 Linkifier
.prototype.setHypertextLinkHandler = function (handler
) {
1373 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1375 Linkifier
.prototype.setHypertextValidationCallback = function (callback
) {
1376 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].validationCallback
= callback
;
1378 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1379 if (options
=== void 0) { options
= {}; }
1380 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1381 throw new Error('handler must be defined');
1384 id
: this._nextLinkMatcherId
++,
1387 matchIndex
: options
.matchIndex
,
1388 validationCallback
: options
.validationCallback
,
1389 priority
: options
.priority
|| 0
1391 this._addLinkMatcherToList(matcher
);
1394 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1395 if (this._linkMatchers
.length
=== 0) {
1396 this._linkMatchers
.push(matcher
);
1399 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1400 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1401 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1405 this._linkMatchers
.splice(0, 0, matcher
);
1407 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1408 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1409 if (this._linkMatchers
[i
].id
=== matcherId
) {
1410 this._linkMatchers
.splice(i
, 1);
1416 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1417 var row
= this._rows
[rowIndex
];
1421 var text
= row
.textContent
;
1422 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1423 var matcher
= this._linkMatchers
[i
];
1424 var linkElements
= this._doLinkifyRow(row
, matcher
);
1425 if (linkElements
.length
> 0) {
1426 if (matcher
.validationCallback
) {
1427 var _loop_1 = function (j
) {
1428 var element
= linkElements
[j
];
1429 matcher
.validationCallback(element
.textContent
, element
, function (isValid
) {
1431 element
.classList
.add(INVALID_LINK_CLASS
);
1435 for (var j
= 0; j
< linkElements
.length
; j
++) {
1443 Linkifier
.prototype._doLinkifyRow = function (row
, matcher
) {
1445 var isHttpLinkMatcher
= matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
;
1446 var nodes
= row
.childNodes
;
1447 var match
= row
.textContent
.match(matcher
.regex
);
1448 if (!match
|| match
.length
=== 0) {
1451 var uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1452 var rowStartIndex
= match
.index
+ uri
.length
;
1453 for (var i
= 0; i
< nodes
.length
; i
++) {
1454 var node
= nodes
[i
];
1455 var searchIndex
= node
.textContent
.indexOf(uri
);
1456 if (searchIndex
>= 0) {
1457 var linkElement
= this._createAnchorElement(uri
, matcher
.handler
, isHttpLinkMatcher
);
1458 if (node
.textContent
.length
=== uri
.length
) {
1459 if (node
.nodeType
=== 3) {
1460 this._replaceNode(node
, linkElement
);
1464 if (element
.nodeName
=== 'A') {
1467 element
.innerHTML
= '';
1468 element
.appendChild(linkElement
);
1472 var nodesAdded
= this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1475 result
.push(linkElement
);
1476 match
= row
.textContent
.substring(rowStartIndex
).match(matcher
.regex
);
1477 if (!match
|| match
.length
=== 0) {
1480 uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1481 rowStartIndex
+= match
.index
+ uri
.length
;
1486 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1487 var element
= this._document
.createElement('a');
1488 element
.textContent
= uri
;
1489 element
.draggable
= false;
1490 if (isHypertextLinkHandler
) {
1492 element
.target
= '_blank';
1493 element
.addEventListener('click', function (event
) {
1495 return handler(event
, uri
);
1500 element
.addEventListener('click', function (event
) {
1501 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1504 return handler(event
, uri
);
1509 Linkifier
.prototype._replaceNode = function (oldNode
) {
1511 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1512 newNodes
[_i
- 1] = arguments
[_i
];
1514 var parent
= oldNode
.parentNode
;
1515 for (var i
= 0; i
< newNodes
.length
; i
++) {
1516 parent
.insertBefore(newNodes
[i
], oldNode
);
1518 parent
.removeChild(oldNode
);
1520 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1521 var node
= targetNode
;
1522 if (node
.nodeType
!== 3) {
1523 node
= node
.childNodes
[0];
1525 if (node
.childNodes
.length
=== 0 && node
.nodeType
!== 3) {
1526 throw new Error('targetNode must be a text node or only contain a single text node');
1528 var fullText
= node
.textContent
;
1529 if (substringIndex
=== 0) {
1530 var rightText_1
= fullText
.substring(substring
.length
);
1531 var rightTextNode_1
= this._document
.createTextNode(rightText_1
);
1532 this._replaceNode(node
, newNode
, rightTextNode_1
);
1535 if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1536 var leftText_1
= fullText
.substring(0, substringIndex
);
1537 var leftTextNode_1
= this._document
.createTextNode(leftText_1
);
1538 this._replaceNode(node
, leftTextNode_1
, newNode
);
1541 var leftText
= fullText
.substring(0, substringIndex
);
1542 var leftTextNode
= this._document
.createTextNode(leftText
);
1543 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1544 var rightTextNode
= this._document
.createTextNode(rightText
);
1545 this._replaceNode(node
, leftTextNode
, newNode
, rightTextNode
);
1550 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1551 exports
.Linkifier
= Linkifier
;
1555 },{}],7:[function(require
,module
,exports
){
1557 Object
.defineProperty(exports
, "__esModule", { value
: true });
1558 var EscapeSequences_1
= require("./EscapeSequences");
1559 var Charsets_1
= require("./Charsets");
1560 var normalStateHandler
= {};
1561 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1562 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1563 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1564 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1565 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1566 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1567 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1568 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1569 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1570 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1571 var escapedStateHandler
= {};
1572 escapedStateHandler
['['] = function (parser
, terminal
) {
1573 terminal
.params
= [];
1574 terminal
.currentParam
= 0;
1575 parser
.setState(ParserState
.CSI_PARAM
);
1577 escapedStateHandler
[']'] = function (parser
, terminal
) {
1578 terminal
.params
= [];
1579 terminal
.currentParam
= 0;
1580 parser
.setState(ParserState
.OSC
);
1582 escapedStateHandler
['P'] = function (parser
, terminal
) {
1583 terminal
.params
= [];
1584 terminal
.currentParam
= 0;
1585 parser
.setState(ParserState
.DCS
);
1587 escapedStateHandler
['_'] = function (parser
, terminal
) {
1588 parser
.setState(ParserState
.IGNORE
);
1590 escapedStateHandler
['^'] = function (parser
, terminal
) {
1591 parser
.setState(ParserState
.IGNORE
);
1593 escapedStateHandler
['c'] = function (parser
, terminal
) {
1596 escapedStateHandler
['E'] = function (parser
, terminal
) {
1599 parser
.setState(ParserState
.NORMAL
);
1601 escapedStateHandler
['D'] = function (parser
, terminal
) {
1603 parser
.setState(ParserState
.NORMAL
);
1605 escapedStateHandler
['M'] = function (parser
, terminal
) {
1606 terminal
.reverseIndex();
1607 parser
.setState(ParserState
.NORMAL
);
1609 escapedStateHandler
['%'] = function (parser
, terminal
) {
1610 terminal
.setgLevel(0);
1611 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1612 parser
.setState(ParserState
.NORMAL
);
1613 parser
.skipNextChar();
1615 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1616 var csiParamStateHandler
= {};
1617 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1618 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1619 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1620 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1621 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1622 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1623 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1624 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1625 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1626 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1627 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1628 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1629 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1630 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1631 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1632 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1633 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1634 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1635 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1636 var csiStateHandler
= {};
1637 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1638 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1639 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1640 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1641 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1642 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1643 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1644 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1645 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1646 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1647 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1648 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1649 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1650 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1651 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1652 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1653 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1654 if (params
.length
< 2 && !prefix
) {
1655 handler
.scrollDown(params
);
1658 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1659 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1660 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1661 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1662 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1663 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1664 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1665 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1666 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1667 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1668 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1669 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1670 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1671 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1672 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1675 handler
.softReset(params
);
1679 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1680 if (postfix
=== ' ') {
1681 handler
.setCursorStyle(params
);
1684 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1685 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1686 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1687 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1689 (function (ParserState
) {
1690 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1691 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1692 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1693 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1694 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1695 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1696 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1697 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1698 })(ParserState
|| (ParserState
= {}));
1699 var Parser
= (function () {
1700 function Parser(_inputHandler
, _terminal
) {
1701 this._inputHandler
= _inputHandler
;
1702 this._terminal
= _terminal
;
1703 this._state
= ParserState
.NORMAL
;
1705 Parser
.prototype.parse = function (data
) {
1706 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1708 if (this._terminal
.surrogate_high
) {
1709 data
= this._terminal
.surrogate_high
+ data
;
1710 this._terminal
.surrogate_high
= '';
1712 for (; this._position
< l
; this._position
++) {
1713 ch
= data
[this._position
];
1714 code
= data
.charCodeAt(this._position
);
1715 if (0xD800 <= code
&& code
<= 0xDBFF) {
1716 low
= data
.charCodeAt(this._position
+ 1);
1718 this._terminal
.surrogate_high
= ch
;
1721 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1722 ch
+= data
.charAt(this._position
+ 1);
1724 if (0xDC00 <= code
&& code
<= 0xDFFF)
1726 switch (this._state
) {
1727 case ParserState
.NORMAL
:
1728 if (ch
in normalStateHandler
) {
1729 normalStateHandler
[ch
](this, this._inputHandler
);
1732 this._inputHandler
.addChar(ch
, code
);
1735 case ParserState
.ESCAPED
:
1736 if (ch
in escapedStateHandler
) {
1737 escapedStateHandler
[ch
](this, this._terminal
);
1749 this._terminal
.gcharset
= 0;
1752 this._terminal
.gcharset
= 1;
1755 this._terminal
.gcharset
= 2;
1758 this._terminal
.gcharset
= 3;
1761 this._terminal
.gcharset
= 1;
1764 this._terminal
.gcharset
= 2;
1767 this._state
= ParserState
.CHARSET
;
1770 this._terminal
.gcharset
= 3;
1771 this._state
= ParserState
.CHARSET
;
1779 this._terminal
.setgLevel(2);
1782 this._terminal
.setgLevel(3);
1785 this._terminal
.setgLevel(3);
1788 this._terminal
.setgLevel(2);
1791 this._terminal
.setgLevel(1);
1794 this._inputHandler
.saveCursor();
1795 this._state
= ParserState
.NORMAL
;
1798 this._inputHandler
.restoreCursor();
1799 this._state
= ParserState
.NORMAL
;
1802 this._state
= ParserState
.NORMAL
;
1806 this._terminal
.tabSet();
1807 this._state
= ParserState
.NORMAL
;
1810 this._terminal
.log('Serial port requested application keypad.');
1811 this._terminal
.applicationKeypad
= true;
1812 this._terminal
.viewport
.syncScrollArea();
1813 this._state
= ParserState
.NORMAL
;
1816 this._terminal
.log('Switching back to normal keypad.');
1817 this._terminal
.applicationKeypad
= false;
1818 this._terminal
.viewport
.syncScrollArea();
1819 this._state
= ParserState
.NORMAL
;
1822 this._state
= ParserState
.NORMAL
;
1823 this._terminal
.error('Unknown ESC control: %s.', ch
);
1827 case ParserState
.CHARSET
:
1828 if (ch
in Charsets_1
.CHARSETS
) {
1829 cs
= Charsets_1
.CHARSETS
[ch
];
1831 this.skipNextChar();
1835 cs
= Charsets_1
.DEFAULT_CHARSET
;
1837 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1838 this._terminal
.gcharset
= null;
1839 this._state
= ParserState
.NORMAL
;
1841 case ParserState
.OSC
:
1842 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1843 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1845 this._terminal
.params
.push(this._terminal
.currentParam
);
1846 switch (this._terminal
.params
[0]) {
1850 if (this._terminal
.params
[1]) {
1851 this._terminal
.title
= this._terminal
.params
[1];
1852 this._terminal
.handleTitle(this._terminal
.title
);
1892 this._terminal
.params
= [];
1893 this._terminal
.currentParam
= 0;
1894 this._state
= ParserState
.NORMAL
;
1897 if (!this._terminal
.params
.length
) {
1898 if (ch
>= '0' && ch
<= '9') {
1899 this._terminal
.currentParam
=
1900 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1902 else if (ch
=== ';') {
1903 this._terminal
.params
.push(this._terminal
.currentParam
);
1904 this._terminal
.currentParam
= '';
1908 this._terminal
.currentParam
+= ch
;
1912 case ParserState
.CSI_PARAM
:
1913 if (ch
in csiParamStateHandler
) {
1914 csiParamStateHandler
[ch
](this);
1917 this.finalizeParam();
1918 this._state
= ParserState
.CSI
;
1919 case ParserState
.CSI
:
1920 if (ch
in csiStateHandler
) {
1921 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1924 this._terminal
.error('Unknown CSI code: %s.', ch
);
1926 this._state
= ParserState
.NORMAL
;
1927 this._terminal
.prefix
= '';
1928 this._terminal
.postfix
= '';
1930 case ParserState
.DCS
:
1931 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1932 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1936 switch (this._terminal
.prefix
) {
1940 pt
= this._terminal
.currentParam
;
1951 + (this._terminal
.scrollTop
+ 1)
1953 + (this._terminal
.scrollBottom
+ 1)
1960 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1964 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1969 pt
= this._terminal
.currentParam
;
1971 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1974 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1977 this._terminal
.currentParam
= 0;
1978 this._terminal
.prefix
= '';
1979 this._state
= ParserState
.NORMAL
;
1981 else if (!this._terminal
.currentParam
) {
1982 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1983 this._terminal
.currentParam
= ch
;
1985 else if (this._terminal
.prefix
.length
=== 2) {
1986 this._terminal
.currentParam
= ch
;
1989 this._terminal
.prefix
+= ch
;
1993 this._terminal
.currentParam
+= ch
;
1996 case ParserState
.IGNORE
:
1997 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1998 if (ch
=== EscapeSequences_1
.C0
.ESC
)
2000 this._state
= ParserState
.NORMAL
;
2007 Parser
.prototype.setState = function (state
) {
2008 this._state
= state
;
2010 Parser
.prototype.setPrefix = function (prefix
) {
2011 this._terminal
.prefix
= prefix
;
2013 Parser
.prototype.setPostfix = function (postfix
) {
2014 this._terminal
.postfix
= postfix
;
2016 Parser
.prototype.setParam = function (param
) {
2017 this._terminal
.currentParam
= param
;
2019 Parser
.prototype.getParam = function () {
2020 return this._terminal
.currentParam
;
2022 Parser
.prototype.finalizeParam = function () {
2023 this._terminal
.params
.push(this._terminal
.currentParam
);
2024 this._terminal
.currentParam
= 0;
2026 Parser
.prototype.skipNextChar = function () {
2031 exports
.Parser
= Parser
;
2035 },{"./Charsets":1,"./EscapeSequences":3}],8:[function(require
,module
,exports
){
2037 Object
.defineProperty(exports
, "__esModule", { value
: true });
2038 var DomElementObjectPool_1
= require("./utils/DomElementObjectPool");
2039 var MAX_REFRESH_FRAME_SKIP
= 5;
2042 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2043 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2044 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2045 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2046 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2047 })(FLAGS
|| (FLAGS
= {}));
2049 var brokenBold
= null;
2050 var Renderer
= (function () {
2051 function Renderer(_terminal
) {
2052 this._terminal
= _terminal
;
2053 this._refreshRowsQueue
= [];
2054 this._refreshFramesSkipped
= 0;
2055 this._refreshAnimationFrame
= null;
2056 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2057 if (brokenBold
=== null) {
2058 brokenBold
= checkBoldBroken(this._terminal
.element
);
2060 this._spanElementObjectPool
= new DomElementObjectPool_1
.DomElementObjectPool('span');
2062 Renderer
.prototype.queueRefresh = function (start
, end
) {
2063 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2064 if (!this._refreshAnimationFrame
) {
2065 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2068 Renderer
.prototype._refreshLoop = function () {
2069 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2071 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2074 this._refreshFramesSkipped
= 0;
2077 if (this._refreshRowsQueue
.length
> 4) {
2079 end
= this._terminal
.rows
- 1;
2082 start
= this._refreshRowsQueue
[0].start
;
2083 end
= this._refreshRowsQueue
[0].end
;
2084 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2085 if (this._refreshRowsQueue
[i
].start
< start
) {
2086 start
= this._refreshRowsQueue
[i
].start
;
2088 if (this._refreshRowsQueue
[i
].end
> end
) {
2089 end
= this._refreshRowsQueue
[i
].end
;
2093 this._refreshRowsQueue
= [];
2094 this._refreshAnimationFrame
= null;
2095 this._refresh(start
, end
);
2097 Renderer
.prototype._refresh = function (start
, end
) {
2099 if (end
- start
>= this._terminal
.rows
/ 2) {
2100 parent
= this._terminal
.element
.parentNode
;
2102 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2105 var width
= this._terminal
.cols
;
2107 if (end
>= this._terminal
.rows
) {
2108 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2109 end
= this._terminal
.rows
- 1;
2111 for (; y
<= end
; y
++) {
2112 var row
= y
+ this._terminal
.ydisp
;
2113 var line
= this._terminal
.lines
.get(row
);
2115 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
) &&
2116 this._terminal
.cursorState
&&
2117 !this._terminal
.cursorHidden
) {
2118 x
= this._terminal
.x
;
2123 var attr
= this._terminal
.defAttr
;
2124 var documentFragment
= document
.createDocumentFragment();
2126 var currentElement
= void 0;
2127 while (this._terminal
.children
[y
].children
.length
) {
2128 var child
= this._terminal
.children
[y
].children
[0];
2129 this._terminal
.children
[y
].removeChild(child
);
2130 this._spanElementObjectPool
.release(child
);
2132 for (var i
= 0; i
< width
; i
++) {
2133 var data
= line
[i
][0];
2134 var ch
= line
[i
][1];
2135 var ch_width
= line
[i
][2];
2142 if (data
!== attr
) {
2143 if (attr
!== this._terminal
.defAttr
) {
2145 currentElement
.innerHTML
= innerHTML
;
2148 documentFragment
.appendChild(currentElement
);
2149 currentElement
= null;
2151 if (data
!== this._terminal
.defAttr
) {
2152 if (innerHTML
&& !currentElement
) {
2153 currentElement
= this._spanElementObjectPool
.acquire();
2155 if (currentElement
) {
2157 currentElement
.innerHTML
= innerHTML
;
2160 documentFragment
.appendChild(currentElement
);
2162 currentElement
= this._spanElementObjectPool
.acquire();
2164 currentElement
.classList
.add('reverse-video', 'terminal-cursor');
2167 var bg
= data
& 0x1ff;
2168 var fg
= (data
>> 9) & 0x1ff;
2169 var flags
= data
>> 18;
2170 if (flags
& FLAGS
.BOLD
) {
2172 currentElement
.classList
.add('xterm-bold');
2178 if (flags
& FLAGS
.UNDERLINE
) {
2179 currentElement
.classList
.add('xterm-underline');
2181 if (flags
& FLAGS
.BLINK
) {
2182 currentElement
.classList
.add('xterm-blink');
2184 if (flags
& FLAGS
.INVERSE
) {
2188 if ((flags
& 1) && fg
< 8) {
2192 if (flags
& FLAGS
.INVISIBLE
) {
2193 currentElement
.classList
.add('xterm-hidden');
2195 if (flags
& FLAGS
.INVERSE
) {
2204 currentElement
.classList
.add("xterm-bg-color-" + bg
);
2207 currentElement
.classList
.add("xterm-color-" + fg
);
2212 if (ch_width
=== 2) {
2213 innerHTML
+= "<span class=\"xterm-wide-char\">" + ch
+ "</span>";
2215 else if (ch
.charCodeAt(0) > 255) {
2216 innerHTML
+= "<span class=\"xterm-normal-char\">" + ch
+ "</span>";
2221 innerHTML
+= '&';
2224 innerHTML
+= '<';
2227 innerHTML
+= '>';
2231 innerHTML
+= ' ';
2241 if (innerHTML
&& !currentElement
) {
2242 currentElement
= this._spanElementObjectPool
.acquire();
2244 if (currentElement
) {
2246 currentElement
.innerHTML
= innerHTML
;
2249 documentFragment
.appendChild(currentElement
);
2250 currentElement
= null;
2252 this._terminal
.children
[y
].appendChild(documentFragment
);
2255 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2257 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2262 exports
.Renderer
= Renderer
;
2263 function checkBoldBroken(terminal
) {
2264 var document
= terminal
.ownerDocument
;
2265 var el
= document
.createElement('span');
2266 el
.innerHTML
= 'hello world';
2267 terminal
.appendChild(el
);
2268 var w1
= el
.offsetWidth
;
2269 var h1
= el
.offsetHeight
;
2270 el
.style
.fontWeight
= 'bold';
2271 var w2
= el
.offsetWidth
;
2272 var h2
= el
.offsetHeight
;
2273 terminal
.removeChild(el
);
2274 return w1
!== w2
|| h1
!== h2
;
2279 },{"./utils/DomElementObjectPool":14}],9:[function(require
,module
,exports
){
2281 Object
.defineProperty(exports
, "__esModule", { value
: true });
2282 var Viewport
= (function () {
2283 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2285 this.terminal
= terminal
;
2286 this.viewportElement
= viewportElement
;
2287 this.scrollArea
= scrollArea
;
2288 this.charMeasure
= charMeasure
;
2289 this.currentRowHeight
= 0;
2290 this.lastRecordedBufferLength
= 0;
2291 this.lastRecordedViewportHeight
= 0;
2292 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2293 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2294 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2295 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2297 Viewport
.prototype.refresh = function () {
2298 if (this.charMeasure
.height
> 0) {
2299 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2300 if (rowHeightChanged
) {
2301 this.currentRowHeight
= this.charMeasure
.height
;
2302 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2303 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2305 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2306 if (rowHeightChanged
|| viewportHeightChanged
) {
2307 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2308 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2310 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2313 Viewport
.prototype.syncScrollArea = function () {
2314 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2315 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2318 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2322 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2326 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2327 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2328 this.viewportElement
.scrollTop
= scrollTop
;
2331 Viewport
.prototype.onScroll = function (ev
) {
2332 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2333 var diff
= newRow
- this.terminal
.ydisp
;
2334 this.terminal
.scrollDisp(diff
, true);
2336 Viewport
.prototype.onWheel = function (ev
) {
2337 if (ev
.deltaY
=== 0) {
2341 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2342 multiplier
= this.currentRowHeight
;
2344 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2345 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2347 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2348 ev
.preventDefault();
2353 exports
.Viewport
= Viewport
;
2357 },{}],10:[function(require
,module
,exports
){
2359 Object
.defineProperty(exports
, "__esModule", { value
: true });
2360 function prepareTextForClipboard(text
) {
2361 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
2362 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
2363 return processedLine
;
2365 return processedText
;
2367 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
2368 function prepareTextForTerminal(text
, isMSWindows
) {
2370 return text
.replace(/\r?\n/g, '\n');
2374 exports
.prepareTextForTerminal
= prepareTextForTerminal
;
2375 function copyHandler(ev
, term
) {
2376 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
2377 if (term
.browser
.isMSIE
) {
2378 window
.clipboardData
.setData('Text', text
);
2381 ev
.clipboardData
.setData('text/plain', text
);
2383 ev
.preventDefault();
2385 exports
.copyHandler
= copyHandler
;
2386 function pasteHandler(ev
, term
) {
2387 ev
.stopPropagation();
2389 var dispatchPaste = function (text
) {
2390 text
= prepareTextForTerminal(text
, term
.browser
.isMSWindows
);
2392 term
.textarea
.value
= '';
2393 term
.emit('paste', text
);
2394 return term
.cancel(ev
);
2396 if (term
.browser
.isMSIE
) {
2397 if (window
.clipboardData
) {
2398 text
= window
.clipboardData
.getData('Text');
2399 dispatchPaste(text
);
2403 if (ev
.clipboardData
) {
2404 text
= ev
.clipboardData
.getData('text/plain');
2405 dispatchPaste(text
);
2409 exports
.pasteHandler
= pasteHandler
;
2410 function rightClickHandler(ev
, term
) {
2411 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
2413 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
2414 for (var i
= 0; i
< cr
.length
; i
++) {
2416 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
2417 (y
> rect
.top
) && (y
< rect
.bottom
));
2418 if (clickIsOnSelection
) {
2422 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
2423 clickIsOnSelection
= false;
2426 if (!clickIsOnSelection
) {
2427 term
.textarea
.style
.position
= 'fixed';
2428 term
.textarea
.style
.width
= '20px';
2429 term
.textarea
.style
.height
= '20px';
2430 term
.textarea
.style
.left
= (x
- 10) + 'px';
2431 term
.textarea
.style
.top
= (y
- 10) + 'px';
2432 term
.textarea
.style
.zIndex
= '1000';
2433 term
.textarea
.focus();
2434 setTimeout(function () {
2435 term
.textarea
.style
.position
= null;
2436 term
.textarea
.style
.width
= null;
2437 term
.textarea
.style
.height
= null;
2438 term
.textarea
.style
.left
= null;
2439 term
.textarea
.style
.top
= null;
2440 term
.textarea
.style
.zIndex
= null;
2444 exports
.rightClickHandler
= rightClickHandler
;
2448 },{}],11:[function(require
,module
,exports
){
2450 Object
.defineProperty(exports
, "__esModule", { value
: true });
2451 var Generic_1
= require("./Generic");
2452 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2453 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2454 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2455 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2456 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2457 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2458 exports
.isIpad
= platform
=== 'iPad';
2459 exports
.isIphone
= platform
=== 'iPhone';
2460 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2464 },{"./Generic":15}],12:[function(require
,module
,exports
){
2466 var __extends
= (this && this.__extends
) || (function () {
2467 var extendStatics
= Object
.setPrototypeOf
||
2468 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
2469 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
2470 return function (d
, b
) {
2471 extendStatics(d
, b
);
2472 function __() { this.constructor = d
; }
2473 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2476 Object
.defineProperty(exports
, "__esModule", { value
: true });
2477 var EventEmitter_js_1
= require("../EventEmitter.js");
2478 var CharMeasure
= (function (_super
) {
2479 __extends(CharMeasure
, _super
);
2480 function CharMeasure(document
, parentElement
) {
2481 var _this
= _super
.call(this) || this;
2482 _this
._document
= document
;
2483 _this
._parentElement
= parentElement
;
2486 Object
.defineProperty(CharMeasure
.prototype, "width", {
2493 Object
.defineProperty(CharMeasure
.prototype, "height", {
2495 return this._height
;
2500 CharMeasure
.prototype.measure = function () {
2502 if (!this._measureElement
) {
2503 this._measureElement
= this._document
.createElement('span');
2504 this._measureElement
.style
.position
= 'absolute';
2505 this._measureElement
.style
.top
= '0';
2506 this._measureElement
.style
.left
= '-9999em';
2507 this._measureElement
.textContent
= 'W';
2508 this._measureElement
.setAttribute('aria-hidden', 'true');
2509 this._parentElement
.appendChild(this._measureElement
);
2510 setTimeout(function () { return _this
._doMeasure(); }, 0);
2516 CharMeasure
.prototype._doMeasure = function () {
2517 var geometry
= this._measureElement
.getBoundingClientRect();
2518 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
2521 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
2522 this._width
= geometry
.width
;
2523 this._height
= geometry
.height
;
2524 this.emit('charsizechanged');
2528 }(EventEmitter_js_1
.EventEmitter
));
2529 exports
.CharMeasure
= CharMeasure
;
2533 },{"../EventEmitter.js":4}],13:[function(require
,module
,exports
){
2535 Object
.defineProperty(exports
, "__esModule", { value
: true });
2536 var CircularList
= (function () {
2537 function CircularList(maxLength
) {
2538 this._array
= new Array(maxLength
);
2539 this._startIndex
= 0;
2542 Object
.defineProperty(CircularList
.prototype, "maxLength", {
2544 return this._array
.length
;
2546 set: function (newMaxLength
) {
2547 var newArray
= new Array(newMaxLength
);
2548 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
2549 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
2551 this._array
= newArray
;
2552 this._startIndex
= 0;
2557 Object
.defineProperty(CircularList
.prototype, "length", {
2559 return this._length
;
2561 set: function (newLength
) {
2562 if (newLength
> this._length
) {
2563 for (var i
= this._length
; i
< newLength
; i
++) {
2564 this._array
[i
] = undefined;
2567 this._length
= newLength
;
2572 Object
.defineProperty(CircularList
.prototype, "forEach", {
2574 return this._array
.forEach
;
2579 CircularList
.prototype.get = function (index
) {
2580 return this._array
[this._getCyclicIndex(index
)];
2582 CircularList
.prototype.set = function (index
, value
) {
2583 this._array
[this._getCyclicIndex(index
)] = value
;
2585 CircularList
.prototype.push = function (value
) {
2586 this._array
[this._getCyclicIndex(this._length
)] = value
;
2587 if (this._length
=== this.maxLength
) {
2589 if (this._startIndex
=== this.maxLength
) {
2590 this._startIndex
= 0;
2597 CircularList
.prototype.pop = function () {
2598 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
2600 CircularList
.prototype.splice = function (start
, deleteCount
) {
2602 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
2603 items
[_i
- 2] = arguments
[_i
];
2606 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
2607 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
2609 this._length
-= deleteCount
;
2611 if (items
&& items
.length
) {
2612 for (var i
= this._length
- 1; i
>= start
; i
--) {
2613 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
2615 for (var i
= 0; i
< items
.length
; i
++) {
2616 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
2618 if (this._length
+ items
.length
> this.maxLength
) {
2619 this._startIndex
+= (this._length
+ items
.length
) - this.maxLength
;
2620 this._length
= this.maxLength
;
2623 this._length
+= items
.length
;
2627 CircularList
.prototype.trimStart = function (count
) {
2628 if (count
> this._length
) {
2629 count
= this._length
;
2631 this._startIndex
+= count
;
2632 this._length
-= count
;
2634 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
2638 if (start
< 0 || start
>= this._length
) {
2639 throw new Error('start argument out of range');
2641 if (start
+ offset
< 0) {
2642 throw new Error('Cannot shift elements in list beyond index 0');
2645 for (var i
= count
- 1; i
>= 0; i
--) {
2646 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2648 var expandListBy
= (start
+ count
+ offset
) - this._length
;
2649 if (expandListBy
> 0) {
2650 this._length
+= expandListBy
;
2651 while (this._length
> this.maxLength
) {
2658 for (var i
= 0; i
< count
; i
++) {
2659 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2663 CircularList
.prototype._getCyclicIndex = function (index
) {
2664 return (this._startIndex
+ index
) % this.maxLength
;
2666 return CircularList
;
2668 exports
.CircularList
= CircularList
;
2672 },{}],14:[function(require
,module
,exports
){
2674 Object
.defineProperty(exports
, "__esModule", { value
: true });
2675 var DomElementObjectPool
= (function () {
2676 function DomElementObjectPool(type
) {
2682 DomElementObjectPool
.prototype.acquire = function () {
2684 if (this._pool
.length
=== 0) {
2685 element
= this._createNew();
2688 element
= this._pool
.pop();
2690 this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)] = element
;
2693 DomElementObjectPool
.prototype.release = function (element
) {
2694 if (!this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)]) {
2695 throw new Error('Could not release an element not yet acquired');
2697 delete this._inUse
[element
.getAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
)];
2698 this._cleanElement(element
);
2699 this._pool
.push(element
);
2701 DomElementObjectPool
.prototype._createNew = function () {
2702 var element
= document
.createElement(this._type
);
2703 var id
= DomElementObjectPool
._objectCount
++;
2704 element
.setAttribute(DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
, id
.toString(10));
2707 DomElementObjectPool
.prototype._cleanElement = function (element
) {
2708 element
.className
= '';
2709 element
.innerHTML
= '';
2711 return DomElementObjectPool
;
2713 DomElementObjectPool
.OBJECT_ID_ATTRIBUTE
= 'data-obj-id';
2714 DomElementObjectPool
._objectCount
= 0;
2715 exports
.DomElementObjectPool
= DomElementObjectPool
;
2719 },{}],15:[function(require
,module
,exports
){
2721 Object
.defineProperty(exports
, "__esModule", { value
: true });
2722 function contains(arr
, el
) {
2723 return arr
.indexOf(el
) >= 0;
2725 exports
.contains
= contains
;
2730 },{}],16:[function(require
,module
,exports
){
2732 Object
.defineProperty(exports
, "__esModule", { value
: true });
2733 function getCoords(event
, rowContainer
, charMeasure
) {
2734 if (event
.pageX
== null) {
2737 var x
= event
.pageX
;
2738 var y
= event
.pageY
;
2739 var el
= rowContainer
;
2740 while (el
&& el
!== self
.document
.documentElement
) {
2743 el
= 'offsetParent' in el
? el
.offsetParent
: el
.parentElement
;
2745 x
= Math
.ceil(x
/ charMeasure
.width
);
2746 y
= Math
.ceil(y
/ charMeasure
.height
);
2749 exports
.getCoords
= getCoords
;
2750 function getRawByteCoords(event
, rowContainer
, charMeasure
, colCount
, rowCount
) {
2751 var coords
= getCoords(event
, rowContainer
, charMeasure
);
2754 x
= Math
.min(Math
.max(x
, 0), colCount
);
2755 y
= Math
.min(Math
.max(y
, 0), rowCount
);
2758 return { x
: x
, y
: y
};
2760 exports
.getRawByteCoords
= getRawByteCoords
;
2764 },{}],17:[function(require
,module
,exports
){
2766 Object
.defineProperty(exports
, "__esModule", { value
: true });
2767 var CompositionHelper_1
= require("./CompositionHelper");
2768 var EventEmitter_1
= require("./EventEmitter");
2769 var Viewport_1
= require("./Viewport");
2770 var Clipboard_1
= require("./handlers/Clipboard");
2771 var CircularList_1
= require("./utils/CircularList");
2772 var EscapeSequences_1
= require("./EscapeSequences");
2773 var InputHandler_1
= require("./InputHandler");
2774 var Parser_1
= require("./Parser");
2775 var Renderer_1
= require("./Renderer");
2776 var Linkifier_1
= require("./Linkifier");
2777 var CharMeasure_1
= require("./utils/CharMeasure");
2778 var Browser
= require("./utils/Browser");
2779 var Mouse_1
= require("./utils/Mouse");
2780 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
2781 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
2782 var WRITE_BATCH_SIZE
= 300;
2783 var CURSOR_BLINK_INTERVAL
= 600;
2784 function Terminal(options
) {
2786 if (!(this instanceof Terminal
)) {
2787 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
2789 self
.browser
= Browser
;
2790 self
.cancel
= Terminal
.cancel
;
2791 EventEmitter_1
.EventEmitter
.call(this);
2792 if (typeof options
=== 'number') {
2796 handler
: arguments
[2]
2799 options
= options
|| {};
2800 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
2801 if (options
[key
] == null) {
2802 options
[key
] = Terminal
.options
[key
];
2803 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
2804 options
[key
] = Terminal
[key
];
2807 self
[key
] = options
[key
];
2809 if (options
.colors
.length
=== 8) {
2810 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
2812 else if (options
.colors
.length
=== 16) {
2813 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
2815 else if (options
.colors
.length
=== 10) {
2816 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
2818 else if (options
.colors
.length
=== 18) {
2819 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
2821 this.colors
= options
.colors
;
2822 this.options
= options
;
2823 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
2824 this.cols
= options
.cols
|| options
.geometry
[0];
2825 this.rows
= options
.rows
|| options
.geometry
[1];
2826 this.geometry
= [this.cols
, this.rows
];
2827 if (options
.handler
) {
2828 this.on('data', options
.handler
);
2834 this.cursorState
= 0;
2835 this.cursorHidden
= false;
2839 this.scrollBottom
= this.rows
- 1;
2840 this.customKeydownHandler
= null;
2841 this.cursorBlinkInterval
= null;
2842 this.applicationKeypad
= false;
2843 this.applicationCursor
= false;
2844 this.originMode
= false;
2845 this.insertMode
= false;
2846 this.wraparoundMode
= true;
2848 this.charset
= null;
2849 this.gcharset
= null;
2851 this.charsets
= [null];
2869 this.readable
= true;
2870 this.writable
= true;
2871 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
2872 this.curAttr
= this.defAttr
;
2874 this.currentParam
= 0;
2877 this.inputHandler
= new InputHandler_1
.InputHandler(this);
2878 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
2879 this.renderer
= this.renderer
|| null;
2880 this.linkifier
= this.linkifier
|| new Linkifier_1
.Linkifier();
2881 this.writeBuffer
= [];
2882 this.writeInProgress
= false;
2883 this.xoffSentToCatchUp
= false;
2884 this.writeStopped
= false;
2885 this.surrogate_high
= '';
2886 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
2889 this.lines
.push(this.blankLine());
2893 this.userScrolling
= false;
2895 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
2896 Terminal
.prototype.eraseAttr = function () {
2897 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
2899 Terminal
.tangoColors
= [
2917 Terminal
.colors
= (function () {
2918 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
2920 for (; i
< 216; i
++) {
2921 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
2924 for (; i
< 24; i
++) {
2928 function out(r
, g
, b
) {
2929 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
2933 return c
.length
< 2 ? '0' + c
: c
;
2937 Terminal
._colors
= Terminal
.colors
.slice();
2938 Terminal
.vcolors
= (function () {
2939 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
2940 for (; i
< 256; i
++) {
2941 color
= parseInt(colors
[i
].substring(1), 16);
2943 (color
>> 16) & 0xff,
2944 (color
>> 8) & 0xff,
2950 Terminal
.defaults
= {
2951 colors
: Terminal
.colors
,
2957 cursorStyle
: 'block',
2963 cancelEvents
: false,
2964 disableStdin
: false,
2965 useFlowControl
: false,
2968 Terminal
.options
= {};
2969 Terminal
.focus
= null;
2970 each(keys(Terminal
.defaults
), function (key
) {
2971 Terminal
[key
] = Terminal
.defaults
[key
];
2972 Terminal
.options
[key
] = Terminal
.defaults
[key
];
2974 Terminal
.prototype.focus = function () {
2975 return this.textarea
.focus();
2977 Terminal
.prototype.getOption = function (key
, value
) {
2978 if (!(key
in Terminal
.defaults
)) {
2979 throw new Error('No option with key "' + key
+ '"');
2981 if (typeof this.options
[key
] !== 'undefined') {
2982 return this.options
[key
];
2986 Terminal
.prototype.setOption = function (key
, value
) {
2987 if (!(key
in Terminal
.defaults
)) {
2988 throw new Error('No option with key "' + key
+ '"');
2992 if (this.options
[key
] !== value
) {
2993 if (this.lines
.length
> value
) {
2994 var amountToTrim
= this.lines
.length
- value
;
2995 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
2996 this.lines
.trimStart(amountToTrim
);
2997 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
2998 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
3000 this.refresh(0, this.rows
- 1);
3003 this.lines
.maxLength
= value
;
3004 this.viewport
.syncScrollArea();
3009 this.options
[key
] = value
;
3012 this.setCursorBlinking(value
);
3015 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
3016 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
3018 case 'tabStopWidth':
3023 Terminal
.prototype.restartCursorBlinking = function () {
3024 this.setCursorBlinking(this.options
.cursorBlink
);
3026 Terminal
.prototype.setCursorBlinking = function (enabled
) {
3027 this.element
.classList
.toggle('xterm-cursor-blink', enabled
);
3028 this.clearCursorBlinkingInterval();
3031 this.cursorBlinkInterval
= setInterval(function () {
3032 self
.element
.classList
.toggle('xterm-cursor-blink-on');
3033 }, CURSOR_BLINK_INTERVAL
);
3036 Terminal
.prototype.clearCursorBlinkingInterval = function () {
3037 this.element
.classList
.remove('xterm-cursor-blink-on');
3038 if (this.cursorBlinkInterval
) {
3039 clearInterval(this.cursorBlinkInterval
);
3040 this.cursorBlinkInterval
= null;
3043 Terminal
.bindFocus = function (term
) {
3044 on(term
.textarea
, 'focus', function (ev
) {
3045 if (term
.sendFocus
) {
3046 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
3048 term
.element
.classList
.add('focus');
3050 term
.restartCursorBlinking
.apply(term
);
3051 Terminal
.focus
= term
;
3052 term
.emit('focus', { terminal
: term
});
3055 Terminal
.prototype.blur = function () {
3056 return this.textarea
.blur();
3058 Terminal
.bindBlur = function (term
) {
3059 on(term
.textarea
, 'blur', function (ev
) {
3060 term
.refresh(term
.y
, term
.y
);
3061 if (term
.sendFocus
) {
3062 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
3064 term
.element
.classList
.remove('focus');
3065 term
.clearCursorBlinkingInterval
.apply(term
);
3066 Terminal
.focus
= null;
3067 term
.emit('blur', { terminal
: term
});
3070 Terminal
.prototype.initGlobal = function () {
3072 Terminal
.bindKeys(this);
3073 Terminal
.bindFocus(this);
3074 Terminal
.bindBlur(this);
3075 on(this.element
, 'copy', function (ev
) {
3076 Clipboard_1
.copyHandler
.call(this, ev
, term
);
3078 on(this.textarea
, 'paste', function (ev
) {
3079 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
3081 on(this.element
, 'paste', function (ev
) {
3082 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
3084 function rightClickHandlerWrapper(ev
) {
3085 Clipboard_1
.rightClickHandler
.call(this, ev
, term
);
3087 if (term
.browser
.isFirefox
) {
3088 on(this.element
, 'mousedown', function (ev
) {
3089 if (ev
.button
== 2) {
3090 rightClickHandlerWrapper(ev
);
3095 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
3098 Terminal
.bindKeys = function (term
) {
3099 on(term
.element
, 'keydown', function (ev
) {
3100 if (document
.activeElement
!= this) {
3105 on(term
.element
, 'keypress', function (ev
) {
3106 if (document
.activeElement
!= this) {
3111 on(term
.element
, 'keyup', function (ev
) {
3112 if (!wasMondifierKeyOnlyEvent(ev
)) {
3116 on(term
.textarea
, 'keydown', function (ev
) {
3119 on(term
.textarea
, 'keypress', function (ev
) {
3123 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
3124 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
3125 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
3126 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
3127 term
.on('refresh', function (data
) {
3128 term
.queueLinkification(data
.start
, data
.end
);
3131 Terminal
.prototype.insertRow = function (row
) {
3132 if (typeof row
!= 'object') {
3133 row
= document
.createElement('div');
3135 this.rowContainer
.appendChild(row
);
3136 this.children
.push(row
);
3139 Terminal
.prototype.open = function (parent
, focus
) {
3140 var self
= this, i
= 0, div
;
3141 this.parent
= parent
|| this.parent
;
3143 throw new Error('Terminal requires a parent element.');
3145 this.context
= this.parent
.ownerDocument
.defaultView
;
3146 this.document
= this.parent
.ownerDocument
;
3147 this.body
= this.document
.getElementsByTagName('body')[0];
3148 this.element
= this.document
.createElement('div');
3149 this.element
.classList
.add('terminal');
3150 this.element
.classList
.add('xterm');
3151 this.element
.classList
.add('xterm-theme-' + this.theme
);
3152 this.setCursorBlinking(this.options
.cursorBlink
);
3153 this.element
.style
.height
;
3154 this.element
.setAttribute('tabindex', 0);
3155 this.viewportElement
= document
.createElement('div');
3156 this.viewportElement
.classList
.add('xterm-viewport');
3157 this.element
.appendChild(this.viewportElement
);
3158 this.viewportScrollArea
= document
.createElement('div');
3159 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
3160 this.viewportElement
.appendChild(this.viewportScrollArea
);
3161 this.rowContainer
= document
.createElement('div');
3162 this.rowContainer
.classList
.add('xterm-rows');
3163 this.element
.appendChild(this.rowContainer
);
3165 this.linkifier
.attachToDom(document
, this.children
);
3166 this.helperContainer
= document
.createElement('div');
3167 this.helperContainer
.classList
.add('xterm-helpers');
3168 this.element
.appendChild(this.helperContainer
);
3169 this.textarea
= document
.createElement('textarea');
3170 this.textarea
.classList
.add('xterm-helper-textarea');
3171 this.textarea
.setAttribute('autocorrect', 'off');
3172 this.textarea
.setAttribute('autocapitalize', 'off');
3173 this.textarea
.setAttribute('spellcheck', 'false');
3174 this.textarea
.tabIndex
= 0;
3175 this.textarea
.addEventListener('focus', function () {
3176 self
.emit('focus', { terminal
: self
});
3178 this.textarea
.addEventListener('blur', function () {
3179 self
.emit('blur', { terminal
: self
});
3181 this.helperContainer
.appendChild(this.textarea
);
3182 this.compositionView
= document
.createElement('div');
3183 this.compositionView
.classList
.add('composition-view');
3184 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
3185 this.helperContainer
.appendChild(this.compositionView
);
3186 this.charSizeStyleElement
= document
.createElement('style');
3187 this.helperContainer
.appendChild(this.charSizeStyleElement
);
3188 for (; i
< this.rows
; i
++) {
3191 this.parent
.appendChild(this.element
);
3192 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
3193 this.charMeasure
.on('charsizechanged', function () {
3194 self
.updateCharSizeCSS();
3196 this.charMeasure
.measure();
3197 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
3198 this.renderer
= new Renderer_1
.Renderer(this);
3199 this.refresh(0, this.rows
- 1);
3201 if (typeof focus
== 'undefined') {
3202 var message
= 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
3203 message
+= 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
3204 message
+= 'it will default to `false`.';
3205 console
.warn(message
);
3211 on(this.element
, 'click', function () {
3212 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
3220 Terminal
.loadAddon = function (addon
, callback
) {
3221 if (typeof exports
=== 'object' && typeof module
=== 'object') {
3222 return require('./addons/' + addon
+ '/' + addon
);
3224 else if (typeof define
== 'function') {
3225 return require(['./addons/' + addon
+ '/' + addon
], callback
);
3228 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
3232 Terminal
.prototype.updateCharSizeCSS = function () {
3233 this.charSizeStyleElement
.textContent
=
3234 ".xterm-wide-char{width:" + this.charMeasure
.width
* 2 + "px;}" +
3235 (".xterm-normal-char{width:" + this.charMeasure
.width
+ "px;}");
3237 Terminal
.prototype.bindMouse = function () {
3238 var el
= this.element
, self
= this, pressed
= 32;
3239 function sendButton(ev
) {
3241 button
= getButton(ev
);
3242 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
3245 sendEvent(button
, pos
);
3246 switch (ev
.overrideType
|| ev
.type
) {
3257 function sendMove(ev
) {
3258 var button
= pressed
, pos
;
3259 pos
= Mouse_1
.getRawByteCoords(ev
, self
.rowContainer
, self
.charMeasure
, self
.cols
, self
.rows
);
3263 sendEvent(button
, pos
);
3265 function encode(data
, ch
) {
3266 if (!self
.utfMouse
) {
3268 return data
.push(0);
3275 return data
.push(0);
3282 data
.push(0xC0 | (ch
>> 6));
3283 data
.push(0x80 | (ch
& 0x3F));
3287 function sendEvent(button
, pos
) {
3288 if (self
.vt300Mouse
) {
3292 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
3295 else if (button
=== 1)
3297 else if (button
=== 2)
3299 else if (button
=== 3)
3303 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
3307 if (self
.decLocator
) {
3313 else if (button
=== 1)
3315 else if (button
=== 2)
3317 else if (button
=== 3)
3319 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
3322 + (button
=== 3 ? 4 : 0)
3332 if (self
.urxvtMouse
) {
3337 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
3340 if (self
.sgrMouse
) {
3343 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
3344 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
3349 + ((button
& 3) === 3 ? 'm' : 'M'));
3353 encode(data
, button
);
3354 encode(data
, pos
.x
);
3355 encode(data
, pos
.y
);
3356 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
3358 function getButton(ev
) {
3359 var button
, shift
, meta
, ctrl
, mod
;
3360 switch (ev
.overrideType
|| ev
.type
) {
3362 button
= ev
.button
!= null
3367 if (self
.browser
.isMSIE
) {
3368 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
3374 case 'DOMMouseScroll':
3375 button
= ev
.detail
< 0
3380 button
= ev
.wheelDeltaY
> 0
3385 shift
= ev
.shiftKey
? 4 : 0;
3386 meta
= ev
.metaKey
? 8 : 0;
3387 ctrl
= ev
.ctrlKey
? 16 : 0;
3388 mod
= shift
| meta
| ctrl
;
3389 if (self
.vt200Mouse
) {
3392 else if (!self
.normalMouse
) {
3395 button
= (32 + (mod
<< 2)) + button
;
3398 on(el
, 'mousedown', function (ev
) {
3399 if (!self
.mouseEvents
)
3403 if (self
.vt200Mouse
) {
3404 ev
.overrideType
= 'mouseup';
3406 return self
.cancel(ev
);
3408 if (self
.normalMouse
)
3409 on(self
.document
, 'mousemove', sendMove
);
3410 if (!self
.x10Mouse
) {
3411 on(self
.document
, 'mouseup', function up(ev
) {
3413 if (self
.normalMouse
)
3414 off(self
.document
, 'mousemove', sendMove
);
3415 off(self
.document
, 'mouseup', up
);
3416 return self
.cancel(ev
);
3419 return self
.cancel(ev
);
3421 on(el
, 'wheel', function (ev
) {
3422 if (!self
.mouseEvents
)
3429 return self
.cancel(ev
);
3431 on(el
, 'wheel', function (ev
) {
3432 if (self
.mouseEvents
)
3434 self
.viewport
.onWheel(ev
);
3435 return self
.cancel(ev
);
3438 Terminal
.prototype.destroy = function () {
3439 this.readable
= false;
3440 this.writable
= false;
3442 this.handler = function () { };
3443 this.write = function () { };
3444 if (this.element
&& this.element
.parentNode
) {
3445 this.element
.parentNode
.removeChild(this.element
);
3448 Terminal
.prototype.refresh = function (start
, end
) {
3449 if (this.renderer
) {
3450 this.renderer
.queueRefresh(start
, end
);
3453 Terminal
.prototype.queueLinkification = function (start
, end
) {
3454 if (this.linkifier
) {
3455 for (var i
= start
; i
<= end
; i
++) {
3456 this.linkifier
.linkifyRow(i
);
3460 Terminal
.prototype.showCursor = function () {
3461 if (!this.cursorState
) {
3462 this.cursorState
= 1;
3463 this.refresh(this.y
, this.y
);
3466 Terminal
.prototype.scroll = function () {
3468 if (this.lines
.length
=== this.lines
.maxLength
) {
3469 this.lines
.trimStart(1);
3471 if (this.ydisp
!== 0) {
3476 if (!this.userScrolling
) {
3477 this.ydisp
= this.ybase
;
3479 row
= this.ybase
+ this.rows
- 1;
3480 row
-= this.rows
- 1 - this.scrollBottom
;
3481 if (row
=== this.lines
.length
) {
3482 this.lines
.push(this.blankLine());
3485 this.lines
.splice(row
, 0, this.blankLine());
3487 if (this.scrollTop
!== 0) {
3488 if (this.ybase
!== 0) {
3490 if (!this.userScrolling
) {
3491 this.ydisp
= this.ybase
;
3494 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
3496 this.updateRange(this.scrollTop
);
3497 this.updateRange(this.scrollBottom
);
3498 this.emit('scroll', this.ydisp
);
3500 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
3502 this.userScrolling
= true;
3504 else if (disp
+ this.ydisp
>= this.ybase
) {
3505 this.userScrolling
= false;
3508 if (this.ydisp
> this.ybase
) {
3509 this.ydisp
= this.ybase
;
3511 else if (this.ydisp
< 0) {
3514 if (!suppressScrollEvent
) {
3515 this.emit('scroll', this.ydisp
);
3517 this.refresh(0, this.rows
- 1);
3519 Terminal
.prototype.scrollPages = function (pageCount
) {
3520 this.scrollDisp(pageCount
* (this.rows
- 1));
3522 Terminal
.prototype.scrollToTop = function () {
3523 this.scrollDisp(-this.ydisp
);
3525 Terminal
.prototype.scrollToBottom = function () {
3526 this.scrollDisp(this.ybase
- this.ydisp
);
3528 Terminal
.prototype.write = function (data
) {
3529 this.writeBuffer
.push(data
);
3530 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
3531 this.send(EscapeSequences_1
.C0
.DC3
);
3532 this.xoffSentToCatchUp
= true;
3534 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
3535 this.writeInProgress
= true;
3537 setTimeout(function () {
3542 Terminal
.prototype.innerWrite = function () {
3543 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
3544 while (writeBatch
.length
> 0) {
3545 var data
= writeBatch
.shift();
3546 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
3547 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
3548 this.send(EscapeSequences_1
.C0
.DC1
);
3549 this.xoffSentToCatchUp
= false;
3551 this.refreshStart
= this.y
;
3552 this.refreshEnd
= this.y
;
3553 var state
= this.parser
.parse(data
);
3554 this.parser
.setState(state
);
3555 this.updateRange(this.y
);
3556 this.refresh(this.refreshStart
, this.refreshEnd
);
3558 if (this.writeBuffer
.length
> 0) {
3560 setTimeout(function () {
3565 this.writeInProgress
= false;
3568 Terminal
.prototype.writeln = function (data
) {
3569 this.write(data
+ '\r\n');
3571 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
3572 this.customKeydownHandler
= customKeydownHandler
;
3574 Terminal
.prototype.setHypertextLinkHandler = function (handler
) {
3575 if (!this.linkifier
) {
3576 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
3578 this.linkifier
.setHypertextLinkHandler(handler
);
3579 this.refresh(0, this.rows
- 1);
3581 Terminal
.prototype.setHypertextValidationCallback = function (handler
) {
3582 if (!this.linkifier
) {
3583 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
3585 this.linkifier
.setHypertextValidationCallback(handler
);
3586 this.refresh(0, this.rows
- 1);
3588 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
3589 if (this.linkifier
) {
3590 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
3591 this.refresh(0, this.rows
- 1);
3595 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
3596 if (this.linkifier
) {
3597 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
3598 this.refresh(0, this.rows
- 1);
3602 Terminal
.prototype.keyDown = function (ev
) {
3603 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
3606 this.restartCursorBlinking();
3607 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
3608 if (this.ybase
!== this.ydisp
) {
3609 this.scrollToBottom();
3614 var result
= this.evaluateKeyEscapeSequence(ev
);
3615 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
3616 this.writeStopped
= true;
3618 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
3619 this.writeStopped
= false;
3621 if (result
.scrollDisp
) {
3622 this.scrollDisp(result
.scrollDisp
);
3623 return this.cancel(ev
, true);
3625 if (isThirdLevelShift(this, ev
)) {
3628 if (result
.cancel
) {
3629 this.cancel(ev
, true);
3634 this.emit('keydown', ev
);
3635 this.emit('key', result
.key
, ev
);
3637 this.handler(result
.key
);
3638 return this.cancel(ev
, true);
3640 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
3644 scrollDisp
: undefined
3646 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
3647 switch (ev
.keyCode
) {
3650 result
.key
= EscapeSequences_1
.C0
.BS
;
3653 result
.key
= EscapeSequences_1
.C0
.DEL
;
3657 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
3660 result
.key
= EscapeSequences_1
.C0
.HT
;
3661 result
.cancel
= true;
3664 result
.key
= EscapeSequences_1
.C0
.CR
;
3665 result
.cancel
= true;
3668 result
.key
= EscapeSequences_1
.C0
.ESC
;
3669 result
.cancel
= true;
3673 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
3674 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
3675 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
3678 else if (this.applicationCursor
) {
3679 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
3682 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
3687 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
3688 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
3689 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
3692 else if (this.applicationCursor
) {
3693 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
3696 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
3701 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
3702 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
3703 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
3706 else if (this.applicationCursor
) {
3707 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
3710 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
3715 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
3716 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
3717 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
3720 else if (this.applicationCursor
) {
3721 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
3724 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
3728 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
3729 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
3734 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
3737 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
3742 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
3743 else if (this.applicationCursor
)
3744 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
3746 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
3750 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
3751 else if (this.applicationCursor
)
3752 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
3754 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
3758 result
.scrollDisp
= -(this.rows
- 1);
3761 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
3766 result
.scrollDisp
= this.rows
- 1;
3769 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
3774 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
3777 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
3782 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
3785 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
3790 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
3793 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
3798 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
3801 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
3806 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
3809 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
3814 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
3817 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
3822 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
3825 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
3830 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
3833 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
3838 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
3841 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
3846 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
3849 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
3854 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
3857 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
3862 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
3865 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
3869 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
3870 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3871 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
3873 else if (ev
.keyCode
=== 32) {
3874 result
.key
= String
.fromCharCode(0);
3876 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
3877 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
3879 else if (ev
.keyCode
=== 56) {
3880 result
.key
= String
.fromCharCode(127);
3882 else if (ev
.keyCode
=== 219) {
3883 result
.key
= String
.fromCharCode(27);
3885 else if (ev
.keyCode
=== 220) {
3886 result
.key
= String
.fromCharCode(28);
3888 else if (ev
.keyCode
=== 221) {
3889 result
.key
= String
.fromCharCode(29);
3892 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
3893 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3894 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
3896 else if (ev
.keyCode
=== 192) {
3897 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
3899 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
3900 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
3907 Terminal
.prototype.setgLevel = function (g
) {
3909 this.charset
= this.charsets
[g
];
3911 Terminal
.prototype.setgCharset = function (g
, charset
) {
3912 this.charsets
[g
] = charset
;
3913 if (this.glevel
=== g
) {
3914 this.charset
= charset
;
3917 Terminal
.prototype.keyPress = function (ev
) {
3923 else if (ev
.which
== null) {
3926 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3932 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3935 key
= String
.fromCharCode(key
);
3936 this.emit('keypress', key
, ev
);
3937 this.emit('key', key
, ev
);
3942 Terminal
.prototype.send = function (data
) {
3945 setTimeout(function () {
3946 self
.handler(self
.queue
);
3952 Terminal
.prototype.bell = function () {
3953 if (!this.visualBell
)
3956 this.element
.style
.borderColor
= 'white';
3957 setTimeout(function () {
3958 self
.element
.style
.borderColor
= '';
3963 Terminal
.prototype.log = function () {
3966 if (!this.context
.console
|| !this.context
.console
.log
)
3968 var args
= Array
.prototype.slice
.call(arguments
);
3969 this.context
.console
.log
.apply(this.context
.console
, args
);
3971 Terminal
.prototype.error = function () {
3974 if (!this.context
.console
|| !this.context
.console
.error
)
3976 var args
= Array
.prototype.slice
.call(arguments
);
3977 this.context
.console
.error
.apply(this.context
.console
, args
);
3979 Terminal
.prototype.resize = function (x
, y
) {
3980 if (isNaN(x
) || isNaN(y
)) {
3983 var line
, el
, i
, j
, ch
, addToY
;
3984 if (x
=== this.cols
&& y
=== this.rows
) {
3993 ch
= [this.defAttr
, ' ', 1];
3994 i
= this.lines
.length
;
3996 while (this.lines
.get(i
).length
< x
) {
3997 this.lines
.get(i
).push(ch
);
4002 this.setupStops(this.cols
);
4008 if (this.lines
.length
< y
+ this.ybase
) {
4009 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
4012 if (this.ydisp
> 0) {
4017 this.lines
.push(this.blankLine());
4020 if (this.children
.length
< y
) {
4027 if (this.lines
.length
> y
+ this.ybase
) {
4028 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
4036 if (this.children
.length
> y
) {
4037 el
= this.children
.shift();
4040 el
.parentNode
.removeChild(el
);
4055 this.scrollBottom
= y
- 1;
4056 this.charMeasure
.measure();
4057 this.refresh(0, this.rows
- 1);
4059 this.geometry
= [this.cols
, this.rows
];
4060 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
4062 Terminal
.prototype.updateRange = function (y
) {
4063 if (y
< this.refreshStart
)
4064 this.refreshStart
= y
;
4065 if (y
> this.refreshEnd
)
4066 this.refreshEnd
= y
;
4068 Terminal
.prototype.maxRange = function () {
4069 this.refreshStart
= 0;
4070 this.refreshEnd
= this.rows
- 1;
4072 Terminal
.prototype.setupStops = function (i
) {
4074 if (!this.tabs
[i
]) {
4075 i
= this.prevStop(i
);
4082 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
4083 this.tabs
[i
] = true;
4086 Terminal
.prototype.prevStop = function (x
) {
4089 while (!this.tabs
[--x
] && x
> 0)
4091 return x
>= this.cols
4095 Terminal
.prototype.nextStop = function (x
) {
4098 while (!this.tabs
[++x
] && x
< this.cols
)
4100 return x
>= this.cols
4104 Terminal
.prototype.eraseRight = function (x
, y
) {
4105 var line
= this.lines
.get(this.ybase
+ y
);
4109 var ch
= [this.eraseAttr(), ' ', 1];
4110 for (; x
< this.cols
; x
++) {
4113 this.updateRange(y
);
4115 Terminal
.prototype.eraseLeft = function (x
, y
) {
4116 var line
= this.lines
.get(this.ybase
+ y
);
4120 var ch
= [this.eraseAttr(), ' ', 1];
4125 this.updateRange(y
);
4127 Terminal
.prototype.clear = function () {
4128 if (this.ybase
=== 0 && this.y
=== 0) {
4131 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
4132 this.lines
.length
= 1;
4136 for (var i
= 1; i
< this.rows
; i
++) {
4137 this.lines
.push(this.blankLine());
4139 this.refresh(0, this.rows
- 1);
4140 this.emit('scroll', this.ydisp
);
4142 Terminal
.prototype.eraseLine = function (y
) {
4143 this.eraseRight(0, y
);
4145 Terminal
.prototype.blankLine = function (cur
) {
4149 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
4150 for (; i
< this.cols
; i
++) {
4155 Terminal
.prototype.ch = function (cur
) {
4157 ? [this.eraseAttr(), ' ', 1]
4158 : [this.defAttr
, ' ', 1];
4160 Terminal
.prototype.is = function (term
) {
4161 var name
= this.termName
;
4162 return (name
+ '').indexOf(term
) === 0;
4164 Terminal
.prototype.handler = function (data
) {
4165 if (this.options
.disableStdin
) {
4168 if (this.ybase
!== this.ydisp
) {
4169 this.scrollToBottom();
4171 this.emit('data', data
);
4173 Terminal
.prototype.handleTitle = function (title
) {
4174 this.emit('title', title
);
4176 Terminal
.prototype.index = function () {
4178 if (this.y
> this.scrollBottom
) {
4182 if (this.x
>= this.cols
) {
4186 Terminal
.prototype.reverseIndex = function () {
4188 if (this.y
=== this.scrollTop
) {
4189 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
4190 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
4191 this.updateRange(this.scrollTop
);
4192 this.updateRange(this.scrollBottom
);
4198 Terminal
.prototype.reset = function () {
4199 this.options
.rows
= this.rows
;
4200 this.options
.cols
= this.cols
;
4201 var customKeydownHandler
= this.customKeydownHandler
;
4202 var cursorBlinkInterval
= this.cursorBlinkInterval
;
4203 Terminal
.call(this, this.options
);
4204 this.customKeydownHandler
= customKeydownHandler
;
4205 this.cursorBlinkInterval
= cursorBlinkInterval
;
4206 this.refresh(0, this.rows
- 1);
4207 this.viewport
.syncScrollArea();
4209 Terminal
.prototype.tabSet = function () {
4210 this.tabs
[this.x
] = true;
4212 function on(el
, type
, handler
, capture
) {
4213 if (!Array
.isArray(el
)) {
4216 el
.forEach(function (element
) {
4217 element
.addEventListener(type
, handler
, capture
|| false);
4220 function off(el
, type
, handler
, capture
) {
4221 el
.removeEventListener(type
, handler
, capture
|| false);
4223 function cancel(ev
, force
) {
4224 if (!this.cancelEvents
&& !force
) {
4227 ev
.preventDefault();
4228 ev
.stopPropagation();
4231 function inherits(child
, parent
) {
4233 this.constructor = child
;
4235 f
.prototype = parent
.prototype;
4236 child
.prototype = new f
;
4238 function indexOf(obj
, el
) {
4246 function isThirdLevelShift(term
, ev
) {
4247 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4248 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4249 if (ev
.type
== 'keypress') {
4250 return thirdLevelKey
;
4252 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4254 Terminal
.prototype.matchColor
= matchColor
;
4255 function matchColor(r1
, g1
, b1
) {
4256 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4257 if (matchColor
._cache
[hash
] != null) {
4258 return matchColor
._cache
[hash
];
4260 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
4261 for (; i
< Terminal
.vcolors
.length
; i
++) {
4262 c
= Terminal
.vcolors
[i
];
4266 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4276 return matchColor
._cache
[hash
] = li
;
4278 matchColor
._cache
= {};
4279 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
4280 return Math
.pow(30 * (r1
- r2
), 2)
4281 + Math
.pow(59 * (g1
- g2
), 2)
4282 + Math
.pow(11 * (b1
- b2
), 2);
4284 function each(obj
, iter
, con
) {
4286 return obj
.forEach(iter
, con
);
4287 for (var i
= 0; i
< obj
.length
; i
++) {
4288 iter
.call(con
, obj
[i
], i
, obj
);
4291 function wasMondifierKeyOnlyEvent(ev
) {
4292 return ev
.keyCode
=== 16 ||
4293 ev
.keyCode
=== 17 ||
4296 function keys(obj
) {
4298 return Object
.keys(obj
);
4301 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4307 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
4308 Terminal
.inherits
= inherits
;
4311 Terminal
.cancel
= cancel
;
4312 module
.exports
= Terminal
;
4316 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./Viewport":9,"./handlers/Clipboard":10,"./utils/Browser":11,"./utils/CharMeasure":12,"./utils/CircularList":13,"./utils/Mouse":16}]},{},[17])(17)
4318 //# sourceMappingURL=xterm.js.map