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
) {
375 if (!this._events
[type
]) {
378 var args
= Array
.prototype.slice
.call(arguments
, 1);
379 var obj
= this._events
[type
];
380 for (var i
= 0; i
< obj
.length
; i
++) {
381 obj
[i
].apply(this, args
);
384 EventEmitter
.prototype.listeners = function (type
) {
385 return this._events
[type
] || [];
389 exports
.EventEmitter
= EventEmitter
;
393 },{}],5:[function(require
,module
,exports
){
395 Object
.defineProperty(exports
, "__esModule", { value
: true });
396 var EscapeSequences_1
= require("./EscapeSequences");
397 var Charsets_1
= require("./Charsets");
398 var InputHandler
= (function () {
399 function InputHandler(_terminal
) {
400 this._terminal
= _terminal
;
402 InputHandler
.prototype.addChar = function (char, code
) {
404 var ch_width
= wcwidth(code
);
405 if (this._terminal
.charset
&& this._terminal
.charset
[char]) {
406 char = this._terminal
.charset
[char];
408 var row
= this._terminal
.y
+ this._terminal
.ybase
;
409 if (!ch_width
&& this._terminal
.x
) {
410 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 1]) {
411 if (!this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][2]) {
412 if (this._terminal
.lines
.get(row
)[this._terminal
.x
- 2])
413 this._terminal
.lines
.get(row
)[this._terminal
.x
- 2][1] += char;
416 this._terminal
.lines
.get(row
)[this._terminal
.x
- 1][1] += char;
418 this._terminal
.updateRange(this._terminal
.y
);
422 if (this._terminal
.x
+ ch_width
- 1 >= this._terminal
.cols
) {
423 if (this._terminal
.wraparoundMode
) {
424 this._terminal
.x
= 0;
426 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
428 this._terminal
.scroll();
436 row
= this._terminal
.y
+ this._terminal
.ybase
;
437 if (this._terminal
.insertMode
) {
438 for (var moves
= 0; moves
< ch_width
; ++moves
) {
439 var removed
= this._terminal
.lines
.get(this._terminal
.y
+ this._terminal
.ybase
).pop();
441 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2]
442 && this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2][2] === 2)
443 this._terminal
.lines
.get(row
)[this._terminal
.cols
- 2] = [this._terminal
.curAttr
, ' ', 1];
444 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 0, [this._terminal
.curAttr
, ' ', 1]);
447 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, char, ch_width
];
449 this._terminal
.updateRange(this._terminal
.y
);
450 if (ch_width
=== 2) {
451 this._terminal
.lines
.get(row
)[this._terminal
.x
] = [this._terminal
.curAttr
, '', 0];
456 InputHandler
.prototype.bell = function () {
458 if (!this._terminal
.visualBell
) {
461 this._terminal
.element
.style
.borderColor
= 'white';
462 setTimeout(function () { return _this
._terminal
.element
.style
.borderColor
= ''; }, 10);
463 if (this._terminal
.popOnBell
) {
464 this._terminal
.focus();
467 InputHandler
.prototype.lineFeed = function () {
468 if (this._terminal
.convertEol
) {
469 this._terminal
.x
= 0;
472 if (this._terminal
.y
> this._terminal
.scrollBottom
) {
474 this._terminal
.scroll();
476 if (this._terminal
.x
>= this._terminal
.cols
) {
480 InputHandler
.prototype.carriageReturn = function () {
481 this._terminal
.x
= 0;
483 InputHandler
.prototype.backspace = function () {
484 if (this._terminal
.x
> 0) {
488 InputHandler
.prototype.tab = function () {
489 this._terminal
.x
= this._terminal
.nextStop();
491 InputHandler
.prototype.shiftOut = function () {
492 this._terminal
.setgLevel(1);
494 InputHandler
.prototype.shiftIn = function () {
495 this._terminal
.setgLevel(0);
497 InputHandler
.prototype.insertChars = function (params
) {
498 var param
, row
, j
, ch
;
502 row
= this._terminal
.y
+ this._terminal
.ybase
;
503 j
= this._terminal
.x
;
504 ch
= [this._terminal
.eraseAttr(), ' ', 1];
505 while (param
-- && j
< this._terminal
.cols
) {
506 this._terminal
.lines
.get(row
).splice(j
++, 0, ch
);
507 this._terminal
.lines
.get(row
).pop();
510 InputHandler
.prototype.cursorUp = function (params
) {
511 var param
= params
[0];
515 this._terminal
.y
-= param
;
516 if (this._terminal
.y
< 0) {
517 this._terminal
.y
= 0;
520 InputHandler
.prototype.cursorDown = function (params
) {
521 var param
= params
[0];
525 this._terminal
.y
+= param
;
526 if (this._terminal
.y
>= this._terminal
.rows
) {
527 this._terminal
.y
= this._terminal
.rows
- 1;
529 if (this._terminal
.x
>= this._terminal
.cols
) {
533 InputHandler
.prototype.cursorForward = function (params
) {
534 var param
= params
[0];
538 this._terminal
.x
+= param
;
539 if (this._terminal
.x
>= this._terminal
.cols
) {
540 this._terminal
.x
= this._terminal
.cols
- 1;
543 InputHandler
.prototype.cursorBackward = function (params
) {
544 var param
= params
[0];
548 if (this._terminal
.x
>= this._terminal
.cols
) {
551 this._terminal
.x
-= param
;
552 if (this._terminal
.x
< 0) {
553 this._terminal
.x
= 0;
556 InputHandler
.prototype.cursorNextLine = function (params
) {
557 var param
= params
[0];
561 this._terminal
.y
+= param
;
562 if (this._terminal
.y
>= this._terminal
.rows
) {
563 this._terminal
.y
= this._terminal
.rows
- 1;
565 this._terminal
.x
= 0;
568 InputHandler
.prototype.cursorPrecedingLine = function (params
) {
569 var param
= params
[0];
573 this._terminal
.y
-= param
;
574 if (this._terminal
.y
< 0) {
575 this._terminal
.y
= 0;
577 this._terminal
.x
= 0;
580 InputHandler
.prototype.cursorCharAbsolute = function (params
) {
581 var param
= params
[0];
585 this._terminal
.x
= param
- 1;
587 InputHandler
.prototype.cursorPosition = function (params
) {
590 if (params
.length
>= 2) {
599 else if (row
>= this._terminal
.rows
) {
600 row
= this._terminal
.rows
- 1;
605 else if (col
>= this._terminal
.cols
) {
606 col
= this._terminal
.cols
- 1;
608 this._terminal
.x
= col
;
609 this._terminal
.y
= row
;
611 InputHandler
.prototype.cursorForwardTab = function (params
) {
612 var param
= params
[0] || 1;
614 this._terminal
.x
= this._terminal
.nextStop();
617 InputHandler
.prototype.eraseInDisplay = function (params
) {
621 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
622 j
= this._terminal
.y
+ 1;
623 for (; j
< this._terminal
.rows
; j
++) {
624 this._terminal
.eraseLine(j
);
628 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
629 j
= this._terminal
.y
;
631 this._terminal
.eraseLine(j
);
635 j
= this._terminal
.rows
;
637 this._terminal
.eraseLine(j
);
640 var scrollBackSize
= this._terminal
.lines
.length
- this._terminal
.rows
;
641 if (scrollBackSize
> 0) {
642 this._terminal
.lines
.trimStart(scrollBackSize
);
643 this._terminal
.ybase
= Math
.max(this._terminal
.ybase
- scrollBackSize
, 0);
644 this._terminal
.ydisp
= Math
.max(this._terminal
.ydisp
- scrollBackSize
, 0);
649 InputHandler
.prototype.eraseInLine = function (params
) {
652 this._terminal
.eraseRight(this._terminal
.x
, this._terminal
.y
);
655 this._terminal
.eraseLeft(this._terminal
.x
, this._terminal
.y
);
658 this._terminal
.eraseLine(this._terminal
.y
);
662 InputHandler
.prototype.insertLines = function (params
) {
668 row
= this._terminal
.y
+ this._terminal
.ybase
;
669 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
670 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
+ 1;
672 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
673 this._terminal
.lines
.trimStart(1);
674 this._terminal
.ybase
--;
675 this._terminal
.ydisp
--;
679 this._terminal
.lines
.splice(row
, 0, this._terminal
.blankLine(true));
680 this._terminal
.lines
.splice(j
, 1);
682 this._terminal
.updateRange(this._terminal
.y
);
683 this._terminal
.updateRange(this._terminal
.scrollBottom
);
685 InputHandler
.prototype.deleteLines = function (params
) {
691 row
= this._terminal
.y
+ this._terminal
.ybase
;
692 j
= this._terminal
.rows
- 1 - this._terminal
.scrollBottom
;
693 j
= this._terminal
.rows
- 1 + this._terminal
.ybase
- j
;
695 if (this._terminal
.lines
.length
=== this._terminal
.lines
.maxLength
) {
696 this._terminal
.lines
.trimStart(1);
697 this._terminal
.ybase
-= 1;
698 this._terminal
.ydisp
-= 1;
700 this._terminal
.lines
.splice(j
+ 1, 0, this._terminal
.blankLine(true));
701 this._terminal
.lines
.splice(row
, 1);
703 this._terminal
.updateRange(this._terminal
.y
);
704 this._terminal
.updateRange(this._terminal
.scrollBottom
);
706 InputHandler
.prototype.deleteChars = function (params
) {
712 row
= this._terminal
.y
+ this._terminal
.ybase
;
713 ch
= [this._terminal
.eraseAttr(), ' ', 1];
715 this._terminal
.lines
.get(row
).splice(this._terminal
.x
, 1);
716 this._terminal
.lines
.get(row
).push(ch
);
719 InputHandler
.prototype.scrollUp = function (params
) {
720 var param
= params
[0] || 1;
722 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 1);
723 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 0, this._terminal
.blankLine());
725 this._terminal
.updateRange(this._terminal
.scrollTop
);
726 this._terminal
.updateRange(this._terminal
.scrollBottom
);
728 InputHandler
.prototype.scrollDown = function (params
) {
729 var param
= params
[0] || 1;
731 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollBottom
, 1);
732 this._terminal
.lines
.splice(this._terminal
.ybase
+ this._terminal
.scrollTop
, 0, this._terminal
.blankLine());
734 this._terminal
.updateRange(this._terminal
.scrollTop
);
735 this._terminal
.updateRange(this._terminal
.scrollBottom
);
737 InputHandler
.prototype.eraseChars = function (params
) {
738 var param
, row
, j
, ch
;
743 row
= this._terminal
.y
+ this._terminal
.ybase
;
744 j
= this._terminal
.x
;
745 ch
= [this._terminal
.eraseAttr(), ' ', 1];
746 while (param
-- && j
< this._terminal
.cols
) {
747 this._terminal
.lines
.get(row
)[j
++] = ch
;
750 InputHandler
.prototype.cursorBackwardTab = function (params
) {
751 var param
= params
[0] || 1;
753 this._terminal
.x
= this._terminal
.prevStop();
756 InputHandler
.prototype.charPosAbsolute = function (params
) {
757 var param
= params
[0];
761 this._terminal
.x
= param
- 1;
762 if (this._terminal
.x
>= this._terminal
.cols
) {
763 this._terminal
.x
= this._terminal
.cols
- 1;
766 InputHandler
.prototype.HPositionRelative = function (params
) {
767 var param
= params
[0];
771 this._terminal
.x
+= param
;
772 if (this._terminal
.x
>= this._terminal
.cols
) {
773 this._terminal
.x
= this._terminal
.cols
- 1;
776 InputHandler
.prototype.repeatPrecedingCharacter = function (params
) {
777 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];
779 line
[this._terminal
.x
++] = ch
;
782 InputHandler
.prototype.sendDeviceAttributes = function (params
) {
786 if (!this._terminal
.prefix
) {
787 if (this._terminal
.is('xterm') || this._terminal
.is('rxvt-unicode') || this._terminal
.is('screen')) {
788 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?1;2c');
790 else if (this._terminal
.is('linux')) {
791 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?6c');
794 else if (this._terminal
.prefix
=== '>') {
795 if (this._terminal
.is('xterm')) {
796 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>0;276;0c');
798 else if (this._terminal
.is('rxvt-unicode')) {
799 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>85;95;0c');
801 else if (this._terminal
.is('linux')) {
802 this._terminal
.send(params
[0] + 'c');
804 else if (this._terminal
.is('screen')) {
805 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[>83;40003;0c');
809 InputHandler
.prototype.linePosAbsolute = function (params
) {
810 var param
= params
[0];
814 this._terminal
.y
= param
- 1;
815 if (this._terminal
.y
>= this._terminal
.rows
) {
816 this._terminal
.y
= this._terminal
.rows
- 1;
819 InputHandler
.prototype.VPositionRelative = function (params
) {
820 var param
= params
[0];
824 this._terminal
.y
+= param
;
825 if (this._terminal
.y
>= this._terminal
.rows
) {
826 this._terminal
.y
= this._terminal
.rows
- 1;
828 if (this._terminal
.x
>= this._terminal
.cols
) {
832 InputHandler
.prototype.HVPosition = function (params
) {
837 this._terminal
.y
= params
[0] - 1;
838 if (this._terminal
.y
>= this._terminal
.rows
) {
839 this._terminal
.y
= this._terminal
.rows
- 1;
841 this._terminal
.x
= params
[1] - 1;
842 if (this._terminal
.x
>= this._terminal
.cols
) {
843 this._terminal
.x
= this._terminal
.cols
- 1;
846 InputHandler
.prototype.tabClear = function (params
) {
847 var param
= params
[0];
849 delete this._terminal
.tabs
[this._terminal
.x
];
851 else if (param
=== 3) {
852 this._terminal
.tabs
= {};
855 InputHandler
.prototype.setMode = function (params
) {
856 if (params
.length
> 1) {
857 for (var i
= 0; i
< params
.length
; i
++) {
858 this.setMode([params
[i
]]);
862 if (!this._terminal
.prefix
) {
865 this._terminal
.insertMode
= true;
871 else if (this._terminal
.prefix
=== '?') {
874 this._terminal
.applicationCursor
= true;
877 this._terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
878 this._terminal
.setgCharset(1, Charsets_1
.DEFAULT_CHARSET
);
879 this._terminal
.setgCharset(2, Charsets_1
.DEFAULT_CHARSET
);
880 this._terminal
.setgCharset(3, Charsets_1
.DEFAULT_CHARSET
);
883 this._terminal
.savedCols
= this._terminal
.cols
;
884 this._terminal
.resize(132, this._terminal
.rows
);
887 this._terminal
.originMode
= true;
890 this._terminal
.wraparoundMode
= true;
895 this._terminal
.log('Serial port requested application keypad.');
896 this._terminal
.applicationKeypad
= true;
897 this._terminal
.viewport
.syncScrollArea();
903 this._terminal
.x10Mouse
= params
[0] === 9;
904 this._terminal
.vt200Mouse
= params
[0] === 1000;
905 this._terminal
.normalMouse
= params
[0] > 1000;
906 this._terminal
.mouseEvents
= true;
907 this._terminal
.element
.style
.cursor
= 'default';
908 this._terminal
.log('Binding to mouse events.');
911 this._terminal
.sendFocus
= true;
914 this._terminal
.utfMouse
= true;
917 this._terminal
.sgrMouse
= true;
920 this._terminal
.urxvtMouse
= true;
923 this._terminal
.cursorHidden
= false;
929 if (!this._terminal
.normal
) {
931 lines
: this._terminal
.lines
,
932 ybase
: this._terminal
.ybase
,
933 ydisp
: this._terminal
.ydisp
,
936 scrollTop
: this._terminal
.scrollTop
,
937 scrollBottom
: this._terminal
.scrollBottom
,
938 tabs
: this._terminal
.tabs
940 this._terminal
.reset();
941 this._terminal
.viewport
.syncScrollArea();
942 this._terminal
.normal
= normal
;
943 this._terminal
.showCursor();
949 InputHandler
.prototype.resetMode = function (params
) {
950 if (params
.length
> 1) {
951 for (var i
= 0; i
< params
.length
; i
++) {
952 this.resetMode([params
[i
]]);
956 if (!this._terminal
.prefix
) {
959 this._terminal
.insertMode
= false;
965 else if (this._terminal
.prefix
=== '?') {
968 this._terminal
.applicationCursor
= false;
971 if (this._terminal
.cols
=== 132 && this._terminal
.savedCols
) {
972 this._terminal
.resize(this._terminal
.savedCols
, this._terminal
.rows
);
974 delete this._terminal
.savedCols
;
977 this._terminal
.originMode
= false;
980 this._terminal
.wraparoundMode
= false;
985 this._terminal
.log('Switching back to normal keypad.');
986 this._terminal
.applicationKeypad
= false;
987 this._terminal
.viewport
.syncScrollArea();
993 this._terminal
.x10Mouse
= false;
994 this._terminal
.vt200Mouse
= false;
995 this._terminal
.normalMouse
= false;
996 this._terminal
.mouseEvents
= false;
997 this._terminal
.element
.style
.cursor
= '';
1000 this._terminal
.sendFocus
= false;
1003 this._terminal
.utfMouse
= false;
1006 this._terminal
.sgrMouse
= false;
1009 this._terminal
.urxvtMouse
= false;
1012 this._terminal
.cursorHidden
= true;
1018 if (this._terminal
.normal
) {
1019 this._terminal
.lines
= this._terminal
.normal
.lines
;
1020 this._terminal
.ybase
= this._terminal
.normal
.ybase
;
1021 this._terminal
.ydisp
= this._terminal
.normal
.ydisp
;
1022 this._terminal
.x
= this._terminal
.normal
.x
;
1023 this._terminal
.y
= this._terminal
.normal
.y
;
1024 this._terminal
.scrollTop
= this._terminal
.normal
.scrollTop
;
1025 this._terminal
.scrollBottom
= this._terminal
.normal
.scrollBottom
;
1026 this._terminal
.tabs
= this._terminal
.normal
.tabs
;
1027 this._terminal
.normal
= null;
1028 this._terminal
.refresh(0, this._terminal
.rows
- 1);
1029 this._terminal
.viewport
.syncScrollArea();
1030 this._terminal
.showCursor();
1036 InputHandler
.prototype.charAttributes = function (params
) {
1037 if (params
.length
=== 1 && params
[0] === 0) {
1038 this._terminal
.curAttr
= this._terminal
.defAttr
;
1041 var l
= params
.length
, i
= 0, flags
= this._terminal
.curAttr
>> 18, fg
= (this._terminal
.curAttr
>> 9) & 0x1ff, bg
= this._terminal
.curAttr
& 0x1ff, p
;
1042 for (; i
< l
; i
++) {
1044 if (p
>= 30 && p
<= 37) {
1047 else if (p
>= 40 && p
<= 47) {
1050 else if (p
>= 90 && p
<= 97) {
1054 else if (p
>= 100 && p
<= 107) {
1059 flags
= this._terminal
.defAttr
>> 18;
1060 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1061 bg
= this._terminal
.defAttr
& 0x1ff;
1078 else if (p
=== 22) {
1081 else if (p
=== 24) {
1084 else if (p
=== 25) {
1087 else if (p
=== 27) {
1090 else if (p
=== 28) {
1093 else if (p
=== 39) {
1094 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1096 else if (p
=== 49) {
1097 bg
= this._terminal
.defAttr
& 0x1ff;
1099 else if (p
=== 38) {
1100 if (params
[i
+ 1] === 2) {
1102 fg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1107 else if (params
[i
+ 1] === 5) {
1109 p
= params
[i
] & 0xff;
1113 else if (p
=== 48) {
1114 if (params
[i
+ 1] === 2) {
1116 bg
= this._terminal
.matchColor(params
[i
] & 0xff, params
[i
+ 1] & 0xff, params
[i
+ 2] & 0xff);
1121 else if (params
[i
+ 1] === 5) {
1123 p
= params
[i
] & 0xff;
1127 else if (p
=== 100) {
1128 fg
= (this._terminal
.defAttr
>> 9) & 0x1ff;
1129 bg
= this._terminal
.defAttr
& 0x1ff;
1132 this._terminal
.error('Unknown SGR attribute: %d.', p
);
1135 this._terminal
.curAttr
= (flags
<< 18) | (fg
<< 9) | bg
;
1137 InputHandler
.prototype.deviceStatus = function (params
) {
1138 if (!this._terminal
.prefix
) {
1139 switch (params
[0]) {
1141 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[0n');
1144 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '['
1145 + (this._terminal
.y
+ 1)
1147 + (this._terminal
.x
+ 1)
1152 else if (this._terminal
.prefix
=== '?') {
1153 switch (params
[0]) {
1155 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ '[?'
1156 + (this._terminal
.y
+ 1)
1158 + (this._terminal
.x
+ 1)
1172 InputHandler
.prototype.softReset = function (params
) {
1173 this._terminal
.cursorHidden
= false;
1174 this._terminal
.insertMode
= false;
1175 this._terminal
.originMode
= false;
1176 this._terminal
.wraparoundMode
= true;
1177 this._terminal
.applicationKeypad
= false;
1178 this._terminal
.viewport
.syncScrollArea();
1179 this._terminal
.applicationCursor
= false;
1180 this._terminal
.scrollTop
= 0;
1181 this._terminal
.scrollBottom
= this._terminal
.rows
- 1;
1182 this._terminal
.curAttr
= this._terminal
.defAttr
;
1183 this._terminal
.x
= this._terminal
.y
= 0;
1184 this._terminal
.charset
= null;
1185 this._terminal
.glevel
= 0;
1186 this._terminal
.charsets
= [null];
1188 InputHandler
.prototype.setCursorStyle = function (params
) {
1189 var param
= params
[0] < 1 ? 1 : params
[0];
1193 this._terminal
.setOption('cursorStyle', 'block');
1197 this._terminal
.setOption('cursorStyle', 'underline');
1201 this._terminal
.setOption('cursorStyle', 'bar');
1204 var isBlinking
= param
% 2 === 1;
1205 this._terminal
.setOption('cursorBlink', isBlinking
);
1207 InputHandler
.prototype.setScrollRegion = function (params
) {
1208 if (this._terminal
.prefix
)
1210 this._terminal
.scrollTop
= (params
[0] || 1) - 1;
1211 this._terminal
.scrollBottom
= (params
[1] && params
[1] <= this._terminal
.rows
? params
[1] : this._terminal
.rows
) - 1;
1212 this._terminal
.x
= 0;
1213 this._terminal
.y
= 0;
1215 InputHandler
.prototype.saveCursor = function (params
) {
1216 this._terminal
.savedX
= this._terminal
.x
;
1217 this._terminal
.savedY
= this._terminal
.y
;
1219 InputHandler
.prototype.restoreCursor = function (params
) {
1220 this._terminal
.x
= this._terminal
.savedX
|| 0;
1221 this._terminal
.y
= this._terminal
.savedY
|| 0;
1223 return InputHandler
;
1225 exports
.InputHandler
= InputHandler
;
1226 var wcwidth
= (function (opts
) {
1228 [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
1229 [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
1230 [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
1231 [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
1232 [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
1233 [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
1234 [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
1235 [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
1236 [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
1237 [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
1238 [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
1239 [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
1240 [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
1241 [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
1242 [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
1243 [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
1244 [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
1245 [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
1246 [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
1247 [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
1248 [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
1249 [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
1250 [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
1251 [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
1252 [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
1253 [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
1254 [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
1255 [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
1256 [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
1257 [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
1258 [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
1259 [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
1260 [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
1261 [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
1262 [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
1263 [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
1264 [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
1265 [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
1266 [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
1267 [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
1268 [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
1269 [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
1270 [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
1271 [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
1272 [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
1273 [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
1274 [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
1277 function bisearch(ucs
) {
1279 var max
= COMBINING
.length
- 1;
1281 if (ucs
< COMBINING
[0][0] || ucs
> COMBINING
[max
][1])
1283 while (max
>= min
) {
1284 mid
= Math
.floor((min
+ max
) / 2);
1285 if (ucs
> COMBINING
[mid
][1])
1287 else if (ucs
< COMBINING
[mid
][0])
1294 function wcwidth(ucs
) {
1297 if (ucs
< 32 || (ucs
>= 0x7f && ucs
< 0xa0))
1298 return opts
.control
;
1306 function isWide(ucs
) {
1307 return (ucs
>= 0x1100 && (ucs
<= 0x115f ||
1310 (ucs
>= 0x2e80 && ucs
<= 0xa4cf && ucs
!== 0x303f) ||
1311 (ucs
>= 0xac00 && ucs
<= 0xd7a3) ||
1312 (ucs
>= 0xf900 && ucs
<= 0xfaff) ||
1313 (ucs
>= 0xfe10 && ucs
<= 0xfe19) ||
1314 (ucs
>= 0xfe30 && ucs
<= 0xfe6f) ||
1315 (ucs
>= 0xff00 && ucs
<= 0xff60) ||
1316 (ucs
>= 0xffe0 && ucs
<= 0xffe6) ||
1317 (ucs
>= 0x20000 && ucs
<= 0x2fffd) ||
1318 (ucs
>= 0x30000 && ucs
<= 0x3fffd)));
1321 })({ nul
: 0, control
: 0 });
1325 },{"./Charsets":1,"./EscapeSequences":3}],6:[function(require
,module
,exports
){
1327 Object
.defineProperty(exports
, "__esModule", { value
: true });
1328 var INVALID_LINK_CLASS
= 'xterm-invalid-link';
1329 var protocolClause
= '(https?:\\/\\/)';
1330 var domainCharacterSet
= '[\\da-z\\.-]+';
1331 var negatedDomainCharacterSet
= '[^\\da-z\\.-]+';
1332 var domainBodyClause
= '(' + domainCharacterSet
+ ')';
1333 var tldClause
= '([a-z\\.]{2,6})';
1334 var ipClause
= '((\\d{1,3}\\.){3}\\d{1,3})';
1335 var localHostClause
= '(localhost)';
1336 var portClause
= '(:\\d{1,5})';
1337 var hostClause
= '((' + domainBodyClause
+ '\\.' + tldClause
+ ')|' + ipClause
+ '|' + localHostClause
+ ')' + portClause
+ '?';
1338 var pathClause
= '(\\/[\\/\\w\\.\\-%~]*)*';
1339 var queryStringHashFragmentCharacterSet
= '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*';
1340 var queryStringClause
= '(\\?' + queryStringHashFragmentCharacterSet
+ ')?';
1341 var hashFragmentClause
= '(#' + queryStringHashFragmentCharacterSet
+ ')?';
1342 var negatedPathCharacterSet
= '[^\\/\\w\\.\\-%]+';
1343 var bodyClause
= hostClause
+ pathClause
+ queryStringClause
+ hashFragmentClause
;
1344 var start
= '(?:^|' + negatedDomainCharacterSet
+ ')(';
1345 var end
= ')($|' + negatedPathCharacterSet
+ ')';
1346 var strictUrlRegex
= new RegExp(start
+ protocolClause
+ bodyClause
+ end
);
1347 var HYPERTEXT_LINK_MATCHER_ID
= 0;
1348 var Linkifier
= (function () {
1349 function Linkifier() {
1350 this._nextLinkMatcherId
= HYPERTEXT_LINK_MATCHER_ID
;
1351 this._rowTimeoutIds
= [];
1352 this._linkMatchers
= [];
1353 this.registerLinkMatcher(strictUrlRegex
, null, { matchIndex
: 1 });
1355 Linkifier
.prototype.attachToDom = function (document
, rows
) {
1356 this._document
= document
;
1359 Linkifier
.prototype.linkifyRow = function (rowIndex
) {
1360 if (!this._document
) {
1363 var timeoutId
= this._rowTimeoutIds
[rowIndex
];
1365 clearTimeout(timeoutId
);
1367 this._rowTimeoutIds
[rowIndex
] = setTimeout(this._linkifyRow
.bind(this, rowIndex
), Linkifier
.TIME_BEFORE_LINKIFY
);
1369 Linkifier
.prototype.setHypertextLinkHandler = function (handler
) {
1370 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].handler
= handler
;
1372 Linkifier
.prototype.setHypertextValidationCallback = function (callback
) {
1373 this._linkMatchers
[HYPERTEXT_LINK_MATCHER_ID
].validationCallback
= callback
;
1375 Linkifier
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
1376 if (options
=== void 0) { options
= {}; }
1377 if (this._nextLinkMatcherId
!== HYPERTEXT_LINK_MATCHER_ID
&& !handler
) {
1378 throw new Error('handler must be defined');
1381 id
: this._nextLinkMatcherId
++,
1384 matchIndex
: options
.matchIndex
,
1385 validationCallback
: options
.validationCallback
,
1386 priority
: options
.priority
|| 0
1388 this._addLinkMatcherToList(matcher
);
1391 Linkifier
.prototype._addLinkMatcherToList = function (matcher
) {
1392 if (this._linkMatchers
.length
=== 0) {
1393 this._linkMatchers
.push(matcher
);
1396 for (var i
= this._linkMatchers
.length
- 1; i
>= 0; i
--) {
1397 if (matcher
.priority
<= this._linkMatchers
[i
].priority
) {
1398 this._linkMatchers
.splice(i
+ 1, 0, matcher
);
1402 this._linkMatchers
.splice(0, 0, matcher
);
1404 Linkifier
.prototype.deregisterLinkMatcher = function (matcherId
) {
1405 for (var i
= 1; i
< this._linkMatchers
.length
; i
++) {
1406 if (this._linkMatchers
[i
].id
=== matcherId
) {
1407 this._linkMatchers
.splice(i
, 1);
1413 Linkifier
.prototype._linkifyRow = function (rowIndex
) {
1414 var row
= this._rows
[rowIndex
];
1418 var text
= row
.textContent
;
1419 for (var i
= 0; i
< this._linkMatchers
.length
; i
++) {
1420 var matcher
= this._linkMatchers
[i
];
1421 var linkElements
= this._doLinkifyRow(row
, matcher
);
1422 if (linkElements
.length
> 0) {
1423 if (matcher
.validationCallback
) {
1424 var _loop_1 = function (j
) {
1425 var element
= linkElements
[j
];
1426 matcher
.validationCallback(element
.textContent
, element
, function (isValid
) {
1428 element
.classList
.add(INVALID_LINK_CLASS
);
1432 for (var j
= 0; j
< linkElements
.length
; j
++) {
1440 Linkifier
.prototype._doLinkifyRow = function (row
, matcher
) {
1442 var isHttpLinkMatcher
= matcher
.id
=== HYPERTEXT_LINK_MATCHER_ID
;
1443 var nodes
= row
.childNodes
;
1444 var match
= row
.textContent
.match(matcher
.regex
);
1445 if (!match
|| match
.length
=== 0) {
1448 var uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1449 var rowStartIndex
= match
.index
+ uri
.length
;
1450 for (var i
= 0; i
< nodes
.length
; i
++) {
1451 var node
= nodes
[i
];
1452 var searchIndex
= node
.textContent
.indexOf(uri
);
1453 if (searchIndex
>= 0) {
1454 var linkElement
= this._createAnchorElement(uri
, matcher
.handler
, isHttpLinkMatcher
);
1455 if (node
.textContent
.length
=== uri
.length
) {
1456 if (node
.nodeType
=== 3) {
1457 this._replaceNode(node
, linkElement
);
1461 if (element
.nodeName
=== 'A') {
1464 element
.innerHTML
= '';
1465 element
.appendChild(linkElement
);
1469 var nodesAdded
= this._replaceNodeSubstringWithNode(node
, linkElement
, uri
, searchIndex
);
1472 result
.push(linkElement
);
1473 match
= row
.textContent
.substring(rowStartIndex
).match(matcher
.regex
);
1474 if (!match
|| match
.length
=== 0) {
1477 uri
= match
[typeof matcher
.matchIndex
!== 'number' ? 0 : matcher
.matchIndex
];
1478 rowStartIndex
+= match
.index
+ uri
.length
;
1483 Linkifier
.prototype._createAnchorElement = function (uri
, handler
, isHypertextLinkHandler
) {
1484 var element
= this._document
.createElement('a');
1485 element
.textContent
= uri
;
1486 element
.draggable
= false;
1487 if (isHypertextLinkHandler
) {
1489 element
.target
= '_blank';
1490 element
.addEventListener('click', function (event
) {
1492 return handler(event
, uri
);
1497 element
.addEventListener('click', function (event
) {
1498 if (element
.classList
.contains(INVALID_LINK_CLASS
)) {
1501 return handler(event
, uri
);
1506 Linkifier
.prototype._replaceNode = function (oldNode
) {
1508 for (var _i
= 1; _i
< arguments
.length
; _i
++) {
1509 newNodes
[_i
- 1] = arguments
[_i
];
1511 var parent
= oldNode
.parentNode
;
1512 for (var i
= 0; i
< newNodes
.length
; i
++) {
1513 parent
.insertBefore(newNodes
[i
], oldNode
);
1515 parent
.removeChild(oldNode
);
1517 Linkifier
.prototype._replaceNodeSubstringWithNode = function (targetNode
, newNode
, substring
, substringIndex
) {
1518 var node
= targetNode
;
1519 if (node
.nodeType
!== 3) {
1520 node
= node
.childNodes
[0];
1522 if (node
.childNodes
.length
=== 0 && node
.nodeType
!== 3) {
1523 throw new Error('targetNode must be a text node or only contain a single text node');
1525 var fullText
= node
.textContent
;
1526 if (substringIndex
=== 0) {
1527 var rightText_1
= fullText
.substring(substring
.length
);
1528 var rightTextNode_1
= this._document
.createTextNode(rightText_1
);
1529 this._replaceNode(node
, newNode
, rightTextNode_1
);
1532 if (substringIndex
=== targetNode
.textContent
.length
- substring
.length
) {
1533 var leftText_1
= fullText
.substring(0, substringIndex
);
1534 var leftTextNode_1
= this._document
.createTextNode(leftText_1
);
1535 this._replaceNode(node
, leftTextNode_1
, newNode
);
1538 var leftText
= fullText
.substring(0, substringIndex
);
1539 var leftTextNode
= this._document
.createTextNode(leftText
);
1540 var rightText
= fullText
.substring(substringIndex
+ substring
.length
);
1541 var rightTextNode
= this._document
.createTextNode(rightText
);
1542 this._replaceNode(node
, leftTextNode
, newNode
, rightTextNode
);
1547 Linkifier
.TIME_BEFORE_LINKIFY
= 200;
1548 exports
.Linkifier
= Linkifier
;
1552 },{}],7:[function(require
,module
,exports
){
1554 Object
.defineProperty(exports
, "__esModule", { value
: true });
1555 var EscapeSequences_1
= require("./EscapeSequences");
1556 var Charsets_1
= require("./Charsets");
1557 var normalStateHandler
= {};
1558 normalStateHandler
[EscapeSequences_1
.C0
.BEL
] = function (parser
, handler
) { return handler
.bell(); };
1559 normalStateHandler
[EscapeSequences_1
.C0
.LF
] = function (parser
, handler
) { return handler
.lineFeed(); };
1560 normalStateHandler
[EscapeSequences_1
.C0
.VT
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1561 normalStateHandler
[EscapeSequences_1
.C0
.FF
] = normalStateHandler
[EscapeSequences_1
.C0
.LF
];
1562 normalStateHandler
[EscapeSequences_1
.C0
.CR
] = function (parser
, handler
) { return handler
.carriageReturn(); };
1563 normalStateHandler
[EscapeSequences_1
.C0
.BS
] = function (parser
, handler
) { return handler
.backspace(); };
1564 normalStateHandler
[EscapeSequences_1
.C0
.HT
] = function (parser
, handler
) { return handler
.tab(); };
1565 normalStateHandler
[EscapeSequences_1
.C0
.SO
] = function (parser
, handler
) { return handler
.shiftOut(); };
1566 normalStateHandler
[EscapeSequences_1
.C0
.SI
] = function (parser
, handler
) { return handler
.shiftIn(); };
1567 normalStateHandler
[EscapeSequences_1
.C0
.ESC
] = function (parser
, handler
) { return parser
.setState(ParserState
.ESCAPED
); };
1568 var escapedStateHandler
= {};
1569 escapedStateHandler
['['] = function (parser
, terminal
) {
1570 terminal
.params
= [];
1571 terminal
.currentParam
= 0;
1572 parser
.setState(ParserState
.CSI_PARAM
);
1574 escapedStateHandler
[']'] = function (parser
, terminal
) {
1575 terminal
.params
= [];
1576 terminal
.currentParam
= 0;
1577 parser
.setState(ParserState
.OSC
);
1579 escapedStateHandler
['P'] = function (parser
, terminal
) {
1580 terminal
.params
= [];
1581 terminal
.currentParam
= 0;
1582 parser
.setState(ParserState
.DCS
);
1584 escapedStateHandler
['_'] = function (parser
, terminal
) {
1585 parser
.setState(ParserState
.IGNORE
);
1587 escapedStateHandler
['^'] = function (parser
, terminal
) {
1588 parser
.setState(ParserState
.IGNORE
);
1590 escapedStateHandler
['c'] = function (parser
, terminal
) {
1593 escapedStateHandler
['E'] = function (parser
, terminal
) {
1596 parser
.setState(ParserState
.NORMAL
);
1598 escapedStateHandler
['D'] = function (parser
, terminal
) {
1600 parser
.setState(ParserState
.NORMAL
);
1602 escapedStateHandler
['M'] = function (parser
, terminal
) {
1603 terminal
.reverseIndex();
1604 parser
.setState(ParserState
.NORMAL
);
1606 escapedStateHandler
['%'] = function (parser
, terminal
) {
1607 terminal
.setgLevel(0);
1608 terminal
.setgCharset(0, Charsets_1
.DEFAULT_CHARSET
);
1609 parser
.setState(ParserState
.NORMAL
);
1610 parser
.skipNextChar();
1612 escapedStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1613 var csiParamStateHandler
= {};
1614 csiParamStateHandler
['?'] = function (parser
) { return parser
.setPrefix('?'); };
1615 csiParamStateHandler
['>'] = function (parser
) { return parser
.setPrefix('>'); };
1616 csiParamStateHandler
['!'] = function (parser
) { return parser
.setPrefix('!'); };
1617 csiParamStateHandler
['0'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10); };
1618 csiParamStateHandler
['1'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 1); };
1619 csiParamStateHandler
['2'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 2); };
1620 csiParamStateHandler
['3'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 3); };
1621 csiParamStateHandler
['4'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 4); };
1622 csiParamStateHandler
['5'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 5); };
1623 csiParamStateHandler
['6'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 6); };
1624 csiParamStateHandler
['7'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 7); };
1625 csiParamStateHandler
['8'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 8); };
1626 csiParamStateHandler
['9'] = function (parser
) { return parser
.setParam(parser
.getParam() * 10 + 9); };
1627 csiParamStateHandler
['$'] = function (parser
) { return parser
.setPostfix('$'); };
1628 csiParamStateHandler
['"'] = function (parser
) { return parser
.setPostfix('"'); };
1629 csiParamStateHandler
[' '] = function (parser
) { return parser
.setPostfix(' '); };
1630 csiParamStateHandler
['\''] = function (parser
) { return parser
.setPostfix('\''); };
1631 csiParamStateHandler
[';'] = function (parser
) { return parser
.finalizeParam(); };
1632 csiParamStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (parser
) { return parser
.setState(ParserState
.NORMAL
); };
1633 var csiStateHandler
= {};
1634 csiStateHandler
['@'] = function (handler
, params
, prefix
) { return handler
.insertChars(params
); };
1635 csiStateHandler
['A'] = function (handler
, params
, prefix
) { return handler
.cursorUp(params
); };
1636 csiStateHandler
['B'] = function (handler
, params
, prefix
) { return handler
.cursorDown(params
); };
1637 csiStateHandler
['C'] = function (handler
, params
, prefix
) { return handler
.cursorForward(params
); };
1638 csiStateHandler
['D'] = function (handler
, params
, prefix
) { return handler
.cursorBackward(params
); };
1639 csiStateHandler
['E'] = function (handler
, params
, prefix
) { return handler
.cursorNextLine(params
); };
1640 csiStateHandler
['F'] = function (handler
, params
, prefix
) { return handler
.cursorPrecedingLine(params
); };
1641 csiStateHandler
['G'] = function (handler
, params
, prefix
) { return handler
.cursorCharAbsolute(params
); };
1642 csiStateHandler
['H'] = function (handler
, params
, prefix
) { return handler
.cursorPosition(params
); };
1643 csiStateHandler
['I'] = function (handler
, params
, prefix
) { return handler
.cursorForwardTab(params
); };
1644 csiStateHandler
['J'] = function (handler
, params
, prefix
) { return handler
.eraseInDisplay(params
); };
1645 csiStateHandler
['K'] = function (handler
, params
, prefix
) { return handler
.eraseInLine(params
); };
1646 csiStateHandler
['L'] = function (handler
, params
, prefix
) { return handler
.insertLines(params
); };
1647 csiStateHandler
['M'] = function (handler
, params
, prefix
) { return handler
.deleteLines(params
); };
1648 csiStateHandler
['P'] = function (handler
, params
, prefix
) { return handler
.deleteChars(params
); };
1649 csiStateHandler
['S'] = function (handler
, params
, prefix
) { return handler
.scrollUp(params
); };
1650 csiStateHandler
['T'] = function (handler
, params
, prefix
) {
1651 if (params
.length
< 2 && !prefix
) {
1652 handler
.scrollDown(params
);
1655 csiStateHandler
['X'] = function (handler
, params
, prefix
) { return handler
.eraseChars(params
); };
1656 csiStateHandler
['Z'] = function (handler
, params
, prefix
) { return handler
.cursorBackwardTab(params
); };
1657 csiStateHandler
['`'] = function (handler
, params
, prefix
) { return handler
.charPosAbsolute(params
); };
1658 csiStateHandler
['a'] = function (handler
, params
, prefix
) { return handler
.HPositionRelative(params
); };
1659 csiStateHandler
['b'] = function (handler
, params
, prefix
) { return handler
.repeatPrecedingCharacter(params
); };
1660 csiStateHandler
['c'] = function (handler
, params
, prefix
) { return handler
.sendDeviceAttributes(params
); };
1661 csiStateHandler
['d'] = function (handler
, params
, prefix
) { return handler
.linePosAbsolute(params
); };
1662 csiStateHandler
['e'] = function (handler
, params
, prefix
) { return handler
.VPositionRelative(params
); };
1663 csiStateHandler
['f'] = function (handler
, params
, prefix
) { return handler
.HVPosition(params
); };
1664 csiStateHandler
['g'] = function (handler
, params
, prefix
) { return handler
.tabClear(params
); };
1665 csiStateHandler
['h'] = function (handler
, params
, prefix
) { return handler
.setMode(params
); };
1666 csiStateHandler
['l'] = function (handler
, params
, prefix
) { return handler
.resetMode(params
); };
1667 csiStateHandler
['m'] = function (handler
, params
, prefix
) { return handler
.charAttributes(params
); };
1668 csiStateHandler
['n'] = function (handler
, params
, prefix
) { return handler
.deviceStatus(params
); };
1669 csiStateHandler
['p'] = function (handler
, params
, prefix
) {
1672 handler
.softReset(params
);
1676 csiStateHandler
['q'] = function (handler
, params
, prefix
, postfix
) {
1677 if (postfix
=== ' ') {
1678 handler
.setCursorStyle(params
);
1681 csiStateHandler
['r'] = function (handler
, params
) { return handler
.setScrollRegion(params
); };
1682 csiStateHandler
['s'] = function (handler
, params
) { return handler
.saveCursor(params
); };
1683 csiStateHandler
['u'] = function (handler
, params
) { return handler
.restoreCursor(params
); };
1684 csiStateHandler
[EscapeSequences_1
.C0
.CAN
] = function (handler
, params
, prefix
, postfix
, parser
) { return parser
.setState(ParserState
.NORMAL
); };
1686 (function (ParserState
) {
1687 ParserState
[ParserState
["NORMAL"] = 0] = "NORMAL";
1688 ParserState
[ParserState
["ESCAPED"] = 1] = "ESCAPED";
1689 ParserState
[ParserState
["CSI_PARAM"] = 2] = "CSI_PARAM";
1690 ParserState
[ParserState
["CSI"] = 3] = "CSI";
1691 ParserState
[ParserState
["OSC"] = 4] = "OSC";
1692 ParserState
[ParserState
["CHARSET"] = 5] = "CHARSET";
1693 ParserState
[ParserState
["DCS"] = 6] = "DCS";
1694 ParserState
[ParserState
["IGNORE"] = 7] = "IGNORE";
1695 })(ParserState
|| (ParserState
= {}));
1696 var Parser
= (function () {
1697 function Parser(_inputHandler
, _terminal
) {
1698 this._inputHandler
= _inputHandler
;
1699 this._terminal
= _terminal
;
1700 this._state
= ParserState
.NORMAL
;
1702 Parser
.prototype.parse = function (data
) {
1703 var l
= data
.length
, j
, cs
, ch
, code
, low
;
1705 if (this._terminal
.surrogate_high
) {
1706 data
= this._terminal
.surrogate_high
+ data
;
1707 this._terminal
.surrogate_high
= '';
1709 for (; this._position
< l
; this._position
++) {
1710 ch
= data
[this._position
];
1711 code
= data
.charCodeAt(this._position
);
1712 if (0xD800 <= code
&& code
<= 0xDBFF) {
1713 low
= data
.charCodeAt(this._position
+ 1);
1715 this._terminal
.surrogate_high
= ch
;
1718 code
= ((code
- 0xD800) * 0x400) + (low
- 0xDC00) + 0x10000;
1719 ch
+= data
.charAt(this._position
+ 1);
1721 if (0xDC00 <= code
&& code
<= 0xDFFF)
1723 switch (this._state
) {
1724 case ParserState
.NORMAL
:
1725 if (ch
in normalStateHandler
) {
1726 normalStateHandler
[ch
](this, this._inputHandler
);
1729 this._inputHandler
.addChar(ch
, code
);
1732 case ParserState
.ESCAPED
:
1733 if (ch
in escapedStateHandler
) {
1734 escapedStateHandler
[ch
](this, this._terminal
);
1746 this._terminal
.gcharset
= 0;
1749 this._terminal
.gcharset
= 1;
1752 this._terminal
.gcharset
= 2;
1755 this._terminal
.gcharset
= 3;
1758 this._terminal
.gcharset
= 1;
1761 this._terminal
.gcharset
= 2;
1764 this._state
= ParserState
.CHARSET
;
1767 this._terminal
.gcharset
= 3;
1768 this._state
= ParserState
.CHARSET
;
1776 this._terminal
.setgLevel(2);
1779 this._terminal
.setgLevel(3);
1782 this._terminal
.setgLevel(3);
1785 this._terminal
.setgLevel(2);
1788 this._terminal
.setgLevel(1);
1791 this._inputHandler
.saveCursor();
1792 this._state
= ParserState
.NORMAL
;
1795 this._inputHandler
.restoreCursor();
1796 this._state
= ParserState
.NORMAL
;
1799 this._state
= ParserState
.NORMAL
;
1803 this._terminal
.tabSet();
1804 this._state
= ParserState
.NORMAL
;
1807 this._terminal
.log('Serial port requested application keypad.');
1808 this._terminal
.applicationKeypad
= true;
1809 this._terminal
.viewport
.syncScrollArea();
1810 this._state
= ParserState
.NORMAL
;
1813 this._terminal
.log('Switching back to normal keypad.');
1814 this._terminal
.applicationKeypad
= false;
1815 this._terminal
.viewport
.syncScrollArea();
1816 this._state
= ParserState
.NORMAL
;
1819 this._state
= ParserState
.NORMAL
;
1820 this._terminal
.error('Unknown ESC control: %s.', ch
);
1824 case ParserState
.CHARSET
:
1825 if (ch
in Charsets_1
.CHARSETS
) {
1826 cs
= Charsets_1
.CHARSETS
[ch
];
1828 this.skipNextChar();
1832 cs
= Charsets_1
.DEFAULT_CHARSET
;
1834 this._terminal
.setgCharset(this._terminal
.gcharset
, cs
);
1835 this._terminal
.gcharset
= null;
1836 this._state
= ParserState
.NORMAL
;
1838 case ParserState
.OSC
:
1839 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1840 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1842 this._terminal
.params
.push(this._terminal
.currentParam
);
1843 switch (this._terminal
.params
[0]) {
1847 if (this._terminal
.params
[1]) {
1848 this._terminal
.title
= this._terminal
.params
[1];
1849 this._terminal
.handleTitle(this._terminal
.title
);
1889 this._terminal
.params
= [];
1890 this._terminal
.currentParam
= 0;
1891 this._state
= ParserState
.NORMAL
;
1894 if (!this._terminal
.params
.length
) {
1895 if (ch
>= '0' && ch
<= '9') {
1896 this._terminal
.currentParam
=
1897 this._terminal
.currentParam
* 10 + ch
.charCodeAt(0) - 48;
1899 else if (ch
=== ';') {
1900 this._terminal
.params
.push(this._terminal
.currentParam
);
1901 this._terminal
.currentParam
= '';
1905 this._terminal
.currentParam
+= ch
;
1909 case ParserState
.CSI_PARAM
:
1910 if (ch
in csiParamStateHandler
) {
1911 csiParamStateHandler
[ch
](this);
1914 this.finalizeParam();
1915 this._state
= ParserState
.CSI
;
1916 case ParserState
.CSI
:
1917 if (ch
in csiStateHandler
) {
1918 csiStateHandler
[ch
](this._inputHandler
, this._terminal
.params
, this._terminal
.prefix
, this._terminal
.postfix
, this);
1921 this._terminal
.error('Unknown CSI code: %s.', ch
);
1923 this._state
= ParserState
.NORMAL
;
1924 this._terminal
.prefix
= '';
1925 this._terminal
.postfix
= '';
1927 case ParserState
.DCS
:
1928 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1929 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1931 switch (this._terminal
.prefix
) {
1935 var pt
= this._terminal
.currentParam
, valid
= false;
1945 + (this._terminal
.scrollTop
+ 1)
1947 + (this._terminal
.scrollBottom
+ 1)
1954 this._terminal
.error('Unknown DCS Pt: %s.', pt
);
1958 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '$r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1963 pt
= this._terminal
.currentParam
1965 this._terminal
.send(EscapeSequences_1
.C0
.ESC
+ 'P' + +valid
+ '+r' + pt
+ EscapeSequences_1
.C0
.ESC
+ '\\');
1968 this._terminal
.error('Unknown DCS prefix: %s.', this._terminal
.prefix
);
1971 this._terminal
.currentParam
= 0;
1972 this._terminal
.prefix
= '';
1973 this._state
= ParserState
.NORMAL
;
1975 else if (!this._terminal
.currentParam
) {
1976 if (!this._terminal
.prefix
&& ch
!== '$' && ch
!== '+') {
1977 this._terminal
.currentParam
= ch
;
1979 else if (this._terminal
.prefix
.length
=== 2) {
1980 this._terminal
.currentParam
= ch
;
1983 this._terminal
.prefix
+= ch
;
1987 this._terminal
.currentParam
+= ch
;
1990 case ParserState
.IGNORE
:
1991 if (ch
=== EscapeSequences_1
.C0
.ESC
|| ch
=== EscapeSequences_1
.C0
.BEL
) {
1992 if (ch
=== EscapeSequences_1
.C0
.ESC
)
1994 this._state
= ParserState
.NORMAL
;
2000 Parser
.prototype.setState = function (state
) {
2001 this._state
= state
;
2003 Parser
.prototype.setPrefix = function (prefix
) {
2004 this._terminal
.prefix
= prefix
;
2006 Parser
.prototype.setPostfix = function (postfix
) {
2007 this._terminal
.postfix
= postfix
;
2009 Parser
.prototype.setParam = function (param
) {
2010 this._terminal
.currentParam
= param
;
2012 Parser
.prototype.getParam = function () {
2013 return this._terminal
.currentParam
;
2015 Parser
.prototype.finalizeParam = function () {
2016 this._terminal
.params
.push(this._terminal
.currentParam
);
2017 this._terminal
.currentParam
= 0;
2019 Parser
.prototype.skipNextChar = function () {
2024 exports
.Parser
= Parser
;
2028 },{"./Charsets":1,"./EscapeSequences":3}],8:[function(require
,module
,exports
){
2030 Object
.defineProperty(exports
, "__esModule", { value
: true });
2031 var MAX_REFRESH_FRAME_SKIP
= 5;
2034 FLAGS
[FLAGS
["BOLD"] = 1] = "BOLD";
2035 FLAGS
[FLAGS
["UNDERLINE"] = 2] = "UNDERLINE";
2036 FLAGS
[FLAGS
["BLINK"] = 4] = "BLINK";
2037 FLAGS
[FLAGS
["INVERSE"] = 8] = "INVERSE";
2038 FLAGS
[FLAGS
["INVISIBLE"] = 16] = "INVISIBLE";
2039 })(FLAGS
|| (FLAGS
= {}));
2041 var brokenBold
= null;
2042 var Renderer
= (function () {
2043 function Renderer(_terminal
) {
2044 this._terminal
= _terminal
;
2045 this._refreshRowsQueue
= [];
2046 this._refreshFramesSkipped
= 0;
2047 this._refreshAnimationFrame
= null;
2048 if (brokenBold
=== null) {
2049 brokenBold
= checkBoldBroken(this._terminal
.element
);
2052 Renderer
.prototype.queueRefresh = function (start
, end
) {
2053 this._refreshRowsQueue
.push({ start
: start
, end
: end
});
2054 if (!this._refreshAnimationFrame
) {
2055 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2058 Renderer
.prototype._refreshLoop = function () {
2059 var skipFrame
= this._terminal
.writeBuffer
.length
> 0 && this._refreshFramesSkipped
++ <= MAX_REFRESH_FRAME_SKIP
;
2061 this._refreshAnimationFrame
= window
.requestAnimationFrame(this._refreshLoop
.bind(this));
2064 this._refreshFramesSkipped
= 0;
2067 if (this._refreshRowsQueue
.length
> 4) {
2069 end
= this._terminal
.rows
- 1;
2072 start
= this._refreshRowsQueue
[0].start
;
2073 end
= this._refreshRowsQueue
[0].end
;
2074 for (var i
= 1; i
< this._refreshRowsQueue
.length
; i
++) {
2075 if (this._refreshRowsQueue
[i
].start
< start
) {
2076 start
= this._refreshRowsQueue
[i
].start
;
2078 if (this._refreshRowsQueue
[i
].end
> end
) {
2079 end
= this._refreshRowsQueue
[i
].end
;
2083 this._refreshRowsQueue
= [];
2084 this._refreshAnimationFrame
= null;
2085 this._refresh(start
, end
);
2087 Renderer
.prototype._refresh = function (start
, end
) {
2088 var x
, y
, i
, line
, out
, ch
, ch_width
, width
, data
, attr
, bg
, fg
, flags
, row
, parent
, focused
= document
.activeElement
;
2089 if (end
- start
>= this._terminal
.rows
/ 2) {
2090 parent
= this._terminal
.element
.parentNode
;
2092 this._terminal
.element
.removeChild(this._terminal
.rowContainer
);
2095 width
= this._terminal
.cols
;
2097 if (end
>= this._terminal
.rows
) {
2098 this._terminal
.log('`end` is too large. Most likely a bad CSR.');
2099 end
= this._terminal
.rows
- 1;
2101 for (; y
<= end
; y
++) {
2102 row
= y
+ this._terminal
.ydisp
;
2103 line
= this._terminal
.lines
.get(row
);
2104 if (!line
|| !this._terminal
.children
[y
]) {
2108 if (this._terminal
.y
=== y
- (this._terminal
.ybase
- this._terminal
.ydisp
)
2109 && this._terminal
.cursorState
2110 && !this._terminal
.cursorHidden
) {
2111 x
= this._terminal
.x
;
2116 attr
= this._terminal
.defAttr
;
2118 for (; i
< width
; i
++) {
2124 ch_width
= line
[i
][2];
2129 if (data
!== attr
) {
2130 if (attr
!== this._terminal
.defAttr
) {
2133 if (data
!== this._terminal
.defAttr
) {
2135 out
+= '<span class="reverse-video terminal-cursor">';
2138 var classNames
= [];
2140 fg
= (data
>> 9) & 0x1ff;
2142 if (flags
& FLAGS
.BOLD
) {
2144 classNames
.push('xterm-bold');
2149 if (flags
& FLAGS
.UNDERLINE
) {
2150 classNames
.push('xterm-underline');
2152 if (flags
& FLAGS
.BLINK
) {
2153 classNames
.push('xterm-blink');
2155 if (flags
& FLAGS
.INVERSE
) {
2156 bg
= [fg
, fg
= bg
][0];
2157 if ((flags
& 1) && fg
< 8)
2160 if (flags
& FLAGS
.INVISIBLE
) {
2161 classNames
.push('xterm-hidden');
2163 if (flags
& FLAGS
.INVERSE
) {
2172 classNames
.push('xterm-bg-color-' + bg
);
2175 classNames
.push('xterm-color-' + fg
);
2178 if (classNames
.length
) {
2179 out
+= ' class="' + classNames
.join(' ') + '"';
2185 if (ch_width
=== 2) {
2186 out
+= '<span class="xterm-wide-char">';
2207 if (ch_width
=== 2) {
2212 if (attr
!== this._terminal
.defAttr
) {
2215 this._terminal
.children
[y
].innerHTML
= out
;
2218 this._terminal
.element
.appendChild(this._terminal
.rowContainer
);
2220 this._terminal
.emit('refresh', { element
: this._terminal
.element
, start
: start
, end
: end
});
2225 exports
.Renderer
= Renderer
;
2226 function checkBoldBroken(terminal
) {
2227 var document
= terminal
.ownerDocument
;
2228 var el
= document
.createElement('span');
2229 el
.innerHTML
= 'hello world';
2230 terminal
.appendChild(el
);
2231 var w1
= el
.offsetWidth
;
2232 var h1
= el
.offsetHeight
;
2233 el
.style
.fontWeight
= 'bold';
2234 var w2
= el
.offsetWidth
;
2235 var h2
= el
.offsetHeight
;
2236 terminal
.removeChild(el
);
2237 return w1
!== w2
|| h1
!== h2
;
2242 },{}],9:[function(require
,module
,exports
){
2244 Object
.defineProperty(exports
, "__esModule", { value
: true });
2245 var Viewport
= (function () {
2246 function Viewport(terminal
, viewportElement
, scrollArea
, charMeasure
) {
2248 this.terminal
= terminal
;
2249 this.viewportElement
= viewportElement
;
2250 this.scrollArea
= scrollArea
;
2251 this.charMeasure
= charMeasure
;
2252 this.currentRowHeight
= 0;
2253 this.lastRecordedBufferLength
= 0;
2254 this.lastRecordedViewportHeight
= 0;
2255 this.terminal
.on('scroll', this.syncScrollArea
.bind(this));
2256 this.terminal
.on('resize', this.syncScrollArea
.bind(this));
2257 this.viewportElement
.addEventListener('scroll', this.onScroll
.bind(this));
2258 setTimeout(function () { return _this
.syncScrollArea(); }, 0);
2260 Viewport
.prototype.refresh = function () {
2261 if (this.charMeasure
.height
> 0) {
2262 var rowHeightChanged
= this.charMeasure
.height
!== this.currentRowHeight
;
2263 if (rowHeightChanged
) {
2264 this.currentRowHeight
= this.charMeasure
.height
;
2265 this.viewportElement
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2266 this.terminal
.rowContainer
.style
.lineHeight
= this.charMeasure
.height
+ 'px';
2268 var viewportHeightChanged
= this.lastRecordedViewportHeight
!== this.terminal
.rows
;
2269 if (rowHeightChanged
|| viewportHeightChanged
) {
2270 this.lastRecordedViewportHeight
= this.terminal
.rows
;
2271 this.viewportElement
.style
.height
= this.charMeasure
.height
* this.terminal
.rows
+ 'px';
2273 this.scrollArea
.style
.height
= (this.charMeasure
.height
* this.lastRecordedBufferLength
) + 'px';
2276 Viewport
.prototype.syncScrollArea = function () {
2277 if (this.lastRecordedBufferLength
!== this.terminal
.lines
.length
) {
2278 this.lastRecordedBufferLength
= this.terminal
.lines
.length
;
2281 else if (this.lastRecordedViewportHeight
!== this.terminal
.rows
) {
2285 if (this.charMeasure
.height
!== this.currentRowHeight
) {
2289 var scrollTop
= this.terminal
.ydisp
* this.currentRowHeight
;
2290 if (this.viewportElement
.scrollTop
!== scrollTop
) {
2291 this.viewportElement
.scrollTop
= scrollTop
;
2294 Viewport
.prototype.onScroll = function (ev
) {
2295 var newRow
= Math
.round(this.viewportElement
.scrollTop
/ this.currentRowHeight
);
2296 var diff
= newRow
- this.terminal
.ydisp
;
2297 this.terminal
.scrollDisp(diff
, true);
2299 Viewport
.prototype.onWheel = function (ev
) {
2300 if (ev
.deltaY
=== 0) {
2304 if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
2305 multiplier
= this.currentRowHeight
;
2307 else if (ev
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
2308 multiplier
= this.currentRowHeight
* this.terminal
.rows
;
2310 this.viewportElement
.scrollTop
+= ev
.deltaY
* multiplier
;
2311 ev
.preventDefault();
2316 exports
.Viewport
= Viewport
;
2320 },{}],10:[function(require
,module
,exports
){
2322 Object
.defineProperty(exports
, "__esModule", { value
: true });
2323 function prepareTextForClipboard(text
) {
2324 var space
= String
.fromCharCode(32), nonBreakingSpace
= String
.fromCharCode(160), allNonBreakingSpaces
= new RegExp(nonBreakingSpace
, 'g'), processedText
= text
.split('\n').map(function (line
) {
2325 var processedLine
= line
.replace(/\s+$/g, '').replace(allNonBreakingSpaces
, space
);
2326 return processedLine
;
2328 return processedText
;
2330 exports
.prepareTextForClipboard
= prepareTextForClipboard
;
2331 function copyHandler(ev
, term
) {
2332 var copiedText
= window
.getSelection().toString(), text
= prepareTextForClipboard(copiedText
);
2333 if (term
.browser
.isMSIE
) {
2334 window
.clipboardData
.setData('Text', text
);
2337 ev
.clipboardData
.setData('text/plain', text
);
2339 ev
.preventDefault();
2341 exports
.copyHandler
= copyHandler
;
2342 function pasteHandler(ev
, term
) {
2343 ev
.stopPropagation();
2345 var dispatchPaste = function (text
) {
2347 term
.textarea
.value
= '';
2348 return term
.cancel(ev
);
2350 if (term
.browser
.isMSIE
) {
2351 if (window
.clipboardData
) {
2352 text
= window
.clipboardData
.getData('Text');
2353 dispatchPaste(text
);
2357 if (ev
.clipboardData
) {
2358 text
= ev
.clipboardData
.getData('text/plain');
2359 dispatchPaste(text
);
2363 exports
.pasteHandler
= pasteHandler
;
2364 function rightClickHandler(ev
, term
) {
2365 var s
= document
.getSelection(), selectedText
= prepareTextForClipboard(s
.toString()), clickIsOnSelection
= false, x
= ev
.clientX
, y
= ev
.clientY
;
2367 var r
= s
.getRangeAt(0), cr
= r
.getClientRects();
2368 for (var i
= 0; i
< cr
.length
; i
++) {
2370 clickIsOnSelection
= ((x
> rect
.left
) && (x
< rect
.right
) &&
2371 (y
> rect
.top
) && (y
< rect
.bottom
));
2372 if (clickIsOnSelection
) {
2376 if (selectedText
.match(/^\s$/) || !selectedText
.length
) {
2377 clickIsOnSelection
= false;
2380 if (!clickIsOnSelection
) {
2381 term
.textarea
.style
.position
= 'fixed';
2382 term
.textarea
.style
.width
= '20px';
2383 term
.textarea
.style
.height
= '20px';
2384 term
.textarea
.style
.left
= (x
- 10) + 'px';
2385 term
.textarea
.style
.top
= (y
- 10) + 'px';
2386 term
.textarea
.style
.zIndex
= '1000';
2387 term
.textarea
.focus();
2388 setTimeout(function () {
2389 term
.textarea
.style
.position
= null;
2390 term
.textarea
.style
.width
= null;
2391 term
.textarea
.style
.height
= null;
2392 term
.textarea
.style
.left
= null;
2393 term
.textarea
.style
.top
= null;
2394 term
.textarea
.style
.zIndex
= null;
2398 exports
.rightClickHandler
= rightClickHandler
;
2402 },{}],11:[function(require
,module
,exports
){
2404 Object
.defineProperty(exports
, "__esModule", { value
: true });
2405 var Generic_1
= require("./Generic");
2406 var isNode
= (typeof navigator
=== 'undefined') ? true : false;
2407 var userAgent
= (isNode
) ? 'node' : navigator
.userAgent
;
2408 var platform
= (isNode
) ? 'node' : navigator
.platform
;
2409 exports
.isFirefox
= !!~userAgent
.indexOf('Firefox');
2410 exports
.isMSIE
= !!~userAgent
.indexOf('MSIE') || !!~userAgent
.indexOf('Trident');
2411 exports
.isMac
= Generic_1
.contains(['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], platform
);
2412 exports
.isIpad
= platform
=== 'iPad';
2413 exports
.isIphone
= platform
=== 'iPhone';
2414 exports
.isMSWindows
= Generic_1
.contains(['Windows', 'Win16', 'Win32', 'WinCE'], platform
);
2418 },{"./Generic":14}],12:[function(require
,module
,exports
){
2420 var __extends
= (this && this.__extends
) || (function () {
2421 var extendStatics
= Object
.setPrototypeOf
||
2422 ({ __proto__
: [] } instanceof Array
&& function (d
, b
) { d
.__proto__
= b
; }) ||
2423 function (d
, b
) { for (var p
in b
) if (b
.hasOwnProperty(p
)) d
[p
] = b
[p
]; };
2424 return function (d
, b
) {
2425 extendStatics(d
, b
);
2426 function __() { this.constructor = d
; }
2427 d
.prototype = b
=== null ? Object
.create(b
) : (__
.prototype = b
.prototype, new __());
2430 Object
.defineProperty(exports
, "__esModule", { value
: true });
2431 var EventEmitter_js_1
= require("../EventEmitter.js");
2432 var CharMeasure
= (function (_super
) {
2433 __extends(CharMeasure
, _super
);
2434 function CharMeasure(document
, parentElement
) {
2435 var _this
= _super
.call(this) || this;
2436 _this
._document
= document
;
2437 _this
._parentElement
= parentElement
;
2440 Object
.defineProperty(CharMeasure
.prototype, "width", {
2447 Object
.defineProperty(CharMeasure
.prototype, "height", {
2449 return this._height
;
2454 CharMeasure
.prototype.measure = function () {
2456 if (!this._measureElement
) {
2457 this._measureElement
= this._document
.createElement('span');
2458 this._measureElement
.style
.position
= 'absolute';
2459 this._measureElement
.style
.top
= '0';
2460 this._measureElement
.style
.left
= '-9999em';
2461 this._measureElement
.textContent
= 'W';
2462 this._measureElement
.setAttribute('aria-hidden', 'true');
2463 this._parentElement
.appendChild(this._measureElement
);
2464 setTimeout(function () { return _this
._doMeasure(); }, 0);
2470 CharMeasure
.prototype._doMeasure = function () {
2471 var geometry
= this._measureElement
.getBoundingClientRect();
2472 if (geometry
.width
=== 0 || geometry
.height
=== 0) {
2475 if (this._width
!== geometry
.width
|| this._height
!== geometry
.height
) {
2476 this._width
= geometry
.width
;
2477 this._height
= geometry
.height
;
2478 this.emit('charsizechanged');
2482 }(EventEmitter_js_1
.EventEmitter
));
2483 exports
.CharMeasure
= CharMeasure
;
2487 },{"../EventEmitter.js":4}],13:[function(require
,module
,exports
){
2489 Object
.defineProperty(exports
, "__esModule", { value
: true });
2490 var CircularList
= (function () {
2491 function CircularList(maxLength
) {
2492 this._array
= new Array(maxLength
);
2493 this._startIndex
= 0;
2496 Object
.defineProperty(CircularList
.prototype, "maxLength", {
2498 return this._array
.length
;
2500 set: function (newMaxLength
) {
2501 var newArray
= new Array(newMaxLength
);
2502 for (var i
= 0; i
< Math
.min(newMaxLength
, this.length
); i
++) {
2503 newArray
[i
] = this._array
[this._getCyclicIndex(i
)];
2505 this._array
= newArray
;
2506 this._startIndex
= 0;
2511 Object
.defineProperty(CircularList
.prototype, "length", {
2513 return this._length
;
2515 set: function (newLength
) {
2516 if (newLength
> this._length
) {
2517 for (var i
= this._length
; i
< newLength
; i
++) {
2518 this._array
[i
] = undefined;
2521 this._length
= newLength
;
2526 Object
.defineProperty(CircularList
.prototype, "forEach", {
2528 return this._array
.forEach
;
2533 CircularList
.prototype.get = function (index
) {
2534 return this._array
[this._getCyclicIndex(index
)];
2536 CircularList
.prototype.set = function (index
, value
) {
2537 this._array
[this._getCyclicIndex(index
)] = value
;
2539 CircularList
.prototype.push = function (value
) {
2540 this._array
[this._getCyclicIndex(this._length
)] = value
;
2541 if (this._length
=== this.maxLength
) {
2543 if (this._startIndex
=== this.maxLength
) {
2544 this._startIndex
= 0;
2551 CircularList
.prototype.pop = function () {
2552 return this._array
[this._getCyclicIndex(this._length
-- - 1)];
2554 CircularList
.prototype.splice = function (start
, deleteCount
) {
2556 for (var _i
= 2; _i
< arguments
.length
; _i
++) {
2557 items
[_i
- 2] = arguments
[_i
];
2560 for (var i
= start
; i
< this._length
- deleteCount
; i
++) {
2561 this._array
[this._getCyclicIndex(i
)] = this._array
[this._getCyclicIndex(i
+ deleteCount
)];
2563 this._length
-= deleteCount
;
2565 if (items
&& items
.length
) {
2566 for (var i
= this._length
- 1; i
>= start
; i
--) {
2567 this._array
[this._getCyclicIndex(i
+ items
.length
)] = this._array
[this._getCyclicIndex(i
)];
2569 for (var i
= 0; i
< items
.length
; i
++) {
2570 this._array
[this._getCyclicIndex(start
+ i
)] = items
[i
];
2572 if (this._length
+ items
.length
> this.maxLength
) {
2573 this._startIndex
+= (this._length
+ items
.length
) - this.maxLength
;
2574 this._length
= this.maxLength
;
2577 this._length
+= items
.length
;
2581 CircularList
.prototype.trimStart = function (count
) {
2582 if (count
> this._length
) {
2583 count
= this._length
;
2585 this._startIndex
+= count
;
2586 this._length
-= count
;
2588 CircularList
.prototype.shiftElements = function (start
, count
, offset
) {
2592 if (start
< 0 || start
>= this._length
) {
2593 throw new Error('start argument out of range');
2595 if (start
+ offset
< 0) {
2596 throw new Error('Cannot shift elements in list beyond index 0');
2599 for (var i
= count
- 1; i
>= 0; i
--) {
2600 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2602 var expandListBy
= (start
+ count
+ offset
) - this._length
;
2603 if (expandListBy
> 0) {
2604 this._length
+= expandListBy
;
2605 while (this._length
> this.maxLength
) {
2612 for (var i
= 0; i
< count
; i
++) {
2613 this.set(start
+ i
+ offset
, this.get(start
+ i
));
2617 CircularList
.prototype._getCyclicIndex = function (index
) {
2618 return (this._startIndex
+ index
) % this.maxLength
;
2620 return CircularList
;
2622 exports
.CircularList
= CircularList
;
2626 },{}],14:[function(require
,module
,exports
){
2628 Object
.defineProperty(exports
, "__esModule", { value
: true });
2629 function contains(arr
, el
) {
2630 return arr
.indexOf(el
) >= 0;
2632 exports
.contains
= contains
;
2637 },{}],15:[function(require
,module
,exports
){
2639 Object
.defineProperty(exports
, "__esModule", { value
: true });
2640 var CompositionHelper_1
= require("./CompositionHelper");
2641 var EventEmitter_1
= require("./EventEmitter");
2642 var Viewport_1
= require("./Viewport");
2643 var Clipboard_1
= require("./handlers/Clipboard");
2644 var CircularList_1
= require("./utils/CircularList");
2645 var EscapeSequences_1
= require("./EscapeSequences");
2646 var InputHandler_1
= require("./InputHandler");
2647 var Parser_1
= require("./Parser");
2648 var Renderer_1
= require("./Renderer");
2649 var Linkifier_1
= require("./Linkifier");
2650 var CharMeasure_1
= require("./utils/CharMeasure");
2651 var Browser
= require("./utils/Browser");
2652 var document
= (typeof window
!= 'undefined') ? window
.document
: null;
2653 var WRITE_BUFFER_PAUSE_THRESHOLD
= 5;
2654 var WRITE_BATCH_SIZE
= 300;
2655 var CURSOR_BLINK_INTERVAL
= 600;
2656 function Terminal(options
) {
2658 if (!(this instanceof Terminal
)) {
2659 return new Terminal(arguments
[0], arguments
[1], arguments
[2]);
2661 self
.browser
= Browser
;
2662 self
.cancel
= Terminal
.cancel
;
2663 EventEmitter_1
.EventEmitter
.call(this);
2664 if (typeof options
=== 'number') {
2668 handler
: arguments
[2]
2671 options
= options
|| {};
2672 Object
.keys(Terminal
.defaults
).forEach(function (key
) {
2673 if (options
[key
] == null) {
2674 options
[key
] = Terminal
.options
[key
];
2675 if (Terminal
[key
] !== Terminal
.defaults
[key
]) {
2676 options
[key
] = Terminal
[key
];
2679 self
[key
] = options
[key
];
2681 if (options
.colors
.length
=== 8) {
2682 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(8));
2684 else if (options
.colors
.length
=== 16) {
2685 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16));
2687 else if (options
.colors
.length
=== 10) {
2688 options
.colors
= options
.colors
.slice(0, -2).concat(Terminal
._colors
.slice(8, -2), options
.colors
.slice(-2));
2690 else if (options
.colors
.length
=== 18) {
2691 options
.colors
= options
.colors
.concat(Terminal
._colors
.slice(16, -2), options
.colors
.slice(-2));
2693 this.colors
= options
.colors
;
2694 this.options
= options
;
2695 this.parent
= options
.body
|| options
.parent
|| (document
? document
.getElementsByTagName('body')[0] : null);
2696 this.cols
= options
.cols
|| options
.geometry
[0];
2697 this.rows
= options
.rows
|| options
.geometry
[1];
2698 this.geometry
= [this.cols
, this.rows
];
2699 if (options
.handler
) {
2700 this.on('data', options
.handler
);
2706 this.cursorState
= 0;
2707 this.cursorHidden
= false;
2711 this.scrollBottom
= this.rows
- 1;
2712 this.customKeydownHandler
= null;
2713 this.cursorBlinkInterval
= null;
2714 this.applicationKeypad
= false;
2715 this.applicationCursor
= false;
2716 this.originMode
= false;
2717 this.insertMode
= false;
2718 this.wraparoundMode
= true;
2720 this.charset
= null;
2721 this.gcharset
= null;
2723 this.charsets
= [null];
2741 this.readable
= true;
2742 this.writable
= true;
2743 this.defAttr
= (0 << 18) | (257 << 9) | (256 << 0);
2744 this.curAttr
= this.defAttr
;
2746 this.currentParam
= 0;
2749 this.inputHandler
= new InputHandler_1
.InputHandler(this);
2750 this.parser
= new Parser_1
.Parser(this.inputHandler
, this);
2751 this.renderer
= this.renderer
|| null;
2752 this.linkifier
= this.linkifier
|| new Linkifier_1
.Linkifier();
2753 this.writeBuffer
= [];
2754 this.writeInProgress
= false;
2755 this.xoffSentToCatchUp
= false;
2756 this.writeStopped
= false;
2757 this.surrogate_high
= '';
2758 this.lines
= new CircularList_1
.CircularList(this.scrollback
);
2761 this.lines
.push(this.blankLine());
2765 this.userScrolling
= false;
2767 inherits(Terminal
, EventEmitter_1
.EventEmitter
);
2768 Terminal
.prototype.eraseAttr = function () {
2769 return (this.defAttr
& ~0x1ff) | (this.curAttr
& 0x1ff);
2771 Terminal
.tangoColors
= [
2789 Terminal
.colors
= (function () {
2790 var colors
= Terminal
.tangoColors
.slice(), r
= [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff], i
;
2792 for (; i
< 216; i
++) {
2793 out(r
[(i
/ 36) % 6 | 0], r
[(i
/ 6) % 6 | 0], r
[i
% 6]);
2796 for (; i
< 24; i
++) {
2800 function out(r
, g
, b
) {
2801 colors
.push('#' + hex(r
) + hex(g
) + hex(b
));
2805 return c
.length
< 2 ? '0' + c
: c
;
2809 Terminal
._colors
= Terminal
.colors
.slice();
2810 Terminal
.vcolors
= (function () {
2811 var out
= [], colors
= Terminal
.colors
, i
= 0, color
;
2812 for (; i
< 256; i
++) {
2813 color
= parseInt(colors
[i
].substring(1), 16);
2815 (color
>> 16) & 0xff,
2816 (color
>> 8) & 0xff,
2822 Terminal
.defaults
= {
2823 colors
: Terminal
.colors
,
2829 cursorStyle
: 'block',
2835 cancelEvents
: false,
2836 disableStdin
: false,
2837 useFlowControl
: false,
2840 Terminal
.options
= {};
2841 Terminal
.focus
= null;
2842 each(keys(Terminal
.defaults
), function (key
) {
2843 Terminal
[key
] = Terminal
.defaults
[key
];
2844 Terminal
.options
[key
] = Terminal
.defaults
[key
];
2846 Terminal
.prototype.focus = function () {
2847 return this.textarea
.focus();
2849 Terminal
.prototype.getOption = function (key
, value
) {
2850 if (!(key
in Terminal
.defaults
)) {
2851 throw new Error('No option with key "' + key
+ '"');
2853 if (typeof this.options
[key
] !== 'undefined') {
2854 return this.options
[key
];
2858 Terminal
.prototype.setOption = function (key
, value
) {
2859 if (!(key
in Terminal
.defaults
)) {
2860 throw new Error('No option with key "' + key
+ '"');
2864 if (this.options
[key
] !== value
) {
2865 if (this.lines
.length
> value
) {
2866 var amountToTrim
= this.lines
.length
- value
;
2867 var needsRefresh
= (this.ydisp
- amountToTrim
< 0);
2868 this.lines
.trimStart(amountToTrim
);
2869 this.ybase
= Math
.max(this.ybase
- amountToTrim
, 0);
2870 this.ydisp
= Math
.max(this.ydisp
- amountToTrim
, 0);
2872 this.refresh(0, this.rows
- 1);
2875 this.lines
.maxLength
= value
;
2876 this.viewport
.syncScrollArea();
2881 this.options
[key
] = value
;
2884 this.setCursorBlinking(value
);
2887 this.element
.classList
.toggle("xterm-cursor-style-underline", value
=== 'underline');
2888 this.element
.classList
.toggle("xterm-cursor-style-bar", value
=== 'bar');
2890 case 'tabStopWidth':
2895 Terminal
.prototype.restartCursorBlinking = function () {
2896 this.setCursorBlinking(this.options
.cursorBlink
);
2898 Terminal
.prototype.setCursorBlinking = function (enabled
) {
2899 this.element
.classList
.toggle('xterm-cursor-blink', enabled
);
2900 this.clearCursorBlinkingInterval();
2903 this.cursorBlinkInterval
= setInterval(function () {
2904 self
.element
.classList
.toggle('xterm-cursor-blink-on');
2905 }, CURSOR_BLINK_INTERVAL
);
2908 Terminal
.prototype.clearCursorBlinkingInterval = function () {
2909 this.element
.classList
.remove('xterm-cursor-blink-on');
2910 if (this.cursorBlinkInterval
) {
2911 clearInterval(this.cursorBlinkInterval
);
2912 this.cursorBlinkInterval
= null;
2915 Terminal
.bindFocus = function (term
) {
2916 on(term
.textarea
, 'focus', function (ev
) {
2917 if (term
.sendFocus
) {
2918 term
.send(EscapeSequences_1
.C0
.ESC
+ '[I');
2920 term
.element
.classList
.add('focus');
2922 term
.restartCursorBlinking
.apply(term
);
2923 Terminal
.focus
= term
;
2924 term
.emit('focus', { terminal
: term
});
2927 Terminal
.prototype.blur = function () {
2928 return this.textarea
.blur();
2930 Terminal
.bindBlur = function (term
) {
2931 on(term
.textarea
, 'blur', function (ev
) {
2932 term
.refresh(term
.y
, term
.y
);
2933 if (term
.sendFocus
) {
2934 term
.send(EscapeSequences_1
.C0
.ESC
+ '[O');
2936 term
.element
.classList
.remove('focus');
2937 term
.clearCursorBlinkingInterval
.apply(term
);
2938 Terminal
.focus
= null;
2939 term
.emit('blur', { terminal
: term
});
2942 Terminal
.prototype.initGlobal = function () {
2944 Terminal
.bindKeys(this);
2945 Terminal
.bindFocus(this);
2946 Terminal
.bindBlur(this);
2947 on(this.element
, 'copy', function (ev
) {
2948 Clipboard_1
.copyHandler
.call(this, ev
, term
);
2950 on(this.textarea
, 'paste', function (ev
) {
2951 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2953 on(this.element
, 'paste', function (ev
) {
2954 Clipboard_1
.pasteHandler
.call(this, ev
, term
);
2956 function rightClickHandlerWrapper(ev
) {
2957 Clipboard_1
.rightClickHandler
.call(this, ev
, term
);
2959 if (term
.browser
.isFirefox
) {
2960 on(this.element
, 'mousedown', function (ev
) {
2961 if (ev
.button
== 2) {
2962 rightClickHandlerWrapper(ev
);
2967 on(this.element
, 'contextmenu', rightClickHandlerWrapper
);
2970 Terminal
.bindKeys = function (term
) {
2971 on(term
.element
, 'keydown', function (ev
) {
2972 if (document
.activeElement
!= this) {
2977 on(term
.element
, 'keypress', function (ev
) {
2978 if (document
.activeElement
!= this) {
2983 on(term
.element
, 'keyup', function (ev
) {
2984 if (!wasMondifierKeyOnlyEvent(ev
)) {
2988 on(term
.textarea
, 'keydown', function (ev
) {
2991 on(term
.textarea
, 'keypress', function (ev
) {
2995 on(term
.textarea
, 'compositionstart', term
.compositionHelper
.compositionstart
.bind(term
.compositionHelper
));
2996 on(term
.textarea
, 'compositionupdate', term
.compositionHelper
.compositionupdate
.bind(term
.compositionHelper
));
2997 on(term
.textarea
, 'compositionend', term
.compositionHelper
.compositionend
.bind(term
.compositionHelper
));
2998 term
.on('refresh', term
.compositionHelper
.updateCompositionElements
.bind(term
.compositionHelper
));
2999 term
.on('refresh', function (data
) {
3000 term
.queueLinkification(data
.start
, data
.end
);
3003 Terminal
.prototype.insertRow = function (row
) {
3004 if (typeof row
!= 'object') {
3005 row
= document
.createElement('div');
3007 this.rowContainer
.appendChild(row
);
3008 this.children
.push(row
);
3011 Terminal
.prototype.open = function (parent
, focus
) {
3012 var self
= this, i
= 0, div
;
3013 this.parent
= parent
|| this.parent
;
3015 throw new Error('Terminal requires a parent element.');
3017 this.context
= this.parent
.ownerDocument
.defaultView
;
3018 this.document
= this.parent
.ownerDocument
;
3019 this.body
= this.document
.getElementsByTagName('body')[0];
3020 this.element
= this.document
.createElement('div');
3021 this.element
.classList
.add('terminal');
3022 this.element
.classList
.add('xterm');
3023 this.element
.classList
.add('xterm-theme-' + this.theme
);
3024 this.setCursorBlinking(this.options
.cursorBlink
);
3025 this.element
.style
.height
;
3026 this.element
.setAttribute('tabindex', 0);
3027 this.viewportElement
= document
.createElement('div');
3028 this.viewportElement
.classList
.add('xterm-viewport');
3029 this.element
.appendChild(this.viewportElement
);
3030 this.viewportScrollArea
= document
.createElement('div');
3031 this.viewportScrollArea
.classList
.add('xterm-scroll-area');
3032 this.viewportElement
.appendChild(this.viewportScrollArea
);
3033 this.rowContainer
= document
.createElement('div');
3034 this.rowContainer
.classList
.add('xterm-rows');
3035 this.element
.appendChild(this.rowContainer
);
3037 this.linkifier
.attachToDom(document
, this.children
);
3038 this.helperContainer
= document
.createElement('div');
3039 this.helperContainer
.classList
.add('xterm-helpers');
3040 this.element
.appendChild(this.helperContainer
);
3041 this.textarea
= document
.createElement('textarea');
3042 this.textarea
.classList
.add('xterm-helper-textarea');
3043 this.textarea
.setAttribute('autocorrect', 'off');
3044 this.textarea
.setAttribute('autocapitalize', 'off');
3045 this.textarea
.setAttribute('spellcheck', 'false');
3046 this.textarea
.tabIndex
= 0;
3047 this.textarea
.addEventListener('focus', function () {
3048 self
.emit('focus', { terminal
: self
});
3050 this.textarea
.addEventListener('blur', function () {
3051 self
.emit('blur', { terminal
: self
});
3053 this.helperContainer
.appendChild(this.textarea
);
3054 this.compositionView
= document
.createElement('div');
3055 this.compositionView
.classList
.add('composition-view');
3056 this.compositionHelper
= new CompositionHelper_1
.CompositionHelper(this.textarea
, this.compositionView
, this);
3057 this.helperContainer
.appendChild(this.compositionView
);
3058 this.charSizeStyleElement
= document
.createElement('style');
3059 this.helperContainer
.appendChild(this.charSizeStyleElement
);
3060 for (; i
< this.rows
; i
++) {
3063 this.parent
.appendChild(this.element
);
3064 this.charMeasure
= new CharMeasure_1
.CharMeasure(document
, this.helperContainer
);
3065 this.charMeasure
.on('charsizechanged', function () {
3066 self
.updateCharSizeCSS();
3068 this.charMeasure
.measure();
3069 this.viewport
= new Viewport_1
.Viewport(this, this.viewportElement
, this.viewportScrollArea
, this.charMeasure
);
3070 this.renderer
= new Renderer_1
.Renderer(this);
3071 this.refresh(0, this.rows
- 1);
3073 if (typeof focus
== 'undefined') {
3074 var message
= 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';
3075 message
+= 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
3076 message
+= 'it will default to `false`.';
3077 console
.warn(message
);
3083 on(this.element
, 'click', function () {
3084 var selection
= document
.getSelection(), collapsed
= selection
.isCollapsed
, isRange
= typeof collapsed
== 'boolean' ? !collapsed
: selection
.type
== 'Range';
3092 Terminal
.loadAddon = function (addon
, callback
) {
3093 if (typeof exports
=== 'object' && typeof module
=== 'object') {
3094 return require('./addons/' + addon
+ '/' + addon
);
3096 else if (typeof define
== 'function') {
3097 return require(['./addons/' + addon
+ '/' + addon
], callback
);
3100 console
.error('Cannot load a module without a CommonJS or RequireJS environment.');
3104 Terminal
.prototype.updateCharSizeCSS = function () {
3105 this.charSizeStyleElement
.textContent
= '.xterm-wide-char{width:' + (this.charMeasure
.width
* 2) + 'px;}';
3107 Terminal
.prototype.bindMouse = function () {
3108 var el
= this.element
, self
= this, pressed
= 32;
3109 function sendButton(ev
) {
3111 button
= getButton(ev
);
3112 pos
= getCoords(ev
);
3115 sendEvent(button
, pos
);
3116 switch (ev
.overrideType
|| ev
.type
) {
3127 function sendMove(ev
) {
3128 var button
= pressed
, pos
;
3129 pos
= getCoords(ev
);
3133 sendEvent(button
, pos
);
3135 function encode(data
, ch
) {
3136 if (!self
.utfMouse
) {
3138 return data
.push(0);
3145 return data
.push(0);
3152 data
.push(0xC0 | (ch
>> 6));
3153 data
.push(0x80 | (ch
& 0x3F));
3157 function sendEvent(button
, pos
) {
3158 if (self
.vt300Mouse
) {
3162 var data
= EscapeSequences_1
.C0
.ESC
+ '[24';
3165 else if (button
=== 1)
3167 else if (button
=== 2)
3169 else if (button
=== 3)
3173 data
+= '~[' + pos
.x
+ ',' + pos
.y
+ ']\r';
3177 if (self
.decLocator
) {
3183 else if (button
=== 1)
3185 else if (button
=== 2)
3187 else if (button
=== 3)
3189 self
.send(EscapeSequences_1
.C0
.ESC
+ '['
3192 + (button
=== 3 ? 4 : 0)
3202 if (self
.urxvtMouse
) {
3207 self
.send(EscapeSequences_1
.C0
.ESC
+ '[' + button
+ ';' + pos
.x
+ ';' + pos
.y
+ 'M');
3210 if (self
.sgrMouse
) {
3213 self
.send(EscapeSequences_1
.C0
.ESC
+ '[<'
3214 + (((button
& 3) === 3 ? button
& ~3 : button
) - 32)
3219 + ((button
& 3) === 3 ? 'm' : 'M'));
3223 encode(data
, button
);
3224 encode(data
, pos
.x
);
3225 encode(data
, pos
.y
);
3226 self
.send(EscapeSequences_1
.C0
.ESC
+ '[M' + String
.fromCharCode
.apply(String
, data
));
3228 function getButton(ev
) {
3229 var button
, shift
, meta
, ctrl
, mod
;
3230 switch (ev
.overrideType
|| ev
.type
) {
3232 button
= ev
.button
!= null
3237 if (self
.browser
.isMSIE
) {
3238 button
= button
=== 1 ? 0 : button
=== 4 ? 1 : button
;
3244 case 'DOMMouseScroll':
3245 button
= ev
.detail
< 0
3250 button
= ev
.wheelDeltaY
> 0
3255 shift
= ev
.shiftKey
? 4 : 0;
3256 meta
= ev
.metaKey
? 8 : 0;
3257 ctrl
= ev
.ctrlKey
? 16 : 0;
3258 mod
= shift
| meta
| ctrl
;
3259 if (self
.vt200Mouse
) {
3262 else if (!self
.normalMouse
) {
3265 button
= (32 + (mod
<< 2)) + button
;
3268 function getCoords(ev
) {
3270 if (ev
.pageX
== null)
3275 while (el
&& el
!== self
.document
.documentElement
) {
3278 el
= 'offsetParent' in el
3282 x
= Math
.ceil(x
/ self
.charMeasure
.width
);
3283 y
= Math
.ceil(y
/ self
.charMeasure
.height
);
3300 on(el
, 'mousedown', function (ev
) {
3301 if (!self
.mouseEvents
)
3305 if (self
.vt200Mouse
) {
3306 ev
.overrideType
= 'mouseup';
3308 return self
.cancel(ev
);
3310 if (self
.normalMouse
)
3311 on(self
.document
, 'mousemove', sendMove
);
3312 if (!self
.x10Mouse
) {
3313 on(self
.document
, 'mouseup', function up(ev
) {
3315 if (self
.normalMouse
)
3316 off(self
.document
, 'mousemove', sendMove
);
3317 off(self
.document
, 'mouseup', up
);
3318 return self
.cancel(ev
);
3321 return self
.cancel(ev
);
3323 on(el
, 'wheel', function (ev
) {
3324 if (!self
.mouseEvents
)
3331 return self
.cancel(ev
);
3333 on(el
, 'wheel', function (ev
) {
3334 if (self
.mouseEvents
)
3336 self
.viewport
.onWheel(ev
);
3337 return self
.cancel(ev
);
3340 Terminal
.prototype.destroy = function () {
3341 this.readable
= false;
3342 this.writable
= false;
3344 this.handler = function () { };
3345 this.write = function () { };
3346 if (this.element
&& this.element
.parentNode
) {
3347 this.element
.parentNode
.removeChild(this.element
);
3350 Terminal
.prototype.refresh = function (start
, end
) {
3351 if (this.renderer
) {
3352 this.renderer
.queueRefresh(start
, end
);
3355 Terminal
.prototype.queueLinkification = function (start
, end
) {
3356 if (this.linkifier
) {
3357 for (var i
= start
; i
<= end
; i
++) {
3358 this.linkifier
.linkifyRow(i
);
3362 Terminal
.prototype.showCursor = function () {
3363 if (!this.cursorState
) {
3364 this.cursorState
= 1;
3365 this.refresh(this.y
, this.y
);
3368 Terminal
.prototype.scroll = function () {
3370 if (this.lines
.length
=== this.lines
.maxLength
) {
3371 this.lines
.trimStart(1);
3373 if (this.ydisp
!== 0) {
3378 if (!this.userScrolling
) {
3379 this.ydisp
= this.ybase
;
3381 row
= this.ybase
+ this.rows
- 1;
3382 row
-= this.rows
- 1 - this.scrollBottom
;
3383 if (row
=== this.lines
.length
) {
3384 this.lines
.push(this.blankLine());
3387 this.lines
.splice(row
, 0, this.blankLine());
3389 if (this.scrollTop
!== 0) {
3390 if (this.ybase
!== 0) {
3392 if (!this.userScrolling
) {
3393 this.ydisp
= this.ybase
;
3396 this.lines
.splice(this.ybase
+ this.scrollTop
, 1);
3398 this.updateRange(this.scrollTop
);
3399 this.updateRange(this.scrollBottom
);
3400 this.emit('scroll', this.ydisp
);
3402 Terminal
.prototype.scrollDisp = function (disp
, suppressScrollEvent
) {
3404 this.userScrolling
= true;
3406 else if (disp
+ this.ydisp
>= this.ybase
) {
3407 this.userScrolling
= false;
3410 if (this.ydisp
> this.ybase
) {
3411 this.ydisp
= this.ybase
;
3413 else if (this.ydisp
< 0) {
3416 if (!suppressScrollEvent
) {
3417 this.emit('scroll', this.ydisp
);
3419 this.refresh(0, this.rows
- 1);
3421 Terminal
.prototype.scrollPages = function (pageCount
) {
3422 this.scrollDisp(pageCount
* (this.rows
- 1));
3424 Terminal
.prototype.scrollToTop = function () {
3425 this.scrollDisp(-this.ydisp
);
3427 Terminal
.prototype.scrollToBottom = function () {
3428 this.scrollDisp(this.ybase
- this.ydisp
);
3430 Terminal
.prototype.write = function (data
) {
3431 this.writeBuffer
.push(data
);
3432 if (this.options
.useFlowControl
&& !this.xoffSentToCatchUp
&& this.writeBuffer
.length
>= WRITE_BUFFER_PAUSE_THRESHOLD
) {
3433 this.send(EscapeSequences_1
.C0
.DC3
);
3434 this.xoffSentToCatchUp
= true;
3436 if (!this.writeInProgress
&& this.writeBuffer
.length
> 0) {
3437 this.writeInProgress
= true;
3439 setTimeout(function () {
3444 Terminal
.prototype.innerWrite = function () {
3445 var writeBatch
= this.writeBuffer
.splice(0, WRITE_BATCH_SIZE
);
3446 while (writeBatch
.length
> 0) {
3447 var data
= writeBatch
.shift();
3448 var l
= data
.length
, i
= 0, j
, cs
, ch
, code
, low
, ch_width
, row
;
3449 if (this.xoffSentToCatchUp
&& writeBatch
.length
=== 0 && this.writeBuffer
.length
=== 0) {
3450 this.send(EscapeSequences_1
.C0
.DC1
);
3451 this.xoffSentToCatchUp
= false;
3453 this.refreshStart
= this.y
;
3454 this.refreshEnd
= this.y
;
3455 this.parser
.parse(data
);
3456 this.updateRange(this.y
);
3457 this.refresh(this.refreshStart
, this.refreshEnd
);
3459 if (this.writeBuffer
.length
> 0) {
3461 setTimeout(function () {
3466 this.writeInProgress
= false;
3469 Terminal
.prototype.writeln = function (data
) {
3470 this.write(data
+ '\r\n');
3472 Terminal
.prototype.attachCustomKeydownHandler = function (customKeydownHandler
) {
3473 this.customKeydownHandler
= customKeydownHandler
;
3475 Terminal
.prototype.setHypertextLinkHandler = function (handler
) {
3476 if (!this.linkifier
) {
3477 throw new Error('Cannot attach a hypertext link handler before Terminal.open is called');
3479 this.linkifier
.setHypertextLinkHandler(handler
);
3480 this.refresh(0, this.rows
- 1);
3482 Terminal
.prototype.setHypertextValidationCallback = function (handler
) {
3483 if (!this.linkifier
) {
3484 throw new Error('Cannot attach a hypertext validation callback before Terminal.open is called');
3486 this.linkifier
.setHypertextValidationCallback(handler
);
3487 this.refresh(0, this.rows
- 1);
3489 Terminal
.prototype.registerLinkMatcher = function (regex
, handler
, options
) {
3490 if (this.linkifier
) {
3491 var matcherId
= this.linkifier
.registerLinkMatcher(regex
, handler
, options
);
3492 this.refresh(0, this.rows
- 1);
3496 Terminal
.prototype.deregisterLinkMatcher = function (matcherId
) {
3497 if (this.linkifier
) {
3498 if (this.linkifier
.deregisterLinkMatcher(matcherId
)) {
3499 this.refresh(0, this.rows
- 1);
3503 Terminal
.prototype.keyDown = function (ev
) {
3504 if (this.customKeydownHandler
&& this.customKeydownHandler(ev
) === false) {
3507 this.restartCursorBlinking();
3508 if (!this.compositionHelper
.keydown
.bind(this.compositionHelper
)(ev
)) {
3509 if (this.ybase
!== this.ydisp
) {
3510 this.scrollToBottom();
3515 var result
= this.evaluateKeyEscapeSequence(ev
);
3516 if (result
.key
=== EscapeSequences_1
.C0
.DC3
) {
3517 this.writeStopped
= true;
3519 else if (result
.key
=== EscapeSequences_1
.C0
.DC1
) {
3520 this.writeStopped
= false;
3522 if (result
.scrollDisp
) {
3523 this.scrollDisp(result
.scrollDisp
);
3524 return this.cancel(ev
, true);
3526 if (isThirdLevelShift(this, ev
)) {
3529 if (result
.cancel
) {
3530 this.cancel(ev
, true);
3535 this.emit('keydown', ev
);
3536 this.emit('key', result
.key
, ev
);
3538 this.handler(result
.key
);
3539 return this.cancel(ev
, true);
3541 Terminal
.prototype.evaluateKeyEscapeSequence = function (ev
) {
3545 scrollDisp
: undefined
3547 var modifiers
= ev
.shiftKey
<< 0 | ev
.altKey
<< 1 | ev
.ctrlKey
<< 2 | ev
.metaKey
<< 3;
3548 switch (ev
.keyCode
) {
3551 result
.key
= EscapeSequences_1
.C0
.BS
;
3554 result
.key
= EscapeSequences_1
.C0
.DEL
;
3558 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[Z';
3561 result
.key
= EscapeSequences_1
.C0
.HT
;
3562 result
.cancel
= true;
3565 result
.key
= EscapeSequences_1
.C0
.CR
;
3566 result
.cancel
= true;
3569 result
.key
= EscapeSequences_1
.C0
.ESC
;
3570 result
.cancel
= true;
3574 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'D';
3575 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3D') {
3576 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'b' : EscapeSequences_1
.C0
.ESC
+ '[1;5D';
3579 else if (this.applicationCursor
) {
3580 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OD';
3583 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[D';
3588 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'C';
3589 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3C') {
3590 result
.key
= (this.browser
.isMac
) ? EscapeSequences_1
.C0
.ESC
+ 'f' : EscapeSequences_1
.C0
.ESC
+ '[1;5C';
3593 else if (this.applicationCursor
) {
3594 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OC';
3597 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[C';
3602 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'A';
3603 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3A') {
3604 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5A';
3607 else if (this.applicationCursor
) {
3608 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OA';
3611 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[A';
3616 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'B';
3617 if (result
.key
== EscapeSequences_1
.C0
.ESC
+ '[1;3B') {
3618 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;5B';
3621 else if (this.applicationCursor
) {
3622 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OB';
3625 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[B';
3629 if (!ev
.shiftKey
&& !ev
.ctrlKey
) {
3630 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[2~';
3635 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3;' + (modifiers
+ 1) + '~';
3638 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[3~';
3643 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'H';
3644 else if (this.applicationCursor
)
3645 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OH';
3647 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[H';
3651 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'F';
3652 else if (this.applicationCursor
)
3653 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OF';
3655 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[F';
3659 result
.scrollDisp
= -(this.rows
- 1);
3662 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[5~';
3667 result
.scrollDisp
= this.rows
- 1;
3670 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[6~';
3675 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'P';
3678 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OP';
3683 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'Q';
3686 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OQ';
3691 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'R';
3694 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OR';
3699 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[1;' + (modifiers
+ 1) + 'S';
3702 result
.key
= EscapeSequences_1
.C0
.ESC
+ 'OS';
3707 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15;' + (modifiers
+ 1) + '~';
3710 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[15~';
3715 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17;' + (modifiers
+ 1) + '~';
3718 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[17~';
3723 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18;' + (modifiers
+ 1) + '~';
3726 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[18~';
3731 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19;' + (modifiers
+ 1) + '~';
3734 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[19~';
3739 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20;' + (modifiers
+ 1) + '~';
3742 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[20~';
3747 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21;' + (modifiers
+ 1) + '~';
3750 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[21~';
3755 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23;' + (modifiers
+ 1) + '~';
3758 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[23~';
3763 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24;' + (modifiers
+ 1) + '~';
3766 result
.key
= EscapeSequences_1
.C0
.ESC
+ '[24~';
3770 if (ev
.ctrlKey
&& !ev
.shiftKey
&& !ev
.altKey
&& !ev
.metaKey
) {
3771 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3772 result
.key
= String
.fromCharCode(ev
.keyCode
- 64);
3774 else if (ev
.keyCode
=== 32) {
3775 result
.key
= String
.fromCharCode(0);
3777 else if (ev
.keyCode
>= 51 && ev
.keyCode
<= 55) {
3778 result
.key
= String
.fromCharCode(ev
.keyCode
- 51 + 27);
3780 else if (ev
.keyCode
=== 56) {
3781 result
.key
= String
.fromCharCode(127);
3783 else if (ev
.keyCode
=== 219) {
3784 result
.key
= String
.fromCharCode(27);
3786 else if (ev
.keyCode
=== 220) {
3787 result
.key
= String
.fromCharCode(28);
3789 else if (ev
.keyCode
=== 221) {
3790 result
.key
= String
.fromCharCode(29);
3793 else if (!this.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) {
3794 if (ev
.keyCode
>= 65 && ev
.keyCode
<= 90) {
3795 result
.key
= EscapeSequences_1
.C0
.ESC
+ String
.fromCharCode(ev
.keyCode
+ 32);
3797 else if (ev
.keyCode
=== 192) {
3798 result
.key
= EscapeSequences_1
.C0
.ESC
+ '`';
3800 else if (ev
.keyCode
>= 48 && ev
.keyCode
<= 57) {
3801 result
.key
= EscapeSequences_1
.C0
.ESC
+ (ev
.keyCode
- 48);
3808 Terminal
.prototype.setgLevel = function (g
) {
3810 this.charset
= this.charsets
[g
];
3812 Terminal
.prototype.setgCharset = function (g
, charset
) {
3813 this.charsets
[g
] = charset
;
3814 if (this.glevel
=== g
) {
3815 this.charset
= charset
;
3818 Terminal
.prototype.keyPress = function (ev
) {
3824 else if (ev
.which
== null) {
3827 else if (ev
.which
!== 0 && ev
.charCode
!== 0) {
3833 if (!key
|| ((ev
.altKey
|| ev
.ctrlKey
|| ev
.metaKey
) && !isThirdLevelShift(this, ev
))) {
3836 key
= String
.fromCharCode(key
);
3837 this.emit('keypress', key
, ev
);
3838 this.emit('key', key
, ev
);
3843 Terminal
.prototype.send = function (data
) {
3846 setTimeout(function () {
3847 self
.handler(self
.queue
);
3853 Terminal
.prototype.bell = function () {
3854 if (!this.visualBell
)
3857 this.element
.style
.borderColor
= 'white';
3858 setTimeout(function () {
3859 self
.element
.style
.borderColor
= '';
3864 Terminal
.prototype.log = function () {
3867 if (!this.context
.console
|| !this.context
.console
.log
)
3869 var args
= Array
.prototype.slice
.call(arguments
);
3870 this.context
.console
.log
.apply(this.context
.console
, args
);
3872 Terminal
.prototype.error = function () {
3875 if (!this.context
.console
|| !this.context
.console
.error
)
3877 var args
= Array
.prototype.slice
.call(arguments
);
3878 this.context
.console
.error
.apply(this.context
.console
, args
);
3880 Terminal
.prototype.resize = function (x
, y
) {
3881 if (isNaN(x
) || isNaN(y
)) {
3884 var line
, el
, i
, j
, ch
, addToY
;
3885 if (x
=== this.cols
&& y
=== this.rows
) {
3894 ch
= [this.defAttr
, ' ', 1];
3895 i
= this.lines
.length
;
3897 while (this.lines
.get(i
).length
< x
) {
3898 this.lines
.get(i
).push(ch
);
3903 this.setupStops(this.cols
);
3909 if (this.lines
.length
< y
+ this.ybase
) {
3910 if (this.ybase
> 0 && this.lines
.length
<= this.ybase
+ this.y
+ addToY
+ 1) {
3913 if (this.ydisp
> 0) {
3918 this.lines
.push(this.blankLine());
3921 if (this.children
.length
< y
) {
3928 if (this.lines
.length
> y
+ this.ybase
) {
3929 if (this.lines
.length
> this.ybase
+ this.y
+ 1) {
3937 if (this.children
.length
> y
) {
3938 el
= this.children
.shift();
3941 el
.parentNode
.removeChild(el
);
3956 this.scrollBottom
= y
- 1;
3957 this.charMeasure
.measure();
3958 this.refresh(0, this.rows
- 1);
3960 this.geometry
= [this.cols
, this.rows
];
3961 this.emit('resize', { terminal
: this, cols
: x
, rows
: y
});
3963 Terminal
.prototype.updateRange = function (y
) {
3964 if (y
< this.refreshStart
)
3965 this.refreshStart
= y
;
3966 if (y
> this.refreshEnd
)
3967 this.refreshEnd
= y
;
3969 Terminal
.prototype.maxRange = function () {
3970 this.refreshStart
= 0;
3971 this.refreshEnd
= this.rows
- 1;
3973 Terminal
.prototype.setupStops = function (i
) {
3975 if (!this.tabs
[i
]) {
3976 i
= this.prevStop(i
);
3983 for (; i
< this.cols
; i
+= this.getOption('tabStopWidth')) {
3984 this.tabs
[i
] = true;
3987 Terminal
.prototype.prevStop = function (x
) {
3990 while (!this.tabs
[--x
] && x
> 0)
3992 return x
>= this.cols
3996 Terminal
.prototype.nextStop = function (x
) {
3999 while (!this.tabs
[++x
] && x
< this.cols
)
4001 return x
>= this.cols
4005 Terminal
.prototype.eraseRight = function (x
, y
) {
4006 var line
= this.lines
.get(this.ybase
+ y
);
4010 var ch
= [this.eraseAttr(), ' ', 1];
4011 for (; x
< this.cols
; x
++) {
4014 this.updateRange(y
);
4016 Terminal
.prototype.eraseLeft = function (x
, y
) {
4017 var line
= this.lines
.get(this.ybase
+ y
);
4021 var ch
= [this.eraseAttr(), ' ', 1];
4026 this.updateRange(y
);
4028 Terminal
.prototype.clear = function () {
4029 if (this.ybase
=== 0 && this.y
=== 0) {
4032 this.lines
.set(0, this.lines
.get(this.ybase
+ this.y
));
4033 this.lines
.length
= 1;
4037 for (var i
= 1; i
< this.rows
; i
++) {
4038 this.lines
.push(this.blankLine());
4040 this.refresh(0, this.rows
- 1);
4041 this.emit('scroll', this.ydisp
);
4043 Terminal
.prototype.eraseLine = function (y
) {
4044 this.eraseRight(0, y
);
4046 Terminal
.prototype.blankLine = function (cur
) {
4050 var ch
= [attr
, ' ', 1], line
= [], i
= 0;
4051 for (; i
< this.cols
; i
++) {
4056 Terminal
.prototype.ch = function (cur
) {
4058 ? [this.eraseAttr(), ' ', 1]
4059 : [this.defAttr
, ' ', 1];
4061 Terminal
.prototype.is = function (term
) {
4062 var name
= this.termName
;
4063 return (name
+ '').indexOf(term
) === 0;
4065 Terminal
.prototype.handler = function (data
) {
4066 if (this.options
.disableStdin
) {
4069 if (this.ybase
!== this.ydisp
) {
4070 this.scrollToBottom();
4072 this.emit('data', data
);
4074 Terminal
.prototype.handleTitle = function (title
) {
4075 this.emit('title', title
);
4077 Terminal
.prototype.index = function () {
4079 if (this.y
> this.scrollBottom
) {
4083 if (this.x
>= this.cols
) {
4087 Terminal
.prototype.reverseIndex = function () {
4089 if (this.y
=== this.scrollTop
) {
4090 this.lines
.shiftElements(this.y
+ this.ybase
, this.rows
- 1, 1);
4091 this.lines
.set(this.y
+ this.ybase
, this.blankLine(true));
4092 this.updateRange(this.scrollTop
);
4093 this.updateRange(this.scrollBottom
);
4099 Terminal
.prototype.reset = function () {
4100 this.options
.rows
= this.rows
;
4101 this.options
.cols
= this.cols
;
4102 var customKeydownHandler
= this.customKeydownHandler
;
4103 var cursorBlinkInterval
= this.cursorBlinkInterval
;
4104 Terminal
.call(this, this.options
);
4105 this.customKeydownHandler
= customKeydownHandler
;
4106 this.cursorBlinkInterval
= cursorBlinkInterval
;
4107 this.refresh(0, this.rows
- 1);
4108 this.viewport
.syncScrollArea();
4110 Terminal
.prototype.tabSet = function () {
4111 this.tabs
[this.x
] = true;
4113 function on(el
, type
, handler
, capture
) {
4114 if (!Array
.isArray(el
)) {
4117 el
.forEach(function (element
) {
4118 element
.addEventListener(type
, handler
, capture
|| false);
4121 function off(el
, type
, handler
, capture
) {
4122 el
.removeEventListener(type
, handler
, capture
|| false);
4124 function cancel(ev
, force
) {
4125 if (!this.cancelEvents
&& !force
) {
4128 ev
.preventDefault();
4129 ev
.stopPropagation();
4132 function inherits(child
, parent
) {
4134 this.constructor = child
;
4136 f
.prototype = parent
.prototype;
4137 child
.prototype = new f
;
4139 function indexOf(obj
, el
) {
4147 function isThirdLevelShift(term
, ev
) {
4148 var thirdLevelKey
= (term
.browser
.isMac
&& ev
.altKey
&& !ev
.ctrlKey
&& !ev
.metaKey
) ||
4149 (term
.browser
.isMSWindows
&& ev
.altKey
&& ev
.ctrlKey
&& !ev
.metaKey
);
4150 if (ev
.type
== 'keypress') {
4151 return thirdLevelKey
;
4153 return thirdLevelKey
&& (!ev
.keyCode
|| ev
.keyCode
> 47);
4155 Terminal
.prototype.matchColor
= matchColor
;
4156 function matchColor(r1
, g1
, b1
) {
4157 var hash
= (r1
<< 16) | (g1
<< 8) | b1
;
4158 if (matchColor
._cache
[hash
] != null) {
4159 return matchColor
._cache
[hash
];
4161 var ldiff
= Infinity
, li
= -1, i
= 0, c
, r2
, g2
, b2
, diff
;
4162 for (; i
< Terminal
.vcolors
.length
; i
++) {
4163 c
= Terminal
.vcolors
[i
];
4167 diff
= matchColor
.distance(r1
, g1
, b1
, r2
, g2
, b2
);
4177 return matchColor
._cache
[hash
] = li
;
4179 matchColor
._cache
= {};
4180 matchColor
.distance = function (r1
, g1
, b1
, r2
, g2
, b2
) {
4181 return Math
.pow(30 * (r1
- r2
), 2)
4182 + Math
.pow(59 * (g1
- g2
), 2)
4183 + Math
.pow(11 * (b1
- b2
), 2);
4185 function each(obj
, iter
, con
) {
4187 return obj
.forEach(iter
, con
);
4188 for (var i
= 0; i
< obj
.length
; i
++) {
4189 iter
.call(con
, obj
[i
], i
, obj
);
4192 function wasMondifierKeyOnlyEvent(ev
) {
4193 return ev
.keyCode
=== 16 ||
4194 ev
.keyCode
=== 17 ||
4197 function keys(obj
) {
4199 return Object
.keys(obj
);
4202 if (Object
.prototype.hasOwnProperty
.call(obj
, key
)) {
4208 Terminal
.EventEmitter
= EventEmitter_1
.EventEmitter
;
4209 Terminal
.inherits
= inherits
;
4212 Terminal
.cancel
= cancel
;
4213 module
.exports
= Terminal
;
4217 },{"./CompositionHelper":2,"./EscapeSequences":3,"./EventEmitter":4,"./InputHandler":5,"./Linkifier":6,"./Parser":7,"./Renderer":8,"./Viewport":9,"./handlers/Clipboard":10,"./utils/Browser":11,"./utils/CharMeasure":12,"./utils/CircularList":13}]},{},[15])(15)
4219 //# sourceMappingURL=xterm.js.map